| 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 | 9 |
| 10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 namespace net { | 22 namespace net { |
| 23 | 23 |
| 24 void EnableSSLServerSockets() { | 24 void EnableSSLServerSockets() { |
| 25 // No-op because CreateSSLServerSocket() calls crypto::EnsureOpenSSLInit(). | 25 // No-op because CreateSSLServerSocket() calls crypto::EnsureOpenSSLInit(). |
| 26 } | 26 } |
| 27 | 27 |
| 28 scoped_ptr<SSLServerSocket> CreateSSLServerSocket( | 28 scoped_ptr<SSLServerSocket> CreateSSLServerSocket( |
| 29 scoped_ptr<StreamSocket> socket, | 29 scoped_ptr<StreamSocket> socket, |
| 30 X509Certificate* certificate, | 30 X509Certificate* certificate, |
| 31 crypto::RSAPrivateKey* key, | 31 crypto::RSAPrivateKey* key, |
| 32 const SSLConfig& ssl_config) { | 32 const SSLServerConfig& ssl_config) { |
| 33 crypto::EnsureOpenSSLInit(); | 33 crypto::EnsureOpenSSLInit(); |
| 34 return scoped_ptr<SSLServerSocket>( | 34 return scoped_ptr<SSLServerSocket>( |
| 35 new SSLServerSocketOpenSSL(socket.Pass(), certificate, key, ssl_config)); | 35 new SSLServerSocketOpenSSL(socket.Pass(), certificate, key, ssl_config)); |
| 36 } | 36 } |
| 37 | 37 |
| 38 SSLServerSocketOpenSSL::SSLServerSocketOpenSSL( | 38 SSLServerSocketOpenSSL::SSLServerSocketOpenSSL( |
| 39 scoped_ptr<StreamSocket> transport_socket, | 39 scoped_ptr<StreamSocket> transport_socket, |
| 40 scoped_refptr<X509Certificate> certificate, | 40 scoped_refptr<X509Certificate> certificate, |
| 41 crypto::RSAPrivateKey* key, | 41 crypto::RSAPrivateKey* key, |
| 42 const SSLConfig& ssl_config) | 42 const SSLServerConfig& ssl_config) |
| 43 : transport_send_busy_(false), | 43 : transport_send_busy_(false), |
| 44 transport_recv_busy_(false), | 44 transport_recv_busy_(false), |
| 45 transport_recv_eof_(false), | 45 transport_recv_eof_(false), |
| 46 user_read_buf_len_(0), | 46 user_read_buf_len_(0), |
| 47 user_write_buf_len_(0), | 47 user_write_buf_len_(0), |
| 48 transport_write_error_(OK), | 48 transport_write_error_(OK), |
| 49 ssl_(NULL), | 49 ssl_(NULL), |
| 50 transport_bio_(NULL), | 50 transport_bio_(NULL), |
| 51 transport_socket_(transport_socket.Pass()), | 51 transport_socket_(transport_socket.Pass()), |
| 52 ssl_config_(ssl_config), | 52 ssl_config_(ssl_config), |
| (...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 ResetAndReturn(&user_write_callback_).Run(rv); | 611 ResetAndReturn(&user_write_callback_).Run(rv); |
| 612 } | 612 } |
| 613 | 613 |
| 614 int SSLServerSocketOpenSSL::Init() { | 614 int SSLServerSocketOpenSSL::Init() { |
| 615 DCHECK(!ssl_); | 615 DCHECK(!ssl_); |
| 616 DCHECK(!transport_bio_); | 616 DCHECK(!transport_bio_); |
| 617 | 617 |
| 618 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); | 618 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); |
| 619 | 619 |
| 620 ScopedSSL_CTX ssl_ctx(SSL_CTX_new(SSLv23_server_method())); | 620 ScopedSSL_CTX ssl_ctx(SSL_CTX_new(SSLv23_server_method())); |
| 621 |
| 622 if (ssl_config_.require_client_cert) |
| 623 SSL_CTX_set_verify(ssl_ctx.get(), SSL_VERIFY_PEER, NULL); |
| 624 |
| 621 ssl_ = SSL_new(ssl_ctx.get()); | 625 ssl_ = SSL_new(ssl_ctx.get()); |
| 622 if (!ssl_) | 626 if (!ssl_) |
| 623 return ERR_UNEXPECTED; | 627 return ERR_UNEXPECTED; |
| 624 | 628 |
| 625 BIO* ssl_bio = NULL; | 629 BIO* ssl_bio = NULL; |
| 626 // 0 => use default buffer sizes. | 630 // 0 => use default buffer sizes. |
| 627 if (!BIO_new_bio_pair(&ssl_bio, 0, &transport_bio_, 0)) | 631 if (!BIO_new_bio_pair(&ssl_bio, 0, &transport_bio_, 0)) |
| 628 return ERR_UNEXPECTED; | 632 return ERR_UNEXPECTED; |
| 629 DCHECK(ssl_bio); | 633 DCHECK(ssl_bio); |
| 630 DCHECK(transport_bio_); | 634 DCHECK(transport_bio_); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 678 SSL_clear_options(ssl_, options.clear_mask); | 682 SSL_clear_options(ssl_, options.clear_mask); |
| 679 | 683 |
| 680 // Same as above, this time for the SSL mode. | 684 // Same as above, this time for the SSL mode. |
| 681 SslSetClearMask mode; | 685 SslSetClearMask mode; |
| 682 | 686 |
| 683 mode.ConfigureFlag(SSL_MODE_RELEASE_BUFFERS, true); | 687 mode.ConfigureFlag(SSL_MODE_RELEASE_BUFFERS, true); |
| 684 | 688 |
| 685 SSL_set_mode(ssl_, mode.set_mask); | 689 SSL_set_mode(ssl_, mode.set_mask); |
| 686 SSL_clear_mode(ssl_, mode.clear_mask); | 690 SSL_clear_mode(ssl_, mode.clear_mask); |
| 687 | 691 |
| 688 // See SSLConfig::disabled_cipher_suites for description of the suites | 692 // See SSLServerConfig::disabled_cipher_suites for description of the suites |
| 689 // disabled by default. Note that !SHA256 and !SHA384 only remove HMAC-SHA256 | 693 // disabled by default. Note that !SHA256 and !SHA384 only remove HMAC-SHA256 |
| 690 // and HMAC-SHA384 cipher suites, not GCM cipher suites with SHA256 or SHA384 | 694 // and HMAC-SHA384 cipher suites, not GCM cipher suites with SHA256 or SHA384 |
| 691 // as the handshake hash. | 695 // as the handshake hash. |
| 692 std::string command("DEFAULT:!SHA256:!SHA384:!AESGCM+AES256:!aPSK"); | 696 std::string command("DEFAULT:!SHA256:!SHA384:!AESGCM+AES256:!aPSK"); |
| 693 | 697 |
| 694 if (ssl_config_.require_ecdhe) | 698 if (ssl_config_.require_ecdhe) |
| 695 command.append(":!kRSA:!kDHE"); | 699 command.append(":!kRSA:!kDHE"); |
| 696 | 700 |
| 697 // Remove any disabled ciphers. | 701 // Remove any disabled ciphers. |
| 698 for (uint16_t id : ssl_config_.disabled_cipher_suites) { | 702 for (uint16_t id : ssl_config_.disabled_cipher_suites) { |
| 699 const SSL_CIPHER* cipher = SSL_get_cipher_by_value(id); | 703 const SSL_CIPHER* cipher = SSL_get_cipher_by_value(id); |
| 700 if (cipher) { | 704 if (cipher) { |
| 701 command.append(":!"); | 705 command.append(":!"); |
| 702 command.append(SSL_CIPHER_get_name(cipher)); | 706 command.append(SSL_CIPHER_get_name(cipher)); |
| 703 } | 707 } |
| 704 } | 708 } |
| 705 | 709 |
| 706 int rv = SSL_set_cipher_list(ssl_, command.c_str()); | 710 int rv = SSL_set_cipher_list(ssl_, command.c_str()); |
| 707 // If this fails (rv = 0) it means there are no ciphers enabled on this SSL. | 711 // If this fails (rv = 0) it means there are no ciphers enabled on this SSL. |
| 708 // This will almost certainly result in the socket failing to complete the | 712 // This will almost certainly result in the socket failing to complete the |
| 709 // handshake at which point the appropriate error is bubbled up to the client. | 713 // handshake at which point the appropriate error is bubbled up to the client. |
| 710 LOG_IF(WARNING, rv != 1) << "SSL_set_cipher_list('" << command | 714 LOG_IF(WARNING, rv != 1) << "SSL_set_cipher_list('" << command |
| 711 << "') returned " << rv; | 715 << "') returned " << rv; |
| 712 | 716 |
| 713 return OK; | 717 return OK; |
| 714 } | 718 } |
| 715 | 719 |
| 716 } // namespace net | 720 } // namespace net |
| OLD | NEW |