| OLD | NEW |
| 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 enum Flags { NF_REOFFER = 0x1, NF_EXPECT_FAILURE = 0x2 }; | 44 enum Flags { NF_REOFFER = 0x1, NF_EXPECT_FAILURE = 0x2 }; |
| 45 | 45 |
| 46 class DtlsTestClient : public sigslot::has_slots<> { | 46 class DtlsTestClient : public sigslot::has_slots<> { |
| 47 public: | 47 public: |
| 48 DtlsTestClient(const std::string& name, | 48 DtlsTestClient(const std::string& name, |
| 49 rtc::Thread* signaling_thread, | 49 rtc::Thread* signaling_thread, |
| 50 rtc::Thread* worker_thread) : | 50 rtc::Thread* worker_thread) : |
| 51 name_(name), | 51 name_(name), |
| 52 signaling_thread_(signaling_thread), | 52 signaling_thread_(signaling_thread), |
| 53 worker_thread_(worker_thread), | 53 worker_thread_(worker_thread), |
| 54 protocol_(cricket::ICEPROTO_GOOGLE), | |
| 55 packet_size_(0), | 54 packet_size_(0), |
| 56 use_dtls_srtp_(false), | 55 use_dtls_srtp_(false), |
| 57 ssl_max_version_(rtc::SSL_PROTOCOL_DTLS_10), | 56 ssl_max_version_(rtc::SSL_PROTOCOL_DTLS_10), |
| 58 negotiated_dtls_(false), | 57 negotiated_dtls_(false), |
| 59 received_dtls_client_hello_(false), | 58 received_dtls_client_hello_(false), |
| 60 received_dtls_server_hello_(false) { | 59 received_dtls_server_hello_(false) { |
| 61 } | 60 } |
| 62 void SetIceProtocol(cricket::TransportProtocol proto) { | |
| 63 protocol_ = proto; | |
| 64 } | |
| 65 void CreateIdentity(rtc::KeyType key_type) { | 61 void CreateIdentity(rtc::KeyType key_type) { |
| 66 identity_.reset(rtc::SSLIdentity::Generate(name_, key_type)); | 62 identity_.reset(rtc::SSLIdentity::Generate(name_, key_type)); |
| 67 } | 63 } |
| 68 rtc::SSLIdentity* identity() { return identity_.get(); } | 64 rtc::SSLIdentity* identity() { return identity_.get(); } |
| 69 void SetupSrtp() { | 65 void SetupSrtp() { |
| 70 ASSERT(identity_.get() != NULL); | 66 ASSERT(identity_.get() != NULL); |
| 71 use_dtls_srtp_ = true; | 67 use_dtls_srtp_ = true; |
| 72 } | 68 } |
| 73 void SetupMaxProtocolVersion(rtc::SSLProtocolVersion version) { | 69 void SetupMaxProtocolVersion(rtc::SSLProtocolVersion version) { |
| 74 ASSERT(transport_.get() == NULL); | 70 ASSERT(transport_.get() == NULL); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 if (use_dtls_srtp_ && !(flags & NF_REOFFER)) { | 151 if (use_dtls_srtp_ && !(flags & NF_REOFFER)) { |
| 156 // SRTP ciphers will be set only in the beginning. | 152 // SRTP ciphers will be set only in the beginning. |
| 157 for (std::vector<cricket::DtlsTransportChannelWrapper*>::iterator it = | 153 for (std::vector<cricket::DtlsTransportChannelWrapper*>::iterator it = |
| 158 channels_.begin(); it != channels_.end(); ++it) { | 154 channels_.begin(); it != channels_.end(); ++it) { |
| 159 std::vector<std::string> ciphers; | 155 std::vector<std::string> ciphers; |
| 160 ciphers.push_back(AES_CM_128_HMAC_SHA1_80); | 156 ciphers.push_back(AES_CM_128_HMAC_SHA1_80); |
| 161 ASSERT_TRUE((*it)->SetSrtpCiphers(ciphers)); | 157 ASSERT_TRUE((*it)->SetSrtpCiphers(ciphers)); |
| 162 } | 158 } |
| 163 } | 159 } |
| 164 | 160 |
| 165 std::string transport_type = (protocol_ == cricket::ICEPROTO_GOOGLE) ? | |
| 166 cricket::NS_GINGLE_P2P : cricket::NS_JINGLE_ICE_UDP; | |
| 167 cricket::TransportDescription local_desc( | 161 cricket::TransportDescription local_desc( |
| 168 transport_type, std::vector<std::string>(), kIceUfrag1, kIcePwd1, | 162 std::vector<std::string>(), kIceUfrag1, kIcePwd1, |
| 169 cricket::ICEMODE_FULL, local_role, | 163 cricket::ICEMODE_FULL, local_role, |
| 170 // If remote if the offerer and has no DTLS support, answer will be | 164 // If remote if the offerer and has no DTLS support, answer will be |
| 171 // without any fingerprint. | 165 // without any fingerprint. |
| 172 (action == cricket::CA_ANSWER && !remote_identity) ? | 166 (action == cricket::CA_ANSWER && !remote_identity) ? |
| 173 NULL : local_fingerprint.get(), | 167 NULL : local_fingerprint.get(), |
| 174 cricket::Candidates()); | 168 cricket::Candidates()); |
| 175 | 169 |
| 176 cricket::TransportDescription remote_desc( | 170 cricket::TransportDescription remote_desc( |
| 177 transport_type, std::vector<std::string>(), kIceUfrag1, kIcePwd1, | 171 std::vector<std::string>(), kIceUfrag1, kIcePwd1, |
| 178 cricket::ICEMODE_FULL, remote_role, remote_fingerprint.get(), | 172 cricket::ICEMODE_FULL, remote_role, remote_fingerprint.get(), |
| 179 cricket::Candidates()); | 173 cricket::Candidates()); |
| 180 | 174 |
| 181 bool expect_success = (flags & NF_EXPECT_FAILURE) ? false : true; | 175 bool expect_success = (flags & NF_EXPECT_FAILURE) ? false : true; |
| 182 // If |expect_success| is false, expect SRTD or SLTD to fail when | 176 // If |expect_success| is false, expect SRTD or SLTD to fail when |
| 183 // content action is CA_ANSWER. | 177 // content action is CA_ANSWER. |
| 184 if (action == cricket::CA_OFFER) { | 178 if (action == cricket::CA_OFFER) { |
| 185 ASSERT_TRUE(transport_->SetLocalTransportDescription( | 179 ASSERT_TRUE(transport_->SetLocalTransportDescription( |
| 186 local_desc, cricket::CA_OFFER, NULL)); | 180 local_desc, cricket::CA_OFFER, NULL)); |
| 187 ASSERT_EQ(expect_success, transport_->SetRemoteTransportDescription( | 181 ASSERT_EQ(expect_success, transport_->SetRemoteTransportDescription( |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 ASSERT_TRUE(VerifyPacket(data, size, NULL)); | 363 ASSERT_TRUE(VerifyPacket(data, size, NULL)); |
| 370 } | 364 } |
| 371 } | 365 } |
| 372 } | 366 } |
| 373 } | 367 } |
| 374 | 368 |
| 375 private: | 369 private: |
| 376 std::string name_; | 370 std::string name_; |
| 377 rtc::Thread* signaling_thread_; | 371 rtc::Thread* signaling_thread_; |
| 378 rtc::Thread* worker_thread_; | 372 rtc::Thread* worker_thread_; |
| 379 cricket::TransportProtocol protocol_; | |
| 380 rtc::scoped_ptr<rtc::SSLIdentity> identity_; | 373 rtc::scoped_ptr<rtc::SSLIdentity> identity_; |
| 381 rtc::scoped_ptr<cricket::FakeTransport> transport_; | 374 rtc::scoped_ptr<cricket::FakeTransport> transport_; |
| 382 std::vector<cricket::DtlsTransportChannelWrapper*> channels_; | 375 std::vector<cricket::DtlsTransportChannelWrapper*> channels_; |
| 383 size_t packet_size_; | 376 size_t packet_size_; |
| 384 std::set<int> received_; | 377 std::set<int> received_; |
| 385 bool use_dtls_srtp_; | 378 bool use_dtls_srtp_; |
| 386 rtc::SSLProtocolVersion ssl_max_version_; | 379 rtc::SSLProtocolVersion ssl_max_version_; |
| 387 bool negotiated_dtls_; | 380 bool negotiated_dtls_; |
| 388 bool received_dtls_client_hello_; | 381 bool received_dtls_client_hello_; |
| 389 bool received_dtls_server_hello_; | 382 bool received_dtls_server_hello_; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 542 DtlsTestClient client1_; | 535 DtlsTestClient client1_; |
| 543 DtlsTestClient client2_; | 536 DtlsTestClient client2_; |
| 544 int channel_ct_; | 537 int channel_ct_; |
| 545 bool use_dtls_; | 538 bool use_dtls_; |
| 546 bool use_dtls_srtp_; | 539 bool use_dtls_srtp_; |
| 547 rtc::SSLProtocolVersion ssl_expected_version_; | 540 rtc::SSLProtocolVersion ssl_expected_version_; |
| 548 }; | 541 }; |
| 549 | 542 |
| 550 // Test that transport negotiation of ICE, no DTLS works properly. | 543 // Test that transport negotiation of ICE, no DTLS works properly. |
| 551 TEST_F(DtlsTransportChannelTest, TestChannelSetupIce) { | 544 TEST_F(DtlsTransportChannelTest, TestChannelSetupIce) { |
| 552 client1_.SetIceProtocol(cricket::ICEPROTO_RFC5245); | |
| 553 client2_.SetIceProtocol(cricket::ICEPROTO_RFC5245); | |
| 554 Negotiate(); | 545 Negotiate(); |
| 555 cricket::FakeTransportChannel* channel1 = client1_.GetFakeChannel(0); | 546 cricket::FakeTransportChannel* channel1 = client1_.GetFakeChannel(0); |
| 556 cricket::FakeTransportChannel* channel2 = client2_.GetFakeChannel(0); | 547 cricket::FakeTransportChannel* channel2 = client2_.GetFakeChannel(0); |
| 557 ASSERT_TRUE(channel1 != NULL); | |
| 558 ASSERT_TRUE(channel2 != NULL); | |
| 559 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel1->GetIceRole()); | |
| 560 EXPECT_EQ(1U, channel1->IceTiebreaker()); | |
| 561 EXPECT_EQ(cricket::ICEPROTO_RFC5245, channel1->protocol()); | |
| 562 EXPECT_EQ(kIceUfrag1, channel1->ice_ufrag()); | |
| 563 EXPECT_EQ(kIcePwd1, channel1->ice_pwd()); | |
| 564 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, channel2->GetIceRole()); | |
| 565 EXPECT_EQ(2U, channel2->IceTiebreaker()); | |
| 566 EXPECT_EQ(cricket::ICEPROTO_RFC5245, channel2->protocol()); | |
| 567 } | |
| 568 | |
| 569 // Test that transport negotiation of GICE, no DTLS works properly. | |
| 570 TEST_F(DtlsTransportChannelTest, TestChannelSetupGice) { | |
| 571 client1_.SetIceProtocol(cricket::ICEPROTO_GOOGLE); | |
| 572 client2_.SetIceProtocol(cricket::ICEPROTO_GOOGLE); | |
| 573 Negotiate(); | |
| 574 cricket::FakeTransportChannel* channel1 = client1_.GetFakeChannel(0); | |
| 575 cricket::FakeTransportChannel* channel2 = client2_.GetFakeChannel(0); | |
| 576 ASSERT_TRUE(channel1 != NULL); | 548 ASSERT_TRUE(channel1 != NULL); |
| 577 ASSERT_TRUE(channel2 != NULL); | 549 ASSERT_TRUE(channel2 != NULL); |
| 578 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel1->GetIceRole()); | 550 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel1->GetIceRole()); |
| 579 EXPECT_EQ(1U, channel1->IceTiebreaker()); | 551 EXPECT_EQ(1U, channel1->IceTiebreaker()); |
| 580 EXPECT_EQ(cricket::ICEPROTO_GOOGLE, channel1->protocol()); | |
| 581 EXPECT_EQ(kIceUfrag1, channel1->ice_ufrag()); | 552 EXPECT_EQ(kIceUfrag1, channel1->ice_ufrag()); |
| 582 EXPECT_EQ(kIcePwd1, channel1->ice_pwd()); | 553 EXPECT_EQ(kIcePwd1, channel1->ice_pwd()); |
| 583 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, channel2->GetIceRole()); | 554 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, channel2->GetIceRole()); |
| 584 EXPECT_EQ(2U, channel2->IceTiebreaker()); | 555 EXPECT_EQ(2U, channel2->IceTiebreaker()); |
| 585 EXPECT_EQ(cricket::ICEPROTO_GOOGLE, channel2->protocol()); | |
| 586 } | 556 } |
| 587 | 557 |
| 588 // Connect without DTLS, and transfer some data. | 558 // Connect without DTLS, and transfer some data. |
| 589 TEST_F(DtlsTransportChannelTest, TestTransfer) { | 559 TEST_F(DtlsTransportChannelTest, TestTransfer) { |
| 590 ASSERT_TRUE(Connect()); | 560 ASSERT_TRUE(Connect()); |
| 591 TestTransfer(0, 1000, 100, false); | 561 TestTransfer(0, 1000, 100, false); |
| 592 } | 562 } |
| 593 | 563 |
| 594 // Create two channels without DTLS, and transfer some data. | 564 // Create two channels without DTLS, and transfer some data. |
| 595 TEST_F(DtlsTransportChannelTest, TestTransferTwoChannels) { | 565 TEST_F(DtlsTransportChannelTest, TestTransferTwoChannels) { |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 895 // Each side's remote certificate is the other side's local certificate. | 865 // Each side's remote certificate is the other side's local certificate. |
| 896 ASSERT_TRUE( | 866 ASSERT_TRUE( |
| 897 client1_.transport()->GetRemoteCertificate(remote_cert1.accept())); | 867 client1_.transport()->GetRemoteCertificate(remote_cert1.accept())); |
| 898 ASSERT_EQ(remote_cert1->ToPEMString(), | 868 ASSERT_EQ(remote_cert1->ToPEMString(), |
| 899 identity2->certificate().ToPEMString()); | 869 identity2->certificate().ToPEMString()); |
| 900 ASSERT_TRUE( | 870 ASSERT_TRUE( |
| 901 client2_.transport()->GetRemoteCertificate(remote_cert2.accept())); | 871 client2_.transport()->GetRemoteCertificate(remote_cert2.accept())); |
| 902 ASSERT_EQ(remote_cert2->ToPEMString(), | 872 ASSERT_EQ(remote_cert2->ToPEMString(), |
| 903 identity1->certificate().ToPEMString()); | 873 identity1->certificate().ToPEMString()); |
| 904 } | 874 } |
| OLD | NEW |