OLD | NEW |
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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 static const char kAudioTrackLabelBase[] = "audio_track"; | 109 static const char kAudioTrackLabelBase[] = "audio_track"; |
110 static const char kDataChannelLabel[] = "data_channel"; | 110 static const char kDataChannelLabel[] = "data_channel"; |
111 | 111 |
112 // Disable for TSan v2, see | 112 // Disable for TSan v2, see |
113 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. | 113 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. |
114 // This declaration is also #ifdef'd as it causes unused-variable errors. | 114 // This declaration is also #ifdef'd as it causes unused-variable errors. |
115 #if !defined(THREAD_SANITIZER) | 115 #if !defined(THREAD_SANITIZER) |
116 // SRTP cipher name negotiated by the tests. This must be updated if the | 116 // SRTP cipher name negotiated by the tests. This must be updated if the |
117 // default changes. | 117 // default changes. |
118 static const int kDefaultSrtpCryptoSuite = rtc::SRTP_AES128_CM_SHA1_32; | 118 static const int kDefaultSrtpCryptoSuite = rtc::SRTP_AES128_CM_SHA1_32; |
| 119 static const int kDefaultSrtpCryptoSuiteGcm = rtc::SRTP_AEAD_AES_256_GCM; |
119 #endif | 120 #endif |
120 | 121 |
121 static void RemoveLinesFromSdp(const std::string& line_start, | 122 static void RemoveLinesFromSdp(const std::string& line_start, |
122 std::string* sdp) { | 123 std::string* sdp) { |
123 const char kSdpLineEnd[] = "\r\n"; | 124 const char kSdpLineEnd[] = "\r\n"; |
124 size_t ssrc_pos = 0; | 125 size_t ssrc_pos = 0; |
125 while ((ssrc_pos = sdp->find(line_start, ssrc_pos)) != | 126 while ((ssrc_pos = sdp->find(line_start, ssrc_pos)) != |
126 std::string::npos) { | 127 std::string::npos) { |
127 size_t end_ssrc = sdp->find(kSdpLineEnd, ssrc_pos); | 128 size_t end_ssrc = sdp->find(kSdpLineEnd, ssrc_pos); |
128 sdp->erase(ssrc_pos, end_ssrc - ssrc_pos + strlen(kSdpLineEnd)); | 129 sdp->erase(ssrc_pos, end_ssrc - ssrc_pos + strlen(kSdpLineEnd)); |
(...skipping 1032 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1161 | 1162 |
1162 // Set the |receiving_client_| to the |client| passed in and return the | 1163 // Set the |receiving_client_| to the |client| passed in and return the |
1163 // original |receiving_client_|. | 1164 // original |receiving_client_|. |
1164 PeerConnectionTestClient* set_receiving_client( | 1165 PeerConnectionTestClient* set_receiving_client( |
1165 PeerConnectionTestClient* client) { | 1166 PeerConnectionTestClient* client) { |
1166 PeerConnectionTestClient* old = receiving_client_.release(); | 1167 PeerConnectionTestClient* old = receiving_client_.release(); |
1167 receiving_client_.reset(client); | 1168 receiving_client_.reset(client); |
1168 return old; | 1169 return old; |
1169 } | 1170 } |
1170 | 1171 |
| 1172 void TestGcmNegotiation(bool local_gcm_enabled, bool remote_gcm_enabled, |
| 1173 int expected_cipher_suite) { |
| 1174 PeerConnectionFactory::Options init_options; |
| 1175 init_options.crypto_options.enable_gcm_crypto_suites = local_gcm_enabled; |
| 1176 PeerConnectionFactory::Options recv_options; |
| 1177 recv_options.crypto_options.enable_gcm_crypto_suites = remote_gcm_enabled; |
| 1178 ASSERT_TRUE( |
| 1179 CreateTestClients(nullptr, &init_options, nullptr, &recv_options)); |
| 1180 rtc::scoped_refptr<webrtc::FakeMetricsObserver> |
| 1181 init_observer = |
| 1182 new rtc::RefCountedObject<webrtc::FakeMetricsObserver>(); |
| 1183 initializing_client()->pc()->RegisterUMAObserver(init_observer); |
| 1184 LocalP2PTest(); |
| 1185 |
| 1186 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(expected_cipher_suite), |
| 1187 initializing_client()->GetSrtpCipherStats(), |
| 1188 kMaxWaitForStatsMs); |
| 1189 EXPECT_EQ(1, |
| 1190 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, |
| 1191 expected_cipher_suite)); |
| 1192 } |
| 1193 |
1171 private: | 1194 private: |
1172 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; | 1195 rtc::scoped_ptr<rtc::PhysicalSocketServer> pss_; |
1173 rtc::scoped_ptr<rtc::VirtualSocketServer> ss_; | 1196 rtc::scoped_ptr<rtc::VirtualSocketServer> ss_; |
1174 rtc::SocketServerScope ss_scope_; | 1197 rtc::SocketServerScope ss_scope_; |
1175 rtc::scoped_ptr<PeerConnectionTestClient> initiating_client_; | 1198 rtc::scoped_ptr<PeerConnectionTestClient> initiating_client_; |
1176 rtc::scoped_ptr<PeerConnectionTestClient> receiving_client_; | 1199 rtc::scoped_ptr<PeerConnectionTestClient> receiving_client_; |
1177 }; | 1200 }; |
1178 | 1201 |
1179 // Disable for TSan v2, see | 1202 // Disable for TSan v2, see |
1180 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. | 1203 // https://code.google.com/p/webrtc/issues/detail?id=1205 for details. |
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1573 rtc::SSL_PROTOCOL_DTLS_10, rtc::KT_DEFAULT))); | 1596 rtc::SSL_PROTOCOL_DTLS_10, rtc::KT_DEFAULT))); |
1574 | 1597 |
1575 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), | 1598 EXPECT_EQ_WAIT(rtc::SrtpCryptoSuiteToName(kDefaultSrtpCryptoSuite), |
1576 initializing_client()->GetSrtpCipherStats(), | 1599 initializing_client()->GetSrtpCipherStats(), |
1577 kMaxWaitForStatsMs); | 1600 kMaxWaitForStatsMs); |
1578 EXPECT_EQ(1, | 1601 EXPECT_EQ(1, |
1579 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, | 1602 init_observer->GetEnumCounter(webrtc::kEnumCounterAudioSrtpCipher, |
1580 kDefaultSrtpCryptoSuite)); | 1603 kDefaultSrtpCryptoSuite)); |
1581 } | 1604 } |
1582 | 1605 |
| 1606 // Test that a non-GCM cipher is used if both sides only support non-GCM. |
| 1607 TEST_F(P2PTestConductor, GetGcmNone) { |
| 1608 TestGcmNegotiation(false, false, kDefaultSrtpCryptoSuite); |
| 1609 } |
| 1610 |
| 1611 // Test that a GCM cipher is used if both ends support it. |
| 1612 TEST_F(P2PTestConductor, GetGcmBoth) { |
| 1613 TestGcmNegotiation(true, true, kDefaultSrtpCryptoSuiteGcm); |
| 1614 } |
| 1615 |
| 1616 // Test that a non-GCM cipher is used if the initator supports GCM and the |
| 1617 // received supports non-GCM. |
| 1618 TEST_F(P2PTestConductor, GetGcmInit) { |
| 1619 TestGcmNegotiation(true, false, kDefaultSrtpCryptoSuite); |
| 1620 } |
| 1621 |
| 1622 // Test that a non-GCM cipher is used if the initator supports non-GCM and the |
| 1623 // received supports GCM. |
| 1624 TEST_F(P2PTestConductor, GetGcmRecv) { |
| 1625 TestGcmNegotiation(false, true, kDefaultSrtpCryptoSuite); |
| 1626 } |
| 1627 |
1583 // This test sets up a call between two parties with audio, video and an RTP | 1628 // This test sets up a call between two parties with audio, video and an RTP |
1584 // data channel. | 1629 // data channel. |
1585 TEST_F(P2PTestConductor, LocalP2PTestRtpDataChannel) { | 1630 TEST_F(P2PTestConductor, LocalP2PTestRtpDataChannel) { |
1586 FakeConstraints setup_constraints; | 1631 FakeConstraints setup_constraints; |
1587 setup_constraints.SetAllowRtpDataChannels(); | 1632 setup_constraints.SetAllowRtpDataChannels(); |
1588 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); | 1633 ASSERT_TRUE(CreateTestClients(&setup_constraints, &setup_constraints)); |
1589 initializing_client()->CreateDataChannel(); | 1634 initializing_client()->CreateDataChannel(); |
1590 LocalP2PTest(); | 1635 LocalP2PTest(); |
1591 ASSERT_TRUE(initializing_client()->data_channel() != nullptr); | 1636 ASSERT_TRUE(initializing_client()->data_channel() != nullptr); |
1592 ASSERT_TRUE(receiving_client()->data_channel() != nullptr); | 1637 ASSERT_TRUE(receiving_client()->data_channel() != nullptr); |
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2022 PeerConnectionInterface::IceServer server; | 2067 PeerConnectionInterface::IceServer server; |
2023 server.urls.push_back("turn:hostname"); | 2068 server.urls.push_back("turn:hostname"); |
2024 server.urls.push_back("turn:hostname2"); | 2069 server.urls.push_back("turn:hostname2"); |
2025 servers.push_back(server); | 2070 servers.push_back(server); |
2026 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); | 2071 EXPECT_TRUE(webrtc::ParseIceServers(servers, &stun_servers_, &turn_servers_)); |
2027 EXPECT_EQ(2U, turn_servers_.size()); | 2072 EXPECT_EQ(2U, turn_servers_.size()); |
2028 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority); | 2073 EXPECT_NE(turn_servers_[0].priority, turn_servers_[1].priority); |
2029 } | 2074 } |
2030 | 2075 |
2031 #endif // if !defined(THREAD_SANITIZER) | 2076 #endif // if !defined(THREAD_SANITIZER) |
OLD | NEW |