static void srtp_protected_text_stream(void) { text_stream_tester_t* marielle = text_stream_tester_new(); text_stream_tester_t* margaux = text_stream_tester_new(); const char* helloworld = "Hello World !"; int i = 0, strcmpresult = -2; int dummy = 0; init_text_streams(marielle, margaux, FALSE, FALSE, NULL, T140_PAYLOAD_TYPE /* ignored */); BC_ASSERT_EQUAL(ms_media_stream_sessions_set_encryption_mandatory(&marielle->ts->ms.sessions, TRUE), 0, int, "%d"); BC_ASSERT_TRUE(ms_srtp_supported()); BC_ASSERT_TRUE(ms_media_stream_sessions_set_srtp_send_key_b64(&(marielle->ts->ms.sessions), MS_AES_128_SHA1_32, "d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") == 0); BC_ASSERT_TRUE(ms_media_stream_sessions_set_srtp_send_key_b64(&(margaux->ts->ms.sessions), MS_AES_128_SHA1_32, "6jCLmtRkVW9E/BUuJtYj/R2z6+4iEe06/DWohQ9F") == 0); BC_ASSERT_TRUE(ms_media_stream_sessions_set_srtp_recv_key_b64(&(margaux->ts->ms.sessions), MS_AES_128_SHA1_32, "d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") == 0); BC_ASSERT_TRUE(ms_media_stream_sessions_set_srtp_recv_key_b64(&(marielle->ts->ms.sessions), MS_AES_128_SHA1_32, "6jCLmtRkVW9E/BUuJtYj/R2z6+4iEe06/DWohQ9F") == 0); BC_ASSERT_TRUE(media_stream_secured(&marielle->ts->ms)); BC_ASSERT_TRUE(media_stream_secured(&margaux->ts->ms)); for (; i < strlen(helloworld); i++) { char c = helloworld[i]; text_stream_putchar32(margaux->ts, (uint32_t)c); wait_for_until(&marielle->ts->ms, &margaux->ts->ms, &dummy, 1, 500); } BC_ASSERT_TRUE(wait_for_until(&marielle->ts->ms, &margaux->ts->ms, &marielle->stats.number_of_received_char, strlen(helloworld), 1000)); ms_message("Received message is: %s", marielle->stats.received_chars); strcmpresult = strcmp(marielle->stats.received_chars, helloworld); BC_ASSERT_EQUAL(strcmpresult, 0, int, "%d"); uninit_text_streams(marielle, margaux); text_stream_tester_destroy(marielle); text_stream_tester_destroy(margaux); }
static void encrypted_audio_stream_base( bool_t change_ssrc, bool_t change_send_key_in_the_middle ,bool_t set_both_send_recv_key ,bool_t send_key_first) { AudioStream * marielle = audio_stream_new (MARIELLE_RTP_PORT, MARIELLE_RTCP_PORT,FALSE); AudioStream * margaux = audio_stream_new (MARGAUX_RTP_PORT,MARGAUX_RTCP_PORT, FALSE); RtpProfile* profile = rtp_profile_new("default profile"); char* hello_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_file_root(), HELLO_8K_1S_FILE); char* recorded_file = ms_strdup_printf("%s/%s", mediastreamer2_tester_get_writable_dir(), RECORDED_8K_1S_FILE); stats_t marielle_stats; stats_t margaux_stats; int dummy=0; if (ms_srtp_supported()) { reset_stats(&marielle_stats); reset_stats(&margaux_stats); rtp_profile_set_payload (profile,0,&payload_type_pcmu8000); CU_ASSERT_EQUAL(audio_stream_start_full(margaux , profile , MARIELLE_IP , MARIELLE_RTP_PORT , MARIELLE_IP , MARIELLE_RTCP_PORT , 0 , 50 , NULL , recorded_file , NULL , NULL , 0),0); CU_ASSERT_EQUAL(audio_stream_start_full(marielle , profile , MARGAUX_IP , MARGAUX_RTP_PORT , MARGAUX_IP , MARGAUX_RTCP_PORT , 0 , 50 , hello_file , NULL , NULL , NULL , 0),0); if (send_key_first) { CU_ASSERT_TRUE(media_stream_set_srtp_send_key_b64(&(marielle->ms.sessions), MS_AES_128_SHA1_32, "d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") == 0); if (set_both_send_recv_key) CU_ASSERT_TRUE(media_stream_set_srtp_send_key_b64(&(margaux->ms.sessions), MS_AES_128_SHA1_32, "6jCLmtRkVW9E/BUuJtYj/R2z6+4iEe06/DWohQ9F") == 0); CU_ASSERT_TRUE(media_stream_set_srtp_recv_key_b64(&(margaux->ms.sessions), MS_AES_128_SHA1_32, "d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") ==0); if (set_both_send_recv_key) CU_ASSERT_TRUE(media_stream_set_srtp_recv_key_b64(&(marielle->ms.sessions), MS_AES_128_SHA1_32, "6jCLmtRkVW9E/BUuJtYj/R2z6+4iEe06/DWohQ9F") ==0); } else { CU_ASSERT_TRUE(media_stream_set_srtp_recv_key_b64(&(margaux->ms.sessions), MS_AES_128_SHA1_32, "d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") ==0); if (set_both_send_recv_key) CU_ASSERT_TRUE(media_stream_set_srtp_recv_key_b64(&(marielle->ms.sessions), MS_AES_128_SHA1_32, "6jCLmtRkVW9E/BUuJtYj/R2z6+4iEe06/DWohQ9F") ==0); CU_ASSERT_TRUE(media_stream_set_srtp_send_key_b64(&(marielle->ms.sessions), MS_AES_128_SHA1_32, "d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") == 0); if (set_both_send_recv_key) CU_ASSERT_TRUE(media_stream_set_srtp_send_key_b64(&(margaux->ms.sessions), MS_AES_128_SHA1_32, "6jCLmtRkVW9E/BUuJtYj/R2z6+4iEe06/DWohQ9F") == 0); } ms_filter_add_notify_callback(marielle->soundread, notify_cb, &marielle_stats,TRUE); if (change_send_key_in_the_middle) { int dummy=0; wait_for_until(&marielle->ms,&margaux->ms,&dummy,1,2000); CU_ASSERT_TRUE(media_stream_set_srtp_send_key_b64(&(marielle->ms.sessions), MS_AES_128_SHA1_32, "eCYF4nYyCvmCpFWjUeDaxI2GWp2BzCRlIPfg52Te") == 0); CU_ASSERT_TRUE(media_stream_set_srtp_recv_key_b64(&(margaux->ms.sessions), MS_AES_128_SHA1_32, "eCYF4nYyCvmCpFWjUeDaxI2GWp2BzCRlIPfg52Te") ==0); } CU_ASSERT_TRUE(wait_for_until(&marielle->ms,&margaux->ms,&marielle_stats.number_of_EndOfFile,1,12000)); /*make sure packets can cross from sender to receiver*/ wait_for_until(&marielle->ms,&margaux->ms,&dummy,1,500); audio_stream_get_local_rtp_stats(marielle,&marielle_stats.rtp); audio_stream_get_local_rtp_stats(margaux,&margaux_stats.rtp); /* No packet loss is assumed */ if (change_send_key_in_the_middle) { /*we can accept one or 2 error in such case*/ CU_ASSERT_TRUE((marielle_stats.rtp.packet_sent-margaux_stats.rtp.packet_recv)<3); } else CU_ASSERT_EQUAL(marielle_stats.rtp.sent,margaux_stats.rtp.recv); if (change_ssrc) { audio_stream_stop(marielle); marielle = audio_stream_new (MARIELLE_RTP_PORT, MARIELLE_RTCP_PORT,FALSE); CU_ASSERT_EQUAL(audio_stream_start_full(marielle , profile , MARGAUX_IP , MARGAUX_RTP_PORT , MARGAUX_IP , MARGAUX_RTCP_PORT , 0 , 50 , hello_file , NULL , NULL , NULL , 0),0); CU_ASSERT_FATAL(media_stream_set_srtp_send_key_b64(&(marielle->ms.sessions), MS_AES_128_SHA1_32, "d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj") == 0); ms_filter_add_notify_callback(marielle->soundread, notify_cb, &marielle_stats,TRUE); CU_ASSERT_TRUE(wait_for_until(&marielle->ms,&margaux->ms,&marielle_stats.number_of_EndOfFile,2,12000)); /*make sure packets can cross from sender to receiver*/ wait_for_until(&marielle->ms,&margaux->ms,&dummy,1,500); audio_stream_get_local_rtp_stats(marielle,&marielle_stats.rtp); audio_stream_get_local_rtp_stats(margaux,&margaux_stats.rtp); /* No packet loss is assumed */ CU_ASSERT_EQUAL(marielle_stats.rtp.sent*2,margaux_stats.rtp.recv); } unlink(recorded_file); ms_free(recorded_file); ms_free(hello_file); } else { ms_warning("srtp not available, skiping..."); } audio_stream_stop(marielle); audio_stream_stop(margaux); rtp_profile_destroy(profile); }