From 52e41e7324e3e8a54c5991e0bb3e6217a8ef46c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Cr=C3=AAte?= Date: Mon, 5 May 2014 22:32:25 -0400 Subject: rtp: Add srtp test --- tests/check/Makefile.am | 2 +- tests/check/rtp/conference.c | 116 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 115 insertions(+), 3 deletions(-) diff --git a/tests/check/Makefile.am b/tests/check/Makefile.am index 5e6f07a1..314a1849 100644 --- a/tests/check/Makefile.am +++ b/tests/check/Makefile.am @@ -10,7 +10,7 @@ TESTS_ENVIRONMENT = \ CK_DEFAULT_TIMEOUT=120 \ STATE_IGNORE_ELEMENTS="$(STATE_IGNORE_ELEMENTS)" \ $(REGISTRY_ENVIRONMENT) \ - GST_PLUGIN_LOADING_WHITELIST=gstreamer:gst-plugins-base:gst-plugins-good:libnice:valve:siren:autoconvert:rtpmux:dtmf:mimic:shm:spandsp:farstream@$(top_builddir)/gst \ + GST_PLUGIN_LOADING_WHITELIST=gstreamer:gst-plugins-base:gst-plugins-good:libnice:valve:siren:autoconvert:rtpmux:dtmf:mimic:shm:spandsp:srtp:farstream@$(top_builddir)/gst \ GST_PLUGIN_PATH=$(top_builddir)/gst:${GST_PLUGIN_PATH} \ FS_PLUGIN_PATH=$(top_builddir)/transmitters/rawudp/.libs:$(top_builddir)/transmitters/multicast/.libs:$(top_builddir)/transmitters/nice/.libs:$(top_builddir)/transmitters/shm/.libs \ LD_LIBRARY_PATH=$(top_builddir)/farstream/.libs:${LD_LIBRARY_PATH} \ diff --git a/tests/check/rtp/conference.c b/tests/check/rtp/conference.c index 610f3c67..a512a6f8 100644 --- a/tests/check/rtp/conference.c +++ b/tests/check/rtp/conference.c @@ -895,7 +895,6 @@ GST_START_TEST (test_rtpconference_ten_way) } GST_END_TEST; - GST_START_TEST (test_rtpconference_errors) { struct SimpleTestConference *dat = NULL; @@ -1401,6 +1400,102 @@ GST_START_TEST (test_rtpconference_unref_session_in_pad_added) GST_END_TEST; +static void +setup_srtp_sender (struct SimpleTestConference *dat, guint confid) +{ + GstBuffer *key; + GstStructure *s, *s2 = NULL; + GstMapInfo info; + guint i; + GError *error = NULL; + gboolean ret; + + key = gst_buffer_new_allocate (NULL, 30, NULL); + gst_buffer_map (key, &info, GST_MAP_WRITE); + for (i = 0; i < info.size / 4; i++) + GST_WRITE_UINT32_LE (info.data + (i * 4), g_random_int ()); + GST_WRITE_UINT32_LE (info.data + info.size - 4, g_random_int ()); + gst_buffer_unmap (key, &info); + + s = gst_structure_new ("FarstreamSRTP", + "auth", G_TYPE_STRING, "hmac-sha1-80", + "cipher", G_TYPE_STRING, "aes-128-icm", + "key", GST_TYPE_BUFFER, key, NULL); + gst_buffer_unref (key); + + ret = fs_session_set_encryption_parameters (dat->session, s, &error); + g_assert_no_error (error); + fail_unless (ret); + + g_object_get (dat->session, "encryption-parameters", &s2, NULL); + fail_unless (s2 != NULL); + fail_unless (gst_structure_is_equal (s, s2)); + + gst_structure_free (s2); + gst_structure_free (s); +} + +static void +setup_srtp_receiver (struct SimpleTestStream *st, guint confid, guint streamid) +{ + GstStructure *s, *s2 = NULL; + GError *error = NULL; + gboolean ret; + + g_object_get (st->target->session, "encryption-parameters", &s, NULL); + + ret = fs_stream_set_decryption_parameters (st->stream, s, &error); + g_assert_no_error (error); + fail_unless (ret); + + g_object_get (st->stream, "decryption-parameters", &s2, NULL); + fail_unless (s2 != NULL); + fail_unless (gst_structure_is_equal (s, s2)); + + gst_structure_free (s2); + gst_structure_free (s); +} + +GST_START_TEST (test_rtpconference_two_way_srtp) +{ + nway_test (2, setup_srtp_sender, setup_srtp_receiver, "rawudp", 0, NULL); +} +GST_END_TEST; + + +GST_START_TEST (test_rtpconference_three_way_srtp) +{ + nway_test (3, setup_srtp_sender, setup_srtp_receiver, "rawudp", 0, NULL); +} +GST_END_TEST; + +GST_START_TEST (test_rtpconference_ten_way_srtp) +{ + nway_test (10, setup_srtp_sender, setup_srtp_receiver, "rawudp", 0, NULL); +} +GST_END_TEST; + +static void +multicast_srtp_init (struct SimpleTestStream *st, guint confid, guint streamid) +{ + multicast_ssrc_init (st, confid, streamid); + setup_srtp_receiver (st, confid, streamid); +} + +GST_START_TEST (test_rtpconference_multicast_three_way_ssrc_assoc_srtp) +{ + gchar *mcast_addr = find_multicast_capable_address (); + + if (!mcast_addr) + return; + g_free (mcast_addr); + + max_src_pads = 3 * 2; /* x2 because of loopbacks causing fake conflicts */ + nway_test (3, setup_srtp_sender, multicast_srtp_init, "multicast", 0, NULL); + max_src_pads = 1; +} +GST_END_TEST; + static Suite * fsrtpconference_suite (void) { @@ -1454,7 +1549,7 @@ fsrtpconference_suite (void) #if 0 tc_chain = tcase_create ("fsrtpconference_three_way_cname_assoc"); tcase_add_test (tc_chain, test_rtpconference_three_way_cname_assoc); - //suite_add_tcase (s, tc_chain); + suite_add_tcase (s, tc_chain); #endif tc_chain = tcase_create ("fsrtpconference_simple_profile"); @@ -1484,6 +1579,23 @@ fsrtpconference_suite (void) tcase_add_test (tc_chain, test_rtpconference_unref_session_in_pad_added); suite_add_tcase (s, tc_chain); + tc_chain = tcase_create ("fsrtpconference_two_way_srtp"); + tcase_add_test (tc_chain, test_rtpconference_two_way_srtp); + suite_add_tcase (s, tc_chain); + + tc_chain = tcase_create ("fsrtpconference_three_way_srtp"); + tcase_add_test (tc_chain, test_rtpconference_three_way_srtp); + suite_add_tcase (s, tc_chain); + + tc_chain = tcase_create ("fsrtpconference_ten_way_srtp"); + tcase_add_test (tc_chain, test_rtpconference_ten_way_srtp); + suite_add_tcase (s, tc_chain); + + tc_chain = tcase_create ( + "fsrtpconference_multicast_three_way_ssrc_assoc_srtp"); + tcase_add_test (tc_chain, + test_rtpconference_multicast_three_way_ssrc_assoc_srtp); + suite_add_tcase (s, tc_chain); return s; } -- cgit v1.2.1