Chromium Code Reviews| OLD | NEW |
|---|---|
| 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> | |
| 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 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 125 void OnHandshakeIOComplete(int result); | 118 void OnHandshakeIOComplete(int result); |
| 126 void OnSendComplete(int result); | 119 void OnSendComplete(int result); |
| 127 void OnRecvComplete(int result); | 120 void OnRecvComplete(int result); |
| 128 | 121 |
| 129 int DoHandshakeLoop(int last_io_result); | 122 int DoHandshakeLoop(int last_io_result); |
| 130 int DoReadLoop(); | 123 int DoReadLoop(); |
| 131 int DoWriteLoop(); | 124 int DoWriteLoop(); |
| 132 int DoPayloadRead(); | 125 int DoPayloadRead(); |
| 133 int DoPayloadWrite(); | 126 int DoPayloadWrite(); |
| 134 | 127 |
| 128 // Runs both the Read and Write loops in response to an event that either or | |
| 129 // both may have been blocked on. This may occur during a renegotiation, at | |
| 130 // which point both state machines will block on the new handshake. | |
|
Ryan Sleevi
2015/06/23 15:27:28
I still find this comment confusing :( It's certai
davidben
2015/06/24 21:43:12
PumpReadWriteEvents SGTM.
What do you think of th
| |
| 131 void RunReadWriteLoops(); | |
| 132 | |
| 135 int BufferSend(); | 133 int BufferSend(); |
| 136 int BufferRecv(); | 134 int BufferRecv(); |
| 137 void BufferSendComplete(int result); | 135 void BufferSendComplete(int result); |
| 138 void BufferRecvComplete(int result); | 136 void BufferRecvComplete(int result); |
| 139 void TransportWriteComplete(int result); | 137 void TransportWriteComplete(int result); |
| 140 int TransportReadComplete(int result); | 138 int TransportReadComplete(int result); |
| 141 | 139 |
| 142 // Callback from the SSL layer that indicates the remote server is requesting | 140 // Callback from the SSL layer that indicates the remote server is requesting |
| 143 // a certificate for this client. | 141 // a certificate for this client. |
| 144 int ClientCertRequestCallback(SSL* ssl); | 142 int ClientCertRequestCallback(SSL* ssl); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 186 // the |ssl_info|.signed_certificate_timestamps list. | 184 // the |ssl_info|.signed_certificate_timestamps list. |
| 187 void AddSCTInfoToSSLInfo(SSLInfo* ssl_info) const; | 185 void AddSCTInfoToSSLInfo(SSLInfo* ssl_info) const; |
| 188 | 186 |
| 189 // Returns a unique key string for the SSL session cache for | 187 // Returns a unique key string for the SSL session cache for |
| 190 // this socket. | 188 // this socket. |
| 191 std::string GetSessionCacheKey() const; | 189 std::string GetSessionCacheKey() const; |
| 192 | 190 |
| 193 // Returns true if renegotiations are allowed. | 191 // Returns true if renegotiations are allowed. |
| 194 bool IsRenegotiationAllowed() const; | 192 bool IsRenegotiationAllowed() const; |
| 195 | 193 |
| 194 // Callbacks for operations with the private key. | |
| 195 int PrivateKeyTypeCallback(); | |
| 196 int PrivateKeySupportsDigestCallback(const EVP_MD* md); | |
| 197 size_t PrivateKeyMaxSignatureLenCallback(); | |
| 198 ssl_private_key_result_t PrivateKeySignCallback(uint8_t* out, | |
| 199 size_t* out_len, | |
| 200 size_t max_out, | |
| 201 const EVP_MD* md, | |
| 202 const uint8_t* in, | |
| 203 size_t in_len); | |
| 204 ssl_private_key_result_t PrivateKeySignCompleteCallback(uint8_t* out, | |
| 205 size_t* out_len, | |
| 206 size_t max_out); | |
| 207 | |
| 208 void OnPrivateKeySignComplete(Error error, | |
| 209 const std::vector<uint8_t>& signature); | |
| 210 | |
| 196 bool transport_send_busy_; | 211 bool transport_send_busy_; |
| 197 bool transport_recv_busy_; | 212 bool transport_recv_busy_; |
| 198 | 213 |
| 199 // Buffers which are shared by BoringSSL and SSLClientSocketOpenSSL. | 214 // Buffers which are shared by BoringSSL and SSLClientSocketOpenSSL. |
| 200 // GrowableIOBuffer is used to keep ownership and setting offset. | 215 // GrowableIOBuffer is used to keep ownership and setting offset. |
| 201 scoped_refptr<GrowableIOBuffer> send_buffer_; | 216 scoped_refptr<GrowableIOBuffer> send_buffer_; |
| 202 scoped_refptr<GrowableIOBuffer> recv_buffer_; | 217 scoped_refptr<GrowableIOBuffer> recv_buffer_; |
| 203 | 218 |
| 204 CompletionCallback user_connect_callback_; | 219 CompletionCallback user_connect_callback_; |
| 205 CompletionCallback user_read_callback_; | 220 CompletionCallback user_read_callback_; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 294 // True if a channel ID was sent. | 309 // True if a channel ID was sent. |
| 295 bool channel_id_sent_; | 310 bool channel_id_sent_; |
| 296 // True if the initial handshake has completed. | 311 // True if the initial handshake has completed. |
| 297 bool handshake_completed_; | 312 bool handshake_completed_; |
| 298 // True if the initial handshake's certificate has been verified. | 313 // True if the initial handshake's certificate has been verified. |
| 299 bool certificate_verified_; | 314 bool certificate_verified_; |
| 300 // The request handle for |channel_id_service_|. | 315 // The request handle for |channel_id_service_|. |
| 301 ChannelIDService::Request channel_id_request_; | 316 ChannelIDService::Request channel_id_request_; |
| 302 SSLFailureState ssl_failure_state_; | 317 SSLFailureState ssl_failure_state_; |
| 303 | 318 |
| 319 scoped_ptr<SSLPrivateKey> private_key_; | |
| 320 int signature_result_; | |
| 321 std::vector<uint8_t> signature_; | |
| 322 | |
| 304 TransportSecurityState* transport_security_state_; | 323 TransportSecurityState* transport_security_state_; |
| 305 | 324 |
| 306 CertPolicyEnforcer* const policy_enforcer_; | 325 CertPolicyEnforcer* const policy_enforcer_; |
| 307 | 326 |
| 308 // pinning_failure_log contains a message produced by | 327 // pinning_failure_log contains a message produced by |
| 309 // TransportSecurityState::CheckPublicKeyPins in the event of a | 328 // TransportSecurityState::CheckPublicKeyPins in the event of a |
| 310 // pinning failure. It is a (somewhat) human-readable string. | 329 // pinning failure. It is a (somewhat) human-readable string. |
| 311 std::string pinning_failure_log_; | 330 std::string pinning_failure_log_; |
| 312 | 331 |
| 313 BoundNetLog net_log_; | 332 BoundNetLog net_log_; |
| 314 base::WeakPtrFactory<SSLClientSocketOpenSSL> weak_factory_; | 333 base::WeakPtrFactory<SSLClientSocketOpenSSL> weak_factory_; |
| 315 }; | 334 }; |
| 316 | 335 |
| 317 } // namespace net | 336 } // namespace net |
| 318 | 337 |
| 319 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_OPENSSL_H_ | 338 #endif // NET_SOCKET_SSL_CLIENT_SOCKET_OPENSSL_H_ |
| OLD | NEW |