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

Side by Side Diff: net/socket/ssl_client_socket_openssl.h

Issue 1178193002: Sign CertificateVerify messages on a background thread. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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 Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef NET_SOCKET_SSL_CLIENT_SOCKET_OPENSSL_H_ 5 #ifndef NET_SOCKET_SSL_CLIENT_SOCKET_OPENSSL_H_
6 #define NET_SOCKET_SSL_CLIENT_SOCKET_OPENSSL_H_ 6 #define NET_SOCKET_SSL_CLIENT_SOCKET_OPENSSL_H_
7 7
8 #include <openssl/base.h>
9 #include <openssl/ssl.h>
davidben 2015/06/12 21:39:01 base.h's main purpose in life is to forward-declar
10
8 #include <string> 11 #include <string>
12 #include <vector>
9 13
10 #include "base/compiler_specific.h" 14 #include "base/compiler_specific.h"
11 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
12 #include "base/memory/weak_ptr.h" 16 #include "base/memory/weak_ptr.h"
13 #include "net/base/completion_callback.h" 17 #include "net/base/completion_callback.h"
14 #include "net/base/io_buffer.h" 18 #include "net/base/io_buffer.h"
15 #include "net/cert/cert_verifier.h" 19 #include "net/cert/cert_verifier.h"
16 #include "net/cert/cert_verify_result.h" 20 #include "net/cert/cert_verify_result.h"
17 #include "net/cert/ct_verify_result.h" 21 #include "net/cert/ct_verify_result.h"
18 #include "net/socket/client_socket_handle.h" 22 #include "net/socket/client_socket_handle.h"
19 #include "net/socket/ssl_client_socket.h" 23 #include "net/socket/ssl_client_socket.h"
20 #include "net/ssl/channel_id_service.h" 24 #include "net/ssl/channel_id_service.h"
21 #include "net/ssl/openssl_ssl_util.h" 25 #include "net/ssl/openssl_ssl_util.h"
22 #include "net/ssl/ssl_client_cert_type.h" 26 #include "net/ssl/ssl_client_cert_type.h"
23 #include "net/ssl/ssl_config_service.h" 27 #include "net/ssl/ssl_config_service.h"
24 #include "net/ssl/ssl_failure_state.h" 28 #include "net/ssl/ssl_failure_state.h"
25 29
26 // Avoid including misc OpenSSL headers, i.e.:
27 // <openssl/bio.h>
28 typedef struct bio_st BIO;
29 // <openssl/evp.h>
30 typedef struct evp_pkey_st EVP_PKEY;
31 // <openssl/ssl.h>
32 typedef struct ssl_st SSL;
33 // <openssl/x509.h>
34 typedef struct x509_st X509;
35 // <openssl/ossl_type.h>
36 typedef struct x509_store_ctx_st X509_STORE_CTX;
37
38 namespace net { 30 namespace net {
39 31
40 class CertVerifier; 32 class CertVerifier;
41 class CTVerifier; 33 class CTVerifier;
42 class SSLCertRequestInfo; 34 class SSLCertRequestInfo;
43 class SSLInfo; 35 class SSLInfo;
36 class SSLPrivateKey;
44 37
45 // An SSL client socket implemented with OpenSSL. 38 // An SSL client socket implemented with OpenSSL.
46 class SSLClientSocketOpenSSL : public SSLClientSocket { 39 class SSLClientSocketOpenSSL : public SSLClientSocket {
47 public: 40 public:
48 // Takes ownership of the transport_socket, which may already be connected. 41 // Takes ownership of the transport_socket, which may already be connected.
49 // The given hostname will be compared with the name(s) in the server's 42 // The given hostname will be compared with the name(s) in the server's
50 // certificate during the SSL handshake. ssl_config specifies the SSL 43 // certificate during the SSL handshake. ssl_config specifies the SSL
51 // settings. 44 // settings.
52 SSLClientSocketOpenSSL(scoped_ptr<ClientSocketHandle> transport_socket, 45 SSLClientSocketOpenSSL(scoped_ptr<ClientSocketHandle> transport_socket,
53 const HostPortPair& host_and_port, 46 const HostPortPair& host_and_port,
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 void OnHandshakeIOComplete(int result); 123 void OnHandshakeIOComplete(int result);
131 void OnSendComplete(int result); 124 void OnSendComplete(int result);
132 void OnRecvComplete(int result); 125 void OnRecvComplete(int result);
133 126
134 int DoHandshakeLoop(int last_io_result); 127 int DoHandshakeLoop(int last_io_result);
135 int DoReadLoop(); 128 int DoReadLoop();
136 int DoWriteLoop(); 129 int DoWriteLoop();
137 int DoPayloadRead(); 130 int DoPayloadRead();
138 int DoPayloadWrite(); 131 int DoPayloadWrite();
139 132
133 // Runs both the Read and Write loops in response to an event that either or
134 // both may have been blocked on. This may occur during a renegotiation, at
135 // which point both state machines will block on the new handshake.
136 void RunReadWriteLoops();
137
140 int BufferSend(); 138 int BufferSend();
141 int BufferRecv(); 139 int BufferRecv();
142 void BufferSendComplete(int result); 140 void BufferSendComplete(int result);
143 void BufferRecvComplete(int result); 141 void BufferRecvComplete(int result);
144 void TransportWriteComplete(int result); 142 void TransportWriteComplete(int result);
145 int TransportReadComplete(int result); 143 int TransportReadComplete(int result);
146 144
147 // Callback from the SSL layer that indicates the remote server is requesting 145 // Callback from the SSL layer that indicates the remote server is requesting
148 // a certificate for this client. 146 // a certificate for this client.
149 int ClientCertRequestCallback(SSL* ssl); 147 int ClientCertRequestCallback(SSL* ssl);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 // the |ssl_info|.signed_certificate_timestamps list. 189 // the |ssl_info|.signed_certificate_timestamps list.
192 void AddSCTInfoToSSLInfo(SSLInfo* ssl_info) const; 190 void AddSCTInfoToSSLInfo(SSLInfo* ssl_info) const;
193 191
194 // Returns a unique key string for the SSL session cache for 192 // Returns a unique key string for the SSL session cache for
195 // this socket. 193 // this socket.
196 std::string GetSessionCacheKey() const; 194 std::string GetSessionCacheKey() const;
197 195
198 // Returns true if renegotiations are allowed. 196 // Returns true if renegotiations are allowed.
199 bool IsRenegotiationAllowed() const; 197 bool IsRenegotiationAllowed() const;
200 198
199 // Callbacks for operations with the private key.
200 static int PrivateKeyTypeCallback(SSL* ssl);
201 static int PrivateKeySupportsDigestCallback(SSL* ssl, const EVP_MD* md);
202 static size_t PrivateKeyMaxSignatureLenCallback(SSL* ssl);
203 static ssl_private_key_result_t PrivateKeySignCallback(SSL* ssl,
204 uint8_t* out,
205 size_t* out_len,
206 size_t max_out,
207 const EVP_MD* md,
208 const uint8_t* in,
209 size_t in_len);
210 static ssl_private_key_result_t PrivateKeySignCompleteCallback(
211 SSL* ssl,
212 uint8_t* out,
213 size_t* out_len,
214 size_t max_out);
Ryan Sleevi 2015/06/12 23:37:20 The growing number of these callbacks makes me won
davidben 2015/06/15 21:28:24 Arguably that's what SSLContext is. I opted not to
Ryan Sleevi 2015/06/15 22:25:22 https://www.chromium.org/developers/coding-style h
Ryan Sleevi 2015/06/15 22:35:27 Sorry, to be explicit: *This* reviewer highly valu
davidben 2015/06/15 22:37:44 The Chromium one you cited also says:
davidben 2015/06/15 22:53:36 Also note, by the way, that this is the entirety o
Ryan Sleevi 2015/06/15 23:02:06 Except we're not doing that here. And as the C++ D
215
216 void OnPrivateKeySignComplete(Error error,
217 const std::vector<uint8_t>& signature);
218
201 bool transport_send_busy_; 219 bool transport_send_busy_;
202 bool transport_recv_busy_; 220 bool transport_recv_busy_;
203 221
204 // Buffers which are shared by BoringSSL and SSLClientSocketOpenSSL. 222 // Buffers which are shared by BoringSSL and SSLClientSocketOpenSSL.
205 // GrowableIOBuffer is used to keep ownership and setting offset. 223 // GrowableIOBuffer is used to keep ownership and setting offset.
206 scoped_refptr<GrowableIOBuffer> send_buffer_; 224 scoped_refptr<GrowableIOBuffer> send_buffer_;
207 scoped_refptr<GrowableIOBuffer> recv_buffer_; 225 scoped_refptr<GrowableIOBuffer> recv_buffer_;
208 226
209 CompletionCallback user_connect_callback_; 227 CompletionCallback user_connect_callback_;
210 CompletionCallback user_read_callback_; 228 CompletionCallback user_read_callback_;
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 // True if a channel ID was sent. 317 // True if a channel ID was sent.
300 bool channel_id_sent_; 318 bool channel_id_sent_;
301 // True if the initial handshake has completed. 319 // True if the initial handshake has completed.
302 bool handshake_completed_; 320 bool handshake_completed_;
303 // True if the initial handshake's certificate has been verified. 321 // True if the initial handshake's certificate has been verified.
304 bool certificate_verified_; 322 bool certificate_verified_;
305 // The request handle for |channel_id_service_|. 323 // The request handle for |channel_id_service_|.
306 ChannelIDService::Request channel_id_request_; 324 ChannelIDService::Request channel_id_request_;
307 SSLFailureState ssl_failure_state_; 325 SSLFailureState ssl_failure_state_;
308 326
327 scoped_ptr<SSLPrivateKey> private_key_;
328 int signature_result_;
329 std::vector<uint8_t> signature_;
330
309 TransportSecurityState* transport_security_state_; 331 TransportSecurityState* transport_security_state_;
310 332
311 CertPolicyEnforcer* const policy_enforcer_; 333 CertPolicyEnforcer* const policy_enforcer_;
312 334
313 // pinning_failure_log contains a message produced by 335 // pinning_failure_log contains a message produced by
314 // TransportSecurityState::CheckPublicKeyPins in the event of a 336 // TransportSecurityState::CheckPublicKeyPins in the event of a
315 // pinning failure. It is a (somewhat) human-readable string. 337 // pinning failure. It is a (somewhat) human-readable string.
316 std::string pinning_failure_log_; 338 std::string pinning_failure_log_;
317 339
318 BoundNetLog net_log_; 340 BoundNetLog net_log_;
319 base::WeakPtrFactory<SSLClientSocketOpenSSL> weak_factory_; 341 base::WeakPtrFactory<SSLClientSocketOpenSSL> weak_factory_;
320 }; 342 };
321 343
322 } // namespace net 344 } // namespace net
323 345
324 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_OPENSSL_H_ 346 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_OPENSSL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698