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 16 matching lines...) Expand all Loading... |
27 LOG(LS_INFO) << "Feature disabled... skipping"; \ | 27 LOG(LS_INFO) << "Feature disabled... skipping"; \ |
28 return; \ | 28 return; \ |
29 } | 29 } |
30 | 30 |
31 static const char AES_CM_128_HMAC_SHA1_80[] = "AES_CM_128_HMAC_SHA1_80"; | 31 static const char AES_CM_128_HMAC_SHA1_80[] = "AES_CM_128_HMAC_SHA1_80"; |
32 static const char kIceUfrag1[] = "TESTICEUFRAG0001"; | 32 static const char kIceUfrag1[] = "TESTICEUFRAG0001"; |
33 static const char kIcePwd1[] = "TESTICEPWD00000000000001"; | 33 static const char kIcePwd1[] = "TESTICEPWD00000000000001"; |
34 static const size_t kPacketNumOffset = 8; | 34 static const size_t kPacketNumOffset = 8; |
35 static const size_t kPacketHeaderLen = 12; | 35 static const size_t kPacketHeaderLen = 12; |
36 | 36 |
37 static bool IsRtpLeadByte(uint8 b) { | 37 static bool IsRtpLeadByte(uint8_t b) { |
38 return ((b & 0xC0) == 0x80); | 38 return ((b & 0xC0) == 0x80); |
39 } | 39 } |
40 | 40 |
41 using cricket::ConnectionRole; | 41 using cricket::ConnectionRole; |
42 | 42 |
43 enum Flags { NF_REOFFER = 0x1, NF_EXPECT_FAILURE = 0x2 }; | 43 enum Flags { NF_REOFFER = 0x1, NF_EXPECT_FAILURE = 0x2 }; |
44 | 44 |
45 class DtlsTestClient : public sigslot::has_slots<> { | 45 class DtlsTestClient : public sigslot::has_slots<> { |
46 public: | 46 public: |
47 DtlsTestClient(const std::string& name) | 47 DtlsTestClient(const std::string& name) |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 void SendPackets(size_t channel, size_t size, size_t count, bool srtp) { | 247 void SendPackets(size_t channel, size_t size, size_t count, bool srtp) { |
248 ASSERT(channel < channels_.size()); | 248 ASSERT(channel < channels_.size()); |
249 rtc::scoped_ptr<char[]> packet(new char[size]); | 249 rtc::scoped_ptr<char[]> packet(new char[size]); |
250 size_t sent = 0; | 250 size_t sent = 0; |
251 do { | 251 do { |
252 // Fill the packet with a known value and a sequence number to check | 252 // Fill the packet with a known value and a sequence number to check |
253 // against, and make sure that it doesn't look like DTLS. | 253 // against, and make sure that it doesn't look like DTLS. |
254 memset(packet.get(), sent & 0xff, size); | 254 memset(packet.get(), sent & 0xff, size); |
255 packet[0] = (srtp) ? 0x80 : 0x00; | 255 packet[0] = (srtp) ? 0x80 : 0x00; |
256 rtc::SetBE32(packet.get() + kPacketNumOffset, | 256 rtc::SetBE32(packet.get() + kPacketNumOffset, |
257 static_cast<uint32>(sent)); | 257 static_cast<uint32_t>(sent)); |
258 | 258 |
259 // Only set the bypass flag if we've activated DTLS. | 259 // Only set the bypass flag if we've activated DTLS. |
260 int flags = (certificate_ && srtp) ? cricket::PF_SRTP_BYPASS : 0; | 260 int flags = (certificate_ && srtp) ? cricket::PF_SRTP_BYPASS : 0; |
261 rtc::PacketOptions packet_options; | 261 rtc::PacketOptions packet_options; |
262 int rv = channels_[channel]->SendPacket( | 262 int rv = channels_[channel]->SendPacket( |
263 packet.get(), size, packet_options, flags); | 263 packet.get(), size, packet_options, flags); |
264 ASSERT_GT(rv, 0); | 264 ASSERT_GT(rv, 0); |
265 ASSERT_EQ(size, static_cast<size_t>(rv)); | 265 ASSERT_EQ(size, static_cast<size_t>(rv)); |
266 ++sent; | 266 ++sent; |
267 } while (sent < count); | 267 } while (sent < count); |
(...skipping 12 matching lines...) Expand all Loading... |
280 | 280 |
281 void ExpectPackets(size_t channel, size_t size) { | 281 void ExpectPackets(size_t channel, size_t size) { |
282 packet_size_ = size; | 282 packet_size_ = size; |
283 received_.clear(); | 283 received_.clear(); |
284 } | 284 } |
285 | 285 |
286 size_t NumPacketsReceived() { | 286 size_t NumPacketsReceived() { |
287 return received_.size(); | 287 return received_.size(); |
288 } | 288 } |
289 | 289 |
290 bool VerifyPacket(const char* data, size_t size, uint32* out_num) { | 290 bool VerifyPacket(const char* data, size_t size, uint32_t* out_num) { |
291 if (size != packet_size_ || | 291 if (size != packet_size_ || |
292 (data[0] != 0 && static_cast<uint8>(data[0]) != 0x80)) { | 292 (data[0] != 0 && static_cast<uint8_t>(data[0]) != 0x80)) { |
293 return false; | 293 return false; |
294 } | 294 } |
295 uint32 packet_num = rtc::GetBE32(data + kPacketNumOffset); | 295 uint32_t packet_num = rtc::GetBE32(data + kPacketNumOffset); |
296 for (size_t i = kPacketHeaderLen; i < size; ++i) { | 296 for (size_t i = kPacketHeaderLen; i < size; ++i) { |
297 if (static_cast<uint8>(data[i]) != (packet_num & 0xff)) { | 297 if (static_cast<uint8_t>(data[i]) != (packet_num & 0xff)) { |
298 return false; | 298 return false; |
299 } | 299 } |
300 } | 300 } |
301 if (out_num) { | 301 if (out_num) { |
302 *out_num = packet_num; | 302 *out_num = packet_num; |
303 } | 303 } |
304 return true; | 304 return true; |
305 } | 305 } |
306 bool VerifyEncryptedPacket(const char* data, size_t size) { | 306 bool VerifyEncryptedPacket(const char* data, size_t size) { |
307 // This is an encrypted data packet; let's make sure it's mostly random; | 307 // This is an encrypted data packet; let's make sure it's mostly random; |
308 // less than 10% of the bytes should be equal to the cleartext packet. | 308 // less than 10% of the bytes should be equal to the cleartext packet. |
309 if (size <= packet_size_) { | 309 if (size <= packet_size_) { |
310 return false; | 310 return false; |
311 } | 311 } |
312 uint32 packet_num = rtc::GetBE32(data + kPacketNumOffset); | 312 uint32_t packet_num = rtc::GetBE32(data + kPacketNumOffset); |
313 int num_matches = 0; | 313 int num_matches = 0; |
314 for (size_t i = kPacketNumOffset; i < size; ++i) { | 314 for (size_t i = kPacketNumOffset; i < size; ++i) { |
315 if (static_cast<uint8>(data[i]) == (packet_num & 0xff)) { | 315 if (static_cast<uint8_t>(data[i]) == (packet_num & 0xff)) { |
316 ++num_matches; | 316 ++num_matches; |
317 } | 317 } |
318 } | 318 } |
319 return (num_matches < ((static_cast<int>(size) - 5) / 10)); | 319 return (num_matches < ((static_cast<int>(size) - 5) / 10)); |
320 } | 320 } |
321 | 321 |
322 // Transport channel callbacks | 322 // Transport channel callbacks |
323 void OnTransportChannelWritableState(cricket::TransportChannel* channel) { | 323 void OnTransportChannelWritableState(cricket::TransportChannel* channel) { |
324 LOG(LS_INFO) << name_ << ": Channel '" << channel->component() | 324 LOG(LS_INFO) << name_ << ": Channel '" << channel->component() |
325 << "' is writable"; | 325 << "' is writable"; |
326 } | 326 } |
327 | 327 |
328 void OnTransportChannelReadPacket(cricket::TransportChannel* channel, | 328 void OnTransportChannelReadPacket(cricket::TransportChannel* channel, |
329 const char* data, size_t size, | 329 const char* data, size_t size, |
330 const rtc::PacketTime& packet_time, | 330 const rtc::PacketTime& packet_time, |
331 int flags) { | 331 int flags) { |
332 uint32 packet_num = 0; | 332 uint32_t packet_num = 0; |
333 ASSERT_TRUE(VerifyPacket(data, size, &packet_num)); | 333 ASSERT_TRUE(VerifyPacket(data, size, &packet_num)); |
334 received_.insert(packet_num); | 334 received_.insert(packet_num); |
335 // Only DTLS-SRTP packets should have the bypass flag set. | 335 // Only DTLS-SRTP packets should have the bypass flag set. |
336 int expected_flags = | 336 int expected_flags = |
337 (certificate_ && IsRtpLeadByte(data[0])) ? cricket::PF_SRTP_BYPASS : 0; | 337 (certificate_ && IsRtpLeadByte(data[0])) ? cricket::PF_SRTP_BYPASS : 0; |
338 ASSERT_EQ(expected_flags, flags); | 338 ASSERT_EQ(expected_flags, flags); |
339 } | 339 } |
340 | 340 |
341 // Hook into the raw packet stream to make sure DTLS packets are encrypted. | 341 // Hook into the raw packet stream to make sure DTLS packets are encrypted. |
342 void OnFakeTransportChannelReadPacket(cricket::TransportChannel* channel, | 342 void OnFakeTransportChannelReadPacket(cricket::TransportChannel* channel, |
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
864 // Each side's remote certificate is the other side's local certificate. | 864 // Each side's remote certificate is the other side's local certificate. |
865 ASSERT_TRUE( | 865 ASSERT_TRUE( |
866 client1_.transport()->GetRemoteSSLCertificate(remote_cert1.accept())); | 866 client1_.transport()->GetRemoteSSLCertificate(remote_cert1.accept())); |
867 ASSERT_EQ(remote_cert1->ToPEMString(), | 867 ASSERT_EQ(remote_cert1->ToPEMString(), |
868 certificate2->ssl_certificate().ToPEMString()); | 868 certificate2->ssl_certificate().ToPEMString()); |
869 ASSERT_TRUE( | 869 ASSERT_TRUE( |
870 client2_.transport()->GetRemoteSSLCertificate(remote_cert2.accept())); | 870 client2_.transport()->GetRemoteSSLCertificate(remote_cert2.accept())); |
871 ASSERT_EQ(remote_cert2->ToPEMString(), | 871 ASSERT_EQ(remote_cert2->ToPEMString(), |
872 certificate1->ssl_certificate().ToPEMString()); | 872 certificate1->ssl_certificate().ToPEMString()); |
873 } | 873 } |
OLD | NEW |