| 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 28 matching lines...) Expand all Loading... |
| 39 static const int kSSLFilterNativeFieldIndex = 0; | 39 static const int kSSLFilterNativeFieldIndex = 0; |
| 40 static const int kSecurityContextNativeFieldIndex = 0; | 40 static const int kSecurityContextNativeFieldIndex = 0; |
| 41 static const int kX509NativeFieldIndex = 0; | 41 static const int kX509NativeFieldIndex = 0; |
| 42 | 42 |
| 43 static const bool SSL_LOG_STATUS = false; | 43 static const bool SSL_LOG_STATUS = false; |
| 44 static const bool SSL_LOG_DATA = false; | 44 static const bool SSL_LOG_DATA = false; |
| 45 | 45 |
| 46 static const int SSL_ERROR_MESSAGE_BUFFER_SIZE = 200; | 46 static const int SSL_ERROR_MESSAGE_BUFFER_SIZE = 200; |
| 47 | 47 |
| 48 /* Handle an error reported from the BoringSSL library. */ | 48 /* Handle an error reported from the BoringSSL library. */ |
| 49 static void ThrowIOException(const char* exception_type, | 49 static void ThrowIOException(int status, |
| 50 const char* exception_type, |
| 50 const char* message, | 51 const char* message, |
| 51 bool free_message = false) { | 52 bool free_message = false) { |
| 52 // TODO(24068): Get the error code and message from the error stack. | 53 // TODO(24068): Get the error code and message from the error stack. |
| 53 // There may be more than one error on the stack - should we | 54 // There may be more than one error on the stack - should we |
| 54 // concatenate the error messages? | 55 // concatenate the error messages? |
| 55 int error_code = 0; | 56 int error_code = status; |
| 56 const char* error_message = "Unknown error from BoringSSL library"; | 57 const char* error_message = "Error from BoringSSL library"; |
| 57 OSError os_error_struct(error_code, error_message, OSError::kBoringSSL); | 58 OSError os_error_struct(error_code, error_message, OSError::kBoringSSL); |
| 58 Dart_Handle os_error = DartUtils::NewDartOSError(&os_error_struct); | 59 Dart_Handle os_error = DartUtils::NewDartOSError(&os_error_struct); |
| 59 Dart_Handle exception = | 60 Dart_Handle exception = |
| 60 DartUtils::NewDartIOException(exception_type, message, os_error); | 61 DartUtils::NewDartIOException(exception_type, message, os_error); |
| 61 if (free_message) { | 62 if (free_message) { |
| 62 free(const_cast<char*>(message)); | 63 free(const_cast<char*>(message)); |
| 63 } | 64 } |
| 64 Dart_ThrowException(exception); | 65 Dart_ThrowException(exception); |
| 65 UNREACHABLE(); | 66 UNREACHABLE(); |
| 66 } | 67 } |
| (...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 325 SSL_CTX_set_verify(context, SSL_VERIFY_PEER, CertificateCallback); | 326 SSL_CTX_set_verify(context, SSL_VERIFY_PEER, CertificateCallback); |
| 326 SSL_CTX_set_min_version(context, TLS1_VERSION); | 327 SSL_CTX_set_min_version(context, TLS1_VERSION); |
| 327 SSL_CTX_set_cipher_list(context, "HIGH:MEDIUM"); | 328 SSL_CTX_set_cipher_list(context, "HIGH:MEDIUM"); |
| 328 SSL_CTX_set_cipher_list_tls11(context, "HIGH:MEDIUM"); | 329 SSL_CTX_set_cipher_list_tls11(context, "HIGH:MEDIUM"); |
| 329 SetSecurityContext(args, context); | 330 SetSecurityContext(args, context); |
| 330 } | 331 } |
| 331 | 332 |
| 332 | 333 |
| 333 int PasswordCallback(char* buf, int size, int rwflag, void* userdata) { | 334 int PasswordCallback(char* buf, int size, int rwflag, void* userdata) { |
| 334 char* password = static_cast<char*>(userdata); | 335 char* password = static_cast<char*>(userdata); |
| 335 if (static_cast<size_t>(size) < strlen(password) + 1) { | 336 ASSERT(size == PEM_BUFSIZE); |
| 336 Log::PrintErr("Password buffer too small.\n"); | 337 strncpy(buf, password, size); |
| 337 exit(1); | 338 return strlen(password); |
| 338 // TODO(24182): Find the actual value of size passed in here, and | |
| 339 // check for password length longer than this in the Dart function | |
| 340 // that passes in the password, so we never have this problem. | |
| 341 } | |
| 342 strncpy(buf, static_cast<char*>(userdata), size); | |
| 343 return strlen(static_cast<char*>(userdata)); | |
| 344 } | 339 } |
| 345 | 340 |
| 346 | 341 |
| 347 void CheckStatus(int status, const char* message, int line) { | 342 void CheckStatus(int status, |
| 343 const char* type, |
| 344 const char* message) { |
| 348 // TODO(24183): Take appropriate action on failed calls, | 345 // TODO(24183): Take appropriate action on failed calls, |
| 349 // throw exception that includes all messages from the error stack. | 346 // throw exception that includes all messages from the error stack. |
| 350 if (status != 1 && SSL_LOG_STATUS) { | 347 if (status == 1) return; |
| 348 if (SSL_LOG_STATUS) { |
| 351 int error = ERR_get_error(); | 349 int error = ERR_get_error(); |
| 352 Log::PrintErr("Failed: %s line %d\n", message, line); | 350 Log::PrintErr("Failed: %s status %d", message, status); |
| 353 char error_string[SSL_ERROR_MESSAGE_BUFFER_SIZE]; | 351 char error_string[SSL_ERROR_MESSAGE_BUFFER_SIZE]; |
| 354 ERR_error_string_n(error, error_string, SSL_ERROR_MESSAGE_BUFFER_SIZE); | 352 ERR_error_string_n(error, error_string, SSL_ERROR_MESSAGE_BUFFER_SIZE); |
| 355 Log::PrintErr("ERROR: %d %s\n", error, error_string); | 353 Log::PrintErr("ERROR: %d %s\n", error, error_string); |
| 356 } | 354 } |
| 355 ThrowIOException(status, type, message); |
| 357 } | 356 } |
| 358 | 357 |
| 359 | 358 |
| 360 void FUNCTION_NAME(SecurityContext_UsePrivateKey)(Dart_NativeArguments args) { | 359 void FUNCTION_NAME(SecurityContext_UsePrivateKey)(Dart_NativeArguments args) { |
| 361 SSL_CTX* context = GetSecurityContext(args); | 360 SSL_CTX* context = GetSecurityContext(args); |
| 362 Dart_Handle filename_object = ThrowIfError(Dart_GetNativeArgument(args, 1)); | 361 Dart_Handle filename_object = ThrowIfError(Dart_GetNativeArgument(args, 1)); |
| 363 const char* filename = NULL; | 362 const char* filename = NULL; |
| 364 if (Dart_IsString(filename_object)) { | 363 if (Dart_IsString(filename_object)) { |
| 365 ThrowIfError(Dart_StringToCString(filename_object, &filename)); | 364 ThrowIfError(Dart_StringToCString(filename_object, &filename)); |
| 366 } else { | 365 } else { |
| 367 Dart_ThrowException(DartUtils::NewDartArgumentError( | 366 Dart_ThrowException(DartUtils::NewDartArgumentError( |
| 368 "File argument to SecurityContext.usePrivateKey is not a String")); | 367 "File argument to SecurityContext.usePrivateKey is not a String")); |
| 369 } | 368 } |
| 370 Dart_Handle password_object = ThrowIfError(Dart_GetNativeArgument(args, 2)); | 369 Dart_Handle password_object = ThrowIfError(Dart_GetNativeArgument(args, 2)); |
| 371 const char* password = NULL; | 370 const char* password = NULL; |
| 372 if (Dart_IsString(password_object)) { | 371 if (Dart_IsString(password_object)) { |
| 373 ThrowIfError(Dart_StringToCString(password_object, &password)); | 372 ThrowIfError(Dart_StringToCString(password_object, &password)); |
| 373 if (strlen(password) > PEM_BUFSIZE - 1) { |
| 374 Dart_ThrowException(DartUtils::NewDartArgumentError( |
| 375 "SecurityContext.usePrivateKey password length is greater than" |
| 376 " 1023 (PEM_BUFSIZE)")); |
| 377 } |
| 374 } else if (Dart_IsNull(password_object)) { | 378 } else if (Dart_IsNull(password_object)) { |
| 375 password = ""; | 379 password = ""; |
| 376 } else { | 380 } else { |
| 377 Dart_ThrowException(DartUtils::NewDartArgumentError( | 381 Dart_ThrowException(DartUtils::NewDartArgumentError( |
| 378 "Password argument to SecurityContext.usePrivateKey is not " | 382 "SecurityContext.usePrivateKey password is not a String or null")); |
| 379 "a String or null")); | |
| 380 } | 383 } |
| 381 | 384 |
| 382 SSL_CTX_set_default_passwd_cb(context, PasswordCallback); | 385 SSL_CTX_set_default_passwd_cb(context, PasswordCallback); |
| 383 SSL_CTX_set_default_passwd_cb_userdata(context, const_cast<char*>(password)); | 386 SSL_CTX_set_default_passwd_cb_userdata(context, const_cast<char*>(password)); |
| 384 int status = SSL_CTX_use_PrivateKey_file(context, | 387 int status = SSL_CTX_use_PrivateKey_file(context, |
| 385 filename, | 388 filename, |
| 386 SSL_FILETYPE_PEM); | 389 SSL_FILETYPE_PEM); |
| 387 // TODO(24184): Handle different expected errors here - file missing, | 390 // TODO(24184): Handle different expected errors here - file missing, |
| 388 // incorrect password, file not a PEM, and throw exceptions. | 391 // incorrect password, file not a PEM, and throw exceptions. |
| 389 // CheckStatus should also throw an exception in uncaught cases. | 392 // CheckStatus should also throw an exception in uncaught cases. |
| 390 CheckStatus(status, "SSL_CTX_use_PrivateKey_file", __LINE__); | 393 CheckStatus(status, "TlsException", "Failure in usePrivateKey"); |
| 391 SSL_CTX_set_default_passwd_cb_userdata(context, NULL); | 394 SSL_CTX_set_default_passwd_cb_userdata(context, NULL); |
| 392 } | 395 } |
| 393 | 396 |
| 394 | 397 |
| 395 void FUNCTION_NAME(SecurityContext_SetTrustedCertificates)( | 398 void FUNCTION_NAME(SecurityContext_SetTrustedCertificates)( |
| 396 Dart_NativeArguments args) { | 399 Dart_NativeArguments args) { |
| 397 SSL_CTX* context = GetSecurityContext(args); | 400 SSL_CTX* context = GetSecurityContext(args); |
| 398 Dart_Handle filename_object = ThrowIfError(Dart_GetNativeArgument(args, 1)); | 401 Dart_Handle filename_object = ThrowIfError(Dart_GetNativeArgument(args, 1)); |
| 399 const char* filename = NULL; | 402 const char* filename = NULL; |
| 400 if (Dart_IsString(filename_object)) { | 403 if (Dart_IsString(filename_object)) { |
| 401 ThrowIfError(Dart_StringToCString(filename_object, &filename)); | 404 ThrowIfError(Dart_StringToCString(filename_object, &filename)); |
| 402 } | 405 } |
| 403 Dart_Handle directory_object = ThrowIfError(Dart_GetNativeArgument(args, 2)); | 406 Dart_Handle directory_object = ThrowIfError(Dart_GetNativeArgument(args, 2)); |
| 404 const char* directory = NULL; | 407 const char* directory = NULL; |
| 405 if (Dart_IsString(directory_object)) { | 408 if (Dart_IsString(directory_object)) { |
| 406 ThrowIfError(Dart_StringToCString(directory_object, &directory)); | 409 ThrowIfError(Dart_StringToCString(directory_object, &directory)); |
| 407 } else if (Dart_IsNull(directory_object)) { | 410 } else if (Dart_IsNull(directory_object)) { |
| 408 directory = NULL; | 411 directory = NULL; |
| 409 } else { | 412 } else { |
| 410 Dart_ThrowException(DartUtils::NewDartArgumentError( | 413 Dart_ThrowException(DartUtils::NewDartArgumentError( |
| 411 "Directory argument to SecurityContext.usePrivateKey is not " | 414 "Directory argument to SecurityContext.usePrivateKey is not " |
| 412 "a String or null")); | 415 "a String or null")); |
| 413 } | 416 } |
| 414 | 417 |
| 415 int status = SSL_CTX_load_verify_locations(context, filename, directory); | 418 int status = SSL_CTX_load_verify_locations(context, filename, directory); |
| 416 CheckStatus(status, "SSL_CTX_load_verify_locations", __LINE__); | 419 CheckStatus( |
| 420 status, "TlsException", "SSL_CTX_load_verify_locations"); |
| 417 } | 421 } |
| 418 | 422 |
| 419 | 423 |
| 420 void FUNCTION_NAME(SecurityContext_TrustBuiltinRoots)( | 424 void FUNCTION_NAME(SecurityContext_TrustBuiltinRoots)( |
| 421 Dart_NativeArguments args) { | 425 Dart_NativeArguments args) { |
| 422 SSL_CTX* context = GetSecurityContext(args); | 426 SSL_CTX* context = GetSecurityContext(args); |
| 423 X509_STORE* store = SSL_CTX_get_cert_store(context); | 427 X509_STORE* store = SSL_CTX_get_cert_store(context); |
| 424 BIO* roots_bio = | 428 BIO* roots_bio = |
| 425 BIO_new_mem_buf(const_cast<unsigned char*>(root_certificates_pem), | 429 BIO_new_mem_buf(const_cast<unsigned char*>(root_certificates_pem), |
| 426 root_certificates_pem_length); | 430 root_certificates_pem_length); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 441 Dart_Handle filename_object = ThrowIfError(Dart_GetNativeArgument(args, 1)); | 445 Dart_Handle filename_object = ThrowIfError(Dart_GetNativeArgument(args, 1)); |
| 442 const char* filename = NULL; | 446 const char* filename = NULL; |
| 443 if (Dart_IsString(filename_object)) { | 447 if (Dart_IsString(filename_object)) { |
| 444 ThrowIfError(Dart_StringToCString(filename_object, &filename)); | 448 ThrowIfError(Dart_StringToCString(filename_object, &filename)); |
| 445 } else { | 449 } else { |
| 446 Dart_ThrowException(DartUtils::NewDartArgumentError( | 450 Dart_ThrowException(DartUtils::NewDartArgumentError( |
| 447 "file argument in SecurityContext.useCertificateChain" | 451 "file argument in SecurityContext.useCertificateChain" |
| 448 " is not a String")); | 452 " is not a String")); |
| 449 } | 453 } |
| 450 int status = SSL_CTX_use_certificate_chain_file(context, filename); | 454 int status = SSL_CTX_use_certificate_chain_file(context, filename); |
| 451 CheckStatus(status, "SSL_CTX_use_certificate_chain_file", __LINE__); | 455 CheckStatus(status, |
| 456 "TlsException", |
| 457 "Failure in useCertificateChain"); |
| 452 } | 458 } |
| 453 | 459 |
| 454 | 460 |
| 455 void FUNCTION_NAME(SecurityContext_SetClientAuthorities)( | 461 void FUNCTION_NAME(SecurityContext_SetClientAuthorities)( |
| 456 Dart_NativeArguments args) { | 462 Dart_NativeArguments args) { |
| 457 SSL_CTX* context = GetSecurityContext(args); | 463 SSL_CTX* context = GetSecurityContext(args); |
| 458 Dart_Handle filename_object = ThrowIfError(Dart_GetNativeArgument(args, 1)); | 464 Dart_Handle filename_object = ThrowIfError(Dart_GetNativeArgument(args, 1)); |
| 459 const char* filename = NULL; | 465 const char* filename = NULL; |
| 460 if (Dart_IsString(filename_object)) { | 466 if (Dart_IsString(filename_object)) { |
| 461 ThrowIfError(Dart_StringToCString(filename_object, &filename)); | 467 ThrowIfError(Dart_StringToCString(filename_object, &filename)); |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 Dart_Handle protocols_handle) { | 872 Dart_Handle protocols_handle) { |
| 867 is_server_ = is_server; | 873 is_server_ = is_server; |
| 868 if (in_handshake_) { | 874 if (in_handshake_) { |
| 869 FATAL("Connect called twice on the same _SecureFilter."); | 875 FATAL("Connect called twice on the same _SecureFilter."); |
| 870 } | 876 } |
| 871 | 877 |
| 872 int status; | 878 int status; |
| 873 int error; | 879 int error; |
| 874 BIO* ssl_side; | 880 BIO* ssl_side; |
| 875 status = BIO_new_bio_pair(&ssl_side, 10000, &socket_side_, 10000); | 881 status = BIO_new_bio_pair(&ssl_side, 10000, &socket_side_, 10000); |
| 876 CheckStatus(status, "BIO_new_bio_pair", __LINE__); | 882 CheckStatus(status, "TlsException", "BIO_new_bio_pair"); |
| 877 | 883 |
| 878 assert(context != NULL); | 884 assert(context != NULL); |
| 879 ssl_ = SSL_new(context); | 885 ssl_ = SSL_new(context); |
| 880 SSL_set_bio(ssl_, ssl_side, ssl_side); | 886 SSL_set_bio(ssl_, ssl_side, ssl_side); |
| 881 SSL_set_mode(ssl_, SSL_MODE_AUTO_RETRY); // TODO(whesse): Is this right? | 887 SSL_set_mode(ssl_, SSL_MODE_AUTO_RETRY); // TODO(whesse): Is this right? |
| 882 SSL_set_ex_data(ssl_, filter_ssl_index, this); | 888 SSL_set_ex_data(ssl_, filter_ssl_index, this); |
| 883 | 889 |
| 884 if (is_server_) { | 890 if (is_server_) { |
| 885 // Do not request a client certificate. | 891 // Do not request a client certificate. |
| 886 // TODO(24069): Allow server to request a client certificate, when desired. | 892 // TODO(24069): Allow server to request a client certificate, when desired. |
| 887 SSL_set_verify(ssl_, SSL_VERIFY_NONE, NULL); | 893 SSL_set_verify(ssl_, SSL_VERIFY_NONE, NULL); |
| 888 } else { | 894 } else { |
| 889 SetAlpnProtocolList(protocols_handle, ssl_, NULL, false); | 895 SetAlpnProtocolList(protocols_handle, ssl_, NULL, false); |
| 890 status = SSL_set_tlsext_host_name(ssl_, hostname); | 896 status = SSL_set_tlsext_host_name(ssl_, hostname); |
| 891 CheckStatus(status, "Set SNI host name", __LINE__); | 897 CheckStatus(status, "TlsException", "Set SNI host name"); |
| 892 // Sets the hostname in the certificate-checking object, so it is checked | 898 // Sets the hostname in the certificate-checking object, so it is checked |
| 893 // against the certificate presented by the server. | 899 // against the certificate presented by the server. |
| 894 X509_VERIFY_PARAM* certificate_checking_parameters = SSL_get0_param(ssl_); | 900 X509_VERIFY_PARAM* certificate_checking_parameters = SSL_get0_param(ssl_); |
| 895 hostname_ = strdup(hostname); | 901 hostname_ = strdup(hostname); |
| 896 X509_VERIFY_PARAM_set_flags(certificate_checking_parameters, | 902 X509_VERIFY_PARAM_set_flags(certificate_checking_parameters, |
| 897 X509_V_FLAG_PARTIAL_CHAIN | | 903 X509_V_FLAG_PARTIAL_CHAIN | |
| 898 X509_V_FLAG_TRUSTED_FIRST); | 904 X509_V_FLAG_TRUSTED_FIRST); |
| 899 X509_VERIFY_PARAM_set_hostflags(certificate_checking_parameters, 0); | 905 X509_VERIFY_PARAM_set_hostflags(certificate_checking_parameters, 0); |
| 900 status = X509_VERIFY_PARAM_set1_host(certificate_checking_parameters, | 906 status = X509_VERIFY_PARAM_set1_host(certificate_checking_parameters, |
| 901 hostname_, strlen(hostname_)); | 907 hostname_, strlen(hostname_)); |
| 902 CheckStatus(status, "Set hostname for certificate checking", __LINE__); | 908 CheckStatus(status, "TlsException", |
| 909 "Set hostname for certificate checking"); |
| 903 } | 910 } |
| 904 // Make the connection: | 911 // Make the connection: |
| 905 if (is_server_) { | 912 if (is_server_) { |
| 906 status = SSL_accept(ssl_); | 913 status = SSL_accept(ssl_); |
| 907 if (SSL_LOG_STATUS) Log::Print("SSL_accept status: %d\n", status); | 914 if (SSL_LOG_STATUS) Log::Print("SSL_accept status: %d\n", status); |
| 908 if (status != 1) { | 915 if (status != 1) { |
| 909 // TODO(whesse): expect a needs-data error here. Handle other errors. | 916 // TODO(whesse): expect a needs-data error here. Handle other errors. |
| 910 error = SSL_get_error(ssl_, status); | 917 error = SSL_get_error(ssl_, status); |
| 911 if (SSL_LOG_STATUS) Log::Print("SSL_accept error: %d\n", error); | 918 if (SSL_LOG_STATUS) Log::Print("SSL_accept error: %d\n", error); |
| 912 } | 919 } |
| (...skipping 24 matching lines...) Expand all Loading... |
| 937 | 944 |
| 938 | 945 |
| 939 int printErrorCallback(const char *str, size_t len, void *ctx) { | 946 int printErrorCallback(const char *str, size_t len, void *ctx) { |
| 940 Log::PrintErr("%.*s\n", static_cast<int>(len), str); | 947 Log::PrintErr("%.*s\n", static_cast<int>(len), str); |
| 941 return 1; | 948 return 1; |
| 942 } | 949 } |
| 943 | 950 |
| 944 void SSLFilter::Handshake() { | 951 void SSLFilter::Handshake() { |
| 945 // Try and push handshake along. | 952 // Try and push handshake along. |
| 946 int status; | 953 int status; |
| 947 int error; | |
| 948 status = SSL_do_handshake(ssl_); | 954 status = SSL_do_handshake(ssl_); |
| 949 if (callback_error != NULL) { | 955 if (callback_error != NULL) { |
| 950 // The SSL_do_handshake will try performing a handshake and might call | 956 // The SSL_do_handshake will try performing a handshake and might call |
| 951 // a CertificateCallback. If the certificate validation | 957 // a CertificateCallback. If the certificate validation |
| 952 // failed the 'callback_error" will be set by the certificateCallback | 958 // failed the 'callback_error" will be set by the certificateCallback |
| 953 // logic and we propagate the error" | 959 // logic and we propagate the error" |
| 954 Dart_PropagateError(callback_error); | 960 Dart_PropagateError(callback_error); |
| 955 } | 961 } |
| 956 if (SSL_LOG_STATUS) Log::Print("SSL_handshake status: %d\n", status); | 962 if (SSL_want_write(ssl_) || SSL_want_read(ssl_)) { |
| 957 if (status != 1) { | 963 in_handshake_ = true; |
| 958 error = SSL_get_error(ssl_, status); | 964 return; |
| 965 } |
| 966 CheckStatus(status, |
| 967 "HandshakeException", |
| 968 is_server_ ? "Handshake error in server" : "Handshake error in client"); |
| 969 // Handshake succeeded. |
| 970 if (in_handshake_) { |
| 971 // TODO(24071): Check return value of SSL_get_verify_result, this |
| 972 // should give us the hostname check. |
| 973 int result = SSL_get_verify_result(ssl_); |
| 959 if (SSL_LOG_STATUS) { | 974 if (SSL_LOG_STATUS) { |
| 960 Log::Print("ERROR: %d\n", error); | 975 Log::Print("Handshake verification status: %d\n", result); |
| 961 ERR_print_errors_cb(printErrorCallback, NULL); | 976 X509* peer_certificate = SSL_get_peer_certificate(ssl_); |
| 962 } | 977 if (peer_certificate == NULL) { |
| 963 } | 978 Log::Print("No peer certificate received\n"); |
| 964 if (status == 1) { | |
| 965 if (in_handshake_) { | |
| 966 // TODO(24071): Check return value of SSL_get_verify_result, this | |
| 967 // should give us the hostname check. | |
| 968 int result = SSL_get_verify_result(ssl_); | |
| 969 if (SSL_LOG_STATUS) { | |
| 970 Log::Print("Handshake verification status: %d\n", result); | |
| 971 X509* peer_certificate = SSL_get_peer_certificate(ssl_); | |
| 972 if (peer_certificate == NULL) { | |
| 973 Log::Print("No peer certificate received\n"); | |
| 974 } else { | |
| 975 X509_NAME* s_name = X509_get_subject_name(peer_certificate); | |
| 976 printf("Peer certificate SN: "); | |
| 977 X509_NAME_print_ex_fp(stdout, s_name, 4, 0); | |
| 978 printf("\n"); | |
| 979 } | |
| 980 } | |
| 981 ThrowIfError(Dart_InvokeClosure( | |
| 982 Dart_HandleFromPersistent(handshake_complete_), 0, NULL)); | |
| 983 in_handshake_ = false; | |
| 984 } | |
| 985 } else if (status == 0) { | |
| 986 if (is_server_) { | |
| 987 ThrowIOException("HandshakeException", | |
| 988 "Handshake error in server"); | |
| 989 } else { | |
| 990 ThrowIOException("HandshakeException", | |
| 991 "Handshake error in client"); | |
| 992 } | |
| 993 } else if (status < 0) { | |
| 994 if (SSL_want_write(ssl_) || SSL_want_read(ssl_)) { | |
| 995 if (!in_handshake_) { | |
| 996 in_handshake_ = true; | |
| 997 } | |
| 998 } else { | |
| 999 if (is_server_) { | |
| 1000 ThrowIOException("HandshakeException", | |
| 1001 "Handshake error in server"); | |
| 1002 } else { | 979 } else { |
| 1003 ThrowIOException("HandshakeException", | 980 X509_NAME* s_name = X509_get_subject_name(peer_certificate); |
| 1004 "Handshake error in client"); | 981 printf("Peer certificate SN: "); |
| 982 X509_NAME_print_ex_fp(stdout, s_name, 4, 0); |
| 983 printf("\n"); |
| 1005 } | 984 } |
| 1006 } | 985 } |
| 986 ThrowIfError(Dart_InvokeClosure( |
| 987 Dart_HandleFromPersistent(handshake_complete_), 0, NULL)); |
| 988 in_handshake_ = false; |
| 1007 } | 989 } |
| 1008 } | 990 } |
| 1009 | 991 |
| 1010 void SSLFilter::GetSelectedProtocol(Dart_NativeArguments args) { | 992 void SSLFilter::GetSelectedProtocol(Dart_NativeArguments args) { |
| 1011 const uint8_t* protocol; | 993 const uint8_t* protocol; |
| 1012 unsigned length; | 994 unsigned length; |
| 1013 SSL_get0_alpn_selected(ssl_, &protocol, &length); | 995 SSL_get0_alpn_selected(ssl_, &protocol, &length); |
| 1014 if (length == 0) { | 996 if (length == 0) { |
| 1015 Dart_SetReturnValue(args, Dart_Null()); | 997 Dart_SetReturnValue(args, Dart_Null()); |
| 1016 } else { | 998 } else { |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1126 } else { | 1108 } else { |
| 1127 if (SSL_LOG_DATA) Log::Print( | 1109 if (SSL_LOG_DATA) Log::Print( |
| 1128 "WriteEncrypted BIO_read wrote %d bytes\n", bytes_processed); | 1110 "WriteEncrypted BIO_read wrote %d bytes\n", bytes_processed); |
| 1129 } | 1111 } |
| 1130 } | 1112 } |
| 1131 return bytes_processed; | 1113 return bytes_processed; |
| 1132 } | 1114 } |
| 1133 | 1115 |
| 1134 } // namespace bin | 1116 } // namespace bin |
| 1135 } // namespace dart | 1117 } // namespace dart |
| OLD | NEW |