| 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 |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <set> | 12 #include <set> |
| 13 | 13 |
| 14 #include "webrtc/p2p/base/dtlstransportchannel.h" | 14 #include "webrtc/p2p/base/dtlstransportchannel.h" |
| 15 #include "webrtc/p2p/base/faketransportcontroller.h" | 15 #include "webrtc/p2p/base/faketransportcontroller.h" |
| 16 #include "webrtc/p2p/base/packettransportinterface.h" | 16 #include "webrtc/p2p/base/packettransportinterface.h" |
| 17 #include "webrtc/base/checks.h" |
| 17 #include "webrtc/base/common.h" | 18 #include "webrtc/base/common.h" |
| 18 #include "webrtc/base/dscp.h" | 19 #include "webrtc/base/dscp.h" |
| 19 #include "webrtc/base/gunit.h" | 20 #include "webrtc/base/gunit.h" |
| 20 #include "webrtc/base/helpers.h" | 21 #include "webrtc/base/helpers.h" |
| 21 #include "webrtc/base/ssladapter.h" | 22 #include "webrtc/base/ssladapter.h" |
| 22 #include "webrtc/base/sslidentity.h" | 23 #include "webrtc/base/sslidentity.h" |
| 23 #include "webrtc/base/sslstreamadapter.h" | 24 #include "webrtc/base/sslstreamadapter.h" |
| 24 #include "webrtc/base/stringutils.h" | 25 #include "webrtc/base/stringutils.h" |
| 25 | 26 |
| 26 #define MAYBE_SKIP_TEST(feature) \ | 27 #define MAYBE_SKIP_TEST(feature) \ |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 71 DtlsTestClient(const std::string& name) : name_(name) {} | 72 DtlsTestClient(const std::string& name) : name_(name) {} |
| 72 void CreateCertificate(rtc::KeyType key_type) { | 73 void CreateCertificate(rtc::KeyType key_type) { |
| 73 certificate_ = | 74 certificate_ = |
| 74 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>( | 75 rtc::RTCCertificate::Create(std::unique_ptr<rtc::SSLIdentity>( |
| 75 rtc::SSLIdentity::Generate(name_, key_type))); | 76 rtc::SSLIdentity::Generate(name_, key_type))); |
| 76 } | 77 } |
| 77 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate() { | 78 const rtc::scoped_refptr<rtc::RTCCertificate>& certificate() { |
| 78 return certificate_; | 79 return certificate_; |
| 79 } | 80 } |
| 80 void SetupSrtp() { | 81 void SetupSrtp() { |
| 81 ASSERT(certificate_); | 82 EXPECT_TRUE(certificate_ != nullptr); |
| 82 use_dtls_srtp_ = true; | 83 use_dtls_srtp_ = true; |
| 83 } | 84 } |
| 84 void SetupMaxProtocolVersion(rtc::SSLProtocolVersion version) { | 85 void SetupMaxProtocolVersion(rtc::SSLProtocolVersion version) { |
| 85 ssl_max_version_ = version; | 86 ssl_max_version_ = version; |
| 86 } | 87 } |
| 87 void SetupChannels(int count, cricket::IceRole role, int async_delay_ms = 0) { | 88 void SetupChannels(int count, cricket::IceRole role, int async_delay_ms = 0) { |
| 88 transport_.reset( | 89 transport_.reset( |
| 89 new cricket::JsepTransport("dtls content name", certificate_)); | 90 new cricket::JsepTransport("dtls content name", certificate_)); |
| 90 for (int i = 0; i < count; ++i) { | 91 for (int i = 0; i < count; ++i) { |
| 91 cricket::FakeIceTransport* fake_ice_channel = | 92 cricket::FakeIceTransport* fake_ice_channel = |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 | 294 |
| 294 EXPECT_TRUE( | 295 EXPECT_TRUE( |
| 295 rtc::SSLStreamAdapter::IsAcceptableCipher(cipher, rtc::KT_DEFAULT)); | 296 rtc::SSLStreamAdapter::IsAcceptableCipher(cipher, rtc::KT_DEFAULT)); |
| 296 } else { | 297 } else { |
| 297 ASSERT_FALSE(rv); | 298 ASSERT_FALSE(rv); |
| 298 } | 299 } |
| 299 } | 300 } |
| 300 } | 301 } |
| 301 | 302 |
| 302 void SendPackets(size_t channel, size_t size, size_t count, bool srtp) { | 303 void SendPackets(size_t channel, size_t size, size_t count, bool srtp) { |
| 303 ASSERT(channel < channels_.size()); | 304 RTC_CHECK(channel < channels_.size()); |
| 304 std::unique_ptr<char[]> packet(new char[size]); | 305 std::unique_ptr<char[]> packet(new char[size]); |
| 305 size_t sent = 0; | 306 size_t sent = 0; |
| 306 do { | 307 do { |
| 307 // Fill the packet with a known value and a sequence number to check | 308 // Fill the packet with a known value and a sequence number to check |
| 308 // against, and make sure that it doesn't look like DTLS. | 309 // against, and make sure that it doesn't look like DTLS. |
| 309 memset(packet.get(), sent & 0xff, size); | 310 memset(packet.get(), sent & 0xff, size); |
| 310 packet[0] = (srtp) ? 0x80 : 0x00; | 311 packet[0] = (srtp) ? 0x80 : 0x00; |
| 311 rtc::SetBE32(packet.get() + kPacketNumOffset, | 312 rtc::SetBE32(packet.get() + kPacketNumOffset, |
| 312 static_cast<uint32_t>(sent)); | 313 static_cast<uint32_t>(sent)); |
| 313 | 314 |
| 314 // Only set the bypass flag if we've activated DTLS. | 315 // Only set the bypass flag if we've activated DTLS. |
| 315 int flags = (certificate_ && srtp) ? cricket::PF_SRTP_BYPASS : 0; | 316 int flags = (certificate_ && srtp) ? cricket::PF_SRTP_BYPASS : 0; |
| 316 rtc::PacketOptions packet_options; | 317 rtc::PacketOptions packet_options; |
| 317 packet_options.packet_id = kFakePacketId; | 318 packet_options.packet_id = kFakePacketId; |
| 318 int rv = channels_[channel]->SendPacket( | 319 int rv = channels_[channel]->SendPacket( |
| 319 packet.get(), size, packet_options, flags); | 320 packet.get(), size, packet_options, flags); |
| 320 ASSERT_GT(rv, 0); | 321 ASSERT_GT(rv, 0); |
| 321 ASSERT_EQ(size, static_cast<size_t>(rv)); | 322 ASSERT_EQ(size, static_cast<size_t>(rv)); |
| 322 ++sent; | 323 ++sent; |
| 323 } while (sent < count); | 324 } while (sent < count); |
| 324 } | 325 } |
| 325 | 326 |
| 326 int SendInvalidSrtpPacket(size_t channel, size_t size) { | 327 int SendInvalidSrtpPacket(size_t channel, size_t size) { |
| 327 ASSERT(channel < channels_.size()); | 328 RTC_CHECK(channel < channels_.size()); |
| 328 std::unique_ptr<char[]> packet(new char[size]); | 329 std::unique_ptr<char[]> packet(new char[size]); |
| 329 // Fill the packet with 0 to form an invalid SRTP packet. | 330 // Fill the packet with 0 to form an invalid SRTP packet. |
| 330 memset(packet.get(), 0, size); | 331 memset(packet.get(), 0, size); |
| 331 | 332 |
| 332 rtc::PacketOptions packet_options; | 333 rtc::PacketOptions packet_options; |
| 333 return channels_[channel]->SendPacket( | 334 return channels_[channel]->SendPacket( |
| 334 packet.get(), size, packet_options, cricket::PF_SRTP_BYPASS); | 335 packet.get(), size, packet_options, cricket::PF_SRTP_BYPASS); |
| 335 } | 336 } |
| 336 | 337 |
| 337 void ExpectPackets(size_t channel, size_t size) { | 338 void ExpectPackets(size_t channel, size_t size) { |
| (...skipping 845 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1183 std::vector<DtlsTransportEvent>{ | 1184 std::vector<DtlsTransportEvent>{ |
| 1184 CALLER_RECEIVES_CLIENTHELLO, CALLER_RECEIVES_FINGERPRINT, | 1185 CALLER_RECEIVES_CLIENTHELLO, CALLER_RECEIVES_FINGERPRINT, |
| 1185 CALLER_WRITABLE, HANDSHAKE_FINISHES}, | 1186 CALLER_WRITABLE, HANDSHAKE_FINISHES}, |
| 1186 std::vector<DtlsTransportEvent>{ | 1187 std::vector<DtlsTransportEvent>{ |
| 1187 CALLER_RECEIVES_CLIENTHELLO, CALLER_WRITABLE, | 1188 CALLER_RECEIVES_CLIENTHELLO, CALLER_WRITABLE, |
| 1188 CALLER_RECEIVES_FINGERPRINT, HANDSHAKE_FINISHES}, | 1189 CALLER_RECEIVES_FINGERPRINT, HANDSHAKE_FINISHES}, |
| 1189 std::vector<DtlsTransportEvent>{CALLER_RECEIVES_CLIENTHELLO, | 1190 std::vector<DtlsTransportEvent>{CALLER_RECEIVES_CLIENTHELLO, |
| 1190 CALLER_WRITABLE, HANDSHAKE_FINISHES, | 1191 CALLER_WRITABLE, HANDSHAKE_FINISHES, |
| 1191 CALLER_RECEIVES_FINGERPRINT}), | 1192 CALLER_RECEIVES_FINGERPRINT}), |
| 1192 ::testing::Bool())); | 1193 ::testing::Bool())); |
| OLD | NEW |