| 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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 } | 106 } |
| 107 | 107 |
| 108 return rtc::SR_SUCCESS; | 108 return rtc::SR_SUCCESS; |
| 109 } | 109 } |
| 110 | 110 |
| 111 // Catch readability events on in and pass them up. | 111 // Catch readability events on in and pass them up. |
| 112 void OnEventIn(rtc::StreamInterface* stream, int sig, int err) { | 112 void OnEventIn(rtc::StreamInterface* stream, int sig, int err) { |
| 113 int mask = (rtc::SE_READ | rtc::SE_CLOSE); | 113 int mask = (rtc::SE_READ | rtc::SE_CLOSE); |
| 114 | 114 |
| 115 if (sig & mask) { | 115 if (sig & mask) { |
| 116 LOG(LS_INFO) << "SSLDummyStreamBase::OnEvent side=" << side_ << " sig=" | 116 LOG(LS_VERBOSE) << "SSLDummyStreamBase::OnEvent side=" << side_ |
| 117 << sig << " forwarding upward"; | 117 << " sig=" << sig << " forwarding upward"; |
| 118 PostEvent(sig & mask, 0); | 118 PostEvent(sig & mask, 0); |
| 119 } | 119 } |
| 120 } | 120 } |
| 121 | 121 |
| 122 // Catch writeability events on out and pass them up. | 122 // Catch writeability events on out and pass them up. |
| 123 void OnEventOut(rtc::StreamInterface* stream, int sig, int err) { | 123 void OnEventOut(rtc::StreamInterface* stream, int sig, int err) { |
| 124 if (sig & rtc::SE_WRITE) { | 124 if (sig & rtc::SE_WRITE) { |
| 125 LOG(LS_INFO) << "SSLDummyStreamBase::OnEvent side=" << side_ << " sig=" | 125 LOG(LS_VERBOSE) << "SSLDummyStreamBase::OnEvent side=" << side_ |
| 126 << sig << " forwarding upward"; | 126 << " sig=" << sig << " forwarding upward"; |
| 127 | 127 |
| 128 PostEvent(sig & rtc::SE_WRITE, 0); | 128 PostEvent(sig & rtc::SE_WRITE, 0); |
| 129 } | 129 } |
| 130 } | 130 } |
| 131 | 131 |
| 132 // Write to the outgoing FifoBuffer | 132 // Write to the outgoing FifoBuffer |
| 133 rtc::StreamResult WriteData(const void* data, size_t data_len, | 133 rtc::StreamResult WriteData(const void* data, size_t data_len, |
| 134 size_t* written, int* error) { | 134 size_t* written, int* error) { |
| 135 return out_->Write(data, data_len, written, error); | 135 return out_->Write(data, data_len, written, error); |
| 136 } | 136 } |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 server_params.common_name = "server"; | 307 server_params.common_name = "server"; |
| 308 server_params.not_before = now + not_before; | 308 server_params.not_before = now + not_before; |
| 309 server_params.not_after = now + not_after; | 309 server_params.not_after = now + not_after; |
| 310 server_identity_ = rtc::SSLIdentity::GenerateForTest(server_params); | 310 server_identity_ = rtc::SSLIdentity::GenerateForTest(server_params); |
| 311 | 311 |
| 312 client_ssl_->SetIdentity(client_identity_); | 312 client_ssl_->SetIdentity(client_identity_); |
| 313 server_ssl_->SetIdentity(server_identity_); | 313 server_ssl_->SetIdentity(server_identity_); |
| 314 } | 314 } |
| 315 | 315 |
| 316 virtual void OnEvent(rtc::StreamInterface *stream, int sig, int err) { | 316 virtual void OnEvent(rtc::StreamInterface *stream, int sig, int err) { |
| 317 LOG(LS_INFO) << "SSLStreamAdapterTestBase::OnEvent sig=" << sig; | 317 LOG(LS_VERBOSE) << "SSLStreamAdapterTestBase::OnEvent sig=" << sig; |
| 318 | 318 |
| 319 if (sig & rtc::SE_READ) { | 319 if (sig & rtc::SE_READ) { |
| 320 ReadData(stream); | 320 ReadData(stream); |
| 321 } | 321 } |
| 322 | 322 |
| 323 if ((stream == client_ssl_.get()) && (sig & rtc::SE_WRITE)) { | 323 if ((stream == client_ssl_.get()) && (sig & rtc::SE_WRITE)) { |
| 324 WriteData(); | 324 WriteData(); |
| 325 } | 325 } |
| 326 } | 326 } |
| 327 | 327 |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 EXPECT_EQ(rtc::SS_CLOSED, client_ssl_->GetState()); | 459 EXPECT_EQ(rtc::SS_CLOSED, client_ssl_->GetState()); |
| 460 EXPECT_EQ(rtc::SS_CLOSED, server_ssl_->GetState()); | 460 EXPECT_EQ(rtc::SS_CLOSED, server_ssl_->GetState()); |
| 461 } | 461 } |
| 462 } | 462 } |
| 463 | 463 |
| 464 rtc::StreamResult DataWritten(SSLDummyStreamBase *from, const void *data, | 464 rtc::StreamResult DataWritten(SSLDummyStreamBase *from, const void *data, |
| 465 size_t data_len, size_t *written, | 465 size_t data_len, size_t *written, |
| 466 int *error) { | 466 int *error) { |
| 467 // Randomly drop loss_ percent of packets | 467 // Randomly drop loss_ percent of packets |
| 468 if (rtc::CreateRandomId() % 100 < static_cast<uint32_t>(loss_)) { | 468 if (rtc::CreateRandomId() % 100 < static_cast<uint32_t>(loss_)) { |
| 469 LOG(LS_INFO) << "Randomly dropping packet, size=" << data_len; | 469 LOG(LS_VERBOSE) << "Randomly dropping packet, size=" << data_len; |
| 470 *written = data_len; | 470 *written = data_len; |
| 471 return rtc::SR_SUCCESS; | 471 return rtc::SR_SUCCESS; |
| 472 } | 472 } |
| 473 if (dtls_ && (data_len > mtu_)) { | 473 if (dtls_ && (data_len > mtu_)) { |
| 474 LOG(LS_INFO) << "Dropping packet > mtu, size=" << data_len; | 474 LOG(LS_VERBOSE) << "Dropping packet > mtu, size=" << data_len; |
| 475 *written = data_len; | 475 *written = data_len; |
| 476 return rtc::SR_SUCCESS; | 476 return rtc::SR_SUCCESS; |
| 477 } | 477 } |
| 478 | 478 |
| 479 // Optionally damage application data (type 23). Note that we don't damage | 479 // Optionally damage application data (type 23). Note that we don't damage |
| 480 // handshake packets and we damage the last byte to keep the header | 480 // handshake packets and we damage the last byte to keep the header |
| 481 // intact but break the MAC. | 481 // intact but break the MAC. |
| 482 if (damage_ && (*static_cast<const unsigned char *>(data) == 23)) { | 482 if (damage_ && (*static_cast<const unsigned char *>(data) == 23)) { |
| 483 std::vector<char> buf(data_len); | 483 std::vector<char> buf(data_len); |
| 484 | 484 |
| 485 LOG(LS_INFO) << "Damaging packet"; | 485 LOG(LS_VERBOSE) << "Damaging packet"; |
| 486 | 486 |
| 487 memcpy(&buf[0], data, data_len); | 487 memcpy(&buf[0], data, data_len); |
| 488 buf[data_len - 1]++; | 488 buf[data_len - 1]++; |
| 489 | 489 |
| 490 return from->WriteData(&buf[0], data_len, written, error); | 490 return from->WriteData(&buf[0], data_len, written, error); |
| 491 } | 491 } |
| 492 | 492 |
| 493 return from->WriteData(data, data_len, written, error); | 493 return from->WriteData(data, data_len, written, error); |
| 494 } | 494 } |
| 495 | 495 |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 699 // Unfortunately, errors are the way that the stream adapter | 699 // Unfortunately, errors are the way that the stream adapter |
| 700 // signals close in OpenSSL. | 700 // signals close in OpenSSL. |
| 701 stream->Close(); | 701 stream->Close(); |
| 702 return; | 702 return; |
| 703 } | 703 } |
| 704 | 704 |
| 705 if (r == rtc::SR_BLOCK) | 705 if (r == rtc::SR_BLOCK) |
| 706 break; | 706 break; |
| 707 | 707 |
| 708 ASSERT_EQ(rtc::SR_SUCCESS, r); | 708 ASSERT_EQ(rtc::SR_SUCCESS, r); |
| 709 LOG(LS_INFO) << "Read " << bread; | 709 LOG(LS_VERBOSE) << "Read " << bread; |
| 710 | 710 |
| 711 recv_stream_.Write(buffer, bread, NULL, NULL); | 711 recv_stream_.Write(buffer, bread, NULL, NULL); |
| 712 } | 712 } |
| 713 } | 713 } |
| 714 | 714 |
| 715 private: | 715 private: |
| 716 rtc::FifoBuffer client_buffer_; | 716 rtc::FifoBuffer client_buffer_; |
| 717 rtc::FifoBuffer server_buffer_; | 717 rtc::FifoBuffer server_buffer_; |
| 718 rtc::MemoryStream send_stream_; | 718 rtc::MemoryStream send_stream_; |
| 719 rtc::MemoryStream recv_stream_; | 719 rtc::MemoryStream recv_stream_; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 // Unfortunately, errors are the way that the stream adapter | 792 // Unfortunately, errors are the way that the stream adapter |
| 793 // signals close right now | 793 // signals close right now |
| 794 stream->Close(); | 794 stream->Close(); |
| 795 return; | 795 return; |
| 796 } | 796 } |
| 797 | 797 |
| 798 if (r == rtc::SR_BLOCK) | 798 if (r == rtc::SR_BLOCK) |
| 799 break; | 799 break; |
| 800 | 800 |
| 801 ASSERT_EQ(rtc::SR_SUCCESS, r); | 801 ASSERT_EQ(rtc::SR_SUCCESS, r); |
| 802 LOG(LS_INFO) << "Read " << bread; | 802 LOG(LS_VERBOSE) << "Read " << bread; |
| 803 | 803 |
| 804 // Now parse the datagram | 804 // Now parse the datagram |
| 805 ASSERT_EQ(packet_size_, bread); | 805 ASSERT_EQ(packet_size_, bread); |
| 806 unsigned char packet_num = buffer[0]; | 806 unsigned char packet_num = buffer[0]; |
| 807 | 807 |
| 808 unsigned int rand_state = packet_num; | 808 unsigned int rand_state = packet_num; |
| 809 for (size_t i = 1; i < packet_size_; i++) { | 809 for (size_t i = 1; i < packet_size_; i++) { |
| 810 // This is a simple LC PRNG. Keep in synch with identical code above. | 810 // This is a simple LC PRNG. Keep in synch with identical code above. |
| 811 rand_state = (rand_state * 251 + 19937) >> 7; | 811 rand_state = (rand_state * 251 + 19937) >> 7; |
| 812 ASSERT_EQ(rand_state & 0xff, buffer[i]); | 812 ASSERT_EQ(rand_state & 0xff, buffer[i]); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 839 BufferQueueStream server_buffer_; | 839 BufferQueueStream server_buffer_; |
| 840 size_t packet_size_; | 840 size_t packet_size_; |
| 841 int count_; | 841 int count_; |
| 842 int sent_; | 842 int sent_; |
| 843 std::set<int> received_; | 843 std::set<int> received_; |
| 844 }; | 844 }; |
| 845 | 845 |
| 846 | 846 |
| 847 rtc::StreamResult SSLDummyStreamBase::Write(const void* data, size_t data_len, | 847 rtc::StreamResult SSLDummyStreamBase::Write(const void* data, size_t data_len, |
| 848 size_t* written, int* error) { | 848 size_t* written, int* error) { |
| 849 LOG(LS_INFO) << "Writing to loopback " << data_len; | 849 LOG(LS_VERBOSE) << "Writing to loopback " << data_len; |
| 850 | 850 |
| 851 if (first_packet_) { | 851 if (first_packet_) { |
| 852 first_packet_ = false; | 852 first_packet_ = false; |
| 853 if (test_base_->GetLoseFirstPacket()) { | 853 if (test_base_->GetLoseFirstPacket()) { |
| 854 LOG(LS_INFO) << "Losing initial packet of length " << data_len; | 854 LOG(LS_INFO) << "Losing initial packet of length " << data_len; |
| 855 *written = data_len; // Fake successful writing also to writer. | 855 *written = data_len; // Fake successful writing also to writer. |
| 856 return rtc::SR_SUCCESS; | 856 return rtc::SR_SUCCESS; |
| 857 } | 857 } |
| 858 } | 858 } |
| 859 | 859 |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1370 rtc::KeyParams::ECDSA(rtc::EC_NIST_P256)))); | 1370 rtc::KeyParams::ECDSA(rtc::EC_NIST_P256)))); |
| 1371 INSTANTIATE_TEST_CASE_P( | 1371 INSTANTIATE_TEST_CASE_P( |
| 1372 SSLStreamAdapterTestsDTLS, | 1372 SSLStreamAdapterTestsDTLS, |
| 1373 SSLStreamAdapterTestDTLS, | 1373 SSLStreamAdapterTestDTLS, |
| 1374 Combine(Values(rtc::KeyParams::RSA(1024, 65537), | 1374 Combine(Values(rtc::KeyParams::RSA(1024, 65537), |
| 1375 rtc::KeyParams::RSA(1152, 65537), | 1375 rtc::KeyParams::RSA(1152, 65537), |
| 1376 rtc::KeyParams::ECDSA(rtc::EC_NIST_P256)), | 1376 rtc::KeyParams::ECDSA(rtc::EC_NIST_P256)), |
| 1377 Values(rtc::KeyParams::RSA(1024, 65537), | 1377 Values(rtc::KeyParams::RSA(1024, 65537), |
| 1378 rtc::KeyParams::RSA(1152, 65537), | 1378 rtc::KeyParams::RSA(1152, 65537), |
| 1379 rtc::KeyParams::ECDSA(rtc::EC_NIST_P256)))); | 1379 rtc::KeyParams::ECDSA(rtc::EC_NIST_P256)))); |
| OLD | NEW |