Revision
16204
Author
brian
Date
2010-01-07 17:29:06 -0600 (Thu, 07 Jan 2010)

Log Message

 fix mitm for audio for passing sas with zrtp

Modified Paths

Diff

Modified: freeswitch/trunk/src/switch_rtp.c (16203 => 16204)


--- freeswitch/trunk/src/switch_rtp.c	2010-01-07 23:00:34 UTC (rev 16203)
+++ freeswitch/trunk/src/switch_rtp.c	2010-01-07 23:29:06 UTC (rev 16204)
@@ -219,7 +219,8 @@
 #ifdef ENABLE_ZRTP
 	zrtp_session_t *zrtp_session;
 	zrtp_profile_t *zrtp_profile;
-	zrtp_stream_t *zrtp_ctx;
+	zrtp_stream_t *zrtp_audio_ctx;
+	zrtp_stream_t *zrtp_video_ctx;
 	int zrtp_mitm_tries;
 #endif
 
@@ -474,8 +475,8 @@
 #if 0
 	case ZRTP_EVENT_NO_ZRTP_QUICK:
 		{
-			if (rtp_session->zrtp_ctx != NULL) {
-				zrtp_stream_stop(rtp_session->zrtp_ctx);
+			if (rtp_session->zrtp_audio_ctx != NULL) {
+				zrtp_stream_stop(rtp_session->zrtp_audio_ctx);
 			}
 		}
 		break;
@@ -561,7 +562,7 @@
 	zrtp_status_t status = zrtp_status_fail;
 	unsigned int len = datalen;
 
-	status = zrtp_process_srtp(rtp_session->zrtp_ctx, (char*)data, &len);
+	status = zrtp_process_srtp(rtp_session->zrtp_audio_ctx, (char*)data, &len);
 	switch(status) {
 	case zrtp_status_ok:
 		break;
@@ -1190,6 +1191,8 @@
 			zrtp_enabled = NULL;
 		}
 
+		switch_channel_set_private(channel, "__zrtp_rtp_session", rtp_session);
+		
 		if (switch_true(zrtp_enabled)) {
 			if (switch_channel_direction(channel) == SWITCH_CALL_DIRECTION_OUTBOUND) {
 				initiator = 1;
@@ -1210,15 +1213,15 @@
 			
 			zrtp_session_set_userdata(rtp_session->zrtp_session, rtp_session);
 			
-			if (zrtp_status_ok != zrtp_stream_attach(rtp_session->zrtp_session, &rtp_session->zrtp_ctx)) {
+			if (zrtp_status_ok != zrtp_stream_attach(rtp_session->zrtp_session, &rtp_session->zrtp_audio_ctx)) {
 				abort();
 			}
-			zrtp_stream_set_userdata(rtp_session->zrtp_ctx, rtp_session);
+			zrtp_stream_set_userdata(rtp_session->zrtp_audio_ctx, rtp_session);
 			
 			if (switch_true(switch_channel_get_variable(channel, "zrtp_enrollment"))) {
-				zrtp_stream_registration_start(rtp_session->zrtp_ctx, rtp_session->ssrc);
+				zrtp_stream_registration_start(rtp_session->zrtp_audio_ctx, rtp_session->ssrc);
 			} else {
-				zrtp_stream_start(rtp_session->zrtp_ctx, rtp_session->ssrc);
+				zrtp_stream_start(rtp_session->zrtp_audio_ctx, rtp_session->ssrc);
 			}
 		}
 	}
@@ -1481,8 +1484,8 @@
 	/* ZRTP */
 	if (zrtp_on) {
 
-		if ((*rtp_session)->zrtp_ctx != NULL) {
-			zrtp_stream_stop((*rtp_session)->zrtp_ctx);
+		if ((*rtp_session)->zrtp_audio_ctx != NULL) {
+			zrtp_stream_stop((*rtp_session)->zrtp_audio_ctx);
 		}
 
 		if (switch_test_flag((*rtp_session), SWITCH_ZRTP_FLAG_SECURE_SEND)) {
@@ -2129,7 +2132,7 @@
 			unsigned int sbytes = (int) bytes;
 			zrtp_status_t stat = 0;
 			
-			stat = zrtp_process_srtp(rtp_session->zrtp_ctx, (void *)&rtp_session->recv_msg, &sbytes);
+			stat = zrtp_process_srtp(rtp_session->zrtp_audio_ctx, (void *)&rtp_session->recv_msg, &sbytes);
 			
 			switch (stat) {
 			case zrtp_status_ok:
@@ -2497,14 +2500,39 @@
 
 		if (zrtp_status_ok == zrtp_session_get(rtp_session->zrtp_session, &zrtp_session_info)) { 
 			if (zrtp_session_info.sas_is_ready) {    
-				frame->extra_data = rtp_session->zrtp_ctx;
-				switch_set_flag(frame, SFF_ZRTP);
-				if (rtp_session->zrtp_mitm_tries > ZRTP_MITM_TRIES) {
-					zrtp_verified_set(zrtp_global, &rtp_session->zrtp_session->zid, 
-									  &rtp_session->zrtp_session->peer_zid, zrtp_session_info.sas_is_verified^1);
-					switch_clear_flag(rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_RECV);
+				switch_core_session_t *session = switch_core_memory_pool_get_data(rtp_session->pool, "__session");
+				switch_channel_t *channel = switch_core_session_get_channel(session);
+
+				const char *uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE);
+				if (uuid) { 
+					switch_core_session_t *other_session;
+
+					if ((other_session = switch_core_session_locate(uuid))) {
+						switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
+						switch_rtp_t *other_rtp_session = switch_channel_get_private(other_channel, "__zrtp_rtp_session");
+
+						if (other_rtp_session) {
+							if (zrtp_status_ok == zrtp_session_get(other_rtp_session->zrtp_session, &zrtp_session_info)) {
+								if (rtp_session->zrtp_mitm_tries > ZRTP_MITM_TRIES) {
+									switch_clear_flag(other_rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_RECV);
+									switch_clear_flag(other_rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_SEND);
+									switch_clear_flag(rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_RECV);
+									switch_clear_flag(rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_SEND);
+								} else if (zrtp_status_ok == zrtp_resolve_mitm_call(other_rtp_session->zrtp_audio_ctx, rtp_session->zrtp_audio_ctx)) {
+									switch_clear_flag(rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_RECV);
+									switch_clear_flag(rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_SEND);
+									switch_clear_flag(other_rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_RECV);
+									switch_clear_flag(other_rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_SEND);
+									zrtp_verified_set(zrtp_global, &rtp_session->zrtp_session->zid, 
+													  &rtp_session->zrtp_session->peer_zid, zrtp_session_info.sas_is_verified^1);
+									rtp_session->zrtp_mitm_tries++;
+								}
+							}
+						}
+						
+						switch_core_session_rwunlock(other_session);
+					}
 				}
-				rtp_session->zrtp_mitm_tries++;
 			}
 		}
 	}
@@ -2767,7 +2795,7 @@
 			unsigned int sbytes = (int) bytes;
 			zrtp_status_t stat = zrtp_status_fail;
 			
-			stat = zrtp_process_rtp(rtp_session->zrtp_ctx, (void*)send_msg, &sbytes);
+			stat = zrtp_process_rtp(rtp_session->zrtp_audio_ctx, (void*)send_msg, &sbytes);
 
 			switch (stat) {
 			case zrtp_status_ok:
@@ -2974,18 +3002,43 @@
 	}
 
 #ifdef ENABLE_ZRTP
-	if (zrtp_on && switch_test_flag(frame, SFF_ZRTP) && switch_test_flag(rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_SEND)) {
+	if (zrtp_on && switch_test_flag(rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_SEND)) {
 		zrtp_session_info_t zrtp_session_info;
 
 		if (zrtp_status_ok == zrtp_session_get(rtp_session->zrtp_session, &zrtp_session_info)) { 
 			if (zrtp_session_info.sas_is_ready) {    
-				if (rtp_session->zrtp_mitm_tries > ZRTP_MITM_TRIES) {
-					switch_clear_flag(rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_SEND);
-				} else if (zrtp_status_ok == zrtp_resolve_mitm_call(frame->extra_data, rtp_session->zrtp_ctx)) {
-					switch_clear_flag(rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_SEND);
-					zrtp_verified_set(zrtp_global, &rtp_session->zrtp_session->zid, 
-									  &rtp_session->zrtp_session->peer_zid, zrtp_session_info.sas_is_verified^1);
-					rtp_session->zrtp_mitm_tries++;
+				switch_core_session_t *session = switch_core_memory_pool_get_data(rtp_session->pool, "__session");
+				switch_channel_t *channel = switch_core_session_get_channel(session);
+
+				const char *uuid = switch_channel_get_variable(channel, SWITCH_SIGNAL_BOND_VARIABLE);
+				if (uuid) { 
+					switch_core_session_t *other_session;
+
+					if ((other_session = switch_core_session_locate(uuid))) {
+						switch_channel_t *other_channel = switch_core_session_get_channel(other_session);
+						switch_rtp_t *other_rtp_session = switch_channel_get_private(other_channel, "__zrtp_rtp_session");
+						if (other_rtp_session) {
+							if (zrtp_status_ok == zrtp_session_get(other_rtp_session->zrtp_session, &zrtp_session_info)) {
+								if (rtp_session->zrtp_mitm_tries > ZRTP_MITM_TRIES) {
+									switch_clear_flag(rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_RECV);
+									switch_clear_flag(rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_SEND);
+									switch_clear_flag(other_rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_RECV);
+									switch_clear_flag(other_rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_SEND);
+								} else if (zrtp_status_ok == zrtp_resolve_mitm_call(other_rtp_session->zrtp_audio_ctx, rtp_session->zrtp_audio_ctx)) {
+									switch_clear_flag(rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_RECV);
+									switch_clear_flag(rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_SEND);
+									switch_clear_flag(other_rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_RECV);
+									switch_clear_flag(other_rtp_session, SWITCH_ZRTP_FLAG_SECURE_MITM_SEND);
+									zrtp_verified_set(zrtp_global, &rtp_session->zrtp_session->zid, 
+													  &rtp_session->zrtp_session->peer_zid, zrtp_session_info.sas_is_verified^1);
+									rtp_session->zrtp_mitm_tries++;
+								}
+								rtp_session->zrtp_mitm_tries++;
+							}
+						}
+
+						switch_core_session_rwunlock(other_session);
+					}
 				}
 			}
 		}
@@ -3096,7 +3149,7 @@
 		unsigned int sbytes = (int) bytes;
 		zrtp_status_t stat = zrtp_status_fail;
 		
-		stat = zrtp_process_rtp(rtp_session->zrtp_ctx, (void*)&rtp_session->write_msg, &sbytes);
+		stat = zrtp_process_rtp(rtp_session->zrtp_audio_ctx, (void*)&rtp_session->write_msg, &sbytes);
 		
 		switch (stat) {
 		case zrtp_status_ok: