Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: runtime/bin/secure_socket_utils.cc

Issue 2903743002: Porting SecureSocket to use BoringSSL on OSX (Closed)
Patch Set: Addressed nits, confirmed change works on Windows Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/bin/secure_socket_utils.h ('k') | runtime/bin/security_context.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
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.
4
5 #if !defined(DART_IO_DISABLED) && !defined(DART_IO_SECURE_SOCKET_DISABLED)
6
7 #include "bin/secure_socket_utils.h"
8
9 #include <openssl/err.h>
10 #include <openssl/ssl.h>
11
12 #include "platform/globals.h"
13
14 #include "bin/file.h"
15 #include "bin/log.h"
16 #include "bin/secure_socket_filter.h"
17 #include "bin/security_context.h"
18
19 namespace dart {
20 namespace bin {
21
22 // Get the error messages from BoringSSL, and put them in buffer as a
23 // null-terminated string.
24 void SecureSocketUtils::FetchErrorString(const SSL* ssl,
25 TextBuffer* text_buffer) {
26 const char* sep = File::PathSeparator();
27 while (true) {
28 const char* path = NULL;
29 int line = -1;
30 uint32_t error = ERR_get_error_line(&path, &line);
31 if (error == 0) {
32 break;
33 }
34 text_buffer->Printf("\n\t%s", ERR_reason_error_string(error));
35 if ((ssl != NULL) && (ERR_GET_LIB(error) == ERR_LIB_SSL) &&
36 (ERR_GET_REASON(error) == SSL_R_CERTIFICATE_VERIFY_FAILED)) {
37 intptr_t result = SSL_get_verify_result(ssl);
38 text_buffer->Printf(": %s", X509_verify_cert_error_string(result));
39 }
40 if ((path != NULL) && (line >= 0)) {
41 const char* file = strrchr(path, sep[0]);
42 path = file ? file + 1 : path;
43 text_buffer->Printf("(%s:%d)", path, line);
44 }
45 }
46 }
47
48
49 // Handle an error reported from the BoringSSL library.
50 void SecureSocketUtils::ThrowIOException(int status,
51 const char* exception_type,
52 const char* message,
53 const SSL* ssl) {
54 Dart_Handle exception;
55 {
56 TextBuffer error_string(SSL_ERROR_MESSAGE_BUFFER_SIZE);
57 SecureSocketUtils::FetchErrorString(ssl, &error_string);
58 OSError os_error_struct(status, error_string.buf(), OSError::kBoringSSL);
59 Dart_Handle os_error = DartUtils::NewDartOSError(&os_error_struct);
60 exception =
61 DartUtils::NewDartIOException(exception_type, message, os_error);
62 ASSERT(!Dart_IsError(exception));
63 }
64 Dart_ThrowException(exception);
65 UNREACHABLE();
66 }
67
68
69 void SecureSocketUtils::CheckStatusSSL(int status,
70 const char* type,
71 const char* message,
72 const SSL* ssl) {
73 // TODO(24183): Take appropriate action on failed calls,
74 // throw exception that includes all messages from the error stack.
75 if (status == 1) {
76 return;
77 }
78 if (SSL_LOG_STATUS) {
79 int error = ERR_get_error();
80 Log::PrintErr("Failed: %s status %d", message, status);
81 char error_string[SSL_ERROR_MESSAGE_BUFFER_SIZE];
82 ERR_error_string_n(error, error_string, SSL_ERROR_MESSAGE_BUFFER_SIZE);
83 Log::PrintErr("ERROR: %d %s\n", error, error_string);
84 }
85 SecureSocketUtils::ThrowIOException(status, type, message, ssl);
86 }
87
88
89 void SecureSocketUtils::CheckStatus(int status,
90 const char* type,
91 const char* message) {
92 SecureSocketUtils::CheckStatusSSL(status, type, message, NULL);
93 }
94
95 } // namespace bin
96 } // namespace dart
97
98 #endif // !defined(DART_IO_DISABLED) &&
99 // !defined(DART_IO_SECURE_SOCKET_DISABLED)
OLDNEW
« no previous file with comments | « runtime/bin/secure_socket_utils.h ('k') | runtime/bin/security_context.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698