| 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 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 : ssl_mode_(ssl_mode) { | 45 : ssl_mode_(ssl_mode) { |
| 46 rtc::AsyncSocket* socket = CreateSocket(ssl_mode_); | 46 rtc::AsyncSocket* socket = CreateSocket(ssl_mode_); |
| 47 | 47 |
| 48 ssl_adapter_.reset(rtc::SSLAdapter::Create(socket)); | 48 ssl_adapter_.reset(rtc::SSLAdapter::Create(socket)); |
| 49 | 49 |
| 50 ssl_adapter_->SetMode(ssl_mode_); | 50 ssl_adapter_->SetMode(ssl_mode_); |
| 51 | 51 |
| 52 // Ignore any certificate errors for the purpose of testing. | 52 // Ignore any certificate errors for the purpose of testing. |
| 53 // Note: We do this only because we don't have a real certificate. | 53 // Note: We do this only because we don't have a real certificate. |
| 54 // NEVER USE THIS IN PRODUCTION CODE! | 54 // NEVER USE THIS IN PRODUCTION CODE! |
| 55 ssl_adapter_->set_ignore_bad_cert(true); | 55 ssl_adapter_->SetIgnoreBadCert(true); |
| 56 | 56 |
| 57 ssl_adapter_->SignalReadEvent.connect(this, | 57 ssl_adapter_->SignalReadEvent.connect(this, |
| 58 &SSLAdapterTestDummyClient::OnSSLAdapterReadEvent); | 58 &SSLAdapterTestDummyClient::OnSSLAdapterReadEvent); |
| 59 ssl_adapter_->SignalCloseEvent.connect(this, | 59 ssl_adapter_->SignalCloseEvent.connect(this, |
| 60 &SSLAdapterTestDummyClient::OnSSLAdapterCloseEvent); | 60 &SSLAdapterTestDummyClient::OnSSLAdapterCloseEvent); |
| 61 } | 61 } |
| 62 | 62 |
| 63 void SetAlpnProtocols(const std::vector<std::string>& protos) { |
| 64 ssl_adapter_->SetAlpnProtocols(protos); |
| 65 } |
| 66 |
| 63 rtc::SocketAddress GetAddress() const { | 67 rtc::SocketAddress GetAddress() const { |
| 64 return ssl_adapter_->GetLocalAddress(); | 68 return ssl_adapter_->GetLocalAddress(); |
| 65 } | 69 } |
| 66 | 70 |
| 67 rtc::AsyncSocket::ConnState GetState() const { | 71 rtc::AsyncSocket::ConnState GetState() const { |
| 68 return ssl_adapter_->GetState(); | 72 return ssl_adapter_->GetState(); |
| 69 } | 73 } |
| 70 | 74 |
| 71 const std::string& GetReceivedData() const { | 75 const std::string& GetReceivedData() const { |
| 72 return data_; | 76 return data_; |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 vss_(new rtc::VirtualSocketServer()), | 279 vss_(new rtc::VirtualSocketServer()), |
| 276 thread_(vss_.get()), | 280 thread_(vss_.get()), |
| 277 server_(new SSLAdapterTestDummyServer(ssl_mode_, key_params)), | 281 server_(new SSLAdapterTestDummyServer(ssl_mode_, key_params)), |
| 278 client_(new SSLAdapterTestDummyClient(ssl_mode_)), | 282 client_(new SSLAdapterTestDummyClient(ssl_mode_)), |
| 279 handshake_wait_(kTimeout) {} | 283 handshake_wait_(kTimeout) {} |
| 280 | 284 |
| 281 void SetHandshakeWait(int wait) { | 285 void SetHandshakeWait(int wait) { |
| 282 handshake_wait_ = wait; | 286 handshake_wait_ = wait; |
| 283 } | 287 } |
| 284 | 288 |
| 289 void SetAlpnProtocols(const std::vector<std::string>& protos) { |
| 290 client_->SetAlpnProtocols(protos); |
| 291 } |
| 292 |
| 285 void TestHandshake(bool expect_success) { | 293 void TestHandshake(bool expect_success) { |
| 286 int rv; | 294 int rv; |
| 287 | 295 |
| 288 // The initial state is CS_CLOSED | 296 // The initial state is CS_CLOSED |
| 289 ASSERT_EQ(rtc::AsyncSocket::CS_CLOSED, client_->GetState()); | 297 ASSERT_EQ(rtc::AsyncSocket::CS_CLOSED, client_->GetState()); |
| 290 | 298 |
| 291 rv = client_->Connect(server_->GetHostname(), server_->GetAddress()); | 299 rv = client_->Connect(server_->GetHostname(), server_->GetAddress()); |
| 292 ASSERT_EQ(0, rv); | 300 ASSERT_EQ(0, rv); |
| 293 | 301 |
| 294 // Now the state should be CS_CONNECTING | 302 // Now the state should be CS_CONNECTING |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 427 client_->Send(final_message)); | 435 client_->Send(final_message)); |
| 428 EXPECT_EQ_WAIT(expected, server_->GetReceivedData(), kTimeout); | 436 EXPECT_EQ_WAIT(expected, server_->GetReceivedData(), kTimeout); |
| 429 } | 437 } |
| 430 | 438 |
| 431 // Test transfer between client and server, using ECDSA | 439 // Test transfer between client and server, using ECDSA |
| 432 TEST_F(SSLAdapterTestTLS_ECDSA, TestTLSTransfer) { | 440 TEST_F(SSLAdapterTestTLS_ECDSA, TestTLSTransfer) { |
| 433 TestHandshake(true); | 441 TestHandshake(true); |
| 434 TestTransfer("Hello, world!"); | 442 TestTransfer("Hello, world!"); |
| 435 } | 443 } |
| 436 | 444 |
| 445 // Test transfer using ALPN with protos as h2 and http/1.1 |
| 446 TEST_F(SSLAdapterTestTLS_ECDSA, TestTLSALPN) { |
| 447 std::vector<std::string> alpn_protos{"h2", "http/1.1"}; |
| 448 SetAlpnProtocols(alpn_protos); |
| 449 TestHandshake(true); |
| 450 TestTransfer("Hello, world!"); |
| 451 } |
| 452 |
| 437 // Basic tests: DTLS | 453 // Basic tests: DTLS |
| 438 | 454 |
| 439 // Test that handshake works, using RSA | 455 // Test that handshake works, using RSA |
| 440 TEST_F(SSLAdapterTestDTLS_RSA, TestDTLSConnect) { | 456 TEST_F(SSLAdapterTestDTLS_RSA, TestDTLSConnect) { |
| 441 TestHandshake(true); | 457 TestHandshake(true); |
| 442 } | 458 } |
| 443 | 459 |
| 444 // Test that handshake works, using ECDSA | 460 // Test that handshake works, using ECDSA |
| 445 TEST_F(SSLAdapterTestDTLS_ECDSA, TestDTLSConnect) { | 461 TEST_F(SSLAdapterTestDTLS_ECDSA, TestDTLSConnect) { |
| 446 TestHandshake(true); | 462 TestHandshake(true); |
| 447 } | 463 } |
| 448 | 464 |
| 449 // Test transfer between client and server, using RSA | 465 // Test transfer between client and server, using RSA |
| 450 TEST_F(SSLAdapterTestDTLS_RSA, TestDTLSTransfer) { | 466 TEST_F(SSLAdapterTestDTLS_RSA, TestDTLSTransfer) { |
| 451 TestHandshake(true); | 467 TestHandshake(true); |
| 452 TestTransfer("Hello, world!"); | 468 TestTransfer("Hello, world!"); |
| 453 } | 469 } |
| 454 | 470 |
| 455 // Test transfer between client and server, using ECDSA | 471 // Test transfer between client and server, using ECDSA |
| 456 TEST_F(SSLAdapterTestDTLS_ECDSA, TestDTLSTransfer) { | 472 TEST_F(SSLAdapterTestDTLS_ECDSA, TestDTLSTransfer) { |
| 457 TestHandshake(true); | 473 TestHandshake(true); |
| 458 TestTransfer("Hello, world!"); | 474 TestTransfer("Hello, world!"); |
| 459 } | 475 } |
| OLD | NEW |