Chromium Code Reviews| 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 | 11 |
| 12 #include <algorithm> | 12 #include <algorithm> |
| 13 #include <set> | 13 #include <set> |
| 14 #include <string> | 14 #include <string> |
| 15 | 15 |
| 16 #include "webrtc/base/bufferqueue.h" | |
| 16 #include "webrtc/base/gunit.h" | 17 #include "webrtc/base/gunit.h" |
| 17 #include "webrtc/base/helpers.h" | 18 #include "webrtc/base/helpers.h" |
| 18 #include "webrtc/base/scoped_ptr.h" | 19 #include "webrtc/base/scoped_ptr.h" |
| 19 #include "webrtc/base/ssladapter.h" | 20 #include "webrtc/base/ssladapter.h" |
| 20 #include "webrtc/base/sslconfig.h" | 21 #include "webrtc/base/sslconfig.h" |
| 21 #include "webrtc/base/sslidentity.h" | 22 #include "webrtc/base/sslidentity.h" |
| 22 #include "webrtc/base/sslstreamadapter.h" | 23 #include "webrtc/base/sslstreamadapter.h" |
| 23 #include "webrtc/base/stream.h" | 24 #include "webrtc/base/stream.h" |
| 24 #include "webrtc/test/testsupport/gtest_disable.h" | 25 #include "webrtc/test/testsupport/gtest_disable.h" |
| 25 | 26 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 67 "-----END CERTIFICATE-----\n"; | 68 "-----END CERTIFICATE-----\n"; |
| 68 | 69 |
| 69 #define MAYBE_SKIP_TEST(feature) \ | 70 #define MAYBE_SKIP_TEST(feature) \ |
| 70 if (!(rtc::SSLStreamAdapter::feature())) { \ | 71 if (!(rtc::SSLStreamAdapter::feature())) { \ |
| 71 LOG(LS_INFO) << "Feature disabled... skipping"; \ | 72 LOG(LS_INFO) << "Feature disabled... skipping"; \ |
| 72 return; \ | 73 return; \ |
| 73 } | 74 } |
| 74 | 75 |
| 75 class SSLStreamAdapterTestBase; | 76 class SSLStreamAdapterTestBase; |
| 76 | 77 |
| 77 class SSLDummyStream : public rtc::StreamInterface, | 78 class SSLDummyStreamBase : public rtc::StreamInterface, |
| 78 public sigslot::has_slots<> { | 79 public sigslot::has_slots<> { |
| 79 public: | 80 public: |
| 80 explicit SSLDummyStream(SSLStreamAdapterTestBase *test, | 81 SSLDummyStreamBase(SSLStreamAdapterTestBase* test, |
| 81 const std::string &side, | 82 const std::string &side, |
| 82 rtc::FifoBuffer *in, | 83 rtc::StreamInterface* in, |
| 83 rtc::FifoBuffer *out) : | 84 rtc::StreamInterface* out) : |
| 84 test_(test), | 85 test_base_(test), |
| 85 side_(side), | 86 side_(side), |
| 86 in_(in), | 87 in_(in), |
| 87 out_(out), | 88 out_(out), |
| 88 first_packet_(true) { | 89 first_packet_(true) { |
| 89 in_->SignalEvent.connect(this, &SSLDummyStream::OnEventIn); | 90 in_->SignalEvent.connect(this, &SSLDummyStreamBase::OnEventIn); |
| 90 out_->SignalEvent.connect(this, &SSLDummyStream::OnEventOut); | 91 out_->SignalEvent.connect(this, &SSLDummyStreamBase::OnEventOut); |
| 91 } | 92 } |
| 92 | 93 |
| 93 virtual rtc::StreamState GetState() const { return rtc::SS_OPEN; } | 94 rtc::StreamState GetState() const override { return rtc::SS_OPEN; } |
| 94 | 95 |
| 95 virtual rtc::StreamResult Read(void* buffer, size_t buffer_len, | 96 rtc::StreamResult Read(void* buffer, size_t buffer_len, |
| 96 size_t* read, int* error) { | 97 size_t* read, int* error) override { |
| 97 rtc::StreamResult r; | 98 rtc::StreamResult r; |
| 98 | 99 |
| 99 r = in_->Read(buffer, buffer_len, read, error); | 100 r = in_->Read(buffer, buffer_len, read, error); |
| 100 if (r == rtc::SR_BLOCK) | 101 if (r == rtc::SR_BLOCK) |
| 101 return rtc::SR_BLOCK; | 102 return rtc::SR_BLOCK; |
| 102 if (r == rtc::SR_EOS) | 103 if (r == rtc::SR_EOS) |
| 103 return rtc::SR_EOS; | 104 return rtc::SR_EOS; |
| 104 | 105 |
| 105 if (r != rtc::SR_SUCCESS) { | 106 if (r != rtc::SR_SUCCESS) { |
| 106 ADD_FAILURE(); | 107 ADD_FAILURE(); |
| 107 return rtc::SR_ERROR; | 108 return rtc::SR_ERROR; |
| 108 } | 109 } |
| 109 | 110 |
| 110 return rtc::SR_SUCCESS; | 111 return rtc::SR_SUCCESS; |
| 111 } | 112 } |
| 112 | 113 |
| 113 // Catch readability events on in and pass them up. | 114 // Catch readability events on in and pass them up. |
| 114 virtual void OnEventIn(rtc::StreamInterface *stream, int sig, | 115 void OnEventIn(rtc::StreamInterface* stream, int sig, int err) { |
| 115 int err) { | |
| 116 int mask = (rtc::SE_READ | rtc::SE_CLOSE); | 116 int mask = (rtc::SE_READ | rtc::SE_CLOSE); |
| 117 | 117 |
| 118 if (sig & mask) { | 118 if (sig & mask) { |
| 119 LOG(LS_INFO) << "SSLDummyStream::OnEvent side=" << side_ << " sig=" | 119 LOG(LS_INFO) << "SSLDummyStreamBase::OnEvent side=" << side_ << " sig=" |
| 120 << sig << " forwarding upward"; | 120 << sig << " forwarding upward"; |
| 121 PostEvent(sig & mask, 0); | 121 PostEvent(sig & mask, 0); |
| 122 } | 122 } |
| 123 } | 123 } |
| 124 | 124 |
| 125 // Catch writeability events on out and pass them up. | 125 // Catch writeability events on out and pass them up. |
| 126 virtual void OnEventOut(rtc::StreamInterface *stream, int sig, | 126 void OnEventOut(rtc::StreamInterface* stream, int sig, int err) { |
| 127 int err) { | |
| 128 if (sig & rtc::SE_WRITE) { | 127 if (sig & rtc::SE_WRITE) { |
| 129 LOG(LS_INFO) << "SSLDummyStream::OnEvent side=" << side_ << " sig=" | 128 LOG(LS_INFO) << "SSLDummyStreamBase::OnEvent side=" << side_ << " sig=" |
| 130 << sig << " forwarding upward"; | 129 << sig << " forwarding upward"; |
| 131 | 130 |
| 132 PostEvent(sig & rtc::SE_WRITE, 0); | 131 PostEvent(sig & rtc::SE_WRITE, 0); |
| 133 } | 132 } |
| 134 } | 133 } |
| 135 | 134 |
| 136 // Write to the outgoing FifoBuffer | 135 // Write to the outgoing FifoBuffer |
| 137 rtc::StreamResult WriteData(const void* data, size_t data_len, | 136 rtc::StreamResult WriteData(const void* data, size_t data_len, |
| 138 size_t* written, int* error) { | 137 size_t* written, int* error) { |
| 139 return out_->Write(data, data_len, written, error); | 138 return out_->Write(data, data_len, written, error); |
| 140 } | 139 } |
| 141 | 140 |
| 142 // Defined later | 141 rtc::StreamResult Write(const void* data, size_t data_len, |
| 143 virtual rtc::StreamResult Write(const void* data, size_t data_len, | 142 size_t* written, int* error) override; |
| 144 size_t* written, int* error); | |
| 145 | 143 |
| 146 virtual void Close() { | 144 void Close() override { |
| 147 LOG(LS_INFO) << "Closing outbound stream"; | 145 LOG(LS_INFO) << "Closing outbound stream"; |
| 148 out_->Close(); | 146 out_->Close(); |
| 149 } | 147 } |
| 150 | 148 |
| 151 private: | 149 protected: |
| 152 SSLStreamAdapterTestBase *test_; | 150 SSLStreamAdapterTestBase* test_base_; |
| 153 const std::string side_; | 151 const std::string side_; |
| 154 rtc::FifoBuffer *in_; | 152 rtc::StreamInterface* in_; |
| 155 rtc::FifoBuffer *out_; | 153 rtc::StreamInterface* out_; |
| 156 bool first_packet_; | 154 bool first_packet_; |
| 157 }; | 155 }; |
| 158 | 156 |
| 157 class SSLDummyStreamTLS : public SSLDummyStreamBase { | |
| 158 public: | |
| 159 SSLDummyStreamTLS(SSLStreamAdapterTestBase* test, | |
| 160 const std::string& side, | |
| 161 rtc::FifoBuffer* in, | |
| 162 rtc::FifoBuffer* out) : | |
| 163 SSLDummyStreamBase(test, side, in, out) { | |
| 164 } | |
| 165 }; | |
| 166 | |
| 167 class BufferQueueStream : public rtc::BufferQueue, | |
| 168 public rtc::StreamInterface { | |
| 169 public: | |
| 170 BufferQueueStream(size_t capacity, size_t default_size) | |
| 171 : rtc::BufferQueue(capacity, default_size) { | |
| 172 } | |
| 173 | |
| 174 // Implementation of abstract StreamInterface methods. | |
| 175 | |
| 176 // A buffer queue stream is always "open". | |
| 177 rtc::StreamState GetState() const override { return rtc::SS_OPEN; } | |
| 178 | |
| 179 // Reading a buffer queue stream will either succeed or block. | |
| 180 rtc::StreamResult Read(void* buffer, size_t buffer_len, | |
| 181 size_t* read, int* error) override { | |
| 182 if (!ReadFront(buffer, buffer_len, read)) { | |
| 183 return rtc::SR_BLOCK; | |
| 184 } | |
| 185 return rtc::SR_SUCCESS; | |
| 186 } | |
| 187 | |
| 188 // Writing to a buffer queue stream will either succeed or block. | |
| 189 rtc::StreamResult Write(const void* data, size_t data_len, | |
| 190 size_t* written, int* error) override { | |
| 191 if (!WriteBack(data, data_len, written)) { | |
| 192 return rtc::SR_BLOCK; | |
| 193 } | |
| 194 return rtc::SR_SUCCESS; | |
| 195 } | |
| 196 | |
| 197 // A buffer queue stream can not be closed. | |
| 198 void Close() override {} | |
| 199 | |
| 200 protected: | |
| 201 void NotifyReadableForTest() override { | |
| 202 PostEvent(rtc::SE_READ, 0); | |
| 203 } | |
| 204 | |
| 205 void NotifyWritableForTest() override { | |
| 206 PostEvent(rtc::SE_WRITE, 0); | |
| 207 } | |
| 208 }; | |
| 209 | |
| 210 class SSLDummyStreamDTLS : public SSLDummyStreamBase { | |
| 211 public: | |
| 212 SSLDummyStreamDTLS(SSLStreamAdapterTestBase* test, | |
| 213 const std::string& side, | |
| 214 BufferQueueStream* in, | |
| 215 BufferQueueStream* out) : | |
| 216 SSLDummyStreamBase(test, side, in, out) { | |
| 217 } | |
| 218 }; | |
| 219 | |
| 159 static const int kFifoBufferSize = 4096; | 220 static const int kFifoBufferSize = 4096; |
| 221 static const int kBufferCapacity = 1; | |
| 222 static const size_t kDefaultBufferSize = 2048; | |
| 160 | 223 |
| 161 class SSLStreamAdapterTestBase : public testing::Test, | 224 class SSLStreamAdapterTestBase : public testing::Test, |
| 162 public sigslot::has_slots<> { | 225 public sigslot::has_slots<> { |
| 163 public: | 226 public: |
| 164 SSLStreamAdapterTestBase( | 227 SSLStreamAdapterTestBase( |
| 165 const std::string& client_cert_pem, | 228 const std::string& client_cert_pem, |
| 166 const std::string& client_private_key_pem, | 229 const std::string& client_private_key_pem, |
| 167 bool dtls, | 230 bool dtls, |
| 168 rtc::KeyParams client_key_type = rtc::KeyParams(rtc::KT_DEFAULT), | 231 rtc::KeyParams client_key_type = rtc::KeyParams(rtc::KT_DEFAULT), |
| 169 rtc::KeyParams server_key_type = rtc::KeyParams(rtc::KT_DEFAULT)) | 232 rtc::KeyParams server_key_type = rtc::KeyParams(rtc::KT_DEFAULT)) |
| 170 : client_buffer_(kFifoBufferSize), | 233 : client_cert_pem_(client_cert_pem), |
| 171 server_buffer_(kFifoBufferSize), | 234 client_private_key_pem_(client_private_key_pem), |
| 172 client_stream_( | 235 client_key_type_(client_key_type), |
| 173 new SSLDummyStream(this, "c2s", &client_buffer_, &server_buffer_)), | 236 server_key_type_(server_key_type), |
| 174 server_stream_( | 237 client_stream_(NULL), |
| 175 new SSLDummyStream(this, "s2c", &server_buffer_, &client_buffer_)), | 238 server_stream_(NULL), |
| 176 client_ssl_(rtc::SSLStreamAdapter::Create(client_stream_)), | |
| 177 server_ssl_(rtc::SSLStreamAdapter::Create(server_stream_)), | |
| 178 client_identity_(NULL), | 239 client_identity_(NULL), |
| 179 server_identity_(NULL), | 240 server_identity_(NULL), |
| 180 delay_(0), | 241 delay_(0), |
| 181 mtu_(1460), | 242 mtu_(1460), |
| 182 loss_(0), | 243 loss_(0), |
| 183 lose_first_packet_(false), | 244 lose_first_packet_(false), |
| 184 damage_(false), | 245 damage_(false), |
| 185 dtls_(dtls), | 246 dtls_(dtls), |
| 186 handshake_wait_(5000), | 247 handshake_wait_(5000), |
| 187 identities_set_(false) { | 248 identities_set_(false) { |
| 188 // Set use of the test RNG to get predictable loss patterns. | 249 // Set use of the test RNG to get predictable loss patterns. |
| 189 rtc::SetRandomTestMode(true); | 250 rtc::SetRandomTestMode(true); |
| 190 | |
| 191 // Set up the slots | |
| 192 client_ssl_->SignalEvent.connect(this, &SSLStreamAdapterTestBase::OnEvent); | |
| 193 server_ssl_->SignalEvent.connect(this, &SSLStreamAdapterTestBase::OnEvent); | |
| 194 | |
| 195 if (!client_cert_pem.empty() && !client_private_key_pem.empty()) { | |
| 196 client_identity_ = rtc::SSLIdentity::FromPEMStrings( | |
| 197 client_private_key_pem, client_cert_pem); | |
| 198 } else { | |
| 199 client_identity_ = rtc::SSLIdentity::Generate("client", client_key_type); | |
| 200 } | |
| 201 server_identity_ = rtc::SSLIdentity::Generate("server", server_key_type); | |
| 202 | |
| 203 client_ssl_->SetIdentity(client_identity_); | |
| 204 server_ssl_->SetIdentity(server_identity_); | |
| 205 } | 251 } |
| 206 | 252 |
| 207 ~SSLStreamAdapterTestBase() { | 253 ~SSLStreamAdapterTestBase() { |
| 208 // Put it back for the next test. | 254 // Put it back for the next test. |
| 209 rtc::SetRandomTestMode(false); | 255 rtc::SetRandomTestMode(false); |
| 210 } | 256 } |
| 211 | 257 |
| 258 virtual void SetUp() override { | |
|
torbjorng (webrtc)
2015/11/19 12:51:10
Nit: Remove virtual (here and in 4 more places).
| |
| 259 CreateStreams(); | |
| 260 | |
| 261 client_ssl_.reset(rtc::SSLStreamAdapter::Create(client_stream_)); | |
| 262 server_ssl_.reset(rtc::SSLStreamAdapter::Create(server_stream_)); | |
| 263 | |
| 264 // Set up the slots | |
| 265 client_ssl_->SignalEvent.connect(this, &SSLStreamAdapterTestBase::OnEvent); | |
| 266 server_ssl_->SignalEvent.connect(this, &SSLStreamAdapterTestBase::OnEvent); | |
| 267 | |
| 268 if (!client_cert_pem_.empty() && !client_private_key_pem_.empty()) { | |
|
torbjorng (webrtc)
2015/11/19 12:51:10
Nit: With your slightly changed logic around PEM s
| |
| 269 client_identity_ = rtc::SSLIdentity::FromPEMStrings( | |
| 270 client_private_key_pem_, client_cert_pem_); | |
| 271 } else { | |
| 272 client_identity_ = rtc::SSLIdentity::Generate("client", client_key_type_); | |
| 273 } | |
| 274 server_identity_ = rtc::SSLIdentity::Generate("server", server_key_type_); | |
| 275 | |
| 276 client_ssl_->SetIdentity(client_identity_); | |
| 277 server_ssl_->SetIdentity(server_identity_); | |
| 278 } | |
| 279 | |
| 280 virtual void TearDown() override { | |
| 281 client_ssl_.reset(nullptr); | |
| 282 server_ssl_.reset(nullptr); | |
| 283 } | |
| 284 | |
| 285 virtual void CreateStreams() = 0; | |
| 286 | |
| 212 // Recreate the client/server identities with the specified validity period. | 287 // Recreate the client/server identities with the specified validity period. |
| 213 // |not_before| and |not_after| are offsets from the current time in number | 288 // |not_before| and |not_after| are offsets from the current time in number |
| 214 // of seconds. | 289 // of seconds. |
| 215 void ResetIdentitiesWithValidity(int not_before, int not_after) { | 290 void ResetIdentitiesWithValidity(int not_before, int not_after) { |
| 216 client_stream_ = | 291 CreateStreams(); |
| 217 new SSLDummyStream(this, "c2s", &client_buffer_, &server_buffer_); | |
| 218 server_stream_ = | |
| 219 new SSLDummyStream(this, "s2c", &server_buffer_, &client_buffer_); | |
| 220 | 292 |
| 221 client_ssl_.reset(rtc::SSLStreamAdapter::Create(client_stream_)); | 293 client_ssl_.reset(rtc::SSLStreamAdapter::Create(client_stream_)); |
| 222 server_ssl_.reset(rtc::SSLStreamAdapter::Create(server_stream_)); | 294 server_ssl_.reset(rtc::SSLStreamAdapter::Create(server_stream_)); |
| 223 | 295 |
| 224 client_ssl_->SignalEvent.connect(this, &SSLStreamAdapterTestBase::OnEvent); | 296 client_ssl_->SignalEvent.connect(this, &SSLStreamAdapterTestBase::OnEvent); |
| 225 server_ssl_->SignalEvent.connect(this, &SSLStreamAdapterTestBase::OnEvent); | 297 server_ssl_->SignalEvent.connect(this, &SSLStreamAdapterTestBase::OnEvent); |
| 226 | 298 |
| 227 rtc::SSLIdentityParams client_params; | 299 rtc::SSLIdentityParams client_params; |
| 228 client_params.key_params = rtc::KeyParams(rtc::KT_DEFAULT); | 300 client_params.key_params = rtc::KeyParams(rtc::KT_DEFAULT); |
| 229 client_params.common_name = "client"; | 301 client_params.common_name = "client"; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 324 if (expect_success) { | 396 if (expect_success) { |
| 325 EXPECT_TRUE_WAIT((client_ssl_->GetState() == rtc::SS_OPEN) | 397 EXPECT_TRUE_WAIT((client_ssl_->GetState() == rtc::SS_OPEN) |
| 326 && (server_ssl_->GetState() == rtc::SS_OPEN), | 398 && (server_ssl_->GetState() == rtc::SS_OPEN), |
| 327 handshake_wait_); | 399 handshake_wait_); |
| 328 } else { | 400 } else { |
| 329 EXPECT_TRUE_WAIT(client_ssl_->GetState() == rtc::SS_CLOSED, | 401 EXPECT_TRUE_WAIT(client_ssl_->GetState() == rtc::SS_CLOSED, |
| 330 handshake_wait_); | 402 handshake_wait_); |
| 331 } | 403 } |
| 332 } | 404 } |
| 333 | 405 |
| 334 rtc::StreamResult DataWritten(SSLDummyStream *from, const void *data, | 406 rtc::StreamResult DataWritten(SSLDummyStreamBase *from, const void *data, |
| 335 size_t data_len, size_t *written, | 407 size_t data_len, size_t *written, |
| 336 int *error) { | 408 int *error) { |
| 337 // Randomly drop loss_ percent of packets | 409 // Randomly drop loss_ percent of packets |
| 338 if (rtc::CreateRandomId() % 100 < static_cast<uint32_t>(loss_)) { | 410 if (rtc::CreateRandomId() % 100 < static_cast<uint32_t>(loss_)) { |
| 339 LOG(LS_INFO) << "Randomly dropping packet, size=" << data_len; | 411 LOG(LS_INFO) << "Randomly dropping packet, size=" << data_len; |
| 340 *written = data_len; | 412 *written = data_len; |
| 341 return rtc::SR_SUCCESS; | 413 return rtc::SR_SUCCESS; |
| 342 } | 414 } |
| 343 if (dtls_ && (data_len > mtu_)) { | 415 if (dtls_ && (data_len > mtu_)) { |
| 344 LOG(LS_INFO) << "Dropping packet > mtu, size=" << data_len; | 416 LOG(LS_INFO) << "Dropping packet > mtu, size=" << data_len; |
| 345 *written = data_len; | 417 *written = data_len; |
| 346 return rtc::SR_SUCCESS; | 418 return rtc::SR_SUCCESS; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 436 use_context, | 508 use_context, |
| 437 result, result_len); | 509 result, result_len); |
| 438 } | 510 } |
| 439 | 511 |
| 440 // To be implemented by subclasses. | 512 // To be implemented by subclasses. |
| 441 virtual void WriteData() = 0; | 513 virtual void WriteData() = 0; |
| 442 virtual void ReadData(rtc::StreamInterface *stream) = 0; | 514 virtual void ReadData(rtc::StreamInterface *stream) = 0; |
| 443 virtual void TestTransfer(int size) = 0; | 515 virtual void TestTransfer(int size) = 0; |
| 444 | 516 |
| 445 protected: | 517 protected: |
| 446 rtc::FifoBuffer client_buffer_; | 518 std::string client_cert_pem_; |
| 447 rtc::FifoBuffer server_buffer_; | 519 std::string client_private_key_pem_; |
| 448 SSLDummyStream *client_stream_; // freed by client_ssl_ destructor | 520 rtc::KeyParams client_key_type_; |
| 449 SSLDummyStream *server_stream_; // freed by server_ssl_ destructor | 521 rtc::KeyParams server_key_type_; |
| 522 SSLDummyStreamBase *client_stream_; // freed by client_ssl_ destructor | |
| 523 SSLDummyStreamBase *server_stream_; // freed by server_ssl_ destructor | |
| 450 rtc::scoped_ptr<rtc::SSLStreamAdapter> client_ssl_; | 524 rtc::scoped_ptr<rtc::SSLStreamAdapter> client_ssl_; |
| 451 rtc::scoped_ptr<rtc::SSLStreamAdapter> server_ssl_; | 525 rtc::scoped_ptr<rtc::SSLStreamAdapter> server_ssl_; |
| 452 rtc::SSLIdentity *client_identity_; // freed by client_ssl_ destructor | 526 rtc::SSLIdentity *client_identity_; // freed by client_ssl_ destructor |
| 453 rtc::SSLIdentity *server_identity_; // freed by server_ssl_ destructor | 527 rtc::SSLIdentity *server_identity_; // freed by server_ssl_ destructor |
| 454 int delay_; | 528 int delay_; |
| 455 size_t mtu_; | 529 size_t mtu_; |
| 456 int loss_; | 530 int loss_; |
| 457 bool lose_first_packet_; | 531 bool lose_first_packet_; |
| 458 bool damage_; | 532 bool damage_; |
| 459 bool dtls_; | 533 bool dtls_; |
| 460 int handshake_wait_; | 534 int handshake_wait_; |
| 461 bool identities_set_; | 535 bool identities_set_; |
| 462 }; | 536 }; |
| 463 | 537 |
| 464 class SSLStreamAdapterTestTLS | 538 class SSLStreamAdapterTestTLS |
| 465 : public SSLStreamAdapterTestBase, | 539 : public SSLStreamAdapterTestBase, |
| 466 public WithParamInterface<tuple<rtc::KeyParams, rtc::KeyParams>> { | 540 public WithParamInterface<tuple<rtc::KeyParams, rtc::KeyParams>> { |
| 467 public: | 541 public: |
| 468 SSLStreamAdapterTestTLS() | 542 SSLStreamAdapterTestTLS() |
| 469 : SSLStreamAdapterTestBase("", | 543 : SSLStreamAdapterTestBase("", |
| 470 "", | 544 "", |
| 471 false, | 545 false, |
| 472 ::testing::get<0>(GetParam()), | 546 ::testing::get<0>(GetParam()), |
| 473 ::testing::get<1>(GetParam())){}; | 547 ::testing::get<1>(GetParam())), |
| 548 client_buffer_(kFifoBufferSize), | |
| 549 server_buffer_(kFifoBufferSize) { | |
| 550 } | |
| 551 | |
| 552 virtual void CreateStreams() override { | |
| 553 client_stream_ = | |
| 554 new SSLDummyStreamTLS(this, "c2s", &client_buffer_, &server_buffer_); | |
| 555 server_stream_ = | |
| 556 new SSLDummyStreamTLS(this, "s2c", &server_buffer_, &client_buffer_); | |
| 557 } | |
| 474 | 558 |
| 475 // Test data transfer for TLS | 559 // Test data transfer for TLS |
| 476 virtual void TestTransfer(int size) { | 560 virtual void TestTransfer(int size) { |
| 477 LOG(LS_INFO) << "Starting transfer test with " << size << " bytes"; | 561 LOG(LS_INFO) << "Starting transfer test with " << size << " bytes"; |
| 478 // Create some dummy data to send. | 562 // Create some dummy data to send. |
| 479 size_t received; | 563 size_t received; |
| 480 | 564 |
| 481 send_stream_.ReserveSize(size); | 565 send_stream_.ReserveSize(size); |
| 482 for (int i = 0; i < size; ++i) { | 566 for (int i = 0; i < size; ++i) { |
| 483 char ch = static_cast<char>(i); | 567 char ch = static_cast<char>(i); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 558 break; | 642 break; |
| 559 | 643 |
| 560 ASSERT_EQ(rtc::SR_SUCCESS, r); | 644 ASSERT_EQ(rtc::SR_SUCCESS, r); |
| 561 LOG(LS_INFO) << "Read " << bread; | 645 LOG(LS_INFO) << "Read " << bread; |
| 562 | 646 |
| 563 recv_stream_.Write(buffer, bread, NULL, NULL); | 647 recv_stream_.Write(buffer, bread, NULL, NULL); |
| 564 } | 648 } |
| 565 } | 649 } |
| 566 | 650 |
| 567 private: | 651 private: |
| 652 rtc::FifoBuffer client_buffer_; | |
| 653 rtc::FifoBuffer server_buffer_; | |
| 568 rtc::MemoryStream send_stream_; | 654 rtc::MemoryStream send_stream_; |
| 569 rtc::MemoryStream recv_stream_; | 655 rtc::MemoryStream recv_stream_; |
| 570 }; | 656 }; |
| 571 | 657 |
| 572 class SSLStreamAdapterTestDTLS | 658 class SSLStreamAdapterTestDTLS |
| 573 : public SSLStreamAdapterTestBase, | 659 : public SSLStreamAdapterTestBase, |
| 574 public WithParamInterface<tuple<rtc::KeyParams, rtc::KeyParams>> { | 660 public WithParamInterface<tuple<rtc::KeyParams, rtc::KeyParams>> { |
| 575 public: | 661 public: |
| 576 SSLStreamAdapterTestDTLS() | 662 SSLStreamAdapterTestDTLS() |
| 577 : SSLStreamAdapterTestBase("", | 663 : SSLStreamAdapterTestBase("", |
| 578 "", | 664 "", |
| 579 true, | 665 true, |
| 580 ::testing::get<0>(GetParam()), | 666 ::testing::get<0>(GetParam()), |
| 581 ::testing::get<1>(GetParam())), | 667 ::testing::get<1>(GetParam())), |
| 668 client_buffer_(kBufferCapacity, kDefaultBufferSize), | |
| 669 server_buffer_(kBufferCapacity, kDefaultBufferSize), | |
| 582 packet_size_(1000), | 670 packet_size_(1000), |
| 583 count_(0), | 671 count_(0), |
| 584 sent_(0) {} | 672 sent_(0) {} |
| 585 | 673 |
| 586 SSLStreamAdapterTestDTLS(const std::string& cert_pem, | 674 SSLStreamAdapterTestDTLS(const std::string& cert_pem, |
| 587 const std::string& private_key_pem) : | 675 const std::string& private_key_pem) : |
| 588 SSLStreamAdapterTestBase(cert_pem, private_key_pem, true), | 676 SSLStreamAdapterTestBase(cert_pem, private_key_pem, true), |
| 677 client_buffer_(kBufferCapacity, kDefaultBufferSize), | |
| 678 server_buffer_(kBufferCapacity, kDefaultBufferSize), | |
| 589 packet_size_(1000), count_(0), sent_(0) { | 679 packet_size_(1000), count_(0), sent_(0) { |
| 590 } | 680 } |
| 591 | 681 |
| 682 virtual void CreateStreams() override { | |
| 683 client_stream_ = | |
| 684 new SSLDummyStreamDTLS(this, "c2s", &client_buffer_, &server_buffer_); | |
| 685 server_stream_ = | |
| 686 new SSLDummyStreamDTLS(this, "s2c", &server_buffer_, &client_buffer_); | |
| 687 } | |
| 688 | |
| 592 virtual void WriteData() { | 689 virtual void WriteData() { |
| 593 unsigned char *packet = new unsigned char[1600]; | 690 unsigned char *packet = new unsigned char[1600]; |
| 594 | 691 |
| 595 do { | 692 while (sent_ < count_) { |
| 596 memset(packet, sent_ & 0xff, packet_size_); | 693 memset(packet, sent_ & 0xff, packet_size_); |
| 597 *(reinterpret_cast<uint32_t *>(packet)) = sent_; | 694 *(reinterpret_cast<uint32_t *>(packet)) = sent_; |
| 598 | 695 |
| 599 size_t sent; | 696 size_t sent; |
| 600 int rv = client_ssl_->Write(packet, packet_size_, &sent, 0); | 697 int rv = client_ssl_->Write(packet, packet_size_, &sent, 0); |
| 601 if (rv == rtc::SR_SUCCESS) { | 698 if (rv == rtc::SR_SUCCESS) { |
| 602 LOG(LS_VERBOSE) << "Sent: " << sent_; | 699 LOG(LS_VERBOSE) << "Sent: " << sent_; |
| 603 sent_++; | 700 sent_++; |
| 604 } else if (rv == rtc::SR_BLOCK) { | 701 } else if (rv == rtc::SR_BLOCK) { |
| 605 LOG(LS_VERBOSE) << "Blocked..."; | 702 LOG(LS_VERBOSE) << "Blocked..."; |
| 606 break; | 703 break; |
| 607 } else { | 704 } else { |
| 608 ADD_FAILURE(); | 705 ADD_FAILURE(); |
| 609 break; | 706 break; |
| 610 } | 707 } |
| 611 } while (sent_ < count_); | 708 } |
| 612 | 709 |
| 613 delete [] packet; | 710 delete [] packet; |
| 614 } | 711 } |
| 615 | 712 |
| 616 virtual void ReadData(rtc::StreamInterface *stream) { | 713 virtual void ReadData(rtc::StreamInterface *stream) { |
| 617 unsigned char buffer[2000]; | 714 unsigned char buffer[2000]; |
| 618 size_t bread; | 715 size_t bread; |
| 619 int err2; | 716 int err2; |
| 620 rtc::StreamResult r; | 717 rtc::StreamResult r; |
| 621 | 718 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 660 EXPECT_EQ(0U, received_.size()); | 757 EXPECT_EQ(0U, received_.size()); |
| 661 } else if (loss_ == 0) { | 758 } else if (loss_ == 0) { |
| 662 EXPECT_EQ_WAIT(static_cast<size_t>(sent_), received_.size(), 1000); | 759 EXPECT_EQ_WAIT(static_cast<size_t>(sent_), received_.size(), 1000); |
| 663 } else { | 760 } else { |
| 664 LOG(LS_INFO) << "Sent " << sent_ << " packets; received " << | 761 LOG(LS_INFO) << "Sent " << sent_ << " packets; received " << |
| 665 received_.size(); | 762 received_.size(); |
| 666 } | 763 } |
| 667 }; | 764 }; |
| 668 | 765 |
| 669 private: | 766 private: |
| 767 BufferQueueStream client_buffer_; | |
| 768 BufferQueueStream server_buffer_; | |
| 670 size_t packet_size_; | 769 size_t packet_size_; |
| 671 int count_; | 770 int count_; |
| 672 int sent_; | 771 int sent_; |
| 673 std::set<int> received_; | 772 std::set<int> received_; |
| 674 }; | 773 }; |
| 675 | 774 |
| 676 | 775 |
| 677 rtc::StreamResult SSLDummyStream::Write(const void* data, size_t data_len, | 776 rtc::StreamResult SSLDummyStreamBase::Write(const void* data, size_t data_len, |
| 678 size_t* written, int* error) { | 777 size_t* written, int* error) { |
| 679 *written = data_len; | 778 *written = data_len; |
| 680 | 779 |
| 681 LOG(LS_INFO) << "Writing to loopback " << data_len; | 780 LOG(LS_INFO) << "Writing to loopback " << data_len; |
| 682 | 781 |
| 683 if (first_packet_) { | 782 if (first_packet_) { |
| 684 first_packet_ = false; | 783 first_packet_ = false; |
| 685 if (test_->GetLoseFirstPacket()) { | 784 if (test_base_->GetLoseFirstPacket()) { |
| 686 LOG(LS_INFO) << "Losing initial packet of length " << data_len; | 785 LOG(LS_INFO) << "Losing initial packet of length " << data_len; |
| 687 return rtc::SR_SUCCESS; | 786 return rtc::SR_SUCCESS; |
| 688 } | 787 } |
| 689 } | 788 } |
| 690 | 789 |
| 691 return test_->DataWritten(this, data, data_len, written, error); | 790 return test_base_->DataWritten(this, data, data_len, written, error); |
| 692 | |
| 693 return rtc::SR_SUCCESS; | |
| 694 }; | 791 }; |
| 695 | 792 |
| 696 class SSLStreamAdapterTestDTLSFromPEMStrings : public SSLStreamAdapterTestDTLS { | 793 class SSLStreamAdapterTestDTLSFromPEMStrings : public SSLStreamAdapterTestDTLS { |
| 697 public: | 794 public: |
| 698 SSLStreamAdapterTestDTLSFromPEMStrings() : | 795 SSLStreamAdapterTestDTLSFromPEMStrings() : |
| 699 SSLStreamAdapterTestDTLS(kCERT_PEM, kRSA_PRIVATE_KEY_PEM) { | 796 SSLStreamAdapterTestDTLS(kCERT_PEM, kRSA_PRIVATE_KEY_PEM) { |
| 700 } | 797 } |
| 701 }; | 798 }; |
| 702 | 799 |
| 703 // Basic tests: TLS | 800 // Basic tests: TLS |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 775 // Test a handshake with small MTU | 872 // Test a handshake with small MTU |
| 776 // Disabled due to https://code.google.com/p/webrtc/issues/detail?id=3910 | 873 // Disabled due to https://code.google.com/p/webrtc/issues/detail?id=3910 |
| 777 TEST_P(SSLStreamAdapterTestDTLS, DISABLED_TestDTLSConnectWithSmallMtu) { | 874 TEST_P(SSLStreamAdapterTestDTLS, DISABLED_TestDTLSConnectWithSmallMtu) { |
| 778 MAYBE_SKIP_TEST(HaveDtls); | 875 MAYBE_SKIP_TEST(HaveDtls); |
| 779 SetMtu(700); | 876 SetMtu(700); |
| 780 SetHandshakeWait(20000); | 877 SetHandshakeWait(20000); |
| 781 TestHandshake(); | 878 TestHandshake(); |
| 782 }; | 879 }; |
| 783 | 880 |
| 784 // Test transfer -- trivial | 881 // Test transfer -- trivial |
| 785 // Disabled due to https://code.google.com/p/webrtc/issues/detail?id=5005 | 882 TEST_P(SSLStreamAdapterTestDTLS, TestDTLSTransfer) { |
| 786 TEST_P(SSLStreamAdapterTestDTLS, DISABLED_TestDTLSTransfer) { | |
| 787 MAYBE_SKIP_TEST(HaveDtls); | 883 MAYBE_SKIP_TEST(HaveDtls); |
| 788 TestHandshake(); | 884 TestHandshake(); |
| 789 TestTransfer(100); | 885 TestTransfer(100); |
| 790 }; | 886 }; |
| 791 | 887 |
| 792 // Disabled due to https://code.google.com/p/webrtc/issues/detail?id=5005 | 888 TEST_P(SSLStreamAdapterTestDTLS, TestDTLSTransferWithLoss) { |
| 793 TEST_P(SSLStreamAdapterTestDTLS, DISABLED_TestDTLSTransferWithLoss) { | |
| 794 MAYBE_SKIP_TEST(HaveDtls); | 889 MAYBE_SKIP_TEST(HaveDtls); |
| 795 TestHandshake(); | 890 TestHandshake(); |
| 796 SetLoss(10); | 891 SetLoss(10); |
| 797 TestTransfer(100); | 892 TestTransfer(100); |
| 798 }; | 893 }; |
| 799 | 894 |
| 800 // Disabled due to https://code.google.com/p/webrtc/issues/detail?id=5005 | 895 TEST_P(SSLStreamAdapterTestDTLS, TestDTLSTransferWithDamage) { |
| 801 TEST_P(SSLStreamAdapterTestDTLS, DISABLED_TestDTLSTransferWithDamage) { | |
| 802 MAYBE_SKIP_TEST(HaveDtls); | 896 MAYBE_SKIP_TEST(HaveDtls); |
| 803 SetDamage(); // Must be called first because first packet | 897 SetDamage(); // Must be called first because first packet |
| 804 // write happens at end of handshake. | 898 // write happens at end of handshake. |
| 805 TestHandshake(); | 899 TestHandshake(); |
| 806 TestTransfer(100); | 900 TestTransfer(100); |
| 807 }; | 901 }; |
| 808 | 902 |
| 809 // Test DTLS-SRTP with all high ciphers | 903 // Test DTLS-SRTP with all high ciphers |
| 810 TEST_P(SSLStreamAdapterTestDTLS, TestDTLSSrtpHigh) { | 904 TEST_P(SSLStreamAdapterTestDTLS, TestDTLSSrtpHigh) { |
| 811 MAYBE_SKIP_TEST(HaveDtlsSrtp); | 905 MAYBE_SKIP_TEST(HaveDtlsSrtp); |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1054 rtc::KeyParams::ECDSA(rtc::EC_NIST_P256)))); | 1148 rtc::KeyParams::ECDSA(rtc::EC_NIST_P256)))); |
| 1055 INSTANTIATE_TEST_CASE_P( | 1149 INSTANTIATE_TEST_CASE_P( |
| 1056 SSLStreamAdapterTestsDTLS, | 1150 SSLStreamAdapterTestsDTLS, |
| 1057 SSLStreamAdapterTestDTLS, | 1151 SSLStreamAdapterTestDTLS, |
| 1058 Combine(Values(rtc::KeyParams::RSA(1024, 65537), | 1152 Combine(Values(rtc::KeyParams::RSA(1024, 65537), |
| 1059 rtc::KeyParams::RSA(1152, 65537), | 1153 rtc::KeyParams::RSA(1152, 65537), |
| 1060 rtc::KeyParams::ECDSA(rtc::EC_NIST_P256)), | 1154 rtc::KeyParams::ECDSA(rtc::EC_NIST_P256)), |
| 1061 Values(rtc::KeyParams::RSA(1024, 65537), | 1155 Values(rtc::KeyParams::RSA(1024, 65537), |
| 1062 rtc::KeyParams::RSA(1152, 65537), | 1156 rtc::KeyParams::RSA(1152, 65537), |
| 1063 rtc::KeyParams::ECDSA(rtc::EC_NIST_P256)))); | 1157 rtc::KeyParams::ECDSA(rtc::EC_NIST_P256)))); |
| OLD | NEW |