| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "bin/secure_socket.h" | 5 #include "bin/secure_socket.h" |
| 6 | 6 |
| 7 #include <errno.h> | 7 #include <errno.h> |
| 8 #include <fcntl.h> | 8 #include <fcntl.h> |
| 9 #include <sys/stat.h> | 9 #include <sys/stat.h> |
| 10 #include <stdio.h> | 10 #include <stdio.h> |
| (...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 868 if (in_handshake_) { | 868 if (in_handshake_) { |
| 869 FATAL("Connect called twice on the same _SecureFilter."); | 869 FATAL("Connect called twice on the same _SecureFilter."); |
| 870 } | 870 } |
| 871 | 871 |
| 872 int status; | 872 int status; |
| 873 int error; | 873 int error; |
| 874 BIO* ssl_side; | 874 BIO* ssl_side; |
| 875 status = BIO_new_bio_pair(&ssl_side, 10000, &socket_side_, 10000); | 875 status = BIO_new_bio_pair(&ssl_side, 10000, &socket_side_, 10000); |
| 876 CheckStatus(status, "BIO_new_bio_pair", __LINE__); | 876 CheckStatus(status, "BIO_new_bio_pair", __LINE__); |
| 877 | 877 |
| 878 if (context == NULL) { | 878 assert(context != NULL); |
| 879 DART_CHECK_VALID(Dart_ThrowException(DartUtils::NewDartArgumentError( | |
| 880 "Default SecurityContext not implemented, context cannot be null."))); | |
| 881 } | |
| 882 | |
| 883 ssl_ = SSL_new(context); | 879 ssl_ = SSL_new(context); |
| 884 SSL_set_bio(ssl_, ssl_side, ssl_side); | 880 SSL_set_bio(ssl_, ssl_side, ssl_side); |
| 885 SSL_set_mode(ssl_, SSL_MODE_AUTO_RETRY); // TODO(whesse): Is this right? | 881 SSL_set_mode(ssl_, SSL_MODE_AUTO_RETRY); // TODO(whesse): Is this right? |
| 886 SSL_set_ex_data(ssl_, filter_ssl_index, this); | 882 SSL_set_ex_data(ssl_, filter_ssl_index, this); |
| 887 | 883 |
| 888 if (is_server_) { | 884 if (is_server_) { |
| 889 // Do not request a client certificate. | 885 // Do not request a client certificate. |
| 890 // TODO(24069): Allow server to request a client certificate, when desired. | 886 // TODO(24069): Allow server to request a client certificate, when desired. |
| 891 SSL_set_verify(ssl_, SSL_VERIFY_NONE, NULL); | 887 SSL_set_verify(ssl_, SSL_VERIFY_NONE, NULL); |
| 892 } else { | 888 } else { |
| 893 SetAlpnProtocolList(protocols_handle, ssl_, NULL, false); | 889 SetAlpnProtocolList(protocols_handle, ssl_, NULL, false); |
| 890 status = SSL_set_tlsext_host_name(ssl_, hostname); |
| 891 CheckStatus(status, "Set SNI host name", __LINE__); |
| 894 // Sets the hostname in the certificate-checking object, so it is checked | 892 // Sets the hostname in the certificate-checking object, so it is checked |
| 895 // against the certificate presented by the server. | 893 // against the certificate presented by the server. |
| 896 X509_VERIFY_PARAM* certificate_checking_parameters = SSL_get0_param(ssl_); | 894 X509_VERIFY_PARAM* certificate_checking_parameters = SSL_get0_param(ssl_); |
| 897 hostname_ = strdup(hostname); | 895 hostname_ = strdup(hostname); |
| 898 X509_VERIFY_PARAM_set_flags(certificate_checking_parameters, | 896 X509_VERIFY_PARAM_set_flags(certificate_checking_parameters, |
| 899 X509_V_FLAG_PARTIAL_CHAIN | | 897 X509_V_FLAG_PARTIAL_CHAIN | |
| 900 X509_V_FLAG_TRUSTED_FIRST); | 898 X509_V_FLAG_TRUSTED_FIRST); |
| 901 X509_VERIFY_PARAM_set_hostflags(certificate_checking_parameters, 0); | 899 X509_VERIFY_PARAM_set_hostflags(certificate_checking_parameters, 0); |
| 902 X509_VERIFY_PARAM_set1_host(certificate_checking_parameters, | 900 X509_VERIFY_PARAM_set1_host(certificate_checking_parameters, |
| 903 hostname_, strlen(hostname_)); | 901 hostname_, strlen(hostname_)); |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1126 } else { | 1124 } else { |
| 1127 if (SSL_LOG_DATA) Log::Print( | 1125 if (SSL_LOG_DATA) Log::Print( |
| 1128 "WriteEncrypted BIO_read wrote %d bytes\n", bytes_processed); | 1126 "WriteEncrypted BIO_read wrote %d bytes\n", bytes_processed); |
| 1129 } | 1127 } |
| 1130 } | 1128 } |
| 1131 return bytes_processed; | 1129 return bytes_processed; |
| 1132 } | 1130 } |
| 1133 | 1131 |
| 1134 } // namespace bin | 1132 } // namespace bin |
| 1135 } // namespace dart | 1133 } // namespace dart |
| OLD | NEW |