[asterisk-commits] dlee: branch 11 r380350 - in /branches/11: ./ channels/sip/sdp_crypto.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jan 29 11:14:57 CST 2013


Author: dlee
Date: Tue Jan 29 11:14:51 2013
New Revision: 380350

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=380350
Log:
Corrected crypto tag in SDP ANSWER for SRTP. (again)

The original fix (r380043) for getting Asterisk to respond with the correct
tag overlooked some corner cases, and the fact that the same code is in 1.8.

This patch moves the building of the crypto line out of
sdp_crypto_process(). Instead, it merely copies the accepted tag. The call to
sdp_crypto_offer() will build the crypto line in all cases now, using a tag of
"1" in the case of sending offers.

(closes issue ASTERISK-20849)
Reported by: José Luis Millán
Review: https://reviewboard.asterisk.org/r/2295/
........

Merged revisions 380347 from http://svn.asterisk.org/svn/asterisk/branches/1.8

Modified:
    branches/11/   (props changed)
    branches/11/channels/sip/sdp_crypto.c

Propchange: branches/11/
------------------------------------------------------------------------------
--- branch-1.8-merged (original)
+++ branch-1.8-merged Tue Jan 29 11:14:51 2013
@@ -1,1 +1,1 @@
-/branches/1.8:1-378147,378164,378356,378375,378427,378455-378456,378486,378514,378554,378591,378733,378776,378933,378967,379001,379145,379178,379226,379276,379310,379342,379392,379547,379608,379718,379825,379885,379963,380210,380254,380297
+/branches/1.8:1-378147,378164,378356,378375,378427,378455-378456,378486,378514,378554,378591,378733,378776,378933,378967,379001,379145,379178,379226,379276,379310,379342,379392,379547,379608,379718,379825,379885,379963,380210,380254,380297,380347

Modified: branches/11/channels/sip/sdp_crypto.c
URL: http://svnview.digium.com/svn/asterisk/branches/11/channels/sip/sdp_crypto.c?view=diff&rev=380350&r1=380349&r2=380350
==============================================================================
--- branches/11/channels/sip/sdp_crypto.c (original)
+++ branches/11/channels/sip/sdp_crypto.c Tue Jan 29 11:14:51 2013
@@ -49,6 +49,7 @@
 struct sdp_crypto {
 	char *a_crypto;
 	unsigned char local_key[SRTP_MASTER_LEN];
+	char *tag;
 	char local_key64[SRTP_MASTER_LEN64];
 	unsigned char remote_key[SRTP_MASTER_LEN];
 };
@@ -64,6 +65,8 @@
 {
 	ast_free(crypto->a_crypto);
 	crypto->a_crypto = NULL;
+	ast_free(crypto->tag);
+	crypto->tag = NULL;
 	ast_free(crypto);
 }
 
@@ -197,10 +200,10 @@
 	char *key_salt = NULL;
 	char *lifetime = NULL;
 	int found = 0;
-	int attr_len = strlen(attr);
 	int key_len = 0;
 	int suite_val = 0;
 	unsigned char remote_key[SRTP_MASTER_LEN];
+	int taglen = 0;
 
 	if (!ast_rtp_engine_srtp_is_registered()) {
 		return -1;
@@ -227,9 +230,11 @@
 	if (!strcmp(suite, "AES_CM_128_HMAC_SHA1_80")) {
 		suite_val = AST_AES_CM_128_HMAC_SHA1_80;
 		ast_set_flag(srtp, SRTP_CRYPTO_TAG_80);
+		taglen = 80;
 	} else if (!strcmp(suite, "AES_CM_128_HMAC_SHA1_32")) {
 		suite_val = AST_AES_CM_128_HMAC_SHA1_32;
 		ast_set_flag(srtp, SRTP_CRYPTO_TAG_32);
+		taglen = 32;
 	} else {
 		ast_log(LOG_WARNING, "Unsupported crypto suite: %s\n", suite);
 		return -1;
@@ -276,36 +281,37 @@
 		return -1;
 	}
 
-	if (!p->a_crypto) {
-		if (!(p->a_crypto = ast_calloc(1, attr_len + 11))) {
-			ast_log(LOG_ERROR, "Could not allocate memory for a_crypto\n");
+	if (!p->tag) {
+		ast_log(LOG_DEBUG, "Accepting crypto tag %s\n", tag);
+		p->tag = ast_strdup(tag);
+		if (!p->tag) {
+			ast_log(LOG_ERROR, "Could not allocate memory for tag\n");
 			return -1;
 		}
-		snprintf(p->a_crypto, attr_len + 10, "a=crypto:%s %s inline:%s\r\n", tag, suite, p->local_key64);
-	}
+	}
+
+	/* Finally, rebuild the crypto line */
+	return sdp_crypto_offer(p, taglen);
+}
+
+int sdp_crypto_offer(struct sdp_crypto *p, int taglen)
+{
+	/* Rebuild the crypto line */
+	if (p->a_crypto) {
+		ast_free(p->a_crypto);
+	}
+
+	if (ast_asprintf(&p->a_crypto, "a=crypto:%s AES_CM_128_HMAC_SHA1_%i inline:%s\r\n",
+			 p->tag ? p->tag : "1", taglen, p->local_key64) == -1) {
+			ast_log(LOG_ERROR, "Could not allocate memory for crypto line\n");
+		return -1;
+	}
+
+	ast_log(LOG_DEBUG, "Crypto line: %s", p->a_crypto);
+
 	return 0;
 }
 
-int sdp_crypto_offer(struct sdp_crypto *p, int taglen)
-{
-	char crypto_buf[128];
-
-	if (p->a_crypto) {
-		return 0;
-	}
-
-	if (snprintf(crypto_buf, sizeof(crypto_buf), "a=crypto:1 AES_CM_128_HMAC_SHA1_%i inline:%s\r\n",
-			taglen, p->local_key64) < 1) {
-		return -1;
-	}
-
-	if (!(p->a_crypto = ast_strdup(crypto_buf))) {
-		return -1;
-	}
-
-	return 0;
-}
-
 const char *sdp_crypto_attrib(struct sdp_crypto *p)
 {
 	return p->a_crypto;




More information about the asterisk-commits mailing list