Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(159)

Side by Side Diff: webrtc/pc/webrtcsdp_unittest.cc

Issue 2761143002: Support encrypted RTP extensions (RFC 6904) (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2011 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2011 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 "dummy_session_params\r\n"; 85 "dummy_session_params\r\n";
86 static const char kAttributeCryptoVideo[] = 86 static const char kAttributeCryptoVideo[] =
87 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 " 87 "a=crypto:1 AES_CM_128_HMAC_SHA1_80 "
88 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n"; 88 "inline:d0RmdmcmVCspeEc3QGZiNWpVLFJhQX1cfHAwJSoj|2^20|1:32\r\n";
89 static const char kFingerprint[] = "a=fingerprint:sha-1 " 89 static const char kFingerprint[] = "a=fingerprint:sha-1 "
90 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n"; 90 "4A:AD:B9:B1:3F:82:18:3B:54:02:12:DF:3E:5D:49:6B:19:E5:7C:AB\r\n";
91 static const int kExtmapId = 1; 91 static const int kExtmapId = 1;
92 static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime"; 92 static const char kExtmapUri[] = "http://example.com/082005/ext.htm#ttime";
93 static const char kExtmap[] = 93 static const char kExtmap[] =
94 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n"; 94 "a=extmap:1 http://example.com/082005/ext.htm#ttime\r\n";
95 static const char kExtmapEncrypted[] =
96 "a=extmap:1 urn:ietf:params:rtp-hdrext:encrypt "
97 "http://example.com/082005/ext.htm#ttime\r\n";
95 static const char kExtmapWithDirectionAndAttribute[] = 98 static const char kExtmapWithDirectionAndAttribute[] =
96 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n"; 99 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
100 static const char kExtmapWithDirectionAndAttributeEncrypted[] =
101 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
102 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
97 103
98 static const uint8_t kIdentityDigest[] = { 104 static const uint8_t kIdentityDigest[] = {
99 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02, 105 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
100 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB}; 106 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
101 107
102 static const char kDtlsSctp[] = "DTLS/SCTP"; 108 static const char kDtlsSctp[] = "DTLS/SCTP";
103 static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP"; 109 static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
104 static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP"; 110 static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
105 111
106 struct CodecParams { 112 struct CodecParams {
(...skipping 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 EXPECT_EQ(cd1->streams(), cd2->streams()); 1209 EXPECT_EQ(cd1->streams(), cd2->streams());
1204 1210
1205 // extmap 1211 // extmap
1206 ASSERT_EQ(cd1->rtp_header_extensions().size(), 1212 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1207 cd2->rtp_header_extensions().size()); 1213 cd2->rtp_header_extensions().size());
1208 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) { 1214 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
1209 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i); 1215 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1210 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i); 1216 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
1211 EXPECT_EQ(ext1.uri, ext2.uri); 1217 EXPECT_EQ(ext1.uri, ext2.uri);
1212 EXPECT_EQ(ext1.id, ext2.id); 1218 EXPECT_EQ(ext1.id, ext2.id);
1219 EXPECT_EQ(ext1.encrypted, ext2.encrypted);
1213 } 1220 }
1214 } 1221 }
1215 1222
1216 void CompareDataContentDescription(const DataContentDescription* dcd1, 1223 void CompareDataContentDescription(const DataContentDescription* dcd1,
1217 const DataContentDescription* dcd2) { 1224 const DataContentDescription* dcd2) {
1218 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap()); 1225 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
1219 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2); 1226 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1220 } 1227 }
1221 1228
1222 void CompareSessionDescription(const SessionDescription& desc1, 1229 void CompareSessionDescription(const SessionDescription& desc1,
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
1424 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice, 1431 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1425 cricket::ICEMODE_FULL, 1432 cricket::ICEMODE_FULL,
1426 cricket::CONNECTIONROLE_NONE, &fingerprint)))); 1433 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1427 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( 1434 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1428 kVideoContentName, 1435 kVideoContentName,
1429 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo, 1436 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1430 cricket::ICEMODE_FULL, 1437 cricket::ICEMODE_FULL,
1431 cricket::CONNECTIONROLE_NONE, &fingerprint)))); 1438 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1432 } 1439 }
1433 1440
1434 void AddExtmap() { 1441 void AddExtmap(bool encrypted) {
1435 audio_desc_ = static_cast<AudioContentDescription*>( 1442 audio_desc_ = static_cast<AudioContentDescription*>(
1436 audio_desc_->Copy()); 1443 audio_desc_->Copy());
1437 video_desc_ = static_cast<VideoContentDescription*>( 1444 video_desc_ = static_cast<VideoContentDescription*>(
1438 video_desc_->Copy()); 1445 video_desc_->Copy());
1439 audio_desc_->AddRtpHeaderExtension(RtpExtension(kExtmapUri, kExtmapId)); 1446 audio_desc_->AddRtpHeaderExtension(
1440 video_desc_->AddRtpHeaderExtension(RtpExtension(kExtmapUri, kExtmapId)); 1447 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1448 video_desc_->AddRtpHeaderExtension(
1449 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1441 desc_.RemoveContentByName(kAudioContentName); 1450 desc_.RemoveContentByName(kAudioContentName);
1442 desc_.RemoveContentByName(kVideoContentName); 1451 desc_.RemoveContentByName(kVideoContentName);
1443 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_); 1452 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1444 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_); 1453 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1445 } 1454 }
1446 1455
1447 void RemoveCryptos() { 1456 void RemoveCryptos() {
1448 audio_desc_->set_cryptos(std::vector<CryptoParams>()); 1457 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1449 video_desc_->set_cryptos(std::vector<CryptoParams>()); 1458 video_desc_->set_cryptos(std::vector<CryptoParams>());
1450 } 1459 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1568 video_rejected ? "" : kPwdVideo); 1577 video_rejected ? "" : kPwdVideo);
1569 JsepSessionDescription jdesc_no_candidates(kDummyString); 1578 JsepSessionDescription jdesc_no_candidates(kDummyString);
1570 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(), 1579 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1571 jdesc_.session_version())) { 1580 jdesc_.session_version())) {
1572 return false; 1581 return false;
1573 } 1582 }
1574 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc)); 1583 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
1575 return true; 1584 return true;
1576 } 1585 }
1577 1586
1578 void TestDeserializeExtmap(bool session_level, bool media_level) { 1587 void TestDeserializeExtmap(bool session_level, bool media_level,
1579 AddExtmap(); 1588 bool encrypted) {
1589 AddExtmap(encrypted);
1580 JsepSessionDescription new_jdesc("dummy"); 1590 JsepSessionDescription new_jdesc("dummy");
1581 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), 1591 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1582 jdesc_.session_id(), 1592 jdesc_.session_id(),
1583 jdesc_.session_version())); 1593 jdesc_.session_version()));
1584 JsepSessionDescription jdesc_with_extmap("dummy"); 1594 JsepSessionDescription jdesc_with_extmap("dummy");
1585 std::string sdp_with_extmap = kSdpString; 1595 std::string sdp_with_extmap = kSdpString;
1586 if (session_level) { 1596 if (session_level) {
1587 InjectAfter(kSessionTime, kExtmapWithDirectionAndAttribute, 1597 InjectAfter(kSessionTime,
1598 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1599 : kExtmapWithDirectionAndAttribute,
1588 &sdp_with_extmap); 1600 &sdp_with_extmap);
1589 } 1601 }
1590 if (media_level) { 1602 if (media_level) {
1591 InjectAfter(kAttributeIcePwdVoice, kExtmapWithDirectionAndAttribute, 1603 InjectAfter(kAttributeIcePwdVoice,
1604 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1605 : kExtmapWithDirectionAndAttribute,
1592 &sdp_with_extmap); 1606 &sdp_with_extmap);
1593 InjectAfter(kAttributeIcePwdVideo, kExtmapWithDirectionAndAttribute, 1607 InjectAfter(kAttributeIcePwdVideo,
1608 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1609 : kExtmapWithDirectionAndAttribute,
1594 &sdp_with_extmap); 1610 &sdp_with_extmap);
1595 } 1611 }
1596 // The extmap can't be present at the same time in both session level and 1612 // The extmap can't be present at the same time in both session level and
1597 // media level. 1613 // media level.
1598 if (session_level && media_level) { 1614 if (session_level && media_level) {
1599 SdpParseError error; 1615 SdpParseError error;
1600 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap, 1616 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1601 &jdesc_with_extmap, &error)); 1617 &jdesc_with_extmap, &error));
1602 EXPECT_NE(std::string::npos, error.description.find("a=extmap")); 1618 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1603 } else { 1619 } else {
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
2122 std::string expected_sdp = kSdpString; 2138 std::string expected_sdp = kSdpString;
2123 expected_sdp.append(kSdpRtpDataChannelString); 2139 expected_sdp.append(kSdpRtpDataChannelString);
2124 // Serializing data content shouldn't ignore bandwidth settings. 2140 // Serializing data content shouldn't ignore bandwidth settings.
2125 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n", 2141 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
2126 "b=AS:100\r\n", 2142 "b=AS:100\r\n",
2127 &expected_sdp); 2143 &expected_sdp);
2128 EXPECT_EQ(expected_sdp, message); 2144 EXPECT_EQ(expected_sdp, message);
2129 } 2145 }
2130 2146
2131 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) { 2147 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
2132 AddExtmap(); 2148 bool encrypted = false;
2149 AddExtmap(encrypted);
2133 JsepSessionDescription desc_with_extmap("dummy"); 2150 JsepSessionDescription desc_with_extmap("dummy");
2134 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(), 2151 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
2135 kSessionId, kSessionVersion)); 2152 kSessionId, kSessionVersion));
2136 std::string message = webrtc::SdpSerialize(desc_with_extmap, false); 2153 std::string message = webrtc::SdpSerialize(desc_with_extmap, false);
2137 2154
2138 std::string sdp_with_extmap = kSdpString; 2155 std::string sdp_with_extmap = kSdpString;
2139 InjectAfter("a=mid:audio_content_name\r\n", 2156 InjectAfter("a=mid:audio_content_name\r\n",
2140 kExtmap, &sdp_with_extmap); 2157 kExtmap, &sdp_with_extmap);
2141 InjectAfter("a=mid:video_content_name\r\n", 2158 InjectAfter("a=mid:video_content_name\r\n",
2142 kExtmap, &sdp_with_extmap); 2159 kExtmap, &sdp_with_extmap);
2143 2160
2144 EXPECT_EQ(sdp_with_extmap, message); 2161 EXPECT_EQ(sdp_with_extmap, message);
2145 } 2162 }
2146 2163
2164 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2165 bool encrypted = true;
2166 AddExtmap(encrypted);
2167 JsepSessionDescription desc_with_extmap("dummy");
2168 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
2169 kSessionId, kSessionVersion));
2170 std::string message = webrtc::SdpSerialize(desc_with_extmap, false);
2171
2172 std::string sdp_with_extmap = kSdpString;
2173 InjectAfter("a=mid:audio_content_name\r\n",
2174 kExtmapEncrypted, &sdp_with_extmap);
2175 InjectAfter("a=mid:video_content_name\r\n",
2176 kExtmapEncrypted, &sdp_with_extmap);
2177
2178 EXPECT_EQ(sdp_with_extmap, message);
Taylor Brandstetter 2017/03/22 18:00:11 nit: Tests for SDP string equality are fragile sin
joachim 2017/03/23 00:04:34 I based my test on "SerializeSessionDescriptionWit
2179 }
2180
2147 TEST_F(WebRtcSdpTest, SerializeCandidates) { 2181 TEST_F(WebRtcSdpTest, SerializeCandidates) {
2148 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_); 2182 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
2149 EXPECT_EQ(std::string(kRawCandidate), message); 2183 EXPECT_EQ(std::string(kRawCandidate), message);
2150 2184
2151 Candidate candidate_with_ufrag(candidates_.front()); 2185 Candidate candidate_with_ufrag(candidates_.front());
2152 candidate_with_ufrag.set_username("ABC"); 2186 candidate_with_ufrag.set_username("ABC");
2153 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0, 2187 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2154 candidate_with_ufrag)); 2188 candidate_with_ufrag));
2155 message = webrtc::SdpSerializeCandidate(*jcandidate_); 2189 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2156 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message); 2190 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message);
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after
2782 "b=AS:100\r\n", 2816 "b=AS:100\r\n",
2783 &sdp_with_bandwidth); 2817 &sdp_with_bandwidth);
2784 JsepSessionDescription jdesc_with_bandwidth(kDummyString); 2818 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2785 2819
2786 // SCTP has congestion control, so we shouldn't limit the bandwidth 2820 // SCTP has congestion control, so we shouldn't limit the bandwidth
2787 // as we do for RTP. 2821 // as we do for RTP.
2788 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); 2822 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2789 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth)); 2823 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2790 } 2824 }
2791 2825
2792 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) { 2826 class WebRtcSdpExtmapTest
2793 TestDeserializeExtmap(true, false); 2827 : public WebRtcSdpTest, public testing::WithParamInterface<bool> {
2828 };
2829
2830 TEST_P(WebRtcSdpExtmapTest,
2831 DeserializeSessionDescriptionWithSessionLevelExtmap) {
2832 bool encrypted = GetParam();
2833 TestDeserializeExtmap(true, false, encrypted);
2794 } 2834 }
2795 2835
2796 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) { 2836 TEST_P(WebRtcSdpExtmapTest,
2797 TestDeserializeExtmap(false, true); 2837 DeserializeSessionDescriptionWithMediaLevelExtmap) {
2838 bool encrypted = GetParam();
2839 TestDeserializeExtmap(false, true, encrypted);
2798 } 2840 }
2799 2841
2800 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) { 2842 TEST_P(WebRtcSdpExtmapTest,
2801 TestDeserializeExtmap(true, true); 2843 DeserializeSessionDescriptionWithInvalidExtmap) {
2844 bool encrypted = GetParam();
2845 TestDeserializeExtmap(true, true, encrypted);
2802 } 2846 }
2803 2847
2848 INSTANTIATE_TEST_CASE_P(Encrypted,
2849 WebRtcSdpExtmapTest,
2850 ::testing::Values(false, true));
2851
2804 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) { 2852 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
2805 JsepSessionDescription jdesc(kDummyString); 2853 JsepSessionDescription jdesc(kDummyString);
2806 std::string sdp = kSdpFullString; 2854 std::string sdp = kSdpFullString;
2807 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end. 2855 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2808 // Deserialize 2856 // Deserialize
2809 SdpParseError error; 2857 SdpParseError error;
2810 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error)); 2858 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
2811 const std::string lastline = "a=ssrc:3 label:video_track_id_1"; 2859 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
2812 EXPECT_EQ(lastline, error.line); 2860 EXPECT_EQ(lastline, error.line);
2813 EXPECT_EQ("Invalid SDP line.", error.description); 2861 EXPECT_EQ("Invalid SDP line.", error.description);
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
3497 "s=-\r\n" 3545 "s=-\r\n"
3498 "t=0 0\r\n" 3546 "t=0 0\r\n"
3499 "m=audio 9 RTP/SAVPF 111\r\n" 3547 "m=audio 9 RTP/SAVPF 111\r\n"
3500 "c=IN IP4 0.0.0.0\r\n" 3548 "c=IN IP4 0.0.0.0\r\n"
3501 "a=rtpmap:111 opus/48000/2\r\n" 3549 "a=rtpmap:111 opus/48000/2\r\n"
3502 "a=msid: track_id\r\n"; 3550 "a=msid: track_id\r\n";
3503 3551
3504 JsepSessionDescription jdesc_output(kDummyString); 3552 JsepSessionDescription jdesc_output(kDummyString);
3505 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output)); 3553 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3506 } 3554 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698