Rtsp video streaming with authentication

I'm tring to connect to straming ip cameras, with ip address. I tried to connect with:

rtsp://username:password@ip_camera 

but the video view don't like it. I've tried with map like:

Uri source = Uri.parse("rtsp://ipcamera"); headers = new HashMap<String, String>(); headers.put("Username", "user"); headers.put("Password", "password"); videoView.setVideoURI(source, headers); 

don't works anyway. So I readed on the internet that it want the base_64 basic auth so:

String authHeader = "Basic " + Base64.encodeToString("username:password".getBytes(),Base64.URL_SAFE | Base64.NO_WRAP); headers.put("Authorization", authHeader); Uri source = Uri.parse("rtsp://ipcamera"); videoView.setVideoURI(source, headers); 

nothing. Same error

E/MediaPlayerNative: error (1, -2147483648) 

that it means unknow error (?)

Any advice to find a working method? Thanks

EDIT

I found, with chrome network analyze, that this camera use a Digest Authorization. That is a way to generate it?

4

1 Answer

The library you use to stream rtsp must support digest authentication.

It isn't as simple as adding a header.

Digest Auth with RTSP

A Digest Enabled RTSP server should respond to a DESCRIBE request with 401 unauthorized See D.2.2, returning a nonce in the WWW-Authenticate header, e.g.

WWW-Authenticate: Digest realm="GStreamer RTSP Server", nonce="1c91a068811f1029" 

The client then uses the nonce to generate the authorization header that can be used for authentication,

Authorization: Digest username="admin", realm="GStreamer RTSP Server", nonce="1c91a068811f1029", uri="rtsp://0.0.0.0:8554/live.sdp", response="ef18317f111b1446dc4c6a11b4f4ebf3" 

The reponse value above is generated again per RTSP request by hashing some info as follows

HA1 = MD5(username:realm:password) HA2 = MD5(method:digestURI) response = MD5(HA1:nonce:HA2) 
1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like