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

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

Issue 2903743002: Porting SecureSocket to use BoringSSL on OSX (Closed)
Patch Set: Addressed missed comment from last patch set 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) 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 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_BORINGSSL_H_ 5 #ifndef RUNTIME_BIN_SECURE_SOCKET_FILTER_H_
6 #define RUNTIME_BIN_SECURE_SOCKET_BORINGSSL_H_ 6 #define RUNTIME_BIN_SECURE_SOCKET_FILTER_H_
7
8 #if !defined(RUNTIME_BIN_SECURE_SOCKET_H_)
9 #error Do not include secure_socket_boringssl.h directly. Use secure_socket.h.
10 #endif
11
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include <sys/types.h>
16 7
17 #include <openssl/bio.h> 8 #include <openssl/bio.h>
18 #include <openssl/err.h>
19 #include <openssl/ssl.h> 9 #include <openssl/ssl.h>
20 #include <openssl/x509.h> 10 #include <openssl/x509.h>
21 11
22 #include "bin/builtin.h" 12 #include "bin/builtin.h"
23 #include "bin/dartutils.h"
24 #include "bin/reference_counting.h" 13 #include "bin/reference_counting.h"
25 #include "bin/socket.h" 14 #include "bin/security_context.h"
26 #include "bin/thread.h" 15 #include "platform/utils.h"
27 #include "bin/utils.h"
28 16
29 namespace dart { 17 namespace dart {
30 namespace bin { 18 namespace bin {
31 19
32 /* These are defined in root_certificates.cc. */ 20 /* These are defined in root_certificates.cc. */
33 extern const unsigned char* root_certificates_pem; 21 extern const unsigned char* root_certificates_pem;
34 extern unsigned int root_certificates_pem_length; 22 extern unsigned int root_certificates_pem_length;
35 23
36 class SSLContext { 24 int CertificateCallback(int preverify_ok, X509_STORE_CTX* store_ctx);
zra 2017/06/05 21:06:30 Maybe move this to a private static on SSLCertCont
bkonyi 2017/06/06 00:48:34 I'm pretty sure I've tried, but on either Mac or L
zra 2017/06/06 03:09:39 It has to be public, but this worked for me on Lin
bkonyi 2017/06/06 18:04:43 You're right, that works. I must have been doing s
37 public:
38 static const intptr_t kApproximateSize;
39 25
40 explicit SSLContext(SSL_CTX* context)
41 : context_(context), alpn_protocol_string_(NULL) {}
42
43 ~SSLContext() {
44 SSL_CTX_free(context_);
45 if (alpn_protocol_string_ != NULL) {
46 free(alpn_protocol_string_);
47 }
48 }
49
50 SSL_CTX* context() const { return context_; }
51
52 uint8_t* alpn_protocol_string() const { return alpn_protocol_string_; }
53 void set_alpn_protocol_string(uint8_t* protocol_string) {
54 if (alpn_protocol_string_ != NULL) {
55 free(alpn_protocol_string_);
56 }
57 alpn_protocol_string_ = protocol_string;
58 }
59
60 private:
61 SSL_CTX* context_;
62 uint8_t* alpn_protocol_string_;
63
64 DISALLOW_COPY_AND_ASSIGN(SSLContext);
65 };
66
67 /*
68 * SSLFilter encapsulates the SSL(TLS) code in a filter, that communicates
69 * with the containing _SecureFilterImpl Dart object through four shared
70 * ExternalByteArray buffers, for reading and writing plaintext, and
71 * reading and writing encrypted text. The filter handles handshaking
72 * and certificate verification.
73 */
74 class SSLFilter : public ReferenceCounted<SSLFilter> { 26 class SSLFilter : public ReferenceCounted<SSLFilter> {
75 public: 27 public:
76 // These enums must agree with those in sdk/lib/io/secure_socket.dart. 28 // These enums must agree with those in sdk/lib/io/secure_socket.dart.
77 enum BufferIndex { 29 enum BufferIndex {
78 kReadPlaintext, 30 kReadPlaintext,
79 kWritePlaintext, 31 kWritePlaintext,
80 kReadEncrypted, 32 kReadEncrypted,
81 kWriteEncrypted, 33 kWriteEncrypted,
82 kNumBuffers, 34 kNumBuffers,
83 kFirstEncrypted = kReadEncrypted 35 kFirstEncrypted = kReadEncrypted
84 }; 36 };
85 37
86 static const intptr_t kApproximateSize; 38 static const intptr_t kApproximateSize;
39 static const int kSSLFilterNativeFieldIndex = 0;
40
41 static Dart_Handle WrappedX509Certificate(X509* certificate);
zra 2017/06/05 21:06:30 Maybe move to X509Helper
bkonyi 2017/06/06 00:48:34 Done.
87 42
88 SSLFilter() 43 SSLFilter()
89 : callback_error(NULL), 44 : callback_error(NULL),
90 ssl_(NULL), 45 ssl_(NULL),
91 socket_side_(NULL), 46 socket_side_(NULL),
92 string_start_(NULL), 47 string_start_(NULL),
93 string_length_(NULL), 48 string_length_(NULL),
94 handshake_complete_(NULL), 49 handshake_complete_(NULL),
95 bad_certificate_callback_(NULL), 50 bad_certificate_callback_(NULL),
96 in_handshake_(false), 51 in_handshake_(false),
97 hostname_(NULL) {} 52 hostname_(NULL) {}
98 53
99 ~SSLFilter(); 54 ~SSLFilter();
100 55
101 Dart_Handle Init(Dart_Handle dart_this); 56 Dart_Handle Init(Dart_Handle dart_this);
102 void Connect(const char* hostname, 57 void Connect(const char* hostname,
103 SSL_CTX* context, 58 SSLCertContext* context,
104 bool is_server, 59 bool is_server,
105 bool request_client_certificate, 60 bool request_client_certificate,
106 bool require_client_certificate, 61 bool require_client_certificate,
107 Dart_Handle protocols_handle); 62 Dart_Handle protocols_handle);
108 void Destroy(); 63 void Destroy();
109 void FreeResources(); 64 void FreeResources();
110 void Handshake(); 65 void Handshake();
111 void GetSelectedProtocol(Dart_NativeArguments args); 66 void GetSelectedProtocol(Dart_NativeArguments args);
112 void Renegotiate(bool use_session_cache, 67 void Renegotiate(bool use_session_cache,
113 bool request_client_certificate, 68 bool request_client_certificate,
(...skipping 12 matching lines...) Expand all
126 bool in_handshake); 81 bool in_handshake);
127 Dart_Handle PeerCertificate(); 82 Dart_Handle PeerCertificate();
128 static void InitializeLibrary(); 83 static void InitializeLibrary();
129 Dart_Handle callback_error; 84 Dart_Handle callback_error;
130 85
131 static CObject* ProcessFilterRequest(const CObjectArray& request); 86 static CObject* ProcessFilterRequest(const CObjectArray& request);
132 87
133 // The index of the external data field in _ssl that points to the SSLFilter. 88 // The index of the external data field in _ssl that points to the SSLFilter.
134 static int filter_ssl_index; 89 static int filter_ssl_index;
135 90
136 // TODO(whesse): make private: 91 private:
137 SSL* ssl_; 92 int CertificateCallback(int preverify_ok, X509_STORE_CTX* store_ctx);
zra 2017/06/05 21:06:30 It looks like this is not defined.
bkonyi 2017/06/06 00:48:34 It was at one point when I was trying to pull Cert
138 BIO* socket_side_;
139 93
140 private:
141 static const intptr_t kInternalBIOSize; 94 static const intptr_t kInternalBIOSize;
142 static bool library_initialized_; 95 static bool library_initialized_;
143 static Mutex* mutex_; // To protect library initialization. 96 static Mutex* mutex_; // To protect library initialization.
144 97
98 SSL* ssl_;
99 BIO* socket_side_;
100
145 uint8_t* buffers_[kNumBuffers]; 101 uint8_t* buffers_[kNumBuffers];
146 int buffer_size_; 102 int buffer_size_;
147 int encrypted_buffer_size_; 103 int encrypted_buffer_size_;
148 Dart_PersistentHandle string_start_; 104 Dart_PersistentHandle string_start_;
149 Dart_PersistentHandle string_length_; 105 Dart_PersistentHandle string_length_;
150 Dart_PersistentHandle dart_buffer_objects_[kNumBuffers]; 106 Dart_PersistentHandle dart_buffer_objects_[kNumBuffers];
151 Dart_PersistentHandle handshake_complete_; 107 Dart_PersistentHandle handshake_complete_;
152 Dart_PersistentHandle bad_certificate_callback_; 108 Dart_PersistentHandle bad_certificate_callback_;
153 bool in_handshake_; 109 bool in_handshake_;
154 bool is_server_; 110 bool is_server_;
155 char* hostname_; 111 char* hostname_;
156 112
157 static bool isBufferEncrypted(int i) { 113 static bool IsBufferEncrypted(int i) {
158 return static_cast<BufferIndex>(i) >= kFirstEncrypted; 114 return static_cast<BufferIndex>(i) >= kFirstEncrypted;
159 } 115 }
160 Dart_Handle InitializeBuffers(Dart_Handle dart_this); 116 Dart_Handle InitializeBuffers(Dart_Handle dart_this);
161 void InitializePlatformData(); 117 void InitializePlatformData();
162 118
163 DISALLOW_COPY_AND_ASSIGN(SSLFilter); 119 DISALLOW_COPY_AND_ASSIGN(SSLFilter);
164 }; 120 };
165 121
166 } // namespace bin 122 } // namespace bin
167 } // namespace dart 123 } // namespace dart
168 124
169 #endif // RUNTIME_BIN_SECURE_SOCKET_BORINGSSL_H_ 125 #endif // RUNTIME_BIN_SECURE_SOCKET_FILTER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698