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

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

Issue 2761143002: Support encrypted RTP extensions (RFC 6904) (Closed)
Patch Set: Updated comment. Created 3 years, 7 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 kExtmapWithDirectionAndAttribute[] = 95 static const char kExtmapWithDirectionAndAttribute[] =
96 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n"; 96 "a=extmap:1/sendrecv http://example.com/082005/ext.htm#ttime a1 a2\r\n";
97 static const char kExtmapWithDirectionAndAttributeEncrypted[] =
98 "a=extmap:1/sendrecv urn:ietf:params:rtp-hdrext:encrypt "
99 "http://example.com/082005/ext.htm#ttime a1 a2\r\n";
97 100
98 static const uint8_t kIdentityDigest[] = { 101 static const uint8_t kIdentityDigest[] = {
99 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02, 102 0x4A, 0xAD, 0xB9, 0xB1, 0x3F, 0x82, 0x18, 0x3B, 0x54, 0x02,
100 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB}; 103 0x12, 0xDF, 0x3E, 0x5D, 0x49, 0x6B, 0x19, 0xE5, 0x7C, 0xAB};
101 104
102 static const char kDtlsSctp[] = "DTLS/SCTP"; 105 static const char kDtlsSctp[] = "DTLS/SCTP";
103 static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP"; 106 static const char kUdpDtlsSctp[] = "UDP/DTLS/SCTP";
104 static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP"; 107 static const char kTcpDtlsSctp[] = "TCP/DTLS/SCTP";
105 108
106 struct CodecParams { 109 struct CodecParams {
(...skipping 1096 matching lines...) Expand 10 before | Expand all | Expand 10 after
1203 EXPECT_EQ(cd1->streams(), cd2->streams()); 1206 EXPECT_EQ(cd1->streams(), cd2->streams());
1204 1207
1205 // extmap 1208 // extmap
1206 ASSERT_EQ(cd1->rtp_header_extensions().size(), 1209 ASSERT_EQ(cd1->rtp_header_extensions().size(),
1207 cd2->rtp_header_extensions().size()); 1210 cd2->rtp_header_extensions().size());
1208 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) { 1211 for (size_t i = 0; i< cd1->rtp_header_extensions().size(); ++i) {
1209 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i); 1212 const RtpExtension ext1 = cd1->rtp_header_extensions().at(i);
1210 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i); 1213 const RtpExtension ext2 = cd2->rtp_header_extensions().at(i);
1211 EXPECT_EQ(ext1.uri, ext2.uri); 1214 EXPECT_EQ(ext1.uri, ext2.uri);
1212 EXPECT_EQ(ext1.id, ext2.id); 1215 EXPECT_EQ(ext1.id, ext2.id);
1216 EXPECT_EQ(ext1.encrypt, ext2.encrypt);
1213 } 1217 }
1214 } 1218 }
1215 1219
1216 void CompareDataContentDescription(const DataContentDescription* dcd1, 1220 void CompareDataContentDescription(const DataContentDescription* dcd1,
1217 const DataContentDescription* dcd2) { 1221 const DataContentDescription* dcd2) {
1218 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap()); 1222 EXPECT_EQ(dcd1->use_sctpmap(), dcd2->use_sctpmap());
1219 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2); 1223 CompareMediaContentDescription<DataContentDescription>(dcd1, dcd2);
1220 } 1224 }
1221 1225
1222 void CompareSessionDescription(const SessionDescription& desc1, 1226 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, 1428 TransportDescription(std::vector<std::string>(), kUfragVoice, kPwdVoice,
1425 cricket::ICEMODE_FULL, 1429 cricket::ICEMODE_FULL,
1426 cricket::CONNECTIONROLE_NONE, &fingerprint)))); 1430 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1427 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo( 1431 EXPECT_TRUE(desc_.AddTransportInfo(TransportInfo(
1428 kVideoContentName, 1432 kVideoContentName,
1429 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo, 1433 TransportDescription(std::vector<std::string>(), kUfragVideo, kPwdVideo,
1430 cricket::ICEMODE_FULL, 1434 cricket::ICEMODE_FULL,
1431 cricket::CONNECTIONROLE_NONE, &fingerprint)))); 1435 cricket::CONNECTIONROLE_NONE, &fingerprint))));
1432 } 1436 }
1433 1437
1434 void AddExtmap() { 1438 void AddExtmap(bool encrypted) {
1435 audio_desc_ = static_cast<AudioContentDescription*>( 1439 audio_desc_ = static_cast<AudioContentDescription*>(
1436 audio_desc_->Copy()); 1440 audio_desc_->Copy());
1437 video_desc_ = static_cast<VideoContentDescription*>( 1441 video_desc_ = static_cast<VideoContentDescription*>(
1438 video_desc_->Copy()); 1442 video_desc_->Copy());
1439 audio_desc_->AddRtpHeaderExtension(RtpExtension(kExtmapUri, kExtmapId)); 1443 audio_desc_->AddRtpHeaderExtension(
1440 video_desc_->AddRtpHeaderExtension(RtpExtension(kExtmapUri, kExtmapId)); 1444 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1445 video_desc_->AddRtpHeaderExtension(
1446 RtpExtension(kExtmapUri, kExtmapId, encrypted));
1441 desc_.RemoveContentByName(kAudioContentName); 1447 desc_.RemoveContentByName(kAudioContentName);
1442 desc_.RemoveContentByName(kVideoContentName); 1448 desc_.RemoveContentByName(kVideoContentName);
1443 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_); 1449 desc_.AddContent(kAudioContentName, NS_JINGLE_RTP, audio_desc_);
1444 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_); 1450 desc_.AddContent(kVideoContentName, NS_JINGLE_RTP, video_desc_);
1445 } 1451 }
1446 1452
1447 void RemoveCryptos() { 1453 void RemoveCryptos() {
1448 audio_desc_->set_cryptos(std::vector<CryptoParams>()); 1454 audio_desc_->set_cryptos(std::vector<CryptoParams>());
1449 video_desc_->set_cryptos(std::vector<CryptoParams>()); 1455 video_desc_->set_cryptos(std::vector<CryptoParams>());
1450 } 1456 }
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1568 video_rejected ? "" : kPwdVideo); 1574 video_rejected ? "" : kPwdVideo);
1569 JsepSessionDescription jdesc_no_candidates(kDummyString); 1575 JsepSessionDescription jdesc_no_candidates(kDummyString);
1570 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(), 1576 if (!jdesc_no_candidates.Initialize(desc_.Copy(), jdesc_.session_id(),
1571 jdesc_.session_version())) { 1577 jdesc_.session_version())) {
1572 return false; 1578 return false;
1573 } 1579 }
1574 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc)); 1580 EXPECT_TRUE(CompareSessionDescription(jdesc_no_candidates, new_jdesc));
1575 return true; 1581 return true;
1576 } 1582 }
1577 1583
1578 void TestDeserializeExtmap(bool session_level, bool media_level) { 1584 void TestDeserializeExtmap(bool session_level, bool media_level,
1579 AddExtmap(); 1585 bool encrypted) {
1586 AddExtmap(encrypted);
1580 JsepSessionDescription new_jdesc("dummy"); 1587 JsepSessionDescription new_jdesc("dummy");
1581 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(), 1588 ASSERT_TRUE(new_jdesc.Initialize(desc_.Copy(),
1582 jdesc_.session_id(), 1589 jdesc_.session_id(),
1583 jdesc_.session_version())); 1590 jdesc_.session_version()));
1584 JsepSessionDescription jdesc_with_extmap("dummy"); 1591 JsepSessionDescription jdesc_with_extmap("dummy");
1585 std::string sdp_with_extmap = kSdpString; 1592 std::string sdp_with_extmap = kSdpString;
1586 if (session_level) { 1593 if (session_level) {
1587 InjectAfter(kSessionTime, kExtmapWithDirectionAndAttribute, 1594 InjectAfter(kSessionTime,
1595 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1596 : kExtmapWithDirectionAndAttribute,
1588 &sdp_with_extmap); 1597 &sdp_with_extmap);
1589 } 1598 }
1590 if (media_level) { 1599 if (media_level) {
1591 InjectAfter(kAttributeIcePwdVoice, kExtmapWithDirectionAndAttribute, 1600 InjectAfter(kAttributeIcePwdVoice,
1601 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1602 : kExtmapWithDirectionAndAttribute,
1592 &sdp_with_extmap); 1603 &sdp_with_extmap);
1593 InjectAfter(kAttributeIcePwdVideo, kExtmapWithDirectionAndAttribute, 1604 InjectAfter(kAttributeIcePwdVideo,
1605 encrypted ? kExtmapWithDirectionAndAttributeEncrypted
1606 : kExtmapWithDirectionAndAttribute,
1594 &sdp_with_extmap); 1607 &sdp_with_extmap);
1595 } 1608 }
1596 // The extmap can't be present at the same time in both session level and 1609 // The extmap can't be present at the same time in both session level and
1597 // media level. 1610 // media level.
1598 if (session_level && media_level) { 1611 if (session_level && media_level) {
1599 SdpParseError error; 1612 SdpParseError error;
1600 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap, 1613 EXPECT_FALSE(webrtc::SdpDeserialize(sdp_with_extmap,
1601 &jdesc_with_extmap, &error)); 1614 &jdesc_with_extmap, &error));
1602 EXPECT_NE(std::string::npos, error.description.find("a=extmap")); 1615 EXPECT_NE(std::string::npos, error.description.find("a=extmap"));
1603 } else { 1616 } else {
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
2122 std::string expected_sdp = kSdpString; 2135 std::string expected_sdp = kSdpString;
2123 expected_sdp.append(kSdpRtpDataChannelString); 2136 expected_sdp.append(kSdpRtpDataChannelString);
2124 // Serializing data content shouldn't ignore bandwidth settings. 2137 // 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", 2138 InjectAfter("m=application 9 RTP/SAVPF 101\r\nc=IN IP4 0.0.0.0\r\n",
2126 "b=AS:100\r\n", 2139 "b=AS:100\r\n",
2127 &expected_sdp); 2140 &expected_sdp);
2128 EXPECT_EQ(expected_sdp, message); 2141 EXPECT_EQ(expected_sdp, message);
2129 } 2142 }
2130 2143
2131 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) { 2144 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmap) {
2132 AddExtmap(); 2145 bool encrypted = false;
2146 AddExtmap(encrypted);
2133 JsepSessionDescription desc_with_extmap("dummy"); 2147 JsepSessionDescription desc_with_extmap("dummy");
2134 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(), 2148 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
2135 kSessionId, kSessionVersion)); 2149 kSessionId, kSessionVersion));
2136 std::string message = webrtc::SdpSerialize(desc_with_extmap, false); 2150 std::string message = webrtc::SdpSerialize(desc_with_extmap, false);
2137 2151
2138 std::string sdp_with_extmap = kSdpString; 2152 std::string sdp_with_extmap = kSdpString;
2139 InjectAfter("a=mid:audio_content_name\r\n", 2153 InjectAfter("a=mid:audio_content_name\r\n",
2140 kExtmap, &sdp_with_extmap); 2154 kExtmap, &sdp_with_extmap);
2141 InjectAfter("a=mid:video_content_name\r\n", 2155 InjectAfter("a=mid:video_content_name\r\n",
2142 kExtmap, &sdp_with_extmap); 2156 kExtmap, &sdp_with_extmap);
2143 2157
2144 EXPECT_EQ(sdp_with_extmap, message); 2158 EXPECT_EQ(sdp_with_extmap, message);
2145 } 2159 }
2146 2160
2161 TEST_F(WebRtcSdpTest, SerializeSessionDescriptionWithExtmapEncrypted) {
2162 bool encrypted = true;
2163 AddExtmap(encrypted);
2164 JsepSessionDescription desc_with_extmap("dummy");
2165 ASSERT_TRUE(desc_with_extmap.Initialize(desc_.Copy(),
2166 kSessionId, kSessionVersion));
2167 TestSerialize(desc_with_extmap, false);
2168 }
2169
2147 TEST_F(WebRtcSdpTest, SerializeCandidates) { 2170 TEST_F(WebRtcSdpTest, SerializeCandidates) {
2148 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_); 2171 std::string message = webrtc::SdpSerializeCandidate(*jcandidate_);
2149 EXPECT_EQ(std::string(kRawCandidate), message); 2172 EXPECT_EQ(std::string(kRawCandidate), message);
2150 2173
2151 Candidate candidate_with_ufrag(candidates_.front()); 2174 Candidate candidate_with_ufrag(candidates_.front());
2152 candidate_with_ufrag.set_username("ABC"); 2175 candidate_with_ufrag.set_username("ABC");
2153 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0, 2176 jcandidate_.reset(new JsepIceCandidate(std::string("audio_content_name"), 0,
2154 candidate_with_ufrag)); 2177 candidate_with_ufrag));
2155 message = webrtc::SdpSerializeCandidate(*jcandidate_); 2178 message = webrtc::SdpSerializeCandidate(*jcandidate_);
2156 EXPECT_EQ(std::string(kRawCandidate) + " ufrag ABC", message); 2179 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", 2805 "b=AS:100\r\n",
2783 &sdp_with_bandwidth); 2806 &sdp_with_bandwidth);
2784 JsepSessionDescription jdesc_with_bandwidth(kDummyString); 2807 JsepSessionDescription jdesc_with_bandwidth(kDummyString);
2785 2808
2786 // SCTP has congestion control, so we shouldn't limit the bandwidth 2809 // SCTP has congestion control, so we shouldn't limit the bandwidth
2787 // as we do for RTP. 2810 // as we do for RTP.
2788 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth)); 2811 EXPECT_TRUE(SdpDeserialize(sdp_with_bandwidth, &jdesc_with_bandwidth));
2789 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth)); 2812 EXPECT_TRUE(CompareSessionDescription(jdesc, jdesc_with_bandwidth));
2790 } 2813 }
2791 2814
2792 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithSessionLevelExtmap) { 2815 class WebRtcSdpExtmapTest
2793 TestDeserializeExtmap(true, false); 2816 : public WebRtcSdpTest, public testing::WithParamInterface<bool> {
2817 };
2818
2819 TEST_P(WebRtcSdpExtmapTest,
2820 DeserializeSessionDescriptionWithSessionLevelExtmap) {
2821 bool encrypted = GetParam();
2822 TestDeserializeExtmap(true, false, encrypted);
2794 } 2823 }
2795 2824
2796 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithMediaLevelExtmap) { 2825 TEST_P(WebRtcSdpExtmapTest,
2797 TestDeserializeExtmap(false, true); 2826 DeserializeSessionDescriptionWithMediaLevelExtmap) {
2827 bool encrypted = GetParam();
2828 TestDeserializeExtmap(false, true, encrypted);
2798 } 2829 }
2799 2830
2800 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithInvalidExtmap) { 2831 TEST_P(WebRtcSdpExtmapTest,
2801 TestDeserializeExtmap(true, true); 2832 DeserializeSessionDescriptionWithInvalidExtmap) {
2833 bool encrypted = GetParam();
2834 TestDeserializeExtmap(true, true, encrypted);
2802 } 2835 }
2803 2836
2837 INSTANTIATE_TEST_CASE_P(Encrypted,
2838 WebRtcSdpExtmapTest,
2839 ::testing::Values(false, true));
2840
2804 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) { 2841 TEST_F(WebRtcSdpTest, DeserializeSessionDescriptionWithoutEndLineBreak) {
2805 JsepSessionDescription jdesc(kDummyString); 2842 JsepSessionDescription jdesc(kDummyString);
2806 std::string sdp = kSdpFullString; 2843 std::string sdp = kSdpFullString;
2807 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end. 2844 sdp = sdp.substr(0, sdp.size() - 2); // Remove \r\n at the end.
2808 // Deserialize 2845 // Deserialize
2809 SdpParseError error; 2846 SdpParseError error;
2810 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error)); 2847 EXPECT_FALSE(webrtc::SdpDeserialize(sdp, &jdesc, &error));
2811 const std::string lastline = "a=ssrc:3 label:video_track_id_1"; 2848 const std::string lastline = "a=ssrc:3 label:video_track_id_1";
2812 EXPECT_EQ(lastline, error.line); 2849 EXPECT_EQ(lastline, error.line);
2813 EXPECT_EQ("Invalid SDP line.", error.description); 2850 EXPECT_EQ("Invalid SDP line.", error.description);
(...skipping 683 matching lines...) Expand 10 before | Expand all | Expand 10 after
3497 "s=-\r\n" 3534 "s=-\r\n"
3498 "t=0 0\r\n" 3535 "t=0 0\r\n"
3499 "m=audio 9 RTP/SAVPF 111\r\n" 3536 "m=audio 9 RTP/SAVPF 111\r\n"
3500 "c=IN IP4 0.0.0.0\r\n" 3537 "c=IN IP4 0.0.0.0\r\n"
3501 "a=rtpmap:111 opus/48000/2\r\n" 3538 "a=rtpmap:111 opus/48000/2\r\n"
3502 "a=msid: track_id\r\n"; 3539 "a=msid: track_id\r\n";
3503 3540
3504 JsepSessionDescription jdesc_output(kDummyString); 3541 JsepSessionDescription jdesc_output(kDummyString);
3505 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output)); 3542 EXPECT_FALSE(SdpDeserialize(kSdpWithMissingStreamId, &jdesc_output));
3506 } 3543 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698