Index: channels/chan_iax2.c
===================================================================
--- channels/chan_iax2.c	(revision 34758)
+++ channels/chan_iax2.c	(working copy)
@@ -3796,21 +3796,24 @@
 		/* Search for possible keys, given secrets */
 		struct MD5Context md5;
 		unsigned char digest[16];
-		char *tmppw, *stringp;
+		char *tmppw, *stringp, *tmppw_next;
 		
-		tmppw = ast_strdupa(iaxs[callno]->secret);
-		stringp = tmppw;
-		while ((tmppw = strsep(&stringp, ";"))) {
-			MD5Init(&md5);
-			MD5Update(&md5, (unsigned char *)iaxs[callno]->challenge, strlen(iaxs[callno]->challenge));
-			MD5Update(&md5, (unsigned char *)tmppw, strlen(tmppw));
-			MD5Final(digest, &md5);
-			build_enc_keys(digest, &iaxs[callno]->ecx, &iaxs[callno]->dcx);
-			res = decode_frame(&iaxs[callno]->dcx, fh, f, datalen);
-			if (!res) {
-				ast_set_flag(iaxs[callno], IAX_KEYPOPULATED);
-				break;
-			}
+		stringp = ast_strdupa(iaxs[callno]->secret);
+		if ((tmppw = strsep(&stringp, ";"))) {
+			tmppw_next = strsep(&stringp, ";");
+			do {
+				MD5Init(&md5);
+				MD5Update(&md5, (unsigned char *)iaxs[callno]->challenge, strlen(iaxs[callno]->challenge));
+				MD5Update(&md5, (unsigned char *)tmppw, strlen(tmppw));
+				MD5Final(digest, &md5);
+				build_enc_keys(digest, &iaxs[callno]->ecx, &iaxs[callno]->dcx);
+				res = decode_frame(&iaxs[callno]->dcx, fh, f, datalen);
+				if (!res) {
+					ast_set_flag(iaxs[callno], IAX_KEYPOPULATED);
+					break;
+				}
+				tmppw = tmppw_next;
+			} while (tmppw && (tmppw_next = strsep(&stringp, ";")));
 		}
 	} else 
 		res = decode_frame(&iaxs[callno]->dcx, fh, f, datalen);
@@ -4931,22 +4934,25 @@
 	} else if (p->authmethods & IAX_AUTH_MD5) {
 		struct MD5Context md5;
 		unsigned char digest[16];
-		char *tmppw, *stringp;
+		char *tmppw, *stringp, *tmppw_next;
 		
-		tmppw = ast_strdupa(p->secret);
-		stringp = tmppw;
-		while((tmppw = strsep(&stringp, ";"))) {
-			MD5Init(&md5);
-			MD5Update(&md5, (unsigned char *)p->challenge, strlen(p->challenge));
-			MD5Update(&md5, (unsigned char *)tmppw, strlen(tmppw));
-			MD5Final(digest, &md5);
-			/* If they support md5, authenticate with it.  */
-			for (x=0;x<16;x++)
-				sprintf(requeststr + (x << 1), "%2.2x", digest[x]); /* safe */
-			if (!strcasecmp(requeststr, md5secret)) {
-				res = 0;
-				break;
-			}
+		stringp = ast_strdupa(p->secret);
+		if ((tmppw = strsep(&stringp, ";"))) {
+			tmppw_next = strsep(&stringp, ";");
+			do {
+				MD5Init(&md5);
+				MD5Update(&md5, (unsigned char *)p->challenge, strlen(p->challenge));
+				MD5Update(&md5, (unsigned char *)tmppw, strlen(tmppw));
+				MD5Final(digest, &md5);
+				/* If they support md5, authenticate with it.  */
+				for (x=0;x<16;x++)
+					sprintf(requeststr + (x << 1), "%2.2x", digest[x]); /* safe */
+				if (!strcasecmp(requeststr, md5secret)) {
+					res = 0;
+					break;
+				}
+				tmppw = tmppw_next;
+			} while(tmppw && (tmppw_next = strsep(&stringp, ";")));
 		}
 	} else if (p->authmethods & IAX_AUTH_PLAINTEXT) {
 		if (!strcmp(secret, p->secret))
@@ -5058,19 +5064,24 @@
 	} else if (!ast_strlen_zero(md5secret) && (p->authmethods & IAX_AUTH_MD5) && !ast_strlen_zero(iaxs[callno]->challenge)) {
 		struct MD5Context md5;
 		unsigned char digest[16];
-		char *tmppw, *stringp;
+		char *tmppw, *stringp, *tmppw_next;
 		
-		tmppw = ast_strdupa(p->secret);
-		stringp = tmppw;
-		while((tmppw = strsep(&stringp, ";"))) {
-			MD5Init(&md5);
-			MD5Update(&md5, (unsigned char *)iaxs[callno]->challenge, strlen(iaxs[callno]->challenge));
-			MD5Update(&md5, (unsigned char *)tmppw, strlen(tmppw));
-			MD5Final(digest, &md5);
-			for (x=0;x<16;x++)
-				sprintf(requeststr + (x << 1), "%2.2x", digest[x]); /* safe */
-			if (!strcasecmp(requeststr, md5secret)) 
-				break;
+		stringp = ast_strdupa(p->secret);
+		if ((tmppw = strsep(&stringp, ";"))) {
+			tmppw_next = strsep(&stringp, ";");
+			do {
+				MD5Init(&md5);
+				MD5Update(&md5, (unsigned char *)iaxs[callno]->challenge, strlen(iaxs[callno]->challenge));
+				MD5Update(&md5, (unsigned char *)tmppw, strlen(tmppw));
+				MD5Final(digest, &md5);
+				for (x=0;x<16;x++)
+					sprintf(requeststr + (x << 1), "%2.2x", digest[x]); /* safe */
+				if (!strcasecmp(requeststr, md5secret)) 
+					break;
+				tmppw = tmppw_next;
+			}
+			while(tmppw && (tmppw_next = strsep(&stringp, ";")));
+			tmppw = NULL;
 		}
 		if (tmppw) {
 			ast_set_flag(&iaxs[callno]->state, IAX_STATE_AUTHENTICATED);
