Index: utils.c =================================================================== RCS file: /usr/cvsroot/asterisk/utils.c,v retrieving revision 1.27 diff -u -r1.27 utils.c --- utils.c 21 Jan 2005 07:06:24 -0000 1.27 +++ utils.c 15 Feb 2005 23:11:27 -0000 @@ -25,6 +25,7 @@ #include #include #include +#include static char base64[64]; static char b2a[256]; @@ -243,6 +244,21 @@ test_errors++; pthread_join(test_thread, NULL); return(test_errors); /* return 0 on success. */ +} + +/*--- ast_md5_hash: Produce 16 char MD5 hash of value. ---*/ +void ast_md5_hash(char *output, char *input) +{ + struct MD5Context md5; + unsigned char digest[16]; + char *ptr; + int x; + MD5Init(&md5); + MD5Update(&md5, input, strlen(input)); + MD5Final(digest, &md5); + ptr = output; + for (x=0;x<16;x++) + ptr += sprintf(ptr, "%2.2x", digest[x]); } int ast_base64decode(unsigned char *dst, char *src, int max) Index: include/asterisk/utils.h =================================================================== RCS file: /usr/cvsroot/asterisk/include/asterisk/utils.h,v retrieving revision 1.20 diff -u -r1.20 utils.h --- include/asterisk/utils.h 26 Jan 2005 02:39:22 -0000 1.20 +++ include/asterisk/utils.h 15 Feb 2005 23:11:27 -0000 @@ -127,10 +127,13 @@ extern char *ast_strip(char *buf); extern struct hostent *ast_gethostbyname(const char *host, struct ast_hostent *hp); +/* ast_md5_hash: Produces MD5 hash based on input string */ +extern void ast_md5_hash(char *output, char *input); extern int ast_base64encode(char *dst, unsigned char *src, int srclen, int max); extern int ast_base64decode(unsigned char *dst, char *src, int max); extern int test_for_thread_safety(void); + extern const char *ast_inet_ntoa(char *buf, int bufsiz, struct in_addr ia); extern int ast_utils_init(void); Index: channels/chan_sip.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v retrieving revision 1.661 diff -u -r1.661 chan_sip.c --- channels/chan_sip.c 14 Feb 2005 23:20:01 -0000 1.661 +++ channels/chan_sip.c 15 Feb 2005 23:11:33 -0000 @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -4966,21 +4965,6 @@ list_route(p->route); } -/*--- md5_hash: Produce MD5 hash of value. Used for authentication ---*/ -static void md5_hash(char *output, char *input) -{ - struct MD5Context md5; - unsigned char digest[16]; - char *ptr; - int x; - MD5Init(&md5); - MD5Update(&md5, input, strlen(input)); - MD5Final(digest, &md5); - ptr = output; - for (x=0;x<16;x++) - ptr += sprintf(ptr, "%2.2x", digest[x]); -} - /*--- check_auth: Check user authorization from peer definition ---*/ /* Some actions, like REGISTER and INVITEs from peers require authentication (if peer have secret set) */ @@ -5114,10 +5098,10 @@ if (!ast_strlen_zero(md5secret)) snprintf(a1_hash, sizeof(a1_hash), "%s", md5secret); else - md5_hash(a1_hash, a1); - md5_hash(a2_hash, a2); + ast_md5_hash(a1_hash, a1); + ast_md5_hash(a2_hash, a2); snprintf(resp, sizeof(resp), "%s:%s:%s", a1_hash, randdata, a2_hash); - md5_hash(resp_hash, resp); + ast_md5_hash(resp_hash, resp); /* resp_hash now has the expected response, compare the two */ @@ -7107,15 +7091,15 @@ if (!ast_strlen_zero(p->peermd5secret)) strncpy(a1_hash, p->peermd5secret, sizeof(a1_hash) - 1); else - md5_hash(a1_hash,a1); - md5_hash(a2_hash,a2); + ast_md5_hash(a1_hash,a1); + ast_md5_hash(a2_hash,a2); /* XXX We hard code the nonce-number to 1... What are the odds? Are we seriously going to keep track of every nonce we've seen? Also we hard code to "auth"... XXX */ if (!ast_strlen_zero(p->qop)) snprintf(resp,sizeof(resp),"%s:%s:%s:%s:%s:%s",a1_hash,p->nonce, "00000001", cnonce, "auth", a2_hash); else snprintf(resp,sizeof(resp),"%s:%s:%s",a1_hash,p->nonce,a2_hash); - md5_hash(resp_hash,resp); + ast_md5_hash(resp_hash,resp); /* XXX We hard code our qop to "auth" for now. XXX */ if (!ast_strlen_zero(p->qop)) snprintf(digest,digest_len,"Digest username=\"%s\", realm=\"%s\", algorithm=MD5, uri=\"%s\", nonce=\"%s\", response=\"%s\", opaque=\"%s\", qop=\"%s\", cnonce=\"%s\", nc=%s",p->authname,p->realm,uri,p->nonce,resp_hash, p->opaque, "auth", cnonce, "00000001");