| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2014 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 <string> | 12 #include <string> |
| 12 | 13 |
| 13 #include "webrtc/base/gunit.h" | 14 #include "webrtc/base/gunit.h" |
| 14 #include "webrtc/base/ipaddress.h" | 15 #include "webrtc/base/ipaddress.h" |
| 15 #include "webrtc/base/socketstream.h" | 16 #include "webrtc/base/socketstream.h" |
| 16 #include "webrtc/base/ssladapter.h" | 17 #include "webrtc/base/ssladapter.h" |
| 17 #include "webrtc/base/sslstreamadapter.h" | 18 #include "webrtc/base/sslstreamadapter.h" |
| 18 #include "webrtc/base/sslidentity.h" | 19 #include "webrtc/base/sslidentity.h" |
| 19 #include "webrtc/base/stream.h" | 20 #include "webrtc/base/stream.h" |
| 20 #include "webrtc/base/virtualsocketserver.h" | 21 #include "webrtc/base/virtualsocketserver.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 // closing the socket! Let's close the socket here. This way GetState() can | 117 // closing the socket! Let's close the socket here. This way GetState() can |
| 117 // return CS_CLOSED after failure. | 118 // return CS_CLOSED after failure. |
| 118 if (socket->GetState() != rtc::AsyncSocket::CS_CLOSED) { | 119 if (socket->GetState() != rtc::AsyncSocket::CS_CLOSED) { |
| 119 socket->Close(); | 120 socket->Close(); |
| 120 } | 121 } |
| 121 } | 122 } |
| 122 | 123 |
| 123 private: | 124 private: |
| 124 const rtc::SSLMode ssl_mode_; | 125 const rtc::SSLMode ssl_mode_; |
| 125 | 126 |
| 126 rtc::scoped_ptr<rtc::SSLAdapter> ssl_adapter_; | 127 std::unique_ptr<rtc::SSLAdapter> ssl_adapter_; |
| 127 | 128 |
| 128 std::string data_; | 129 std::string data_; |
| 129 }; | 130 }; |
| 130 | 131 |
| 131 class SSLAdapterTestDummyServer : public sigslot::has_slots<> { | 132 class SSLAdapterTestDummyServer : public sigslot::has_slots<> { |
| 132 public: | 133 public: |
| 133 explicit SSLAdapterTestDummyServer(const rtc::SSLMode& ssl_mode, | 134 explicit SSLAdapterTestDummyServer(const rtc::SSLMode& ssl_mode, |
| 134 const rtc::KeyParams& key_params) | 135 const rtc::KeyParams& key_params) |
| 135 : ssl_mode_(ssl_mode) { | 136 : ssl_mode_(ssl_mode) { |
| 136 // Generate a key pair and a certificate for this host. | 137 // Generate a key pair and a certificate for this host. |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 digest_len); | 253 digest_len); |
| 253 | 254 |
| 254 ssl_stream_adapter_->StartSSLWithPeer(); | 255 ssl_stream_adapter_->StartSSLWithPeer(); |
| 255 | 256 |
| 256 ssl_stream_adapter_->SignalEvent.connect(this, | 257 ssl_stream_adapter_->SignalEvent.connect(this, |
| 257 &SSLAdapterTestDummyServer::OnSSLStreamAdapterEvent); | 258 &SSLAdapterTestDummyServer::OnSSLStreamAdapterEvent); |
| 258 } | 259 } |
| 259 | 260 |
| 260 const rtc::SSLMode ssl_mode_; | 261 const rtc::SSLMode ssl_mode_; |
| 261 | 262 |
| 262 rtc::scoped_ptr<rtc::AsyncSocket> server_socket_; | 263 std::unique_ptr<rtc::AsyncSocket> server_socket_; |
| 263 rtc::scoped_ptr<rtc::SSLStreamAdapter> ssl_stream_adapter_; | 264 std::unique_ptr<rtc::SSLStreamAdapter> ssl_stream_adapter_; |
| 264 | 265 |
| 265 rtc::scoped_ptr<rtc::SSLIdentity> ssl_identity_; | 266 std::unique_ptr<rtc::SSLIdentity> ssl_identity_; |
| 266 | 267 |
| 267 std::string data_; | 268 std::string data_; |
| 268 }; | 269 }; |
| 269 | 270 |
| 270 class SSLAdapterTestBase : public testing::Test, | 271 class SSLAdapterTestBase : public testing::Test, |
| 271 public sigslot::has_slots<> { | 272 public sigslot::has_slots<> { |
| 272 public: | 273 public: |
| 273 explicit SSLAdapterTestBase(const rtc::SSLMode& ssl_mode, | 274 explicit SSLAdapterTestBase(const rtc::SSLMode& ssl_mode, |
| 274 const rtc::KeyParams& key_params) | 275 const rtc::KeyParams& key_params) |
| 275 : ssl_mode_(ssl_mode), | 276 : ssl_mode_(ssl_mode), |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 332 EXPECT_EQ_WAIT(message, client_->GetReceivedData(), kTimeout); | 333 EXPECT_EQ_WAIT(message, client_->GetReceivedData(), kTimeout); |
| 333 | 334 |
| 334 LOG(LS_INFO) << "Transfer complete."; | 335 LOG(LS_INFO) << "Transfer complete."; |
| 335 } | 336 } |
| 336 | 337 |
| 337 private: | 338 private: |
| 338 const rtc::SSLMode ssl_mode_; | 339 const rtc::SSLMode ssl_mode_; |
| 339 | 340 |
| 340 const rtc::SocketServerScope ss_scope_; | 341 const rtc::SocketServerScope ss_scope_; |
| 341 | 342 |
| 342 rtc::scoped_ptr<SSLAdapterTestDummyServer> server_; | 343 std::unique_ptr<SSLAdapterTestDummyServer> server_; |
| 343 rtc::scoped_ptr<SSLAdapterTestDummyClient> client_; | 344 std::unique_ptr<SSLAdapterTestDummyClient> client_; |
| 344 | 345 |
| 345 int handshake_wait_; | 346 int handshake_wait_; |
| 346 }; | 347 }; |
| 347 | 348 |
| 348 class SSLAdapterTestTLS_RSA : public SSLAdapterTestBase { | 349 class SSLAdapterTestTLS_RSA : public SSLAdapterTestBase { |
| 349 public: | 350 public: |
| 350 SSLAdapterTestTLS_RSA() | 351 SSLAdapterTestTLS_RSA() |
| 351 : SSLAdapterTestBase(rtc::SSL_MODE_TLS, rtc::KeyParams::RSA()) {} | 352 : SSLAdapterTestBase(rtc::SSL_MODE_TLS, rtc::KeyParams::RSA()) {} |
| 352 }; | 353 }; |
| 353 | 354 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 TestTransfer("Hello, world!"); | 414 TestTransfer("Hello, world!"); |
| 414 } | 415 } |
| 415 | 416 |
| 416 // Test transfer between client and server, using ECDSA | 417 // Test transfer between client and server, using ECDSA |
| 417 TEST_F(SSLAdapterTestDTLS_ECDSA, TestDTLSTransfer) { | 418 TEST_F(SSLAdapterTestDTLS_ECDSA, TestDTLSTransfer) { |
| 418 TestHandshake(true); | 419 TestHandshake(true); |
| 419 TestTransfer("Hello, world!"); | 420 TestTransfer("Hello, world!"); |
| 420 } | 421 } |
| 421 | 422 |
| 422 #endif // SSL_USE_OPENSSL | 423 #endif // SSL_USE_OPENSSL |
| OLD | NEW |