 Chromium Code Reviews
 Chromium Code Reviews Issue 1376593007:
  SSL in EmbeddedTestServer  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 1376593007:
  SSL in EmbeddedTestServer  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| 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 554 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 607 ResetAndReturn(&user_write_callback_).Run(rv); | 607 ResetAndReturn(&user_write_callback_).Run(rv); | 
| 608 } | 608 } | 
| 609 | 609 | 
| 610 int SSLServerSocketOpenSSL::Init() { | 610 int SSLServerSocketOpenSSL::Init() { | 
| 611 DCHECK(!ssl_); | 611 DCHECK(!ssl_); | 
| 612 DCHECK(!transport_bio_); | 612 DCHECK(!transport_bio_); | 
| 613 | 613 | 
| 614 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); | 614 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); | 
| 615 | 615 | 
| 616 ScopedSSL_CTX ssl_ctx(SSL_CTX_new(SSLv23_server_method())); | 616 ScopedSSL_CTX ssl_ctx(SSL_CTX_new(SSLv23_server_method())); | 
| 617 | |
| 618 if (ssl_config_.require_client_cert) | |
| 619 SSL_CTX_set_verify(ssl_ctx.get(), SSL_VERIFY_PEER, NULL); | |
| 
davidben
2015/10/13 19:43:47
So, I don't see any tests that currently use this.
 
svaldez
2015/10/13 20:54:43
This is for the tests that check to see if the ser
 | |
| 620 | |
| 617 ssl_ = SSL_new(ssl_ctx.get()); | 621 ssl_ = SSL_new(ssl_ctx.get()); | 
| 618 if (!ssl_) | 622 if (!ssl_) | 
| 619 return ERR_UNEXPECTED; | 623 return ERR_UNEXPECTED; | 
| 620 | 624 | 
| 621 BIO* ssl_bio = NULL; | 625 BIO* ssl_bio = NULL; | 
| 622 // 0 => use default buffer sizes. | 626 // 0 => use default buffer sizes. | 
| 623 if (!BIO_new_bio_pair(&ssl_bio, 0, &transport_bio_, 0)) | 627 if (!BIO_new_bio_pair(&ssl_bio, 0, &transport_bio_, 0)) | 
| 624 return ERR_UNEXPECTED; | 628 return ERR_UNEXPECTED; | 
| 625 DCHECK(ssl_bio); | 629 DCHECK(ssl_bio); | 
| 626 DCHECK(transport_bio_); | 630 DCHECK(transport_bio_); | 
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 674 SSL_clear_options(ssl_, options.clear_mask); | 678 SSL_clear_options(ssl_, options.clear_mask); | 
| 675 | 679 | 
| 676 // Same as above, this time for the SSL mode. | 680 // Same as above, this time for the SSL mode. | 
| 677 SslSetClearMask mode; | 681 SslSetClearMask mode; | 
| 678 | 682 | 
| 679 mode.ConfigureFlag(SSL_MODE_RELEASE_BUFFERS, true); | 683 mode.ConfigureFlag(SSL_MODE_RELEASE_BUFFERS, true); | 
| 680 | 684 | 
| 681 SSL_set_mode(ssl_, mode.set_mask); | 685 SSL_set_mode(ssl_, mode.set_mask); | 
| 682 SSL_clear_mode(ssl_, mode.clear_mask); | 686 SSL_clear_mode(ssl_, mode.clear_mask); | 
| 683 | 687 | 
| 684 // See SSLConfig::disabled_cipher_suites for description of the suites | 688 // See SSLServerConfig::disabled_cipher_suites for description of the suites | 
| 685 // disabled by default. Note that !SHA256 and !SHA384 only remove HMAC-SHA256 | 689 // disabled by default. Note that !SHA256 and !SHA384 only remove HMAC-SHA256 | 
| 686 // and HMAC-SHA384 cipher suites, not GCM cipher suites with SHA256 or SHA384 | 690 // and HMAC-SHA384 cipher suites, not GCM cipher suites with SHA256 or SHA384 | 
| 687 // as the handshake hash. | 691 // as the handshake hash. | 
| 688 std::string command("DEFAULT:!SHA256:!SHA384:!AESGCM+AES256:!aPSK"); | 692 std::string command("DEFAULT:!SHA256:!SHA384:!AESGCM+AES256:!aPSK"); | 
| 689 | 693 | 
| 690 if (ssl_config_.require_ecdhe) | 694 if (ssl_config_.require_ecdhe) | 
| 691 command.append(":!kRSA:!kDHE"); | 695 command.append(":!kRSA:!kDHE"); | 
| 692 | 696 | 
| 693 // Remove any disabled ciphers. | 697 // Remove any disabled ciphers. | 
| 694 for (uint16_t id : ssl_config_.disabled_cipher_suites) { | 698 for (uint16_t id : ssl_config_.disabled_cipher_suites) { | 
| 695 const SSL_CIPHER* cipher = SSL_get_cipher_by_value(id); | 699 const SSL_CIPHER* cipher = SSL_get_cipher_by_value(id); | 
| 696 if (cipher) { | 700 if (cipher) { | 
| 697 command.append(":!"); | 701 command.append(":!"); | 
| 698 command.append(SSL_CIPHER_get_name(cipher)); | 702 command.append(SSL_CIPHER_get_name(cipher)); | 
| 699 } | 703 } | 
| 700 } | 704 } | 
| 701 | 705 | 
| 702 int rv = SSL_set_cipher_list(ssl_, command.c_str()); | 706 int rv = SSL_set_cipher_list(ssl_, command.c_str()); | 
| 703 // If this fails (rv = 0) it means there are no ciphers enabled on this SSL. | 707 // If this fails (rv = 0) it means there are no ciphers enabled on this SSL. | 
| 704 // This will almost certainly result in the socket failing to complete the | 708 // This will almost certainly result in the socket failing to complete the | 
| 705 // handshake at which point the appropriate error is bubbled up to the client. | 709 // handshake at which point the appropriate error is bubbled up to the client. | 
| 706 LOG_IF(WARNING, rv != 1) << "SSL_set_cipher_list('" << command | 710 LOG_IF(WARNING, rv != 1) << "SSL_set_cipher_list('" << command | 
| 707 << "') returned " << rv; | 711 << "') returned " << rv; | 
| 708 | 712 | 
| 709 return OK; | 713 return OK; | 
| 710 } | 714 } | 
| 711 | 715 | 
| 712 } // namespace net | 716 } // namespace net | 
| OLD | NEW |