[asterisk-commits] irroot: branch irroot/distrotech-customers-1.8 r320442 - in /team/irroot/dist...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sun May 22 07:35:17 CDT 2011


Author: irroot
Date: Sun May 22 07:35:01 2011
New Revision: 320442

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=320442
Log:

Update SRTP changes to set the correct options based on INVITE


Modified:
    team/irroot/distrotech-customers-1.8/channels/chan_sip.c
    team/irroot/distrotech-customers-1.8/channels/sip/include/sdp_crypto.h
    team/irroot/distrotech-customers-1.8/channels/sip/include/sip.h
    team/irroot/distrotech-customers-1.8/channels/sip/include/srtp.h
    team/irroot/distrotech-customers-1.8/channels/sip/sdp_crypto.c

Modified: team/irroot/distrotech-customers-1.8/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/irroot/distrotech-customers-1.8/channels/chan_sip.c?view=diff&rev=320442&r1=320441&r2=320442
==============================================================================
--- team/irroot/distrotech-customers-1.8/channels/chan_sip.c (original)
+++ team/irroot/distrotech-customers-1.8/channels/chan_sip.c Sun May 22 07:35:01 2011
@@ -10844,14 +10844,25 @@
 	}
 }
 
-static void get_crypto_attrib(struct sip_srtp *srtp, const char **a_crypto, int bitlen)
-{
+static void get_crypto_attrib(struct sip_pvt *p, struct sip_srtp *srtp, const char **a_crypto)
+{
+	int bitlen = 80;
+
 	/* Set encryption properties */
 	if (srtp) {
 		if (!srtp->crypto) {
 			srtp->crypto = sdp_crypto_setup();
 		}
-		if (srtp->crypto && (sdp_crypto_offer(srtp->crypto,bitlen) >= 0)) {
+
+		/* set the key length based on INVITE or settings */
+		if (ast_test_flag(srtp, SRTP_CRYPTO_TAG_80)) {
+			bitlen = 80;
+		} else if (ast_test_flag(&p->flags[2], SIP_PAGE3_SRTP_TAG_32) ||
+		    ast_test_flag(srtp, SRTP_CRYPTO_TAG_32)) {
+			bitlen = 32;
+		}
+
+		if (srtp->crypto && (sdp_crypto_offer(srtp->crypto, bitlen) >= 0)) {
 			*a_crypto = sdp_crypto_attrib(srtp->crypto);
 		}
 
@@ -11011,7 +11022,7 @@
 		/* Ok, we need video. Let's add what we need for video and set codecs.
 		   Video is handled differently than audio since we can not transcode. */
 		if (needvideo) {
-			get_crypto_attrib(p->vsrtp, &v_a_crypto, ast_test_flag(&p->flags[2], SIP_PAGE3_SRTP_KEY32) ? 32 : 80);
+			get_crypto_attrib(p, p->vsrtp, &v_a_crypto);
 			ast_str_append(&m_video, 0, "m=video %d RTP/%s", ast_sockaddr_port(&vdest),
 				v_a_crypto ? "SAVP" : "AVP");
 
@@ -11028,7 +11039,7 @@
 		if (needtext) {
 			if (sipdebug_text)
 				ast_verbose("Lets set up the text sdp\n");
-			get_crypto_attrib(p->tsrtp, &t_a_crypto, ast_test_flag(&p->flags[2], SIP_PAGE3_SRTP_KEY32) ? 32 : 80);
+			get_crypto_attrib(p, p->tsrtp, &t_a_crypto);
 			ast_str_append(&m_text, 0, "m=text %d RTP/%s", ast_sockaddr_port(&tdest),
 				t_a_crypto ? "SAVP" : "AVP");
 			if (debug) {  /* XXX should I use tdest below ? */
@@ -11041,7 +11052,7 @@
 		/* We break with the "recommendation" and send our IP, in order that our
 		   peer doesn't have to ast_gethostbyname() us */
 
-		get_crypto_attrib(p->srtp, &a_crypto, ast_test_flag(&p->flags[2], SIP_PAGE3_SRTP_KEY32) ? 32 : 80);
+		get_crypto_attrib(p, p->srtp, &a_crypto);
 		ast_str_append(&m_audio, 0, "m=audio %d RTP/%s", ast_sockaddr_port(&dest),
 			a_crypto ? "SAVP" : "AVP");
 
@@ -25892,17 +25903,17 @@
 
 		ast_set_flag(&mask[1], SIP_PAGE2_USE_SRTP);
 		ast_set_flag(&mask[2], SIP_PAGE3_SRTP_TRY);
-		ast_set_flag(&mask[2], SIP_PAGE3_SRTP_KEY32);
-		ast_clear_flag(&flags[2], SIP_PAGE3_SRTP_KEY32);
+		ast_set_flag(&mask[2], SIP_PAGE3_SRTP_TAG_32);
+		ast_clear_flag(&flags[2], SIP_PAGE3_SRTP_TAG_32);
 
 		while ((word = strsep(&next, ","))) {
 			if (!strcasecmp(word,"try")) {
 				ast_set_flag(&flags[1], SIP_PAGE2_USE_SRTP);
 				ast_set_flag(&flags[2], SIP_PAGE3_SRTP_TRY);
-			} else if (strcasecmp(word,"32bit")) {
-				ast_set_flag(&flags[2], SIP_PAGE3_SRTP_KEY32);
+			} else if (!strcasecmp(word,"32bit")) {
+				ast_set_flag(&flags[2], SIP_PAGE3_SRTP_TAG_32);
 			} else if (ast_true(word) || ast_false(word)) {
-				ast_set2_flag(&flags[2], ast_true(word), SIP_PAGE3_SRTP_TRY);
+				ast_set2_flag(&flags[1], ast_true(word), SIP_PAGE2_USE_SRTP);
 				ast_clear_flag(&flags[2], SIP_PAGE3_SRTP_TRY);
 			}
 		}
@@ -28551,7 +28562,7 @@
 		return FALSE;
 	}
 
-	if (sdp_crypto_process((*srtp)->crypto, a, rtp) < 0) {
+	if (sdp_crypto_process((*srtp)->crypto, a, rtp, (*srtp)) < 0) {
 		return FALSE;
 	}
 

Modified: team/irroot/distrotech-customers-1.8/channels/sip/include/sdp_crypto.h
URL: http://svnview.digium.com/svn/asterisk/team/irroot/distrotech-customers-1.8/channels/sip/include/sdp_crypto.h?view=diff&rev=320442&r1=320441&r2=320442
==============================================================================
--- team/irroot/distrotech-customers-1.8/channels/sip/include/sdp_crypto.h (original)
+++ team/irroot/distrotech-customers-1.8/channels/sip/include/sdp_crypto.h Sun May 22 07:35:01 2011
@@ -31,6 +31,7 @@
 #include <asterisk/rtp_engine.h>
 
 struct sdp_crypto;
+struct sip_srtp;
 
 /*! \brief Initialize an return an sdp_crypto struct
  *
@@ -51,11 +52,12 @@
  * \param p A valid sdp_crypto struct
  * \param attr the a:crypto line from SDP
  * \param rtp The rtp instance associated with the SDP being parsed
+ * \param srtp SRTP structure
  *
  * \retval 0 success
  * \retval nonzero failure
  */
-int sdp_crypto_process(struct sdp_crypto *p, const char *attr, struct ast_rtp_instance *rtp);
+int sdp_crypto_process(struct sdp_crypto *p, const char *attr, struct ast_rtp_instance *rtp, struct sip_srtp *srtp);
 
 
 /*! \brief Generate an SRTP a=crypto offer

Modified: team/irroot/distrotech-customers-1.8/channels/sip/include/sip.h
URL: http://svnview.digium.com/svn/asterisk/team/irroot/distrotech-customers-1.8/channels/sip/include/sip.h?view=diff&rev=320442&r1=320441&r2=320442
==============================================================================
--- team/irroot/distrotech-customers-1.8/channels/sip/include/sip.h (original)
+++ team/irroot/distrotech-customers-1.8/channels/sip/include/sip.h Sun May 22 07:35:01 2011
@@ -351,11 +351,11 @@
 
 
 #define SIP_PAGE3_SNOM_AOC               (1 << 0)  /*!< DPG: Allow snom aoc messages */
-#define SIP_PAGE3_SRTP_KEY32             (1 << 1)
+#define SIP_PAGE3_SRTP_TAG_32            (1 << 1)
 #define SIP_PAGE3_SRTP_TRY               (1 << 2)
 
 #define SIP_PAGE3_FLAGS_TO_COPY \
-	(SIP_PAGE3_SNOM_AOC | SIP_PAGE3_SRTP_KEY32 | SIP_PAGE3_SRTP_TRY)
+	(SIP_PAGE3_SNOM_AOC | SIP_PAGE3_SRTP_TAG_32 | SIP_PAGE3_SRTP_TRY)
 
 /*@}*/
 

Modified: team/irroot/distrotech-customers-1.8/channels/sip/include/srtp.h
URL: http://svnview.digium.com/svn/asterisk/team/irroot/distrotech-customers-1.8/channels/sip/include/srtp.h?view=diff&rev=320442&r1=320441&r2=320442
==============================================================================
--- team/irroot/distrotech-customers-1.8/channels/sip/include/srtp.h (original)
+++ team/irroot/distrotech-customers-1.8/channels/sip/include/srtp.h Sun May 22 07:35:01 2011
@@ -34,6 +34,8 @@
 #define SRTP_ENCR_OPTIONAL	(1 << 1)	/* SRTP encryption optional */
 #define SRTP_CRYPTO_ENABLE	(1 << 2)
 #define SRTP_CRYPTO_OFFER_OK	(1 << 3)
+#define SRTP_CRYPTO_TAG_32	(1 << 4)
+#define SRTP_CRYPTO_TAG_80	(1 << 5)
 
 /*! \brief structure for secure RTP audio */
 struct sip_srtp {

Modified: team/irroot/distrotech-customers-1.8/channels/sip/sdp_crypto.c
URL: http://svnview.digium.com/svn/asterisk/team/irroot/distrotech-customers-1.8/channels/sip/sdp_crypto.c?view=diff&rev=320442&r1=320441&r2=320442
==============================================================================
--- team/irroot/distrotech-customers-1.8/channels/sip/sdp_crypto.c (original)
+++ team/irroot/distrotech-customers-1.8/channels/sip/sdp_crypto.c Sun May 22 07:35:01 2011
@@ -32,6 +32,7 @@
 #include "asterisk/options.h"
 #include "asterisk/utils.h"
 #include "include/sdp_crypto.h"
+#include "include/srtp.h"
 
 #define SRTP_MASTER_LEN 30
 #define SRTP_MASTERKEY_LEN 16
@@ -188,7 +189,7 @@
 	return res;
 }
 
-int sdp_crypto_process(struct sdp_crypto *p, const char *attr, struct ast_rtp_instance *rtp)
+int sdp_crypto_process(struct sdp_crypto *p, const char *attr, struct ast_rtp_instance *rtp, struct sip_srtp *srtp)
 {
 	char *str = NULL;
 	char *tag = NULL;
@@ -228,8 +229,10 @@
 
 	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);
 	} 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);
 	} else {
 		ast_log(LOG_WARNING, "Unsupported crypto suite: %s\n", suite);
 		return -1;




More information about the asterisk-commits mailing list