[asterisk-commits] file: branch 12 r413159 - /branches/12/res/res_pjsip/config_transport.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu May 1 07:30:56 CDT 2014


Author: file
Date: Thu May  1 07:30:43 2014
New Revision: 413159

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=413159
Log:
res_pjsip: Add the ability to configure ciphers based on name.

Previously this code would only accept the OpenSSL identifier instead
of the documented name.

ASTERISK-23498 #close
ASTERISK-23498 #comment Reported by: Anthony Messina

Review: https://reviewboard.asterisk.org/r/3491/

Modified:
    branches/12/res/res_pjsip/config_transport.c

Modified: branches/12/res/res_pjsip/config_transport.c
URL: http://svnview.digium.com/svn/asterisk/branches/12/res/res_pjsip/config_transport.c?view=diff&rev=413159&r1=413158&r2=413159
==============================================================================
--- branches/12/res/res_pjsip/config_transport.c (original)
+++ branches/12/res/res_pjsip/config_transport.c Thu May  1 07:30:43 2014
@@ -379,6 +379,30 @@
 	return 0;
 }
 
+/*! \brief Helper function which turns a cipher name into an identifier */
+static pj_ssl_cipher cipher_name_to_id(const char *name)
+{
+	pj_ssl_cipher ciphers[100], id = 0;
+	unsigned int cipher_num = PJ_ARRAY_SIZE(ciphers);
+	int pos;
+
+	if (pj_ssl_cipher_get_availables(ciphers, &cipher_num)) {
+		return 0;
+	}
+
+	for (pos = 0; pos < cipher_num; ++pos) {
+		if (!pj_ssl_cipher_name(ciphers[pos]) ||
+			strcmp(pj_ssl_cipher_name(ciphers[pos]), name)) {
+			continue;
+		}
+
+		id = ciphers[pos];
+		break;
+	}
+
+	return id;
+}
+
 /*! \brief Custom handler for TLS cipher setting */
 static int transport_tls_cipher_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)
 {
@@ -389,12 +413,16 @@
 		return -1;
 	}
 
-	/* TODO: Check this over/tweak - it's taken from pjsua for now */
-	if (!strnicmp(var->value, "0x", 2)) {
-		pj_str_t cipher_st = pj_str((char*)var->value + 2);
-		cipher = pj_strtoul2(&cipher_st, NULL, 16);
-	} else {
-		cipher = atoi(var->value);
+	cipher = cipher_name_to_id(var->value);
+
+	if (!cipher) {
+		/* TODO: Check this over/tweak - it's taken from pjsua for now */
+		if (!strnicmp(var->value, "0x", 2)) {
+			pj_str_t cipher_st = pj_str((char*)var->value + 2);
+			cipher = pj_strtoul2(&cipher_st, NULL, 16);
+		} else {
+			cipher = atoi(var->value);
+		}
 	}
 
 	if (pj_ssl_cipher_is_supported(cipher)) {




More information about the asterisk-commits mailing list