The patch adds the new MJ auth. routine to chan_sip, good for using (multi) MJ as native trunk to make/receive calls and eliminate the needs for additional programs. Never messed with Asterisk source code before, lucky enough to get it working on the first try.
8/19:
Patch updated, fix a bug since Asterisk verifies(!!) the return auth. hash value. I missed this part at first. Tested on several versions of Asterisk 1.4.21+, including 1.6 branch, also work for OpenWrt build.
8/22:
Another bug fixed, thanks bent.
Note
For old versions, the first part is in function check_auth() and the second in build_reply_digest(). Try to add them manually...
The forum converts all TABs in source code to spaces, so if the patch doesn't apply, try to use "patch -l" instead of "patch".
Code: Select all
--- old/channels/chan_sip.c 2009-08-13 10:24:40.000000000 -0700
+++ new/channels/chan_sip.c 2009-08-22 13:47:29.000000000 -0700
@@ -8535,6 +8535,32 @@
ast_md5_hash(a2_hash, a2);
snprintf(resp, sizeof(resp), "%s:%s:%s", a1_hash, usednonce, a2_hash);
ast_md5_hash(resp_hash, resp);
+
+
+ /* To a Magicjack domain */
+ if (strstr(uri,"talk4free.com"))
+ {
+ char callid[256];
+ char newnonce[256];
+ char *c;
+ int i;
+ ast_copy_string(callid, p->callid, sizeof(callid));
+ ast_copy_string(newnonce, p->nonce, sizeof(newnonce));
+
+ strcat(newnonce, "_");
+ c = newnonce + strlen(newnonce);
+ char hex[2];
+ hex[1] = 0;
+ for (i = 0; i < 8; i++) {
+ hex[0] = newnonce[i];
+ int x = strtol(hex, NULL, 16);
+ *c++ = callid[x];
+ }
+ *c++ = 0;
+
+ snprintf(resp,sizeof(resp),"%s:%s:%s", a1_hash, newnonce, a2_hash);
+ ast_md5_hash(resp_hash, resp);
+ }
}
good_response = keys[K_RESP].s &&
@@ -11658,6 +11684,31 @@
snprintf(resp,sizeof(resp),"%s:%s:%s", a1_hash, p->nonce, a2_hash);
ast_md5_hash(resp_hash, resp);
+ /* To a Magicjack domain */
+ if (strstr(uri,"talk4free.com"))
+ {
+ char callid[256];
+ char newnonce[256];
+ char *c;
+ int i;
+ ast_copy_string(callid, p->callid, sizeof(callid));
+ ast_copy_string(newnonce, p->nonce, sizeof(newnonce));
+
+ strcat(newnonce, "_");
+ c = newnonce + strlen(newnonce);
+ char hex[2];
+ hex[1] = 0;
+ for (i = 0; i < 8; i++) {
+ hex[0] = newnonce[i];
+ int x = strtol(hex, NULL, 16);
+ *c++ = callid[x];
+ }
+ *c++ = 0;
+
+ snprintf(resp,sizeof(resp),"%s:%s:%s", a1_hash, newnonce, a2_hash);
+ ast_md5_hash(resp_hash, resp);
+ }
+
/* only include the opaque string if it's set */
if (!ast_strlen_zero(p->opaque)) {
snprintf(opaque, sizeof(opaque), ", opaque=\"%s\"", p->opaque);