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

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

Issue 2903743002: Porting SecureSocket to use BoringSSL on OSX (Closed)
Patch Set: Additional cleanup 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
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.h"
17
18 namespace dart {
19 namespace bin {
20
21 // Get the error messages from BoringSSL, and put them in buffer as a
22 // null-terminated string.
23 void SecureSocketUtils::FetchErrorString(const SSL* ssl,
24 TextBuffer* text_buffer) {
25 const char* sep = File::PathSeparator();
26 while (true) {
27 const char* path = NULL;
28 int line = -1;
29 uint32_t error = ERR_get_error_line(&path, &line);
30 if (error == 0) {
31 break;
32 }
33 text_buffer->Printf("\n\t%s", ERR_reason_error_string(error));
34 if ((ssl != NULL) && (ERR_GET_LIB(error) == ERR_LIB_SSL) &&
35 (ERR_GET_REASON(error) == SSL_R_CERTIFICATE_VERIFY_FAILED)) {
36 intptr_t result = SSL_get_verify_result(ssl);
37 text_buffer->Printf(": %s", X509_verify_cert_error_string(result));
38 }
39 if ((path != NULL) && (line >= 0)) {
40 const char* file = strrchr(path, sep[0]);
41 path = file ? file + 1 : path;
42 text_buffer->Printf("(%s:%d)", path, line);
43 }
44 }
45 }
46
47
48 // Handle an error reported from the BoringSSL library.
49 void SecureSocketUtils::ThrowIOException(int status,
50 const char* exception_type,
51 const char* message,
52 const SSL* ssl) {
53 Dart_Handle exception;
54 {
55 TextBuffer error_string(SSL_ERROR_MESSAGE_BUFFER_SIZE);
56 SecureSocketUtils::FetchErrorString(ssl, &error_string);
57 OSError os_error_struct(status, error_string.buf(), OSError::kBoringSSL);
58 Dart_Handle os_error = DartUtils::NewDartOSError(&os_error_struct);
59 exception =
60 DartUtils::NewDartIOException(exception_type, message, os_error);
61 ASSERT(!Dart_IsError(exception));
62 }
63 Dart_ThrowException(exception);
64 UNREACHABLE();
65 }
66
67
68 void SecureSocketUtils::CheckStatusSSL(int status,
69 const char* type,
70 const char* message,
71 const SSL* ssl) {
72 // TODO(24183): Take appropriate action on failed calls,
73 // throw exception that includes all messages from the error stack.
74 if (status == 1) {
75 return;
76 }
77 if (SSL_LOG_STATUS) {
78 int error = ERR_get_error();
79 Log::PrintErr("Failed: %s status %d", message, status);
80 char error_string[SSL_ERROR_MESSAGE_BUFFER_SIZE];
81 ERR_error_string_n(error, error_string, SSL_ERROR_MESSAGE_BUFFER_SIZE);
82 Log::PrintErr("ERROR: %d %s\n", error, error_string);
83 }
84 SecureSocketUtils::ThrowIOException(status, type, message, ssl);
85 }
86
87
88 void SecureSocketUtils::CheckStatus(int status,
89 const char* type,
90 const char* message) {
91 SecureSocketUtils::CheckStatusSSL(status, type, message, NULL);
92 }
93
94 } // namespace bin
95 } // namespace dart
96 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698