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

Side by Side Diff: runtime/bin/secure_socket.h

Issue 2903743002: Porting SecureSocket to use BoringSSL on OSX (Closed)
Patch Set: General 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
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 #ifndef RUNTIME_BIN_SECURE_SOCKET_H_ 5 #ifndef RUNTIME_BIN_SECURE_SOCKET_H_
6 #define RUNTIME_BIN_SECURE_SOCKET_H_ 6 #define RUNTIME_BIN_SECURE_SOCKET_H_
7 7
8 #if defined(DART_IO_DISABLED) || defined(DART_IO_SECURE_SOCKET_DISABLED) 8 #if defined(DART_IO_DISABLED) || defined(DART_IO_SECURE_SOCKET_DISABLED)
9 #error "secure_socket.h can only be included on builds with SSL enabled" 9 #error "secure_socket.h can only be included on builds with SSL enabled"
10 #endif 10 #endif
11 11
12 #include "platform/globals.h" 12 #include "platform/globals.h"
13 #if defined(HOST_OS_ANDROID) || defined(HOST_OS_LINUX) || \ 13 #if defined(HOST_OS_ANDROID) || defined(HOST_OS_LINUX) || \
14 defined(HOST_OS_WINDOWS) || defined(HOST_OS_FUCHSIA) 14 defined(HOST_OS_WINDOWS) || defined(HOST_OS_FUCHSIA)
15 #include "bin/secure_socket_boringssl.h" 15 #include "bin/secure_socket_boringssl.h"
16 #elif defined(HOST_OS_MACOS) 16 #elif defined(HOST_OS_MACOS)
17 #if HOST_OS_IOS 17 #if HOST_OS_IOS
18 #include "bin/secure_socket_ios.h" 18 #include "bin/secure_socket_ios.h"
19 #else // HOST_OS_IOS 19 #else // HOST_OS_IOS
20 #include "bin/secure_socket_macos.h" 20 #include "bin/secure_socket_macos.h"
21 #endif // HOST_OS_IOS 21 #endif // HOST_OS_IOS
22 #else 22 #else
23 #error Unknown target os. 23 #error Unknown target os.
24 #endif 24 #endif
25 25
26 #include <openssl/bio.h>
zra 2017/05/26 18:11:12 These should go after platform/globals.h but befor
bkonyi 2017/05/26 23:35:30 cpplint will complain if we do that. I get this ou
27 #include <openssl/err.h>
28 #include <openssl/ssl.h>
29 #include <openssl/x509.h>
30
31
32 namespace dart {
33 namespace bin {
34
35 /* These are defined in root_certificates.cc. */
36 extern const unsigned char* root_certificates_pem;
37 extern unsigned int root_certificates_pem_length;
38
39 const bool SSL_LOG_STATUS = false;
40 const bool SSL_LOG_DATA = false;
41 const bool SSL_LOG_CERTS = false;
42
43 void ThrowIOException(int status,
zra 2017/05/26 18:11:12 I'd make these statics of an SSLUtils class.
bkonyi 2017/05/26 23:35:30 Done.
44 const char* exception_type,
45 const char* message,
46 const SSL* ssl);
47
48 void CheckStatusSSL(int status,
49 const char* type,
50 const char* message,
51 const SSL* ssl);
52
53 void CheckStatus(int status, const char* type, const char* message);
zra 2017/05/26 18:11:12 "CheckStatus" in particular is probably not a grea
bkonyi 2017/05/26 23:35:30 Yeah, I wasn't sure about this. I'll add it to the
54
55 class SSLFilter : public ReferenceCounted<SSLFilter> {
56 public:
57 // These enums must agree with those in sdk/lib/io/secure_socket.dart.
58 enum BufferIndex {
59 kReadPlaintext,
60 kWritePlaintext,
61 kReadEncrypted,
62 kWriteEncrypted,
63 kNumBuffers,
64 kFirstEncrypted = kReadEncrypted
65 };
66
67 static const intptr_t kApproximateSize;
68
69 SSLFilter()
70 : callback_error(NULL),
71 ssl_(NULL),
72 socket_side_(NULL),
73 string_start_(NULL),
74 string_length_(NULL),
75 handshake_complete_(NULL),
76 bad_certificate_callback_(NULL),
77 in_handshake_(false),
78 hostname_(NULL) {}
79
80 ~SSLFilter();
81
82 Dart_Handle Init(Dart_Handle dart_this);
83 void Connect(const char* hostname,
84 SSLCertContext* context,
85 bool is_server,
86 bool request_client_certificate,
87 bool require_client_certificate,
88 Dart_Handle protocols_handle);
89 void Destroy();
90 void FreeResources();
91 void Handshake();
92 void GetSelectedProtocol(Dart_NativeArguments args);
93 void Renegotiate(bool use_session_cache,
94 bool request_client_certificate,
95 bool require_client_certificate);
96 void RegisterHandshakeCompleteCallback(Dart_Handle handshake_complete);
97 void RegisterBadCertificateCallback(Dart_Handle callback);
98 Dart_Handle bad_certificate_callback() {
99 return Dart_HandleFromPersistent(bad_certificate_callback_);
100 }
101 int ProcessReadPlaintextBuffer(int start, int end);
102 int ProcessWritePlaintextBuffer(int start, int end);
103 int ProcessReadEncryptedBuffer(int start, int end);
104 int ProcessWriteEncryptedBuffer(int start, int end);
105 bool ProcessAllBuffers(int starts[kNumBuffers],
106 int ends[kNumBuffers],
107 bool in_handshake);
108 Dart_Handle PeerCertificate();
109 static void InitializeLibrary();
110 Dart_Handle callback_error;
111
112 static CObject* ProcessFilterRequest(const CObjectArray& request);
113
114 // The index of the external data field in _ssl that points to the SSLFilter.
115 static int filter_ssl_index;
116
117 // TODO(whesse): make private:
zra 2017/05/26 18:11:12 Maybe now is a good time to try to take care of th
bkonyi 2017/05/26 23:35:30 Done.
118 SSL* ssl_;
119 BIO* socket_side_;
120
121 private:
122 void RegisterCallbacks(SSLCertContext* cert_ctx);
123
124 static const intptr_t kInternalBIOSize;
125 static bool library_initialized_;
126 static Mutex* mutex_; // To protect library initialization.
127
128 uint8_t* buffers_[kNumBuffers];
129 int buffer_size_;
130 int encrypted_buffer_size_;
131 Dart_PersistentHandle string_start_;
132 Dart_PersistentHandle string_length_;
133 Dart_PersistentHandle dart_buffer_objects_[kNumBuffers];
134 Dart_PersistentHandle handshake_complete_;
135 Dart_PersistentHandle bad_certificate_callback_;
136 bool in_handshake_;
137 bool is_server_;
138 char* hostname_;
139
140 static bool isBufferEncrypted(int i) {
zra 2017/05/26 18:11:12 IsBufferEncrypted
bkonyi 2017/05/26 23:35:30 Done.
141 return static_cast<BufferIndex>(i) >= kFirstEncrypted;
142 }
143 Dart_Handle InitializeBuffers(Dart_Handle dart_this);
144 void InitializePlatformData();
145
146 DISALLOW_COPY_AND_ASSIGN(SSLFilter);
147 };
148
149 } // namespace bin
150 } // namespace dart
151
26 #endif // RUNTIME_BIN_SECURE_SOCKET_H_ 152 #endif // RUNTIME_BIN_SECURE_SOCKET_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698