| 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 #include "net/socket/ssl_server_socket_openssl.h" | 5 #include "net/socket/ssl_server_socket_openssl.h" |
| 6 | 6 |
| 7 #include <openssl/err.h> | 7 #include <openssl/err.h> |
| 8 #include <openssl/ssl.h> | 8 #include <openssl/ssl.h> |
| 9 #include <utility> |
| 9 | 10 |
| 10 #include "base/callback_helpers.h" | 11 #include "base/callback_helpers.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
| 13 #include "crypto/openssl_util.h" | 14 #include "crypto/openssl_util.h" |
| 14 #include "crypto/rsa_private_key.h" | 15 #include "crypto/rsa_private_key.h" |
| 15 #include "crypto/scoped_openssl_types.h" | 16 #include "crypto/scoped_openssl_types.h" |
| 16 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 17 #include "net/ssl/openssl_ssl_util.h" | 18 #include "net/ssl/openssl_ssl_util.h" |
| 18 #include "net/ssl/scoped_openssl_types.h" | 19 #include "net/ssl/scoped_openssl_types.h" |
| 19 | 20 |
| 20 #define GotoState(s) next_handshake_state_ = s | 21 #define GotoState(s) next_handshake_state_ = s |
| 21 | 22 |
| 22 namespace net { | 23 namespace net { |
| 23 | 24 |
| 24 void EnableSSLServerSockets() { | 25 void EnableSSLServerSockets() { |
| 25 // No-op because CreateSSLServerSocket() calls crypto::EnsureOpenSSLInit(). | 26 // No-op because CreateSSLServerSocket() calls crypto::EnsureOpenSSLInit(). |
| 26 } | 27 } |
| 27 | 28 |
| 28 scoped_ptr<SSLServerSocket> CreateSSLServerSocket( | 29 scoped_ptr<SSLServerSocket> CreateSSLServerSocket( |
| 29 scoped_ptr<StreamSocket> socket, | 30 scoped_ptr<StreamSocket> socket, |
| 30 X509Certificate* certificate, | 31 X509Certificate* certificate, |
| 31 crypto::RSAPrivateKey* key, | 32 crypto::RSAPrivateKey* key, |
| 32 const SSLServerConfig& ssl_config) { | 33 const SSLServerConfig& ssl_config) { |
| 33 crypto::EnsureOpenSSLInit(); | 34 crypto::EnsureOpenSSLInit(); |
| 34 return scoped_ptr<SSLServerSocket>( | 35 return scoped_ptr<SSLServerSocket>(new SSLServerSocketOpenSSL( |
| 35 new SSLServerSocketOpenSSL(socket.Pass(), certificate, key, ssl_config)); | 36 std::move(socket), certificate, key, ssl_config)); |
| 36 } | 37 } |
| 37 | 38 |
| 38 SSLServerSocketOpenSSL::SSLServerSocketOpenSSL( | 39 SSLServerSocketOpenSSL::SSLServerSocketOpenSSL( |
| 39 scoped_ptr<StreamSocket> transport_socket, | 40 scoped_ptr<StreamSocket> transport_socket, |
| 40 scoped_refptr<X509Certificate> certificate, | 41 scoped_refptr<X509Certificate> certificate, |
| 41 crypto::RSAPrivateKey* key, | 42 crypto::RSAPrivateKey* key, |
| 42 const SSLServerConfig& ssl_config) | 43 const SSLServerConfig& ssl_config) |
| 43 : transport_send_busy_(false), | 44 : transport_send_busy_(false), |
| 44 transport_recv_busy_(false), | 45 transport_recv_busy_(false), |
| 45 transport_recv_eof_(false), | 46 transport_recv_eof_(false), |
| 46 user_read_buf_len_(0), | 47 user_read_buf_len_(0), |
| 47 user_write_buf_len_(0), | 48 user_write_buf_len_(0), |
| 48 transport_write_error_(OK), | 49 transport_write_error_(OK), |
| 49 ssl_(NULL), | 50 ssl_(NULL), |
| 50 transport_bio_(NULL), | 51 transport_bio_(NULL), |
| 51 transport_socket_(transport_socket.Pass()), | 52 transport_socket_(std::move(transport_socket)), |
| 52 ssl_config_(ssl_config), | 53 ssl_config_(ssl_config), |
| 53 cert_(certificate), | 54 cert_(certificate), |
| 54 next_handshake_state_(STATE_NONE), | 55 next_handshake_state_(STATE_NONE), |
| 55 completed_handshake_(false) { | 56 completed_handshake_(false) { |
| 56 // TODO(byungchul): Need a better way to clone a key. | 57 // TODO(byungchul): Need a better way to clone a key. |
| 57 std::vector<uint8_t> key_bytes; | 58 std::vector<uint8_t> key_bytes; |
| 58 CHECK(key->ExportPrivateKey(&key_bytes)); | 59 CHECK(key->ExportPrivateKey(&key_bytes)); |
| 59 key_.reset(crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(key_bytes)); | 60 key_.reset(crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(key_bytes)); |
| 60 CHECK(key_.get()); | 61 CHECK(key_.get()); |
| 61 } | 62 } |
| (...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 // If this fails (rv = 0) it means there are no ciphers enabled on this SSL. | 712 // If this fails (rv = 0) it means there are no ciphers enabled on this SSL. |
| 712 // This will almost certainly result in the socket failing to complete the | 713 // This will almost certainly result in the socket failing to complete the |
| 713 // handshake at which point the appropriate error is bubbled up to the client. | 714 // handshake at which point the appropriate error is bubbled up to the client. |
| 714 LOG_IF(WARNING, rv != 1) << "SSL_set_cipher_list('" << command | 715 LOG_IF(WARNING, rv != 1) << "SSL_set_cipher_list('" << command |
| 715 << "') returned " << rv; | 716 << "') returned " << rv; |
| 716 | 717 |
| 717 return OK; | 718 return OK; |
| 718 } | 719 } |
| 719 | 720 |
| 720 } // namespace net | 721 } // namespace net |
| OLD | NEW |