[asterisk-commits] twilson: branch group/srtp_reboot r259798 - in /team/group/srtp_reboot: chann...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Apr 28 14:32:19 CDT 2010


Author: twilson
Date: Wed Apr 28 14:32:16 2010
New Revision: 259798

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=259798
Log:
Don't call res_srtp functions directly

Mainly because people who don't have libsrtp installed would like to
make SIP calls too.

Modified:
    team/group/srtp_reboot/channels/sip/sdp_crypto.c
    team/group/srtp_reboot/include/asterisk/res_srtp.h
    team/group/srtp_reboot/res/res_srtp.c
    team/group/srtp_reboot/res/res_srtp.exports.in

Modified: team/group/srtp_reboot/channels/sip/sdp_crypto.c
URL: http://svnview.digium.com/svn/asterisk/team/group/srtp_reboot/channels/sip/sdp_crypto.c?view=diff&rev=259798&r1=259797&r2=259798
==============================================================================
--- team/group/srtp_reboot/channels/sip/sdp_crypto.c (original)
+++ team/group/srtp_reboot/channels/sip/sdp_crypto.c Wed Apr 28 14:32:16 2010
@@ -38,6 +38,9 @@
 #define SRTP_MASTERSALT_LEN ((SRTP_MASTER_LEN) - (SRTP_MASTERKEY_LEN))
 #define SRTP_MASTER_LEN64 (((SRTP_MASTER_LEN) * 8 + 5) / 6 + 1)
 
+extern struct ast_srtp_res *res_srtp;
+extern struct ast_srtp_policy_res *res_srtp_policy;
+
 struct sdp_crypto {
 	char *a_crypto;
 	unsigned char local_key[SRTP_MASTER_LEN];
@@ -72,11 +75,15 @@
 	int key_len;
 	unsigned char remote_key[SRTP_MASTER_LEN];
 
+	if (!ast_rtp_engine_srtp_is_registered()) {
+		return NULL;
+	}
+
 	if (!(p = sdp_crypto_alloc())) {
 		return NULL;
 	}
 
-	if (ast_srtp_get_random(p->local_key, sizeof(p->local_key)) < 0) {
+	if (res_srtp->get_random(p->local_key, sizeof(p->local_key)) < 0) {
 		sdp_crypto_destroy(p);
 		return NULL;
 	}
@@ -102,17 +109,21 @@
 {
 	const unsigned char *master_salt = NULL;
 
+	if (!ast_rtp_engine_srtp_is_registered()) {
+		return -1;
+	}
+
 	master_salt = master_key + SRTP_MASTERKEY_LEN;
-	if (ast_srtp_policy_set_master_key(policy, master_key, SRTP_MASTERKEY_LEN, master_salt, SRTP_MASTERSALT_LEN) < 0) {
-		return -1;
-	}
-
-	if (ast_srtp_policy_set_suite(policy, suite_val)) {
+	if (res_srtp_policy->set_master_key(policy, master_key, SRTP_MASTERKEY_LEN, master_salt, SRTP_MASTERSALT_LEN) < 0) {
+		return -1;
+	}
+
+	if (res_srtp_policy->set_suite(policy, suite_val)) {
 		ast_log(LOG_WARNING, "Could not set remote SRTP suite\n");
 		return -1;
 	}
 
-	ast_srtp_policy_set_ssrc(policy, ssrc, inbound);
+	res_srtp_policy->set_ssrc(policy, ssrc, inbound);
 
 	return 0;
 }
@@ -124,15 +135,19 @@
 	struct ast_rtp_instance_stats stats = {0,};
 	int res = -1;
 
+	if (!ast_rtp_engine_srtp_is_registered()) {
+		return -1;
+	}
+
 	if (!p) {
 		return -1;
 	}
 
-	if (!(local_policy = ast_srtp_policy_alloc())) {
-		return -1;
-	}
-
-	if (!(remote_policy = ast_srtp_policy_alloc())) {
+	if (!(local_policy = res_srtp_policy->alloc())) {
+		return -1;
+	}
+
+	if (!(remote_policy = res_srtp_policy->alloc())) {
 		goto err;
 	}
 
@@ -165,11 +180,11 @@
 
 err:
 	if (local_policy) {
-		ast_srtp_policy_destroy(local_policy);
+		res_srtp_policy->destroy(local_policy);
 	}
 
 	if (remote_policy) {
-		ast_srtp_policy_destroy(remote_policy);
+		res_srtp_policy->destroy(remote_policy);
 	}
 
 	return res;

Modified: team/group/srtp_reboot/include/asterisk/res_srtp.h
URL: http://svnview.digium.com/svn/asterisk/team/group/srtp_reboot/include/asterisk/res_srtp.h?view=diff&rev=259798&r1=259797&r2=259798
==============================================================================
--- team/group/srtp_reboot/include/asterisk/res_srtp.h (original)
+++ team/group/srtp_reboot/include/asterisk/res_srtp.h Wed Apr 28 14:32:16 2010
@@ -54,12 +54,4 @@
 	void (*set_ssrc)(struct ast_srtp_policy *policy, unsigned long ssrc, int inbound);
 };
 
-struct ast_srtp_policy *ast_srtp_policy_alloc(void);
-int ast_srtp_policy_set_suite(struct ast_srtp_policy *policy, enum ast_srtp_suite suite);
-int ast_srtp_policy_set_master_key(struct ast_srtp_policy *policy, const unsigned char *key, size_t key_len, const unsigned char *salt, size_t salt_len);
-void ast_srtp_policy_set_ssrc(struct ast_srtp_policy *policy, unsigned long ssrc, int inbound);
-
-void ast_srtp_policy_destroy(struct ast_srtp_policy *policy);
-int ast_srtp_get_random(unsigned char *key, size_t len);
-
 #endif /* _ASTERISK_RES_SRTP_H */

Modified: team/group/srtp_reboot/res/res_srtp.c
URL: http://svnview.digium.com/svn/asterisk/team/group/srtp_reboot/res/res_srtp.c?view=diff&rev=259798&r1=259797&r2=259798
==============================================================================
--- team/group/srtp_reboot/res/res_srtp.c (original)
+++ team/group/srtp_reboot/res/res_srtp.c Wed Apr 28 14:32:16 2010
@@ -77,14 +77,14 @@
 static int ast_srtp_unprotect(struct ast_srtp *srtp, void *buf, int *len, int rtcp);
 static int ast_srtp_protect(struct ast_srtp *srtp, void **buf, int *len, int rtcp);
 static void ast_srtp_set_cb(struct ast_srtp *srtp, const struct ast_srtp_cb *cb, void *data);
-int ast_srtp_get_random(unsigned char *key, size_t len);
+static int ast_srtp_get_random(unsigned char *key, size_t len);
 
 /* Policy functions */
-struct ast_srtp_policy *ast_srtp_policy_alloc(void);
-void ast_srtp_policy_destroy(struct ast_srtp_policy *policy);
-int ast_srtp_policy_set_suite(struct ast_srtp_policy *policy, enum ast_srtp_suite suite);
-int ast_srtp_policy_set_master_key(struct ast_srtp_policy *policy, const unsigned char *key, size_t key_len, const unsigned char *salt, size_t salt_len);
-void ast_srtp_policy_set_ssrc(struct ast_srtp_policy *policy, unsigned long ssrc, int inbound);
+static struct ast_srtp_policy *ast_srtp_policy_alloc(void);
+static void ast_srtp_policy_destroy(struct ast_srtp_policy *policy);
+static int ast_srtp_policy_set_suite(struct ast_srtp_policy *policy, enum ast_srtp_suite suite);
+static int ast_srtp_policy_set_master_key(struct ast_srtp_policy *policy, const unsigned char *key, size_t key_len, const unsigned char *salt, size_t salt_len);
+static void ast_srtp_policy_set_ssrc(struct ast_srtp_policy *policy, unsigned long ssrc, int inbound);
 
 static struct ast_srtp_res srtp_res = {
 	.create = ast_srtp_create,
@@ -177,7 +177,7 @@
 	}
 }
 
-void ast_srtp_policy_set_ssrc(struct ast_srtp_policy *policy,
+static void ast_srtp_policy_set_ssrc(struct ast_srtp_policy *policy,
 				     unsigned long ssrc, int inbound)
 {
 	if (ssrc) {
@@ -188,7 +188,7 @@
 	}
 }
 
-struct ast_srtp_policy *ast_srtp_policy_alloc()
+static struct ast_srtp_policy *ast_srtp_policy_alloc()
 {
 	struct ast_srtp_policy *tmp;
 
@@ -199,7 +199,7 @@
 	return tmp;
 }
 
-void ast_srtp_policy_destroy(struct ast_srtp_policy *policy)
+static void ast_srtp_policy_destroy(struct ast_srtp_policy *policy)
 {
 	if (policy->sp.key) {
 		ast_free(policy->sp.key);
@@ -235,12 +235,12 @@
 	}
 }
 
-int ast_srtp_policy_set_suite(struct ast_srtp_policy *policy, enum ast_srtp_suite suite)
+static int ast_srtp_policy_set_suite(struct ast_srtp_policy *policy, enum ast_srtp_suite suite)
 {
 	return policy_set_suite(&policy->sp.rtp, suite) | policy_set_suite(&policy->sp.rtcp, suite);
 }
 
-int ast_srtp_policy_set_master_key(struct ast_srtp_policy *policy, const unsigned char *key, size_t key_len, const unsigned char *salt, size_t salt_len)
+static int ast_srtp_policy_set_master_key(struct ast_srtp_policy *policy, const unsigned char *key, size_t key_len, const unsigned char *salt, size_t salt_len)
 {
 	size_t size = key_len + salt_len;
 	unsigned char *master_key;
@@ -262,7 +262,7 @@
 	return 0;
 }
 
-int ast_srtp_get_random(unsigned char *key, size_t len)
+static int ast_srtp_get_random(unsigned char *key, size_t len)
 {
 	return crypto_get_random(key, len) != err_status_ok ? -1: 0;
 }

Modified: team/group/srtp_reboot/res/res_srtp.exports.in
URL: http://svnview.digium.com/svn/asterisk/team/group/srtp_reboot/res/res_srtp.exports.in?view=diff&rev=259798&r1=259797&r2=259798
==============================================================================
--- team/group/srtp_reboot/res/res_srtp.exports.in (original)
+++ team/group/srtp_reboot/res/res_srtp.exports.in Wed Apr 28 14:32:16 2010
@@ -1,11 +1,4 @@
 {
-	global:
-		LINKER_SYMBOL_PREFIXast_srtp_get_random;
-		LINKER_SYMBOL_PREFIXast_srtp_policy_alloc;
-		LINKER_SYMBOL_PREFIXast_srtp_policy_destroy;
-		LINKER_SYMBOL_PREFIXast_srtp_policy_set_suite;
-		LINKER_SYMBOL_PREFIXast_srtp_policy_set_master_key;
-		LINKER_SYMBOL_PREFIXast_srtp_policy_set_ssrc;
 	local:
 		*;
 };




More information about the asterisk-commits mailing list