| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2016 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 |
| 11 #include "webrtc/p2p/quic/quictransportchannel.h" | 11 #include "webrtc/p2p/quic/quictransportchannel.h" |
| 12 | 12 |
| 13 #include <set> | 13 #include <set> |
| 14 #include <string> | 14 #include <string> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "webrtc/base/common.h" | 17 #include "webrtc/base/common.h" |
| 18 #include "webrtc/base/gunit.h" | 18 #include "webrtc/base/gunit.h" |
| 19 #include "webrtc/base/scoped_ptr.h" | 19 #include "webrtc/base/scoped_ptr.h" |
| 20 #include "webrtc/base/sslfingerprint.h" |
| 20 #include "webrtc/base/sslidentity.h" | 21 #include "webrtc/base/sslidentity.h" |
| 21 #include "webrtc/p2p/base/faketransportcontroller.h" | 22 #include "webrtc/p2p/base/faketransportcontroller.h" |
| 22 | 23 |
| 23 using cricket::ConnectionRole; | 24 using cricket::ConnectionRole; |
| 24 using cricket::IceRole; | 25 using cricket::IceRole; |
| 25 using cricket::QuicTransportChannel; | 26 using cricket::QuicTransportChannel; |
| 26 using cricket::TransportChannel; | 27 using cricket::TransportChannel; |
| 27 using cricket::TransportDescription; | 28 using cricket::TransportDescription; |
| 28 | 29 |
| 29 // Timeout in milliseconds for asynchronous operations in unit tests. | 30 // Timeout in milliseconds for asynchronous operations in unit tests. |
| 30 static const int kTimeoutMs = 1000; | 31 static const int kTimeoutMs = 1000; |
| 31 | 32 |
| 32 // Export keying material parameters. | 33 // Export keying material parameters. |
| 33 static const char kExporterLabel[] = "label"; | 34 static const char kExporterLabel[] = "label"; |
| 34 static const uint8_t kExporterContext[] = "context"; | 35 static const uint8_t kExporterContext[] = "context"; |
| 35 static const size_t kExporterContextLength = sizeof(kExporterContext); | 36 static const size_t kExporterContextLength = sizeof(kExporterContext); |
| 36 static const size_t kOutputKeyLength = 20; | 37 static const size_t kOutputKeyLength = 20; |
| 37 | 38 |
| 38 // Packet size for SRTP. | 39 // Packet size for SRTP. |
| 39 static const size_t kPacketSize = 100; | 40 static const size_t kPacketSize = 100; |
| 40 | 41 |
| 41 // Indicates ICE channel has no write error. | 42 // Indicates ICE channel has no write error. |
| 42 static const int kNoWriteError = 0; | 43 static const int kNoWriteError = 0; |
| 43 | 44 |
| 44 // ICE parameters. | 45 // ICE parameters. |
| 45 static const char kIceUfrag[] = "TESTICEUFRAG0001"; | 46 static const char kIceUfrag1[] = "TESTICEUFRAG0001"; |
| 46 static const char kIcePwd[] = "TESTICEPWD00000000000001"; | 47 static const char kIcePwd1[] = "TESTICEPWD00000000000001"; |
| 48 static const char kIceUfrag2[] = "TESTICEUFRAG0002"; |
| 49 static const char kIcePwd2[] = "TESTICEPWD00000000000002"; |
| 47 | 50 |
| 48 // QUIC packet parameters. | 51 // QUIC packet parameters. |
| 49 static const net::IPAddress kIpAddress(0, 0, 0, 0); | 52 static const net::IPAddress kIpAddress(0, 0, 0, 0); |
| 50 static const net::IPEndPoint kIpEndpoint(kIpAddress, 0); | 53 static const net::IPEndPoint kIpEndpoint(kIpAddress, 0); |
| 51 | 54 |
| 52 // Detects incoming RTP packets. | 55 // Detects incoming RTP packets. |
| 53 static bool IsRtpLeadByte(uint8_t b) { | 56 static bool IsRtpLeadByte(uint8_t b) { |
| 54 return (b & 0xC0) == 0x80; | 57 return (b & 0xC0) == 0x80; |
| 55 } | 58 } |
| 56 | 59 |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 // Generates ICE credentials and passes them to |quic_channel_|. | 121 // Generates ICE credentials and passes them to |quic_channel_|. |
| 119 void SetIceParameters(IceRole local_ice_role, | 122 void SetIceParameters(IceRole local_ice_role, |
| 120 ConnectionRole local_connection_role, | 123 ConnectionRole local_connection_role, |
| 121 ConnectionRole remote_connection_role, | 124 ConnectionRole remote_connection_role, |
| 122 rtc::SSLFingerprint* remote_fingerprint) { | 125 rtc::SSLFingerprint* remote_fingerprint) { |
| 123 quic_channel_.SetIceRole(local_ice_role); | 126 quic_channel_.SetIceRole(local_ice_role); |
| 124 quic_channel_.SetIceTiebreaker( | 127 quic_channel_.SetIceTiebreaker( |
| 125 (local_ice_role == cricket::ICEROLE_CONTROLLING) ? 1 : 2); | 128 (local_ice_role == cricket::ICEROLE_CONTROLLING) ? 1 : 2); |
| 126 | 129 |
| 127 TransportDescription local_desc( | 130 TransportDescription local_desc( |
| 128 std::vector<std::string>(), kIceUfrag, kIcePwd, cricket::ICEMODE_FULL, | 131 std::vector<std::string>(), kIceUfrag1, kIcePwd1, cricket::ICEMODE_FULL, |
| 129 local_connection_role, local_fingerprint_.get()); | 132 local_connection_role, local_fingerprint_.get()); |
| 130 TransportDescription remote_desc( | 133 TransportDescription remote_desc( |
| 131 std::vector<std::string>(), kIceUfrag, kIcePwd, cricket::ICEMODE_FULL, | 134 std::vector<std::string>(), kIceUfrag1, kIcePwd1, cricket::ICEMODE_FULL, |
| 132 remote_connection_role, remote_fingerprint); | 135 remote_connection_role, remote_fingerprint); |
| 133 | 136 |
| 134 quic_channel_.SetIceCredentials(local_desc.ice_ufrag, local_desc.ice_pwd); | 137 quic_channel_.SetIceCredentials(local_desc.ice_ufrag, local_desc.ice_pwd); |
| 135 quic_channel_.SetRemoteIceCredentials(remote_desc.ice_ufrag, | 138 quic_channel_.SetRemoteIceCredentials(remote_desc.ice_ufrag, |
| 136 remote_desc.ice_pwd); | 139 remote_desc.ice_pwd); |
| 137 } | 140 } |
| 138 | 141 |
| 139 // Creates fingerprint from certificate. | 142 // Creates fingerprint from certificate. |
| 140 rtc::SSLFingerprint* CreateFingerprint(rtc::RTCCertificate* cert) { | 143 rtc::SSLFingerprint* CreateFingerprint(rtc::RTCCertificate* cert) { |
| 141 std::string digest_algorithm; | 144 std::string digest_algorithm; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 }; | 294 }; |
| 292 | 295 |
| 293 // Test that the QUIC channel passes ICE parameters to the underlying ICE | 296 // Test that the QUIC channel passes ICE parameters to the underlying ICE |
| 294 // channel. | 297 // channel. |
| 295 TEST_F(QuicTransportChannelTest, ChannelSetupIce) { | 298 TEST_F(QuicTransportChannelTest, ChannelSetupIce) { |
| 296 SetIceAndCryptoParameters(rtc::SSL_CLIENT, rtc::SSL_SERVER); | 299 SetIceAndCryptoParameters(rtc::SSL_CLIENT, rtc::SSL_SERVER); |
| 297 FailableTransportChannel* channel1 = peer1_.ice_channel(); | 300 FailableTransportChannel* channel1 = peer1_.ice_channel(); |
| 298 FailableTransportChannel* channel2 = peer2_.ice_channel(); | 301 FailableTransportChannel* channel2 = peer2_.ice_channel(); |
| 299 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, channel1->GetIceRole()); | 302 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, channel1->GetIceRole()); |
| 300 EXPECT_EQ(2u, channel1->IceTiebreaker()); | 303 EXPECT_EQ(2u, channel1->IceTiebreaker()); |
| 301 EXPECT_EQ(kIceUfrag, channel1->ice_ufrag()); | 304 EXPECT_EQ(kIceUfrag1, channel1->ice_ufrag()); |
| 302 EXPECT_EQ(kIcePwd, channel1->ice_pwd()); | 305 EXPECT_EQ(kIcePwd1, channel1->ice_pwd()); |
| 303 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel2->GetIceRole()); | 306 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel2->GetIceRole()); |
| 304 EXPECT_EQ(1u, channel2->IceTiebreaker()); | 307 EXPECT_EQ(1u, channel2->IceTiebreaker()); |
| 305 } | 308 } |
| 306 | 309 |
| 307 // Test that export keying material generates identical keys for both peers | 310 // Test that export keying material generates identical keys for both peers |
| 308 // after the QUIC handshake. | 311 // after the QUIC handshake. |
| 309 TEST_F(QuicTransportChannelTest, ExportKeyingMaterial) { | 312 TEST_F(QuicTransportChannelTest, ExportKeyingMaterial) { |
| 310 Connect(); | 313 Connect(); |
| 311 ASSERT_TRUE_WAIT(quic_connected(), kTimeoutMs); | 314 ASSERT_TRUE_WAIT(quic_connected(), kTimeoutMs); |
| 312 uint8_t key1[kOutputKeyLength]; | 315 uint8_t key1[kOutputKeyLength]; |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 479 | 482 |
| 480 // Test that if the ICE channel becomes receiving before the QUIC channel is | 483 // Test that if the ICE channel becomes receiving before the QUIC channel is |
| 481 // connected, then the QUIC channel becomes receiving. | 484 // connected, then the QUIC channel becomes receiving. |
| 482 TEST_F(QuicTransportChannelTest, IceReceivingBeforeConnected) { | 485 TEST_F(QuicTransportChannelTest, IceReceivingBeforeConnected) { |
| 483 Connect(); | 486 Connect(); |
| 484 peer1_.ice_channel()->SetReceiving(true); | 487 peer1_.ice_channel()->SetReceiving(true); |
| 485 ASSERT_TRUE(peer1_.ice_channel()->receiving()); | 488 ASSERT_TRUE(peer1_.ice_channel()->receiving()); |
| 486 ASSERT_TRUE_WAIT(quic_connected(), kTimeoutMs); | 489 ASSERT_TRUE_WAIT(quic_connected(), kTimeoutMs); |
| 487 EXPECT_TRUE(peer1_.quic_channel()->receiving()); | 490 EXPECT_TRUE(peer1_.quic_channel()->receiving()); |
| 488 } | 491 } |
| 492 |
| 493 // Test that the Transport base class applies local and remote descriptions to |
| 494 // the QUIC channel. |
| 495 TEST_F(QuicTransportChannelTest, SetLocalAndRemoteTransportDescription) { |
| 496 QuicTransportChannel* quic_channel = peer1_.quic_channel(); |
| 497 // Set the local description. |
| 498 rtc::SSLFingerprint* local_fingerprint = peer1_.local_fingerprint().get(); |
| 499 TransportDescription local_desc( |
| 500 std::vector<std::string>(), kIceUfrag1, kIcePwd1, cricket::ICEMODE_FULL, |
| 501 cricket::CONNECTIONROLE_ACTPASS, local_fingerprint); |
| 502 ASSERT_TRUE(quic_channel->SetLocalTransportDescription( |
| 503 local_desc, cricket::CA_OFFER, nullptr)); |
| 504 const TransportDescription* transport_local_desc = |
| 505 quic_channel->local_description_for_test(); |
| 506 EXPECT_EQ(kIceUfrag1, transport_local_desc->ice_ufrag); |
| 507 EXPECT_EQ(kIcePwd1, transport_local_desc->ice_pwd); |
| 508 EXPECT_EQ(*local_fingerprint, *transport_local_desc->identity_fingerprint); |
| 509 // NegotiateTransportDescription was not called yet. The SSL role should |
| 510 // not be set and neither should the remote fingerprint. |
| 511 rtc::scoped_ptr<rtc::SSLRole> role(new rtc::SSLRole()); |
| 512 EXPECT_FALSE(quic_channel->GetSslRole(role.get())); |
| 513 // Set the remote description. |
| 514 rtc::SSLFingerprint* remote_fingerprint = peer2_.local_fingerprint().get(); |
| 515 TransportDescription remote_desc( |
| 516 std::vector<std::string>(), kIceUfrag2, kIcePwd2, cricket::ICEMODE_FULL, |
| 517 cricket::CONNECTIONROLE_PASSIVE, remote_fingerprint); |
| 518 ASSERT_TRUE(quic_channel->SetRemoteTransportDescription( |
| 519 remote_desc, cricket::CA_ANSWER, nullptr)); |
| 520 const TransportDescription* transport_remote_desc = |
| 521 quic_channel->remote_description_for_test(); |
| 522 EXPECT_EQ(kIceUfrag2, transport_remote_desc->ice_ufrag); |
| 523 EXPECT_EQ(kIcePwd2, transport_remote_desc->ice_pwd); |
| 524 EXPECT_EQ(*remote_fingerprint, *transport_remote_desc->identity_fingerprint); |
| 525 // NegotiateTransportDescription was called because the |
| 526 // transport description was an ANSWER. The SSL role should be set. |
| 527 ASSERT_TRUE(quic_channel->GetSslRole(role.get())); |
| 528 // SSL role should be client because the remote description is an ANSWER. |
| 529 EXPECT_EQ(*role, rtc::SSL_CLIENT); |
| 530 } |
| OLD | NEW |