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

Side by Side Diff: webrtc/api/peerconnection_unittest.cc

Issue 1528843005: Add support for GCM cipher suites from RFC 7714. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Disable GCM if ENABLE_EXTERNAL_AUTH is defined. Created 4 years, 5 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
« no previous file with comments | « webrtc/api/peerconnection.cc ('k') | webrtc/api/peerconnectionfactory.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright 2012 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 static const char kAudioTrackLabelBase[] = "audio_track"; 93 static const char kAudioTrackLabelBase[] = "audio_track";
94 static const char kDataChannelLabel[] = "data_channel"; 94 static const char kDataChannelLabel[] = "data_channel";
95 95
96 // Disable for TSan v2, see 96 // Disable for TSan v2, see
97 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. 97 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details.
98 // This declaration is also #ifdef'd as it causes unused-variable errors. 98 // This declaration is also #ifdef'd as it causes unused-variable errors.
99 #if !defined(THREAD_SANITIZER) 99 #if !defined(THREAD_SANITIZER)
100 // SRTP cipher name negotiated by the tests. This must be updated if the 100 // SRTP cipher name negotiated by the tests. This must be updated if the
101 // default changes. 101 // default changes.
102 static const int kDefaultSrtpCryptoSuite = rtc::SRTP_AES128_CM_SHA1_32; 102 static const int kDefaultSrtpCryptoSuite = rtc::SRTP_AES128_CM_SHA1_32;
103 static const int kDefaultSrtpCryptoSuiteGcm = rtc::SRTP_AEAD_AES_256_GCM;
103 #endif 104 #endif
104 105
105 static void RemoveLinesFromSdp(const std::string& line_start, 106 static void RemoveLinesFromSdp(const std::string& line_start,
106 std::string* sdp) { 107 std::string* sdp) {
107 const char kSdpLineEnd[] = "\r\n"; 108 const char kSdpLineEnd[] = "\r\n";
108 size_t ssrc_pos = 0; 109 size_t ssrc_pos = 0;
109 while ((ssrc_pos = sdp->find(line_start, ssrc_pos)) != 110 while ((ssrc_pos = sdp->find(line_start, ssrc_pos)) !=
110 std::string::npos) { 111 std::string::npos) {
111 size_t end_ssrc = sdp->find(kSdpLineEnd, ssrc_pos); 112 size_t end_ssrc = sdp->find(kSdpLineEnd, ssrc_pos);
112 sdp->erase(ssrc_pos, end_ssrc - ssrc_pos + strlen(kSdpLineEnd)); 113 sdp->erase(ssrc_pos, end_ssrc - ssrc_pos + strlen(kSdpLineEnd));
(...skipping 1244 matching lines...) Expand 10 before | Expand all | Expand 10 after
1357 bool AllObserversReceived( 1358 bool AllObserversReceived(
1358 const std::vector<std::unique_ptr<MockRtpReceiverObserver>>& observers) { 1359 const std::vector<std::unique_ptr<MockRtpReceiverObserver>>& observers) {
1359 for (auto& observer : observers) { 1360 for (auto& observer : observers) {
1360 if (!observer->first_packet_received()) { 1361 if (!observer->first_packet_received()) {
1361 return false; 1362 return false;
1362 } 1363 }
1363 } 1364 }
1364 return true; 1365 return true;
1365 } 1366 }
1366 1367
1368 void TestGcmNegotiation(bool local_gcm_enabled, bool remote_gcm_enabled,
1369 int expected_cipher_suite) {
1370 PeerConnectionFactory::Options init_options;
1371 init_options.crypto_options.enable_gcm_crypto_suites = local_gcm_enabled;
1372 PeerConnectionFactory::Options recv_options;
1373 recv_options.crypto_options.enable_gcm_crypto_suites = remote_gcm_enabled;
1374 ASSERT_TRUE(
1375 CreateTestClients(nullptr, &init_options, nullptr, &recv_options));
1376 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1377 init_observer =
1378 new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1379 initializing_client()->pc()->RegisterUMAObserver(init_observer);
1380 LocalP2PTest();
1381
1382 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(expected_cipher_suite),
1383 initializing_client()->GetSrtpCipherStats(),
1384 kMaxWaitMs);
1385 EXPECT_EQ(1,
1386 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1387 expected_cipher_suite));
1388 }
1389
1367 private: 1390 private:
1368 // |ss_| is used by |network_thread_| so it must be destroyed later. 1391 // |ss_| is used by |network_thread_| so it must be destroyed later.
1369 std::unique_ptr<rtc::PhysicalSocketServer> pss_; 1392 std::unique_ptr<rtc::PhysicalSocketServer> pss_;
1370 std::unique_ptr<rtc::VirtualSocketServer> ss_; 1393 std::unique_ptr<rtc::VirtualSocketServer> ss_;
1371 // |network_thread_| and |worker_thread_| are used by both 1394 // |network_thread_| and |worker_thread_| are used by both
1372 // |initiating_client_| and |receiving_client_| so they must be destroyed 1395 // |initiating_client_| and |receiving_client_| so they must be destroyed
1373 // later. 1396 // later.
1374 std::unique_ptr<rtc::Thread> network_thread_; 1397 std::unique_ptr<rtc::Thread> network_thread_;
1375 std::unique_ptr<rtc::Thread> worker_thread_; 1398 std::unique_ptr<rtc::Thread> worker_thread_;
1376 std::unique_ptr<PeerConnectionTestClient> initiating_client_; 1399 std::unique_ptr<PeerConnectionTestClient> initiating_client_;
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
1807 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT), 1830 initializing_client()->GetDtlsCipherStats(), rtc::KT_DEFAULT),
1808 kMaxWaitForStatsMs); 1831 kMaxWaitForStatsMs);
1809 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), 1832 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
1810 initializing_client()->GetSrtpCipherStats(), 1833 initializing_client()->GetSrtpCipherStats(),
1811 kMaxWaitForStatsMs); 1834 kMaxWaitForStatsMs);
1812 EXPECT_EQ(1, 1835 EXPECT_EQ(1,
1813 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, 1836 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1814 kDefaultSrtpCryptoSuite)); 1837 kDefaultSrtpCryptoSuite));
1815 } 1838 }
1816 1839
1840 // Test that a non-GCM cipher is used if both sides only support non-GCM.
1841 TEST_F(P2PTestConductor, GetGcmNone) {
1842 TestGcmNegotiation(false, false, kDefaultSrtpCryptoSuite);
1843 }
1844
1845 // Test that a GCM cipher is used if both ends support it.
1846 TEST_F(P2PTestConductor, GetGcmBoth) {
1847 TestGcmNegotiation(true, true, kDefaultSrtpCryptoSuiteGcm);
1848 }
1849
1850 // Test that GCM isn't used if only the initiator supports it.
1851 TEST_F(P2PTestConductor, GetGcmInit) {
1852 TestGcmNegotiation(true, false, kDefaultSrtpCryptoSuite);
1853 }
1854
1855 // Test that GCM isn't used if only the receiver supports it.
1856 TEST_F(P2PTestConductor, GetGcmRecv) {
1857 TestGcmNegotiation(false, true, kDefaultSrtpCryptoSuite);
1858 }
1859
1817 // This test sets up a call between two parties with audio, video and an RTP 1860 // This test sets up a call between two parties with audio, video and an RTP
1818 // data channel. 1861 // data channel.
1819 TEST_F(P2PTestConductor, LocalP2PTestRtpDataChannel) { 1862 TEST_F(P2PTestConductor, LocalP2PTestRtpDataChannel) {
1820 FakeConstraints setup_constraints; 1863 FakeConstraints setup_constraints;
1821 setup_constraints.SetAllowRtpDataChannels(); 1864 setup_constraints.SetAllowRtpDataChannels();
1822 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); 1865 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1823 initializing_client()->CreateDataChannel(); 1866 initializing_client()->CreateDataChannel();
1824 LocalP2PTest(); 1867 LocalP2PTest();
1825 ASSERT_TRUE(initializing_client()->data_channel() != nullptr); 1868 ASSERT_TRUE(initializing_client()->data_channel() != nullptr);
1826 ASSERT_TRUE(receiving_client()->data_channel() != nullptr); 1869 ASSERT_TRUE(receiving_client()->data_channel() != nullptr);
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
2291 server.urls.push_back("turn:hostname2"); 2334 server.urls.push_back("turn:hostname2");
2292 servers.push_back(server); 2335 servers.push_back(server);
2293 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); 2336 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_));
2294 EXPECT_EQ(2U, turn_servers_.size()); 2337 EXPECT_EQ(2U, turn_servers_.size());
2295 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority); 2338 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority);
2296 } 2339 }
2297 2340
2298 #endif // if !defined(THREAD_SANITIZER) 2341 #endif // if !defined(THREAD_SANITIZER)
2299 2342
2300 } // namespace 2343 } // namespace
OLDNEW
« no previous file with comments | « webrtc/api/peerconnection.cc ('k') | webrtc/api/peerconnectionfactory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698