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), |
54 packet_size_(0), | 55 packet_size_(0), |
55 use_dtls_srtp_(false), | 56 use_dtls_srtp_(false), |
56 ssl_max_version_(rtc::SSL_PROTOCOL_DTLS_10), | 57 ssl_max_version_(rtc::SSL_PROTOCOL_DTLS_10), |
57 negotiated_dtls_(false), | 58 negotiated_dtls_(false), |
58 received_dtls_client_hello_(false), | 59 received_dtls_client_hello_(false), |
59 received_dtls_server_hello_(false) { | 60 received_dtls_server_hello_(false) { |
60 } | 61 } |
61 void CreateCertificate(rtc::KeyType key_type) { | 62 void CreateCertificate(rtc::KeyType key_type) { |
62 certificate_ = rtc::RTCCertificate::Create( | 63 certificate_ = rtc::RTCCertificate::Create( |
63 rtc::scoped_ptr<rtc::SSLIdentity>( | 64 rtc::scoped_ptr<rtc::SSLIdentity>( |
64 rtc::SSLIdentity::Generate(name_, key_type)).Pass()); | 65 rtc::SSLIdentity::Generate(name_, key_type)).Pass()); |
65 } | 66 } |
66 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate() { | 67 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate() { |
67 return certificate_; | 68 return certificate_; |
68 } | 69 } |
| 70 void SetIceProtocol(cricket::TransportProtocol proto) { |
| 71 protocol_ = proto; |
| 72 } |
69 void SetupSrtp() { | 73 void SetupSrtp() { |
70 ASSERT(certificate_); | 74 ASSERT(certificate_); |
71 use_dtls_srtp_ = true; | 75 use_dtls_srtp_ = true; |
72 } | 76 } |
73 void SetupMaxProtocolVersion(rtc::SSLProtocolVersion version) { | 77 void SetupMaxProtocolVersion(rtc::SSLProtocolVersion version) { |
74 ASSERT(transport_.get() == NULL); | 78 ASSERT(transport_.get() == NULL); |
75 ssl_max_version_ = version; | 79 ssl_max_version_ = version; |
76 } | 80 } |
77 void SetupChannels(int count, cricket::IceRole role) { | 81 void SetupChannels(int count, cricket::IceRole role) { |
78 transport_.reset(new cricket::DtlsTransport<cricket::FakeTransport>( | 82 transport_.reset(new cricket::DtlsTransport<cricket::FakeTransport>( |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 if (use_dtls_srtp_ && !(flags & NF_REOFFER)) { | 159 if (use_dtls_srtp_ && !(flags & NF_REOFFER)) { |
156 // SRTP ciphers will be set only in the beginning. | 160 // SRTP ciphers will be set only in the beginning. |
157 for (std::vector<cricket::DtlsTransportChannelWrapper*>::iterator it = | 161 for (std::vector<cricket::DtlsTransportChannelWrapper*>::iterator it = |
158 channels_.begin(); it != channels_.end(); ++it) { | 162 channels_.begin(); it != channels_.end(); ++it) { |
159 std::vector<std::string> ciphers; | 163 std::vector<std::string> ciphers; |
160 ciphers.push_back(AES_CM_128_HMAC_SHA1_80); | 164 ciphers.push_back(AES_CM_128_HMAC_SHA1_80); |
161 ASSERT_TRUE((*it)->SetSrtpCiphers(ciphers)); | 165 ASSERT_TRUE((*it)->SetSrtpCiphers(ciphers)); |
162 } | 166 } |
163 } | 167 } |
164 | 168 |
| 169 std::string transport_type = (protocol_ == cricket::ICEPROTO_GOOGLE) ? |
| 170 cricket::NS_GINGLE_P2P : cricket::NS_JINGLE_ICE_UDP; |
165 cricket::TransportDescription local_desc( | 171 cricket::TransportDescription local_desc( |
166 std::vector<std::string>(), kIceUfrag1, kIcePwd1, | 172 transport_type, std::vector<std::string>(), kIceUfrag1, kIcePwd1, |
167 cricket::ICEMODE_FULL, local_role, | 173 cricket::ICEMODE_FULL, local_role, |
168 // If remote if the offerer and has no DTLS support, answer will be | 174 // If remote if the offerer and has no DTLS support, answer will be |
169 // without any fingerprint. | 175 // without any fingerprint. |
170 (action == cricket::CA_ANSWER && !remote_cert) ? | 176 (action == cricket::CA_ANSWER && !remote_cert) ? |
171 NULL : local_fingerprint.get(), | 177 NULL : local_fingerprint.get(), |
172 cricket::Candidates()); | 178 cricket::Candidates()); |
173 | 179 |
174 cricket::TransportDescription remote_desc( | 180 cricket::TransportDescription remote_desc( |
175 std::vector<std::string>(), kIceUfrag1, kIcePwd1, | 181 transport_type, std::vector<std::string>(), kIceUfrag1, kIcePwd1, |
176 cricket::ICEMODE_FULL, remote_role, remote_fingerprint.get(), | 182 cricket::ICEMODE_FULL, remote_role, remote_fingerprint.get(), |
177 cricket::Candidates()); | 183 cricket::Candidates()); |
178 | 184 |
179 bool expect_success = (flags & NF_EXPECT_FAILURE) ? false : true; | 185 bool expect_success = (flags & NF_EXPECT_FAILURE) ? false : true; |
180 // If |expect_success| is false, expect SRTD or SLTD to fail when | 186 // If |expect_success| is false, expect SRTD or SLTD to fail when |
181 // content action is CA_ANSWER. | 187 // content action is CA_ANSWER. |
182 if (action == cricket::CA_OFFER) { | 188 if (action == cricket::CA_OFFER) { |
183 ASSERT_TRUE(transport_->SetLocalTransportDescription( | 189 ASSERT_TRUE(transport_->SetLocalTransportDescription( |
184 local_desc, cricket::CA_OFFER, NULL)); | 190 local_desc, cricket::CA_OFFER, NULL)); |
185 ASSERT_EQ(expect_success, transport_->SetRemoteTransportDescription( | 191 ASSERT_EQ(expect_success, transport_->SetRemoteTransportDescription( |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 ASSERT_TRUE(VerifyPacket(data, size, NULL)); | 373 ASSERT_TRUE(VerifyPacket(data, size, NULL)); |
368 } | 374 } |
369 } | 375 } |
370 } | 376 } |
371 } | 377 } |
372 | 378 |
373 private: | 379 private: |
374 std::string name_; | 380 std::string name_; |
375 rtc::Thread* signaling_thread_; | 381 rtc::Thread* signaling_thread_; |
376 rtc::Thread* worker_thread_; | 382 rtc::Thread* worker_thread_; |
| 383 |
377 rtc::scoped_refptr<rtc::RTCCertificate> certificate_; | 384 rtc::scoped_refptr<rtc::RTCCertificate> certificate_; |
| 385 cricket::TransportProtocol protocol_; |
| 386 |
378 rtc::scoped_ptr<cricket::FakeTransport> transport_; | 387 rtc::scoped_ptr<cricket::FakeTransport> transport_; |
379 std::vector<cricket::DtlsTransportChannelWrapper*> channels_; | 388 std::vector<cricket::DtlsTransportChannelWrapper*> channels_; |
380 size_t packet_size_; | 389 size_t packet_size_; |
381 std::set<int> received_; | 390 std::set<int> received_; |
382 bool use_dtls_srtp_; | 391 bool use_dtls_srtp_; |
383 rtc::SSLProtocolVersion ssl_max_version_; | 392 rtc::SSLProtocolVersion ssl_max_version_; |
384 bool negotiated_dtls_; | 393 bool negotiated_dtls_; |
385 bool received_dtls_client_hello_; | 394 bool received_dtls_client_hello_; |
386 bool received_dtls_server_hello_; | 395 bool received_dtls_server_hello_; |
387 }; | 396 }; |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 DtlsTestClient client1_; | 548 DtlsTestClient client1_; |
540 DtlsTestClient client2_; | 549 DtlsTestClient client2_; |
541 int channel_ct_; | 550 int channel_ct_; |
542 bool use_dtls_; | 551 bool use_dtls_; |
543 bool use_dtls_srtp_; | 552 bool use_dtls_srtp_; |
544 rtc::SSLProtocolVersion ssl_expected_version_; | 553 rtc::SSLProtocolVersion ssl_expected_version_; |
545 }; | 554 }; |
546 | 555 |
547 // Test that transport negotiation of ICE, no DTLS works properly. | 556 // Test that transport negotiation of ICE, no DTLS works properly. |
548 TEST_F(DtlsTransportChannelTest, TestChannelSetupIce) { | 557 TEST_F(DtlsTransportChannelTest, TestChannelSetupIce) { |
| 558 client1_.SetIceProtocol(cricket::ICEPROTO_RFC5245); |
| 559 client2_.SetIceProtocol(cricket::ICEPROTO_RFC5245); |
549 Negotiate(); | 560 Negotiate(); |
550 cricket::FakeTransportChannel* channel1 = client1_.GetFakeChannel(0); | 561 cricket::FakeTransportChannel* channel1 = client1_.GetFakeChannel(0); |
551 cricket::FakeTransportChannel* channel2 = client2_.GetFakeChannel(0); | 562 cricket::FakeTransportChannel* channel2 = client2_.GetFakeChannel(0); |
| 563 ASSERT_TRUE(channel1 != NULL); |
| 564 ASSERT_TRUE(channel2 != NULL); |
| 565 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel1->GetIceRole()); |
| 566 EXPECT_EQ(1U, channel1->IceTiebreaker()); |
| 567 EXPECT_EQ(cricket::ICEPROTO_RFC5245, channel1->protocol()); |
| 568 EXPECT_EQ(kIceUfrag1, channel1->ice_ufrag()); |
| 569 EXPECT_EQ(kIcePwd1, channel1->ice_pwd()); |
| 570 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, channel2->GetIceRole()); |
| 571 EXPECT_EQ(2U, channel2->IceTiebreaker()); |
| 572 EXPECT_EQ(cricket::ICEPROTO_RFC5245, channel2->protocol()); |
| 573 } |
| 574 |
| 575 // Test that transport negotiation of GICE, no DTLS works properly. |
| 576 TEST_F(DtlsTransportChannelTest, TestChannelSetupGice) { |
| 577 client1_.SetIceProtocol(cricket::ICEPROTO_GOOGLE); |
| 578 client2_.SetIceProtocol(cricket::ICEPROTO_GOOGLE); |
| 579 Negotiate(); |
| 580 cricket::FakeTransportChannel* channel1 = client1_.GetFakeChannel(0); |
| 581 cricket::FakeTransportChannel* channel2 = client2_.GetFakeChannel(0); |
552 ASSERT_TRUE(channel1 != NULL); | 582 ASSERT_TRUE(channel1 != NULL); |
553 ASSERT_TRUE(channel2 != NULL); | 583 ASSERT_TRUE(channel2 != NULL); |
554 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel1->GetIceRole()); | 584 EXPECT_EQ(cricket::ICEROLE_CONTROLLING, channel1->GetIceRole()); |
555 EXPECT_EQ(1U, channel1->IceTiebreaker()); | 585 EXPECT_EQ(1U, channel1->IceTiebreaker()); |
| 586 EXPECT_EQ(cricket::ICEPROTO_GOOGLE, channel1->protocol()); |
556 EXPECT_EQ(kIceUfrag1, channel1->ice_ufrag()); | 587 EXPECT_EQ(kIceUfrag1, channel1->ice_ufrag()); |
557 EXPECT_EQ(kIcePwd1, channel1->ice_pwd()); | 588 EXPECT_EQ(kIcePwd1, channel1->ice_pwd()); |
558 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, channel2->GetIceRole()); | 589 EXPECT_EQ(cricket::ICEROLE_CONTROLLED, channel2->GetIceRole()); |
559 EXPECT_EQ(2U, channel2->IceTiebreaker()); | 590 EXPECT_EQ(2U, channel2->IceTiebreaker()); |
| 591 EXPECT_EQ(cricket::ICEPROTO_GOOGLE, channel2->protocol()); |
560 } | 592 } |
561 | 593 |
562 // Connect without DTLS, and transfer some data. | 594 // Connect without DTLS, and transfer some data. |
563 TEST_F(DtlsTransportChannelTest, TestTransfer) { | 595 TEST_F(DtlsTransportChannelTest, TestTransfer) { |
564 ASSERT_TRUE(Connect()); | 596 ASSERT_TRUE(Connect()); |
565 TestTransfer(0, 1000, 100, false); | 597 TestTransfer(0, 1000, 100, false); |
566 } | 598 } |
567 | 599 |
568 // Create two channels without DTLS, and transfer some data. | 600 // Create two channels without DTLS, and transfer some data. |
569 TEST_F(DtlsTransportChannelTest, TestTransferTwoChannels) { | 601 TEST_F(DtlsTransportChannelTest, TestTransferTwoChannels) { |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 // Each side's remote certificate is the other side's local certificate. | 901 // Each side's remote certificate is the other side's local certificate. |
870 ASSERT_TRUE( | 902 ASSERT_TRUE( |
871 client1_.transport()->GetRemoteSSLCertificate(remote_cert1.accept())); | 903 client1_.transport()->GetRemoteSSLCertificate(remote_cert1.accept())); |
872 ASSERT_EQ(remote_cert1->ToPEMString(), | 904 ASSERT_EQ(remote_cert1->ToPEMString(), |
873 certificate2->ssl_certificate().ToPEMString()); | 905 certificate2->ssl_certificate().ToPEMString()); |
874 ASSERT_TRUE( | 906 ASSERT_TRUE( |
875 client2_.transport()->GetRemoteSSLCertificate(remote_cert2.accept())); | 907 client2_.transport()->GetRemoteSSLCertificate(remote_cert2.accept())); |
876 ASSERT_EQ(remote_cert2->ToPEMString(), | 908 ASSERT_EQ(remote_cert2->ToPEMString(), |
877 certificate1->ssl_certificate().ToPEMString()); | 909 certificate1->ssl_certificate().ToPEMString()); |
878 } | 910 } |
OLD | NEW |