| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 for (int i = 0; i < count; ++i) { | 90 for (int i = 0; i < count; ++i) { |
| 91 cricket::FakeIceTransport* fake_ice_channel = | 91 cricket::FakeIceTransport* fake_ice_channel = |
| 92 new cricket::FakeIceTransport(transport_->mid(), i); | 92 new cricket::FakeIceTransport(transport_->mid(), i); |
| 93 fake_ice_channel->SetAsync(true); | 93 fake_ice_channel->SetAsync(true); |
| 94 fake_ice_channel->SetAsyncDelay(async_delay_ms); | 94 fake_ice_channel->SetAsyncDelay(async_delay_ms); |
| 95 // Hook the raw packets so that we can verify they are encrypted. | 95 // Hook the raw packets so that we can verify they are encrypted. |
| 96 fake_ice_channel->SignalReadPacket.connect( | 96 fake_ice_channel->SignalReadPacket.connect( |
| 97 this, &DtlsTestClient::OnFakeTransportChannelReadPacket); | 97 this, &DtlsTestClient::OnFakeTransportChannelReadPacket); |
| 98 | 98 |
| 99 cricket::DtlsTransport* dtls = | 99 cricket::DtlsTransport* dtls = |
| 100 new cricket::DtlsTransport(fake_ice_channel); | 100 new cricket::DtlsTransport(fake_ice_channel, rtc::CryptoOptions()); |
| 101 dtls->SetLocalCertificate(certificate_); | 101 dtls->SetLocalCertificate(certificate_); |
| 102 dtls->ice_transport()->SetIceRole(role); | 102 dtls->ice_transport()->SetIceRole(role); |
| 103 dtls->ice_transport()->SetIceTiebreaker( | 103 dtls->ice_transport()->SetIceTiebreaker( |
| 104 (role == cricket::ICEROLE_CONTROLLING) ? 1 : 2); | 104 (role == cricket::ICEROLE_CONTROLLING) ? 1 : 2); |
| 105 dtls->SetSslMaxProtocolVersion(ssl_max_version_); | 105 dtls->SetSslMaxProtocolVersion(ssl_max_version_); |
| 106 dtls->SignalWritableState.connect( | 106 dtls->SignalWritableState.connect( |
| 107 this, &DtlsTestClient::OnTransportChannelWritableState); | 107 this, &DtlsTestClient::OnTransportChannelWritableState); |
| 108 dtls->SignalReadPacket.connect( | 108 dtls->SignalReadPacket.connect( |
| 109 this, &DtlsTestClient::OnTransportChannelReadPacket); | 109 this, &DtlsTestClient::OnTransportChannelReadPacket); |
| 110 dtls->SignalSentPacket.connect( | 110 dtls->SignalSentPacket.connect( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 139 | 139 |
| 140 // Offer DTLS if we have an identity; pass in a remote fingerprint only if | 140 // Offer DTLS if we have an identity; pass in a remote fingerprint only if |
| 141 // both sides support DTLS. | 141 // both sides support DTLS. |
| 142 void Negotiate(DtlsTestClient* peer, cricket::ContentAction action, | 142 void Negotiate(DtlsTestClient* peer, cricket::ContentAction action, |
| 143 ConnectionRole local_role, ConnectionRole remote_role, | 143 ConnectionRole local_role, ConnectionRole remote_role, |
| 144 int flags) { | 144 int flags) { |
| 145 Negotiate(certificate_, certificate_ ? peer->certificate_ : nullptr, action, | 145 Negotiate(certificate_, certificate_ ? peer->certificate_ : nullptr, action, |
| 146 local_role, remote_role, flags); | 146 local_role, remote_role, flags); |
| 147 } | 147 } |
| 148 | 148 |
| 149 void MaybeSetSrtpCryptoSuites() { | |
| 150 if (!use_dtls_srtp_) { | |
| 151 return; | |
| 152 } | |
| 153 std::vector<int> ciphers; | |
| 154 ciphers.push_back(rtc::SRTP_AES128_CM_SHA1_80); | |
| 155 // SRTP ciphers will be set only in the beginning. | |
| 156 for (const auto& dtls : fake_dtls_transports_) { | |
| 157 EXPECT_TRUE(dtls->SetSrtpCryptoSuites(ciphers)); | |
| 158 } | |
| 159 } | |
| 160 | |
| 161 void SetLocalTransportDescription( | 149 void SetLocalTransportDescription( |
| 162 const rtc::scoped_refptr<rtc::RTCCertificate>& cert, | 150 const rtc::scoped_refptr<rtc::RTCCertificate>& cert, |
| 163 cricket::ContentAction action, | 151 cricket::ContentAction action, |
| 164 ConnectionRole role, | 152 ConnectionRole role, |
| 165 int flags) { | 153 int flags) { |
| 166 // If |NF_EXPECT_FAILURE| is set, expect SRTD or SLTD to fail when | 154 // If |NF_EXPECT_FAILURE| is set, expect SRTD or SLTD to fail when |
| 167 // content action is CA_ANSWER. | 155 // content action is CA_ANSWER. |
| 168 bool expect_success = | 156 bool expect_success = |
| 169 !((action == cricket::CA_ANSWER) && (flags & NF_EXPECT_FAILURE)); | 157 !((action == cricket::CA_ANSWER) && (flags & NF_EXPECT_FAILURE)); |
| 170 EXPECT_EQ(expect_success, | 158 EXPECT_EQ(expect_success, |
| (...skipping 15 matching lines...) Expand all Loading... |
| 186 MakeTransportDescription(cert, role), action, nullptr)); | 174 MakeTransportDescription(cert, role), action, nullptr)); |
| 187 } | 175 } |
| 188 | 176 |
| 189 // Allow any DTLS configuration to be specified (including invalid ones). | 177 // Allow any DTLS configuration to be specified (including invalid ones). |
| 190 void Negotiate(const rtc::scoped_refptr<rtc::RTCCertificate>& local_cert, | 178 void Negotiate(const rtc::scoped_refptr<rtc::RTCCertificate>& local_cert, |
| 191 const rtc::scoped_refptr<rtc::RTCCertificate>& remote_cert, | 179 const rtc::scoped_refptr<rtc::RTCCertificate>& remote_cert, |
| 192 cricket::ContentAction action, | 180 cricket::ContentAction action, |
| 193 ConnectionRole local_role, | 181 ConnectionRole local_role, |
| 194 ConnectionRole remote_role, | 182 ConnectionRole remote_role, |
| 195 int flags) { | 183 int flags) { |
| 196 if (!(flags & NF_REOFFER)) { | |
| 197 // SRTP ciphers will be set only in the beginning. | |
| 198 MaybeSetSrtpCryptoSuites(); | |
| 199 } | |
| 200 if (action == cricket::CA_OFFER) { | 184 if (action == cricket::CA_OFFER) { |
| 201 SetLocalTransportDescription(local_cert, cricket::CA_OFFER, local_role, | 185 SetLocalTransportDescription(local_cert, cricket::CA_OFFER, local_role, |
| 202 flags); | 186 flags); |
| 203 SetRemoteTransportDescription(remote_cert, cricket::CA_ANSWER, | 187 SetRemoteTransportDescription(remote_cert, cricket::CA_ANSWER, |
| 204 remote_role, flags); | 188 remote_role, flags); |
| 205 } else { | 189 } else { |
| 206 SetRemoteTransportDescription(remote_cert, cricket::CA_OFFER, remote_role, | 190 SetRemoteTransportDescription(remote_cert, cricket::CA_OFFER, remote_role, |
| 207 flags); | 191 flags); |
| 208 // If remote if the offerer and has no DTLS support, answer will be | 192 // If remote if the offerer and has no DTLS support, answer will be |
| 209 // without any fingerprint. | 193 // without any fingerprint. |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 bool Connect(ConnectionRole client1_role, | 483 bool Connect(ConnectionRole client1_role, |
| 500 ConnectionRole client2_role, | 484 ConnectionRole client2_role, |
| 501 NegotiateOrdering ordering = NEGOTIATE_BEFORE_CONNECT) { | 485 NegotiateOrdering ordering = NEGOTIATE_BEFORE_CONNECT) { |
| 502 bool rv; | 486 bool rv; |
| 503 if (ordering == NEGOTIATE_BEFORE_CONNECT) { | 487 if (ordering == NEGOTIATE_BEFORE_CONNECT) { |
| 504 Negotiate(client1_role, client2_role); | 488 Negotiate(client1_role, client2_role); |
| 505 rv = client1_.Connect(&client2_, false); | 489 rv = client1_.Connect(&client2_, false); |
| 506 } else { | 490 } else { |
| 507 client1_.SetupChannels(channel_ct_, cricket::ICEROLE_CONTROLLING); | 491 client1_.SetupChannels(channel_ct_, cricket::ICEROLE_CONTROLLING); |
| 508 client2_.SetupChannels(channel_ct_, cricket::ICEROLE_CONTROLLED); | 492 client2_.SetupChannels(channel_ct_, cricket::ICEROLE_CONTROLLED); |
| 509 client1_.MaybeSetSrtpCryptoSuites(); | |
| 510 client2_.MaybeSetSrtpCryptoSuites(); | |
| 511 // This is equivalent to an offer being processed on both sides, but an | 493 // This is equivalent to an offer being processed on both sides, but an |
| 512 // answer not yet being received on the initiating side. So the | 494 // answer not yet being received on the initiating side. So the |
| 513 // connection will be made before negotiation has finished on both sides. | 495 // connection will be made before negotiation has finished on both sides. |
| 514 client1_.SetLocalTransportDescription(client1_.certificate(), | 496 client1_.SetLocalTransportDescription(client1_.certificate(), |
| 515 cricket::CA_OFFER, client1_role, 0); | 497 cricket::CA_OFFER, client1_role, 0); |
| 516 client2_.SetRemoteTransportDescription( | 498 client2_.SetRemoteTransportDescription( |
| 517 client1_.certificate(), cricket::CA_OFFER, client1_role, 0); | 499 client1_.certificate(), cricket::CA_OFFER, client1_role, 0); |
| 518 client2_.SetLocalTransportDescription( | 500 client2_.SetLocalTransportDescription( |
| 519 client2_.certificate(), cricket::CA_ANSWER, client2_role, 0); | 501 client2_.certificate(), cricket::CA_ANSWER, client2_role, 0); |
| 520 rv = client1_.Connect(&client2_, false); | 502 rv = client1_.Connect(&client2_, false); |
| (...skipping 635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1156 std::vector<DtlsTransportEvent>{ | 1138 std::vector<DtlsTransportEvent>{ |
| 1157 CALLER_RECEIVES_CLIENTHELLO, CALLER_RECEIVES_FINGERPRINT, | 1139 CALLER_RECEIVES_CLIENTHELLO, CALLER_RECEIVES_FINGERPRINT, |
| 1158 CALLER_WRITABLE, HANDSHAKE_FINISHES}, | 1140 CALLER_WRITABLE, HANDSHAKE_FINISHES}, |
| 1159 std::vector<DtlsTransportEvent>{ | 1141 std::vector<DtlsTransportEvent>{ |
| 1160 CALLER_RECEIVES_CLIENTHELLO, CALLER_WRITABLE, | 1142 CALLER_RECEIVES_CLIENTHELLO, CALLER_WRITABLE, |
| 1161 CALLER_RECEIVES_FINGERPRINT, HANDSHAKE_FINISHES}, | 1143 CALLER_RECEIVES_FINGERPRINT, HANDSHAKE_FINISHES}, |
| 1162 std::vector<DtlsTransportEvent>{CALLER_RECEIVES_CLIENTHELLO, | 1144 std::vector<DtlsTransportEvent>{CALLER_RECEIVES_CLIENTHELLO, |
| 1163 CALLER_WRITABLE, HANDSHAKE_FINISHES, | 1145 CALLER_WRITABLE, HANDSHAKE_FINISHES, |
| 1164 CALLER_RECEIVES_FINGERPRINT}), | 1146 CALLER_RECEIVES_FINGERPRINT}), |
| 1165 ::testing::Bool())); | 1147 ::testing::Bool())); |
| OLD | NEW |