[MPlayer-dev-eng] RN5 authentication for rtsp
Paul
myj at nyct.net
Wed Mar 26 04:58:53 CET 2008
I've written an RN5 authentication code for realplayer streams, which is
used by Helix/Real servers.
Unfortunately, with the current structure of the code, it only works with
the username/password supplied in the url, not on command line.
Hopefully, someone can clean it up/commit it to the CVS ?
Thanks,
P.
Paul Sandys
network operations manager
http://www.nyct.net/
212.293.2620
-------------- next part --------------
--- MPlayer-1.0rc2/stream/realrtsp/real.c 2007-10-07 15:49:25.000000000 -0400
+++ MPlayer-1.0rc2.RN5/stream/realrtsp/real.c 2008-03-25 23:40:49.000000000 -0400
@@ -444,8 +444,9 @@
int status;
uint32_t maxbandwidth = bandwidth;
char* authfield = NULL;
+ static const char hex[]="0123456789abcdef";
int i;
-
+
/* get challenge */
challenge1=strdup(rtsp_search_answers(rtsp_session,"RealChallenge1"));
#ifdef LOG
@@ -488,23 +489,74 @@
mp_msg(MSGT_STREAM, MSGL_ERR, "realrtsp: auth required but no username supplied\n");
goto autherr;
}
- if (!strstr(authreq, "Basic")) {
- mp_msg(MSGT_STREAM, MSGL_ERR, "realrtsp: authenticator not supported (%s)\n", authreq);
- goto autherr;
- }
- authlen = strlen(username) + (password ? strlen(password) : 0) + 2;
- authstr = malloc(authlen);
- sprintf(authstr, "%s:%s", username, password ? password : "");
- authfield = malloc(authlen*2+22);
- strcpy(authfield, "Authorization: Basic ");
- b64_authlen = base64_encode(authstr, authlen, authfield+21, authlen*2);
- free(authstr);
- if (b64_authlen < 0) {
- mp_msg(MSGT_STREAM, MSGL_ERR, "realrtsp: base64 output overflow, this should never happen\n");
- goto autherr;
+ if (strstr(authreq, "Basic")) {
+ authlen = strlen(username) + (password ? strlen(password) : 0) + 2;
+ authstr = malloc(authlen);
+ sprintf(authstr, "%s:%s", username, password ? password : "");
+ authfield = malloc(authlen*2+22);
+ strcpy(authfield, "Authorization: Basic ");
+ b64_authlen = base64_encode(authstr, authlen, authfield+21, authlen*2);
+ free(authstr);
+ if (b64_authlen < 0) {
+ mp_msg(MSGT_STREAM, MSGL_ERR, "realrtsp: base64 output overflow, this should never happen\n");
+ goto autherr;
+ }
+ authfield[b64_authlen+21] = 0;
+ goto rtsp_send_describe;
}
- authfield[b64_authlen+21] = 0;
- goto rtsp_send_describe;
+ if (strstr(authreq, "RN5")) {
+ unsigned char mungedh[33];
+ unsigned char nonce[512];
+ unsigned char realm[512];
+ unsigned char zres[16];
+ char *p,*q;
+
+ if ((p=strstr(authreq,"realm=\""))) {
+ p+=7;
+ q=realm;
+ while (*p && *p!='"') {
+ *q++=*p++;
+ }
+ *q='\0';
+ }
+
+ if ((p=strstr(authreq,"nonce=\""))) {
+ p+=+7;
+ q=nonce;
+ while (*p && *p!='"') {
+ *q++=*p++;
+ }
+ *q='\0';
+ }
+ p = malloc(1024);
+ sprintf(p,"%-.200s:%-.200s:%-.200s", username,realm,password);
+// fprintf(stderr,"munging: %s\n",p);
+ av_md5_sum(zres, p, strlen(p));
+ for(i=0;i<16;i++) {
+ mungedh[i+i] = hex[zres[i] >> 4];
+ mungedh[i+i+1] = hex[zres[i] & 0x0f];
+ }
+ mungedh[i+i] = '\0';
+
+ sprintf(p,"%-.200s%-.200s%-.200sCopyright (C) 1995,1996,1997 RealNetworks, Inc.",
+ mungedh,nonce,"00000000-0000-0000-0000-000000000000");
+ authfield = malloc(2048);
+ authstr = malloc(33);
+ *authstr=0;
+
+ av_md5_sum(zres, p, strlen(p));
+
+ for(i=0;i<16;i++) {
+ authstr[i+i] = hex[zres[i] >> 4];
+ authstr[i+i+1] = hex[zres[i] & 0x0f];
+ }
+ authstr[i+i] = '\0';
+
+ sprintf(authfield, "Authorization: RN5 username=\"%-.200s\", GUID=\"00000000-0000-0000-0000-000000000000\",realm=\"%-.200s\",nonce=\"%s\",response=\"%s\"",username,realm,nonce,authstr);
+
+ goto rtsp_send_describe;
+ }
+ mp_msg(MSGT_STREAM, MSGL_ERR, "realrtsp: authenticator not supported (%s)\n", authreq);
}
autherr:
More information about the MPlayer-dev-eng
mailing list