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

Side by Side Diff: talk/app/webrtc/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: Updates after feedback from Peter Created 5 years 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 * libjingle 2 * libjingle
3 * Copyright 2012 Google Inc. 3 * Copyright 2012 Google Inc.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met: 6 * modification, are permitted provided that the following conditions are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright notice, 8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer. 9 * this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright notice, 10 * 2. Redistributions in binary form must reproduce the above copyright notice,
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 static const char kAudioTrackLabelBase[] = "audio_track"; 108 static const char kAudioTrackLabelBase[] = "audio_track";
109 static const char kDataChannelLabel[] = "data_channel"; 109 static const char kDataChannelLabel[] = "data_channel";
110 110
111 // Disable for TSan v2, see 111 // Disable for TSan v2, see
112 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. 112 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details.
113 // This declaration is also #ifdef'd as it causes unused-variable errors. 113 // This declaration is also #ifdef'd as it causes unused-variable errors.
114 #if !defined(THREAD_SANITIZER) 114 #if !defined(THREAD_SANITIZER)
115 // SRTP cipher name negotiated by the tests. This must be updated if the 115 // SRTP cipher name negotiated by the tests. This must be updated if the
116 // default changes. 116 // default changes.
117 static const int kDefaultSrtpCryptoSuite = rtc::SRTP_AES128_CM_SHA1_32; 117 static const int kDefaultSrtpCryptoSuite = rtc::SRTP_AES128_CM_SHA1_32;
118 static const int kDefaultSrtpCryptoSuiteGcm = rtc::SRTP_AEAD_AES_256_GCM;
118 #endif 119 #endif
119 120
120 static void RemoveLinesFromSdp(const std::string& line_start, 121 static void RemoveLinesFromSdp(const std::string& line_start,
121 std::string* sdp) { 122 std::string* sdp) {
122 const char kSdpLineEnd[] = "\r\n"; 123 const char kSdpLineEnd[] = "\r\n";
123 size_t ssrc_pos = 0; 124 size_t ssrc_pos = 0;
124 while ((ssrc_pos = sdp->find(line_start, ssrc_pos)) != 125 while ((ssrc_pos = sdp->find(line_start, ssrc_pos)) !=
125 std::string::npos) { 126 std::string::npos) {
126 size_t end_ssrc = sdp->find(kSdpLineEnd, ssrc_pos); 127 size_t end_ssrc = sdp->find(kSdpLineEnd, ssrc_pos);
127 sdp->erase(ssrc_pos, end_ssrc - ssrc_pos + strlen(kSdpLineEnd)); 128 sdp->erase(ssrc_pos, end_ssrc - ssrc_pos + strlen(kSdpLineEnd));
(...skipping 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after
1129 1130
1130 // Set the |receiving_client_| to the |client| passed in and return the 1131 // Set the |receiving_client_| to the |client| passed in and return the
1131 // original |receiving_client_|. 1132 // original |receiving_client_|.
1132 PeerConnectionTestClient* set_receiving_client( 1133 PeerConnectionTestClient* set_receiving_client(
1133 PeerConnectionTestClient* client) { 1134 PeerConnectionTestClient* client) {
1134 PeerConnectionTestClient* old = receiving_client_.release(); 1135 PeerConnectionTestClient* old = receiving_client_.release();
1135 receiving_client_.reset(client); 1136 receiving_client_.reset(client);
1136 return old; 1137 return old;
1137 } 1138 }
1138 1139
1140 void TestGcmNegotiation(bool local_gcm_enabled, bool remote_gcm_enabled,
1141 int expected_cipher_suite) {
1142 PeerConnectionFactory::Options init_options;
1143 init_options.enable_gcm_crypto_suites = local_gcm_enabled;
1144 PeerConnectionFactory::Options recv_options;
1145 recv_options.enable_gcm_crypto_suites = remote_gcm_enabled;
1146 ASSERT_TRUE(
1147 CreateTestClients(nullptr, &init_options, nullptr, &recv_options));
1148 rtc::scoped_refptr<webrtc::FakeMetricsObserver>
1149 init_observer =
1150 new rtc::RefCountedObject<webrtc::FakeMetricsObserver>();
1151 initializing_client()->pc()->RegisterUMAObserver(init_observer);
1152 LocalP2PTest();
1153
1154 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(expected_cipher_suite),
1155 initializing_client()->GetSrtpCipherStats(),
1156 kMaxWaitForStatsMs);
1157 EXPECT_EQ(1,
1158 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1159 expected_cipher_suite));
1160 }
1161
1139 private: 1162 private:
1140 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; 1163 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_;
1141 rtc::scoped_ptr<rtc::VirtualSocketServer> ss_; 1164 rtc::scoped_ptr<rtc::VirtualSocketServer> ss_;
1142 rtc::SocketServerScope ss_scope_; 1165 rtc::SocketServerScope ss_scope_;
1143 rtc::scoped_ptr<PeerConnectionTestClient> initiating_client_; 1166 rtc::scoped_ptr<PeerConnectionTestClient> initiating_client_;
1144 rtc::scoped_ptr<PeerConnectionTestClient> receiving_client_; 1167 rtc::scoped_ptr<PeerConnectionTestClient> receiving_client_;
1145 }; 1168 };
1146 1169
1147 // Disable for TSan v2, see 1170 // Disable for TSan v2, see
1148 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. 1171 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details.
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
1523 rtc::SSL_PROTOCOL_DTLS_10, rtc::KT_DEFAULT))); 1546 rtc::SSL_PROTOCOL_DTLS_10, rtc::KT_DEFAULT)));
1524 1547
1525 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), 1548 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite),
1526 initializing_client()->GetSrtpCipherStats(), 1549 initializing_client()->GetSrtpCipherStats(),
1527 kMaxWaitForStatsMs); 1550 kMaxWaitForStatsMs);
1528 EXPECT_EQ(1, 1551 EXPECT_EQ(1,
1529 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, 1552 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher,
1530 kDefaultSrtpCryptoSuite)); 1553 kDefaultSrtpCryptoSuite));
1531 } 1554 }
1532 1555
1556 // Test that a non-GCM cipher is used if both sides only support non-GCM.
1557 TEST_F(P2PTestConductor, GetGcmNone) {
1558 TestGcmNegotiation(false, false, kDefaultSrtpCryptoSuite);
1559 }
1560
1561 // Test that a GCM cipher is used if both ends support it.
1562 TEST_F(P2PTestConductor, GetGcmBoth) {
1563 TestGcmNegotiation(true, true, kDefaultSrtpCryptoSuiteGcm);
1564 }
1565
1566 // Test that a non-GCM cipher is used if the initator supports GCM and the
1567 // received supports non-GCM.
1568 TEST_F(P2PTestConductor, GetGcmInit) {
1569 TestGcmNegotiation(true, false, kDefaultSrtpCryptoSuite);
1570 }
1571
1572 // Test that a non-GCM cipher is used if the initator supports non-GCM and the
1573 // received supports GCM.
1574 TEST_F(P2PTestConductor, GetGcmRecv) {
1575 TestGcmNegotiation(false, true, kDefaultSrtpCryptoSuite);
1576 }
1577
1533 // This test sets up a call between two parties with audio, video and an RTP 1578 // This test sets up a call between two parties with audio, video and an RTP
1534 // data channel. 1579 // data channel.
1535 TEST_F(P2PTestConductor, LocalP2PTestRtpDataChannel) { 1580 TEST_F(P2PTestConductor, LocalP2PTestRtpDataChannel) {
1536 FakeConstraints setup_constraints; 1581 FakeConstraints setup_constraints;
1537 setup_constraints.SetAllowRtpDataChannels(); 1582 setup_constraints.SetAllowRtpDataChannels();
1538 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); 1583 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints));
1539 initializing_client()->CreateDataChannel(); 1584 initializing_client()->CreateDataChannel();
1540 LocalP2PTest(); 1585 LocalP2PTest();
1541 ASSERT_TRUE(initializing_client()->data_channel() != nullptr); 1586 ASSERT_TRUE(initializing_client()->data_channel() != nullptr);
1542 ASSERT_TRUE(receiving_client()->data_channel() != nullptr); 1587 ASSERT_TRUE(receiving_client()->data_channel() != nullptr);
(...skipping 415 matching lines...) Expand 10 before | Expand all | Expand 10 after
1958 server.urls.push_back("stun:hostname"); 2003 server.urls.push_back("stun:hostname");
1959 server.urls.push_back("turn:hostname"); 2004 server.urls.push_back("turn:hostname");
1960 servers.push_back(server); 2005 servers.push_back(server);
1961 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_configurations_, 2006 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_configurations_,
1962 &turn_configurations_)); 2007 &turn_configurations_));
1963 EXPECT_EQ(1U, stun_configurations_.size()); 2008 EXPECT_EQ(1U, stun_configurations_.size());
1964 EXPECT_EQ(1U, turn_configurations_.size()); 2009 EXPECT_EQ(1U, turn_configurations_.size());
1965 } 2010 }
1966 2011
1967 #endif // if !defined(THREAD_SANITIZER) 2012 #endif // if !defined(THREAD_SANITIZER)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698