| 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 25 matching lines...) Expand all Loading... |
| 36 Mutex* SSLFilter::mutex_ = new Mutex(); | 36 Mutex* SSLFilter::mutex_ = new Mutex(); |
| 37 int SSLFilter::filter_ssl_index; | 37 int SSLFilter::filter_ssl_index; |
| 38 | 38 |
| 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 = 1000; |
| 47 | 47 |
| 48 /* Handle an error reported from the BoringSSL library. */ | 48 /* Handle an error reported from the BoringSSL library. */ |
| 49 static void ThrowIOException(int status, | 49 static void ThrowIOException(int status, |
| 50 const char* exception_type, | 50 const char* exception_type, |
| 51 const char* message, | 51 const char* message, |
| 52 bool free_message = false) { | 52 bool free_message = false) { |
| 53 // TODO(24068): Get the error code and message from the error stack. | 53 char error_string[SSL_ERROR_MESSAGE_BUFFER_SIZE]; |
| 54 // There may be more than one error on the stack - should we | 54 error_string[0] = '\0'; |
| 55 // concatenate the error messages? | 55 int error = ERR_get_error(); |
| 56 int error_code = status; | 56 while (error != 0) { |
| 57 const char* error_message = "Error from BoringSSL library"; | 57 int length = strnlen(error_string, SSL_ERROR_MESSAGE_BUFFER_SIZE); |
| 58 OSError os_error_struct(error_code, error_message, OSError::kBoringSSL); | 58 int free_length = SSL_ERROR_MESSAGE_BUFFER_SIZE - length; |
| 59 if (free_length > 16) { |
| 60 // Enough room for error code at least. |
| 61 if (length > 0) { |
| 62 error_string[length] = '\n'; |
| 63 error_string[length + 1] = '\0'; |
| 64 length++; |
| 65 free_length--; |
| 66 } |
| 67 ERR_error_string_n(error, error_string + length, free_length); |
| 68 } |
| 69 error = ERR_get_error(); |
| 70 } |
| 71 OSError os_error_struct(status, error_string, OSError::kBoringSSL); |
| 59 Dart_Handle os_error = DartUtils::NewDartOSError(&os_error_struct); | 72 Dart_Handle os_error = DartUtils::NewDartOSError(&os_error_struct); |
| 60 Dart_Handle exception = | 73 Dart_Handle exception = |
| 61 DartUtils::NewDartIOException(exception_type, message, os_error); | 74 DartUtils::NewDartIOException(exception_type, message, os_error); |
| 62 if (free_message) { | 75 if (free_message) { |
| 63 free(const_cast<char*>(message)); | 76 free(const_cast<char*>(message)); |
| 64 } | 77 } |
| 65 Dart_ThrowException(exception); | 78 Dart_ThrowException(exception); |
| 66 UNREACHABLE(); | 79 UNREACHABLE(); |
| 67 } | 80 } |
| 68 | 81 |
| (...skipping 1039 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1108 } else { | 1121 } else { |
| 1109 if (SSL_LOG_DATA) Log::Print( | 1122 if (SSL_LOG_DATA) Log::Print( |
| 1110 "WriteEncrypted BIO_read wrote %d bytes\n", bytes_processed); | 1123 "WriteEncrypted BIO_read wrote %d bytes\n", bytes_processed); |
| 1111 } | 1124 } |
| 1112 } | 1125 } |
| 1113 return bytes_processed; | 1126 return bytes_processed; |
| 1114 } | 1127 } |
| 1115 | 1128 |
| 1116 } // namespace bin | 1129 } // namespace bin |
| 1117 } // namespace dart | 1130 } // namespace dart |
| OLD | NEW |