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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
74 return certificate_; | 74 return certificate_; |
75 } | 75 } |
76 void SetupSrtp() { | 76 void SetupSrtp() { |
77 ASSERT(certificate_); | 77 ASSERT(certificate_); |
78 use_dtls_srtp_ = true; | 78 use_dtls_srtp_ = true; |
79 } | 79 } |
80 void SetupMaxProtocolVersion(rtc::SSLProtocolVersion version) { | 80 void SetupMaxProtocolVersion(rtc::SSLProtocolVersion version) { |
81 ASSERT(!transport_); | 81 ASSERT(!transport_); |
82 ssl_max_version_ = version; | 82 ssl_max_version_ = version; |
83 } | 83 } |
84 void SetupChannels(int count, cricket::IceRole role) { | 84 void SetupChannels(int count, cricket::IceRole role, int async_delay_ms = 0) { |
85 transport_.reset(new cricket::DtlsTransport<cricket::FakeTransport>( | 85 transport_.reset(new cricket::DtlsTransport<cricket::FakeTransport>( |
86 "dtls content name", nullptr, certificate_)); | 86 "dtls content name", nullptr, certificate_)); |
87 transport_->SetAsync(true); | 87 transport_->SetAsync(true); |
88 transport_->SetAsyncDelay(async_delay_ms); | |
88 transport_->SetIceRole(role); | 89 transport_->SetIceRole(role); |
89 transport_->SetIceTiebreaker( | 90 transport_->SetIceTiebreaker( |
90 (role == cricket::ICEROLE_CONTROLLING) ? 1 : 2); | 91 (role == cricket::ICEROLE_CONTROLLING) ? 1 : 2); |
91 | 92 |
92 for (int i = 0; i < count; ++i) { | 93 for (int i = 0; i < count; ++i) { |
93 cricket::DtlsTransportChannelWrapper* channel = | 94 cricket::DtlsTransportChannelWrapper* channel = |
94 static_cast<cricket::DtlsTransportChannelWrapper*>( | 95 static_cast<cricket::DtlsTransportChannelWrapper*>( |
95 transport_->CreateChannel(i)); | 96 transport_->CreateChannel(i)); |
96 ASSERT_TRUE(channel != NULL); | 97 ASSERT_TRUE(channel != NULL); |
97 channel->SetSslMaxProtocolVersion(ssl_max_version_); | 98 channel->SetSslMaxProtocolVersion(ssl_max_version_); |
(...skipping 14 matching lines...) Expand all Loading... | |
112 cricket::Transport* transport() { return transport_.get(); } | 113 cricket::Transport* transport() { return transport_.get(); } |
113 | 114 |
114 cricket::FakeTransportChannel* GetFakeChannel(int component) { | 115 cricket::FakeTransportChannel* GetFakeChannel(int component) { |
115 cricket::TransportChannelImpl* ch = transport_->GetChannel(component); | 116 cricket::TransportChannelImpl* ch = transport_->GetChannel(component); |
116 cricket::DtlsTransportChannelWrapper* wrapper = | 117 cricket::DtlsTransportChannelWrapper* wrapper = |
117 static_cast<cricket::DtlsTransportChannelWrapper*>(ch); | 118 static_cast<cricket::DtlsTransportChannelWrapper*>(ch); |
118 return (wrapper) ? | 119 return (wrapper) ? |
119 static_cast<cricket::FakeTransportChannel*>(wrapper->channel()) : NULL; | 120 static_cast<cricket::FakeTransportChannel*>(wrapper->channel()) : NULL; |
120 } | 121 } |
121 | 122 |
123 cricket::DtlsTransportChannelWrapper* GetDtlsChannel(int component) { | |
124 cricket::TransportChannelImpl* ch = transport_->GetChannel(component); | |
125 return static_cast<cricket::DtlsTransportChannelWrapper*>(ch); | |
126 } | |
127 | |
122 // Offer DTLS if we have an identity; pass in a remote fingerprint only if | 128 // Offer DTLS if we have an identity; pass in a remote fingerprint only if |
123 // both sides support DTLS. | 129 // both sides support DTLS. |
124 void Negotiate(DtlsTestClient* peer, cricket::ContentAction action, | 130 void Negotiate(DtlsTestClient* peer, cricket::ContentAction action, |
125 ConnectionRole local_role, ConnectionRole remote_role, | 131 ConnectionRole local_role, ConnectionRole remote_role, |
126 int flags) { | 132 int flags) { |
127 Negotiate(certificate_, certificate_ ? peer->certificate_ : nullptr, action, | 133 Negotiate(certificate_, certificate_ ? peer->certificate_ : nullptr, action, |
128 local_role, remote_role, flags); | 134 local_role, remote_role, flags); |
129 } | 135 } |
130 | 136 |
131 void MaybeSetSrtpCryptoSuites() { | 137 void MaybeSetSrtpCryptoSuites() { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 return false; | 228 return false; |
223 } | 229 } |
224 } | 230 } |
225 return true; | 231 return true; |
226 } | 232 } |
227 | 233 |
228 int received_dtls_client_hellos() const { | 234 int received_dtls_client_hellos() const { |
229 return received_dtls_client_hellos_; | 235 return received_dtls_client_hellos_; |
230 } | 236 } |
231 | 237 |
238 int received_dtls_server_hellos() const { | |
239 return received_dtls_server_hellos_; | |
240 } | |
241 | |
232 bool negotiated_dtls() const { return set_local_cert_ && set_remote_cert_; } | 242 bool negotiated_dtls() const { return set_local_cert_ && set_remote_cert_; } |
233 | 243 |
234 void CheckRole(rtc::SSLRole role) { | 244 void CheckRole(rtc::SSLRole role) { |
235 if (role == rtc::SSL_CLIENT) { | 245 if (role == rtc::SSL_CLIENT) { |
236 ASSERT_EQ(0, received_dtls_client_hellos_); | 246 ASSERT_EQ(0, received_dtls_client_hellos_); |
237 ASSERT_GT(received_dtls_server_hellos_, 0); | 247 ASSERT_GT(received_dtls_server_hellos_, 0); |
238 } else { | 248 } else { |
239 ASSERT_GT(received_dtls_client_hellos_, 0); | 249 ASSERT_GT(received_dtls_client_hellos_, 0); |
240 ASSERT_EQ(0, received_dtls_server_hellos_); | 250 ASSERT_EQ(0, received_dtls_server_hellos_); |
241 } | 251 } |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
488 client2_.certificate(), cricket::CA_ANSWER, client2_role, 0); | 498 client2_.certificate(), cricket::CA_ANSWER, client2_role, 0); |
489 rv = client1_.Connect(&client2_, false); | 499 rv = client1_.Connect(&client2_, false); |
490 client1_.SetRemoteTransportDescription( | 500 client1_.SetRemoteTransportDescription( |
491 client2_.certificate(), cricket::CA_ANSWER, client2_role, 0); | 501 client2_.certificate(), cricket::CA_ANSWER, client2_role, 0); |
492 } | 502 } |
493 | 503 |
494 EXPECT_TRUE(rv); | 504 EXPECT_TRUE(rv); |
495 if (!rv) | 505 if (!rv) |
496 return false; | 506 return false; |
497 | 507 |
498 EXPECT_TRUE_WAIT( | 508 EXPECT_TRUE_SIMULATED_WAIT( |
499 client1_.all_channels_writable() && client2_.all_channels_writable(), | 509 client1_.all_channels_writable() && client2_.all_channels_writable(), |
500 kTimeout); | 510 kTimeout, fake_clock_); |
501 if (!client1_.all_channels_writable() || !client2_.all_channels_writable()) | 511 if (!client1_.all_channels_writable() || !client2_.all_channels_writable()) |
502 return false; | 512 return false; |
503 | 513 |
504 // Check that we used the right roles. | 514 // Check that we used the right roles. |
505 if (use_dtls_) { | 515 if (use_dtls_) { |
506 rtc::SSLRole client1_ssl_role = | 516 rtc::SSLRole client1_ssl_role = |
507 (client1_role == cricket::CONNECTIONROLE_ACTIVE || | 517 (client1_role == cricket::CONNECTIONROLE_ACTIVE || |
508 (client2_role == cricket::CONNECTIONROLE_PASSIVE && | 518 (client2_role == cricket::CONNECTIONROLE_PASSIVE && |
509 client1_role == cricket::CONNECTIONROLE_ACTPASS)) ? | 519 client1_role == cricket::CONNECTIONROLE_ACTPASS)) ? |
510 rtc::SSL_CLIENT : rtc::SSL_SERVER; | 520 rtc::SSL_CLIENT : rtc::SSL_SERVER; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
581 client2_role, client1_role, flags); | 591 client2_role, client1_role, flags); |
582 client1_.Negotiate(&client2_, cricket::CA_ANSWER, | 592 client1_.Negotiate(&client2_, cricket::CA_ANSWER, |
583 client1_role, client2_role, flags); | 593 client1_role, client2_role, flags); |
584 } | 594 } |
585 } | 595 } |
586 | 596 |
587 void TestTransfer(size_t channel, size_t size, size_t count, bool srtp) { | 597 void TestTransfer(size_t channel, size_t size, size_t count, bool srtp) { |
588 LOG(LS_INFO) << "Expect packets, size=" << size; | 598 LOG(LS_INFO) << "Expect packets, size=" << size; |
589 client2_.ExpectPackets(channel, size); | 599 client2_.ExpectPackets(channel, size); |
590 client1_.SendPackets(channel, size, count, srtp); | 600 client1_.SendPackets(channel, size, count, srtp); |
591 EXPECT_EQ_WAIT(count, client2_.NumPacketsReceived(), kTimeout); | 601 EXPECT_EQ_SIMULATED_WAIT(count, client2_.NumPacketsReceived(), kTimeout, |
602 fake_clock_); | |
603 } | |
604 | |
605 enum Event { | |
606 CALLER_RECEIVES_FINGERPRINT, | |
607 CALLER_WRITABLE, | |
608 CALLER_RECEIVES_CLIENTHELLO, | |
609 HANDSHAKE_FINISHES | |
610 }; | |
611 void TestEventPermutation(const std::vector<Event>& events) { | |
612 // Pre-setup: Set local certificate on both caller and callee, and | |
613 // remote fingerprint on callee, but neither is writable and the caller | |
614 // doesn't have the callee's fingerprint. | |
615 PrepareDtls(true, true, rtc::KT_DEFAULT); | |
616 // Simulate packets being sent and arriving asynchronously. | |
617 // Otherwise the entire DTLS handshake would occur in one clock tick, and | |
618 // we couldn't inject method calls in the middle of it. | |
619 int simulated_delay_ms = 10; | |
620 client1_.SetupChannels(channel_ct_, cricket::ICEROLE_CONTROLLING, | |
621 simulated_delay_ms); | |
622 client2_.SetupChannels(channel_ct_, cricket::ICEROLE_CONTROLLED, | |
623 simulated_delay_ms); | |
624 client1_.SetLocalTransportDescription(client1_.certificate(), | |
625 cricket::CA_OFFER, | |
626 cricket::CONNECTIONROLE_ACTPASS, 0); | |
627 client2_.Negotiate(&client1_, cricket::CA_ANSWER, | |
628 cricket::CONNECTIONROLE_ACTIVE, | |
629 cricket::CONNECTIONROLE_ACTPASS, 0); | |
630 | |
631 for (Event e : events) { | |
632 switch (e) { | |
633 case CALLER_RECEIVES_FINGERPRINT: | |
634 client1_.SetRemoteTransportDescription( | |
635 client2_.certificate(), cricket::CA_ANSWER, | |
636 cricket::CONNECTIONROLE_ACTIVE, 0); | |
637 break; | |
638 case CALLER_WRITABLE: | |
639 EXPECT_TRUE(client1_.Connect(&client2_, true)); | |
640 EXPECT_TRUE_SIMULATED_WAIT(client1_.all_raw_channels_writable(), | |
641 kTimeout, fake_clock_); | |
642 break; | |
643 case CALLER_RECEIVES_CLIENTHELLO: | |
644 // Sanity check that a ClientHello hasn't already been received. | |
645 EXPECT_EQ(0, client1_.received_dtls_client_hellos()); | |
646 // Making client2_ writable will cause it to send the ClientHello. | |
647 EXPECT_TRUE(client2_.Connect(&client1_, true)); | |
648 EXPECT_TRUE_SIMULATED_WAIT(client2_.all_raw_channels_writable(), | |
649 kTimeout, fake_clock_); | |
650 EXPECT_EQ_SIMULATED_WAIT(1, client1_.received_dtls_client_hellos(), | |
651 kTimeout, fake_clock_); | |
652 break; | |
653 case HANDSHAKE_FINISHES: | |
654 // Sanity check that the handshake hasn't already finished. | |
655 EXPECT_FALSE(client1_.GetDtlsChannel(0)->IsDtlsConnected()); | |
656 EXPECT_TRUE_SIMULATED_WAIT( | |
657 client1_.GetDtlsChannel(0)->IsDtlsConnected(), kTimeout, | |
658 fake_clock_); | |
659 break; | |
660 } | |
661 } | |
662 | |
663 EXPECT_TRUE_SIMULATED_WAIT( | |
664 client1_.all_channels_writable() && client2_.all_channels_writable(), | |
665 kTimeout, fake_clock_); | |
666 EXPECT_EQ(1, client1_.received_dtls_client_hellos()); | |
667 EXPECT_EQ(1, client2_.received_dtls_server_hellos()); | |
668 TestTransfer(0, 1000, 100, false); | |
592 } | 669 } |
593 | 670 |
594 protected: | 671 protected: |
595 rtc::ScopedFakeClock fake_clock_; | 672 rtc::ScopedFakeClock fake_clock_; |
596 DtlsTestClient client1_; | 673 DtlsTestClient client1_; |
597 DtlsTestClient client2_; | 674 DtlsTestClient client2_; |
598 int channel_ct_; | 675 int channel_ct_; |
599 bool use_dtls_; | 676 bool use_dtls_; |
600 bool use_dtls_srtp_; | 677 bool use_dtls_srtp_; |
601 rtc::SSLProtocolVersion ssl_expected_version_; | 678 rtc::SSLProtocolVersion ssl_expected_version_; |
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
877 MAYBE_SKIP_TEST(HaveDtlsSrtp); | 954 MAYBE_SKIP_TEST(HaveDtlsSrtp); |
878 SetChannelCount(2); | 955 SetChannelCount(2); |
879 PrepareDtls(true, true, rtc::KT_DEFAULT); | 956 PrepareDtls(true, true, rtc::KT_DEFAULT); |
880 PrepareDtlsSrtp(true, true); | 957 PrepareDtlsSrtp(true, true); |
881 Negotiate(); | 958 Negotiate(); |
882 | 959 |
883 Renegotiate(&client1_, cricket::CONNECTIONROLE_ACTPASS, | 960 Renegotiate(&client1_, cricket::CONNECTIONROLE_ACTPASS, |
884 cricket::CONNECTIONROLE_ACTIVE, NF_REOFFER); | 961 cricket::CONNECTIONROLE_ACTIVE, NF_REOFFER); |
885 bool rv = client1_.Connect(&client2_, false); | 962 bool rv = client1_.Connect(&client2_, false); |
886 EXPECT_TRUE(rv); | 963 EXPECT_TRUE(rv); |
887 EXPECT_TRUE_WAIT( | 964 EXPECT_TRUE_SIMULATED_WAIT( |
888 client1_.all_channels_writable() && client2_.all_channels_writable(), | 965 client1_.all_channels_writable() && client2_.all_channels_writable(), |
889 kTimeout); | 966 kTimeout, fake_clock_); |
890 | 967 |
891 TestTransfer(0, 1000, 100, true); | 968 TestTransfer(0, 1000, 100, true); |
892 TestTransfer(1, 1000, 100, true); | 969 TestTransfer(1, 1000, 100, true); |
893 } | 970 } |
894 | 971 |
895 // Test Certificates state after negotiation but before connection. | 972 // Test Certificates state after negotiation but before connection. |
896 TEST_F(DtlsTransportChannelTest, TestCertificatesBeforeConnect) { | 973 TEST_F(DtlsTransportChannelTest, TestCertificatesBeforeConnect) { |
897 MAYBE_SKIP_TEST(HaveDtls); | 974 MAYBE_SKIP_TEST(HaveDtls); |
898 PrepareDtls(true, true, rtc::KT_DEFAULT); | 975 PrepareDtls(true, true, rtc::KT_DEFAULT); |
899 Negotiate(); | 976 Negotiate(); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
934 ASSERT_TRUE(remote_cert1); | 1011 ASSERT_TRUE(remote_cert1); |
935 ASSERT_EQ(remote_cert1->ToPEMString(), | 1012 ASSERT_EQ(remote_cert1->ToPEMString(), |
936 certificate2->ssl_certificate().ToPEMString()); | 1013 certificate2->ssl_certificate().ToPEMString()); |
937 std::unique_ptr<rtc::SSLCertificate> remote_cert2 = | 1014 std::unique_ptr<rtc::SSLCertificate> remote_cert2 = |
938 client2_.transport()->GetRemoteSSLCertificate(); | 1015 client2_.transport()->GetRemoteSSLCertificate(); |
939 ASSERT_TRUE(remote_cert2); | 1016 ASSERT_TRUE(remote_cert2); |
940 ASSERT_EQ(remote_cert2->ToPEMString(), | 1017 ASSERT_EQ(remote_cert2->ToPEMString(), |
941 certificate1->ssl_certificate().ToPEMString()); | 1018 certificate1->ssl_certificate().ToPEMString()); |
942 } | 1019 } |
943 | 1020 |
944 // Test that DTLS completes promptly if a ClientHello is received before the | 1021 // The following events can occur in many different orders: |
945 // transport channel is writable (allowing a ServerHello to be sent). | 1022 // 1. Caller receives remote fingerprint. |
946 TEST_F(DtlsTransportChannelTest, TestReceiveClientHelloBeforeWritable) { | 1023 // 2. Caller is writable. |
Taylor Brandstetter
2016/07/19 23:43:05
These tests are now just two of the possible permu
| |
1024 // 3. Caller receives ClientHello. | |
1025 // 4. DTLS handshake finishes. | |
1026 // | |
1027 // The tests below cover all possible permutations of these events, | |
1028 // and verify that a connection is established and fingerprint verified | |
1029 // without any DTLS packet needing to be retransmitted. | |
1030 TEST_F(DtlsTransportChannelTest, EventPermutation1) { | |
Taylor Brandstetter
2016/07/19 23:43:05
"PermutationN" isn't the best name I realize. If y
| |
947 MAYBE_SKIP_TEST(HaveDtls); | 1031 MAYBE_SKIP_TEST(HaveDtls); |
948 PrepareDtls(true, true, rtc::KT_DEFAULT); | 1032 TestEventPermutation(std::vector<Event>{ |
949 // Exchange transport descriptions. | 1033 CALLER_RECEIVES_FINGERPRINT, CALLER_WRITABLE, CALLER_RECEIVES_CLIENTHELLO, |
950 Negotiate(cricket::CONNECTIONROLE_ACTPASS, cricket::CONNECTIONROLE_ACTIVE); | 1034 HANDSHAKE_FINISHES, |
951 | 1035 }); |
952 // Make client2_ writable, but not client1_. | |
953 EXPECT_TRUE(client2_.Connect(&client1_, true)); | |
954 EXPECT_TRUE_WAIT(client2_.all_raw_channels_writable(), kTimeout); | |
955 | |
956 // Expect a DTLS ClientHello to be sent even while client1_ isn't writable. | |
957 EXPECT_EQ_WAIT(1, client1_.received_dtls_client_hellos(), kTimeout); | |
958 EXPECT_FALSE(client1_.all_raw_channels_writable()); | |
959 | |
960 // Now make client1_ writable and expect the handshake to complete | |
961 // without client2_ needing to retransmit the ClientHello. | |
962 EXPECT_TRUE(client1_.Connect(&client2_, true)); | |
963 EXPECT_TRUE_WAIT( | |
964 client1_.all_channels_writable() && client2_.all_channels_writable(), | |
965 kTimeout); | |
966 EXPECT_EQ(1, client1_.received_dtls_client_hellos()); | |
967 } | 1036 } |
968 | 1037 |
969 // Test that DTLS completes promptly if a ClientHello is received before the | 1038 TEST_F(DtlsTransportChannelTest, EventPermutation2) { |
970 // transport channel has a remote fingerprint (allowing a ServerHello to be | |
971 // sent). | |
972 TEST_F(DtlsTransportChannelTest, | |
973 TestReceiveClientHelloBeforeRemoteFingerprint) { | |
974 MAYBE_SKIP_TEST(HaveDtls); | 1039 MAYBE_SKIP_TEST(HaveDtls); |
975 PrepareDtls(true, true, rtc::KT_DEFAULT); | 1040 TestEventPermutation(std::vector<Event>{ |
976 client1_.SetupChannels(channel_ct_, cricket::ICEROLE_CONTROLLING); | 1041 CALLER_WRITABLE, CALLER_RECEIVES_FINGERPRINT, CALLER_RECEIVES_CLIENTHELLO, |
977 client2_.SetupChannels(channel_ct_, cricket::ICEROLE_CONTROLLED); | 1042 HANDSHAKE_FINISHES, |
1043 }); | |
1044 } | |
978 | 1045 |
979 // Make client2_ writable and give it local/remote certs, but don't yet give | 1046 TEST_F(DtlsTransportChannelTest, EventPermutation3) { |
980 // client1_ a remote fingerprint. | 1047 MAYBE_SKIP_TEST(HaveDtls); |
981 client1_.transport()->SetLocalTransportDescription( | 1048 TestEventPermutation(std::vector<Event>{ |
982 MakeTransportDescription(client1_.certificate(), | 1049 CALLER_WRITABLE, CALLER_RECEIVES_CLIENTHELLO, CALLER_RECEIVES_FINGERPRINT, |
983 cricket::CONNECTIONROLE_ACTPASS), | 1050 HANDSHAKE_FINISHES, |
984 cricket::CA_OFFER, nullptr); | 1051 }); |
985 client2_.Negotiate(&client1_, cricket::CA_ANSWER, | 1052 } |
986 cricket::CONNECTIONROLE_ACTIVE, | |
987 cricket::CONNECTIONROLE_ACTPASS, 0); | |
988 EXPECT_TRUE(client2_.Connect(&client1_, true)); | |
989 EXPECT_TRUE_WAIT(client2_.all_raw_channels_writable(), kTimeout); | |
990 | 1053 |
991 // Expect a DTLS ClientHello to be sent even while client1_ doesn't have a | 1054 TEST_F(DtlsTransportChannelTest, EventPermutation4) { |
992 // remote fingerprint. | 1055 MAYBE_SKIP_TEST(HaveDtls); |
993 EXPECT_EQ_WAIT(1, client1_.received_dtls_client_hellos(), kTimeout); | 1056 TestEventPermutation(std::vector<Event>{ |
994 EXPECT_FALSE(client1_.all_raw_channels_writable()); | 1057 CALLER_WRITABLE, CALLER_RECEIVES_CLIENTHELLO, HANDSHAKE_FINISHES, |
1058 CALLER_RECEIVES_FINGERPRINT, | |
1059 }); | |
1060 } | |
995 | 1061 |
996 // Now make give client1_ its remote fingerprint and make it writable, and | 1062 TEST_F(DtlsTransportChannelTest, EventPermutation5) { |
997 // expect the handshake to complete without client2_ needing to retransmit | 1063 MAYBE_SKIP_TEST(HaveDtls); |
998 // the ClientHello. | 1064 TestEventPermutation(std::vector<Event>{ |
999 client1_.transport()->SetRemoteTransportDescription( | 1065 CALLER_RECEIVES_FINGERPRINT, CALLER_RECEIVES_CLIENTHELLO, CALLER_WRITABLE, |
1000 MakeTransportDescription(client2_.certificate(), | 1066 HANDSHAKE_FINISHES, |
1001 cricket::CONNECTIONROLE_ACTIVE), | 1067 }); |
1002 cricket::CA_ANSWER, nullptr); | 1068 } |
1003 EXPECT_TRUE(client1_.Connect(&client2_, true)); | 1069 |
1004 EXPECT_TRUE_WAIT( | 1070 TEST_F(DtlsTransportChannelTest, EventPermutation6) { |
1005 client1_.all_channels_writable() && client2_.all_channels_writable(), | 1071 MAYBE_SKIP_TEST(HaveDtls); |
1006 kTimeout); | 1072 TestEventPermutation(std::vector<Event>{ |
1007 EXPECT_EQ(1, client1_.received_dtls_client_hellos()); | 1073 CALLER_RECEIVES_CLIENTHELLO, CALLER_RECEIVES_FINGERPRINT, CALLER_WRITABLE, |
1074 HANDSHAKE_FINISHES, | |
1075 }); | |
1076 } | |
1077 | |
1078 TEST_F(DtlsTransportChannelTest, EventPermutation7) { | |
1079 MAYBE_SKIP_TEST(HaveDtls); | |
1080 TestEventPermutation(std::vector<Event>{ | |
1081 CALLER_RECEIVES_CLIENTHELLO, CALLER_WRITABLE, CALLER_RECEIVES_FINGERPRINT, | |
1082 HANDSHAKE_FINISHES, | |
1083 }); | |
1084 } | |
1085 | |
1086 TEST_F(DtlsTransportChannelTest, EventPermutation8) { | |
1087 MAYBE_SKIP_TEST(HaveDtls); | |
1088 TestEventPermutation(std::vector<Event>{ | |
1089 CALLER_RECEIVES_CLIENTHELLO, CALLER_WRITABLE, HANDSHAKE_FINISHES, | |
1090 CALLER_RECEIVES_FINGERPRINT, | |
1091 }); | |
1008 } | 1092 } |
1009 | 1093 |
1010 // Test that packets are retransmitted according to the expected schedule. | 1094 // Test that packets are retransmitted according to the expected schedule. |
1011 // Each time a timeout occurs, the retransmission timer should be doubled up to | 1095 // Each time a timeout occurs, the retransmission timer should be doubled up to |
1012 // 60 seconds. The timer defaults to 1 second, but for WebRTC we should be | 1096 // 60 seconds. The timer defaults to 1 second, but for WebRTC we should be |
1013 // initializing it to 50ms. | 1097 // initializing it to 50ms. |
1014 TEST_F(DtlsTransportChannelTest, TestRetransmissionSchedule) { | 1098 TEST_F(DtlsTransportChannelTest, TestRetransmissionSchedule) { |
1015 MAYBE_SKIP_TEST(HaveDtls); | 1099 MAYBE_SKIP_TEST(HaveDtls); |
1016 // We can only change the retransmission schedule with a recently-added | 1100 // We can only change the retransmission schedule with a recently-added |
1017 // BoringSSL API. Skip the test if not built with BoringSSL. | 1101 // BoringSSL API. Skip the test if not built with BoringSSL. |
1018 MAYBE_SKIP_TEST(IsBoringSsl); | 1102 MAYBE_SKIP_TEST(IsBoringSsl); |
1019 | 1103 |
1020 PrepareDtls(true, true, rtc::KT_DEFAULT); | 1104 PrepareDtls(true, true, rtc::KT_DEFAULT); |
1021 // Exchange transport descriptions. | 1105 // Exchange transport descriptions. |
1022 Negotiate(cricket::CONNECTIONROLE_ACTPASS, cricket::CONNECTIONROLE_ACTIVE); | 1106 Negotiate(cricket::CONNECTIONROLE_ACTPASS, cricket::CONNECTIONROLE_ACTIVE); |
1023 | 1107 |
1024 // Make client2_ writable, but not client1_. | 1108 // Make client2_ writable, but not client1_. |
1025 // This means client1_ will send DTLS client hellos but get no response. | 1109 // This means client1_ will send DTLS client hellos but get no response. |
1026 EXPECT_TRUE(client2_.Connect(&client1_, true)); | 1110 EXPECT_TRUE(client2_.Connect(&client1_, true)); |
1027 EXPECT_TRUE_WAIT(client2_.all_raw_channels_writable(), kTimeout); | 1111 EXPECT_TRUE_SIMULATED_WAIT(client2_.all_raw_channels_writable(), kTimeout, |
1112 fake_clock_); | |
1028 | 1113 |
1029 // Wait for the first client hello to be sent. | 1114 // Wait for the first client hello to be sent. |
1030 EXPECT_EQ_WAIT(1, client1_.received_dtls_client_hellos(), kTimeout); | 1115 EXPECT_EQ_WAIT(1, client1_.received_dtls_client_hellos(), kTimeout); |
1031 EXPECT_FALSE(client1_.all_raw_channels_writable()); | 1116 EXPECT_FALSE(client1_.all_raw_channels_writable()); |
1032 | 1117 |
1033 static int timeout_schedule_ms[] = {50, 100, 200, 400, 800, 1600, | 1118 static int timeout_schedule_ms[] = {50, 100, 200, 400, 800, 1600, |
1034 3200, 6400, 12800, 25600, 51200, 60000}; | 1119 3200, 6400, 12800, 25600, 51200, 60000}; |
1035 | 1120 |
1036 int expected_hellos = 1; | 1121 int expected_hellos = 1; |
1037 for (size_t i = 0; | 1122 for (size_t i = 0; |
(...skipping 14 matching lines...) Expand all Loading... | |
1052 // Test that a DTLS connection can be made even if the underlying transport | 1137 // Test that a DTLS connection can be made even if the underlying transport |
1053 // is connected before DTLS fingerprints/roles have been negotiated. | 1138 // is connected before DTLS fingerprints/roles have been negotiated. |
1054 TEST_F(DtlsTransportChannelTest, TestConnectBeforeNegotiate) { | 1139 TEST_F(DtlsTransportChannelTest, TestConnectBeforeNegotiate) { |
1055 MAYBE_SKIP_TEST(HaveDtls); | 1140 MAYBE_SKIP_TEST(HaveDtls); |
1056 PrepareDtls(true, true, rtc::KT_DEFAULT); | 1141 PrepareDtls(true, true, rtc::KT_DEFAULT); |
1057 ASSERT_TRUE(Connect(cricket::CONNECTIONROLE_ACTPASS, | 1142 ASSERT_TRUE(Connect(cricket::CONNECTIONROLE_ACTPASS, |
1058 cricket::CONNECTIONROLE_ACTIVE, | 1143 cricket::CONNECTIONROLE_ACTIVE, |
1059 CONNECT_BEFORE_NEGOTIATE)); | 1144 CONNECT_BEFORE_NEGOTIATE)); |
1060 TestTransfer(0, 1000, 100, false); | 1145 TestTransfer(0, 1000, 100, false); |
1061 } | 1146 } |
OLD | NEW |