| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This test suite uses SSLClientSocket to test the implementation of | 5 // This test suite uses SSLClientSocket to test the implementation of |
| 6 // SSLServerSocket. In order to establish connections between the sockets | 6 // SSLServerSocket. In order to establish connections between the sockets |
| 7 // we need two additional classes: | 7 // we need two additional classes: |
| 8 // 1. FakeSocket | 8 // 1. FakeSocket |
| 9 // Connects SSL socket to FakeDataChannel. This class is just a stub. | 9 // Connects SSL socket to FakeDataChannel. This class is just a stub. |
| 10 // | 10 // |
| 11 // 2. FakeDataChannel | 11 // 2. FakeDataChannel |
| 12 // Implements the actual exchange of data between two FakeSockets. | 12 // Implements the actual exchange of data between two FakeSockets. |
| 13 // | 13 // |
| 14 // Implementations of these two classes are included in this file. | 14 // Implementations of these two classes are included in this file. |
| 15 | 15 |
| 16 #include "net/socket/ssl_server_socket.h" | 16 #include "net/socket/ssl_server_socket.h" |
| 17 | 17 |
| 18 #include <stdint.h> | 18 #include <stdint.h> |
| 19 #include <stdlib.h> | 19 #include <stdlib.h> |
| 20 | 20 |
| 21 #include <queue> | 21 #include <queue> |
| 22 | 22 |
| 23 #include "base/compiler_specific.h" | 23 #include "base/compiler_specific.h" |
| 24 #include "base/files/file_path.h" | 24 #include "base/files/file_path.h" |
| 25 #include "base/files/file_util.h" | 25 #include "base/files/file_util.h" |
| 26 #include "base/location.h" | 26 #include "base/location.h" |
| 27 #include "base/logging.h" | 27 #include "base/logging.h" |
| 28 #include "base/macros.h" |
| 28 #include "base/message_loop/message_loop.h" | 29 #include "base/message_loop/message_loop.h" |
| 29 #include "base/single_thread_task_runner.h" | 30 #include "base/single_thread_task_runner.h" |
| 30 #include "base/thread_task_runner_handle.h" | 31 #include "base/thread_task_runner_handle.h" |
| 31 #include "crypto/nss_util.h" | 32 #include "crypto/nss_util.h" |
| 32 #include "crypto/rsa_private_key.h" | 33 #include "crypto/rsa_private_key.h" |
| 33 #include "net/base/address_list.h" | 34 #include "net/base/address_list.h" |
| 34 #include "net/base/completion_callback.h" | 35 #include "net/base/completion_callback.h" |
| 35 #include "net/base/host_port_pair.h" | 36 #include "net/base/host_port_pair.h" |
| 36 #include "net/base/io_buffer.h" | 37 #include "net/base/io_buffer.h" |
| 37 #include "net/base/ip_endpoint.h" | 38 #include "net/base/ip_endpoint.h" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 184 } | 185 } |
| 185 | 186 |
| 186 int Write(IOBuffer* buf, | 187 int Write(IOBuffer* buf, |
| 187 int buf_len, | 188 int buf_len, |
| 188 const CompletionCallback& callback) override { | 189 const CompletionCallback& callback) override { |
| 189 // Write random number of bytes. | 190 // Write random number of bytes. |
| 190 buf_len = rand() % buf_len + 1; | 191 buf_len = rand() % buf_len + 1; |
| 191 return outgoing_->Write(buf, buf_len, callback); | 192 return outgoing_->Write(buf, buf_len, callback); |
| 192 } | 193 } |
| 193 | 194 |
| 194 int SetReceiveBufferSize(int32 size) override { return OK; } | 195 int SetReceiveBufferSize(int32_t size) override { return OK; } |
| 195 | 196 |
| 196 int SetSendBufferSize(int32 size) override { return OK; } | 197 int SetSendBufferSize(int32_t size) override { return OK; } |
| 197 | 198 |
| 198 int Connect(const CompletionCallback& callback) override { return OK; } | 199 int Connect(const CompletionCallback& callback) override { return OK; } |
| 199 | 200 |
| 200 void Disconnect() override { | 201 void Disconnect() override { |
| 201 incoming_->Close(); | 202 incoming_->Close(); |
| 202 outgoing_->Close(); | 203 outgoing_->Close(); |
| 203 } | 204 } |
| 204 | 205 |
| 205 bool IsConnected() const override { return true; } | 206 bool IsConnected() const override { return true; } |
| 206 | 207 |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 318 base::FilePath cert_path = certs_dir.AppendASCII("unittest.selfsigned.der"); | 319 base::FilePath cert_path = certs_dir.AppendASCII("unittest.selfsigned.der"); |
| 319 std::string cert_der; | 320 std::string cert_der; |
| 320 ASSERT_TRUE(base::ReadFileToString(cert_path, &cert_der)); | 321 ASSERT_TRUE(base::ReadFileToString(cert_path, &cert_der)); |
| 321 | 322 |
| 322 scoped_refptr<X509Certificate> cert = | 323 scoped_refptr<X509Certificate> cert = |
| 323 X509Certificate::CreateFromBytes(cert_der.data(), cert_der.size()); | 324 X509Certificate::CreateFromBytes(cert_der.data(), cert_der.size()); |
| 324 | 325 |
| 325 base::FilePath key_path = certs_dir.AppendASCII("unittest.key.bin"); | 326 base::FilePath key_path = certs_dir.AppendASCII("unittest.key.bin"); |
| 326 std::string key_string; | 327 std::string key_string; |
| 327 ASSERT_TRUE(base::ReadFileToString(key_path, &key_string)); | 328 ASSERT_TRUE(base::ReadFileToString(key_path, &key_string)); |
| 328 std::vector<uint8> key_vector( | 329 std::vector<uint8_t> key_vector( |
| 329 reinterpret_cast<const uint8*>(key_string.data()), | 330 reinterpret_cast<const uint8_t*>(key_string.data()), |
| 330 reinterpret_cast<const uint8*>(key_string.data() + | 331 reinterpret_cast<const uint8_t*>(key_string.data() + |
| 331 key_string.length())); | 332 key_string.length())); |
| 332 | 333 |
| 333 scoped_ptr<crypto::RSAPrivateKey> private_key( | 334 scoped_ptr<crypto::RSAPrivateKey> private_key( |
| 334 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(key_vector)); | 335 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(key_vector)); |
| 335 | 336 |
| 336 client_ssl_config_.false_start_enabled = false; | 337 client_ssl_config_.false_start_enabled = false; |
| 337 client_ssl_config_.channel_id_enabled = false; | 338 client_ssl_config_.channel_id_enabled = false; |
| 338 | 339 |
| 339 // Certificate provided by the host doesn't need authority. | 340 // Certificate provided by the host doesn't need authority. |
| 340 SSLConfig::CertAndStatus cert_and_status; | 341 SSLConfig::CertAndStatus cert_and_status; |
| 341 cert_and_status.cert_status = CERT_STATUS_AUTHORITY_INVALID; | 342 cert_and_status.cert_status = CERT_STATUS_AUTHORITY_INVALID; |
| (...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 int server_ret = server_socket_->Handshake(handshake_callback.callback()); | 622 int server_ret = server_socket_->Handshake(handshake_callback.callback()); |
| 622 | 623 |
| 623 client_ret = connect_callback.GetResult(client_ret); | 624 client_ret = connect_callback.GetResult(client_ret); |
| 624 server_ret = handshake_callback.GetResult(server_ret); | 625 server_ret = handshake_callback.GetResult(server_ret); |
| 625 | 626 |
| 626 ASSERT_EQ(ERR_SSL_VERSION_OR_CIPHER_MISMATCH, client_ret); | 627 ASSERT_EQ(ERR_SSL_VERSION_OR_CIPHER_MISMATCH, client_ret); |
| 627 ASSERT_EQ(ERR_SSL_VERSION_OR_CIPHER_MISMATCH, server_ret); | 628 ASSERT_EQ(ERR_SSL_VERSION_OR_CIPHER_MISMATCH, server_ret); |
| 628 } | 629 } |
| 629 | 630 |
| 630 } // namespace net | 631 } // namespace net |
| OLD | NEW |