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