[email protected] | 61f3ddf | 2012-02-08 02:45:39 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
svaldez | e83af29 | 2016-04-26 14:33:37 | [diff] [blame] | 5 | #ifndef NET_SOCKET_SSL_CLIENT_SOCKET_IMPL_H_ |
| 6 | #define NET_SOCKET_SSL_CLIENT_SOCKET_IMPL_H_ |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 7 | |
davidben | 1d48952 | 2015-07-01 18:48:46 | [diff] [blame] | 8 | #include <openssl/base.h> |
| 9 | #include <openssl/ssl.h> |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 10 | #include <stddef.h> |
tbansal | f82cc8e | 2015-10-14 20:05:49 | [diff] [blame] | 11 | #include <stdint.h> |
davidben | 1d48952 | 2015-07-01 18:48:46 | [diff] [blame] | 12 | |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 13 | #include <memory> |
[email protected] | ea4a1c6a | 2010-12-09 13:33:28 | [diff] [blame] | 14 | #include <string> |
davidben | 1d48952 | 2015-07-01 18:48:46 | [diff] [blame] | 15 | #include <vector> |
[email protected] | ea4a1c6a | 2010-12-09 13:33:28 | [diff] [blame] | 16 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 17 | #include "base/compiler_specific.h" |
| 18 | #include "base/containers/mru_cache.h" |
davidben | 2a811e4e | 2015-12-01 10:49:34 | [diff] [blame] | 19 | #include "base/memory/ref_counted.h" |
[email protected] | be90ba3 | 2013-05-13 20:05:25 | [diff] [blame] | 20 | #include "base/memory/weak_ptr.h" |
davidben | 2a811e4e | 2015-12-01 10:49:34 | [diff] [blame] | 21 | #include "build/build_config.h" |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 22 | #include "net/base/completion_callback.h" |
| 23 | #include "net/base/io_buffer.h" |
eroman | 7f9236a | 2015-05-11 21:23:43 | [diff] [blame] | 24 | #include "net/cert/cert_verifier.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 25 | #include "net/cert/cert_verify_result.h" |
davidben | eb5f8ef3 | 2014-09-04 14:14:32 | [diff] [blame] | 26 | #include "net/cert/ct_verify_result.h" |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 27 | #include "net/socket/client_socket_handle.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 28 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 29 | #include "net/ssl/channel_id_service.h" |
davidben | b8c2321 | 2014-10-28 00:12:16 | [diff] [blame] | 30 | #include "net/ssl/openssl_ssl_util.h" |
davidben | c269cc4b | 2016-07-27 14:55:03 | [diff] [blame] | 31 | #include "net/ssl/scoped_openssl_types.h" |
[email protected] | c078770 | 2014-05-20 21:51:44 | [diff] [blame] | 32 | #include "net/ssl/ssl_client_cert_type.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 33 | #include "net/ssl/ssl_config_service.h" |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 34 | |
davidben | 2a811e4e | 2015-12-01 10:49:34 | [diff] [blame] | 35 | namespace base { |
| 36 | class FilePath; |
| 37 | class SequencedTaskRunner; |
| 38 | } |
| 39 | |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 40 | namespace net { |
| 41 | |
[email protected] | 170e76c | 2010-10-04 15:04:20 | [diff] [blame] | 42 | class CertVerifier; |
davidben | eb5f8ef3 | 2014-09-04 14:14:32 | [diff] [blame] | 43 | class CTVerifier; |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 44 | class SSLCertRequestInfo; |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 45 | class SSLInfo; |
| 46 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 47 | using SignedEkmMap = base::MRUCache<std::string, std::vector<uint8_t>>; |
| 48 | |
svaldez | e83af29 | 2016-04-26 14:33:37 | [diff] [blame] | 49 | class SSLClientSocketImpl : public SSLClientSocket { |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 50 | public: |
| 51 | // Takes ownership of the transport_socket, which may already be connected. |
| 52 | // The given hostname will be compared with the name(s) in the server's |
| 53 | // certificate during the SSL handshake. ssl_config specifies the SSL |
| 54 | // settings. |
svaldez | e83af29 | 2016-04-26 14:33:37 | [diff] [blame] | 55 | SSLClientSocketImpl(std::unique_ptr<ClientSocketHandle> transport_socket, |
| 56 | const HostPortPair& host_and_port, |
| 57 | const SSLConfig& ssl_config, |
| 58 | const SSLClientSocketContext& context); |
| 59 | ~SSLClientSocketImpl() override; |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 60 | |
[email protected] | fbef1393 | 2010-11-23 12:38:53 | [diff] [blame] | 61 | const HostPortPair& host_and_port() const { return host_and_port_; } |
[email protected] | c3456bb | 2011-12-12 22:22:19 | [diff] [blame] | 62 | const std::string& ssl_session_cache_shard() const { |
| 63 | return ssl_session_cache_shard_; |
| 64 | } |
[email protected] | fbef1393 | 2010-11-23 12:38:53 | [diff] [blame] | 65 | |
davidben | 2a811e4e | 2015-12-01 10:49:34 | [diff] [blame] | 66 | #if !defined(OS_NACL) |
| 67 | // Log SSL key material to |path| on |task_runner|. Must be called before any |
| 68 | // SSLClientSockets are created. |
| 69 | static void SetSSLKeyLogFile( |
| 70 | const base::FilePath& path, |
| 71 | const scoped_refptr<base::SequencedTaskRunner>& task_runner); |
| 72 | #endif |
zhongyi | 81f85c6d9 | 2015-10-16 19:34:14 | [diff] [blame] | 73 | |
[email protected] | dbf036f | 2011-12-06 23:33:24 | [diff] [blame] | 74 | // SSLClientSocket implementation. |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 75 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 76 | ChannelIDService* GetChannelIDService() const override; |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 77 | Error GetSignedEKMForTokenBinding(crypto::ECPrivateKey* key, |
| 78 | std::vector<uint8_t>* out) override; |
nharper | b36644f | 2016-02-22 23:14:43 | [diff] [blame] | 79 | crypto::ECPrivateKey* GetChannelIDKey() const override; |
[email protected] | 81ec7c1 | 2012-07-31 18:32:19 | [diff] [blame] | 80 | |
| 81 | // SSLSocket implementation. |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 82 | int ExportKeyingMaterial(const base::StringPiece& label, |
| 83 | bool has_context, |
| 84 | const base::StringPiece& context, |
| 85 | unsigned char* out, |
| 86 | unsigned int outlen) override; |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 87 | |
[email protected] | dbf036f | 2011-12-06 23:33:24 | [diff] [blame] | 88 | // StreamSocket implementation. |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 89 | int Connect(const CompletionCallback& callback) override; |
| 90 | void Disconnect() override; |
| 91 | bool IsConnected() const override; |
| 92 | bool IsConnectedAndIdle() const override; |
| 93 | int GetPeerAddress(IPEndPoint* address) const override; |
| 94 | int GetLocalAddress(IPEndPoint* address) const override; |
| 95 | const BoundNetLog& NetLog() const override; |
| 96 | void SetSubresourceSpeculation() override; |
| 97 | void SetOmniboxSpeculation() override; |
| 98 | bool WasEverUsed() const override; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame^] | 99 | bool WasNpnNegotiated() const override; |
| 100 | NextProto GetNegotiatedProtocol() const override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 101 | bool GetSSLInfo(SSLInfo* ssl_info) override; |
ttuttle | 23fdb7b | 2015-05-15 01:28:03 | [diff] [blame] | 102 | void GetConnectionAttempts(ConnectionAttempts* out) const override; |
| 103 | void ClearConnectionAttempts() override {} |
| 104 | void AddConnectionAttempts(const ConnectionAttempts& attempts) override {} |
tbansal | f82cc8e | 2015-10-14 20:05:49 | [diff] [blame] | 105 | int64_t GetTotalReceivedBytes() const override; |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 106 | |
[email protected] | dbf036f | 2011-12-06 23:33:24 | [diff] [blame] | 107 | // Socket implementation. |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 108 | int Read(IOBuffer* buf, |
| 109 | int buf_len, |
| 110 | const CompletionCallback& callback) override; |
| 111 | int Write(IOBuffer* buf, |
| 112 | int buf_len, |
| 113 | const CompletionCallback& callback) override; |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 114 | int SetReceiveBufferSize(int32_t size) override; |
| 115 | int SetSendBufferSize(int32_t size) override; |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 116 | |
| 117 | private: |
[email protected] | 7f38da8a | 2014-03-17 16:44:26 | [diff] [blame] | 118 | class PeerCertificateChain; |
[email protected] | 821e3bb | 2013-11-08 01:06:01 | [diff] [blame] | 119 | class SSLContext; |
| 120 | friend class SSLClientSocket; |
| 121 | friend class SSLContext; |
| 122 | |
[email protected] | c8a80e9 | 2014-05-17 16:02:08 | [diff] [blame] | 123 | int Init(); |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 124 | void DoReadCallback(int result); |
| 125 | void DoWriteCallback(int result); |
| 126 | |
| 127 | bool DoTransportIO(); |
| 128 | int DoHandshake(); |
davidben | c4212c0 | 2015-05-12 22:30:18 | [diff] [blame] | 129 | int DoHandshakeComplete(int result); |
[email protected] | faff985 | 2014-06-21 06:13:46 | [diff] [blame] | 130 | int DoChannelIDLookup(); |
| 131 | int DoChannelIDLookupComplete(int result); |
[email protected] | 170e76c | 2010-10-04 15:04:20 | [diff] [blame] | 132 | int DoVerifyCert(int result); |
| 133 | int DoVerifyCertComplete(int result); |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 134 | void DoConnectCallback(int result); |
davidben | 30798ed8 | 2014-09-19 19:28:20 | [diff] [blame] | 135 | void UpdateServerCert(); |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 136 | |
| 137 | void OnHandshakeIOComplete(int result); |
| 138 | void OnSendComplete(int result); |
| 139 | void OnRecvComplete(int result); |
| 140 | |
| 141 | int DoHandshakeLoop(int last_io_result); |
davidben | 1b133ad | 2014-10-23 04:23:13 | [diff] [blame] | 142 | int DoReadLoop(); |
| 143 | int DoWriteLoop(); |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 144 | int DoPayloadRead(); |
| 145 | int DoPayloadWrite(); |
| 146 | |
davidben | 1d48952 | 2015-07-01 18:48:46 | [diff] [blame] | 147 | // Called when an asynchronous event completes which may have blocked the |
| 148 | // pending Read or Write calls, if any. Retries both state machines and, if |
| 149 | // complete, runs the respective callbacks. |
| 150 | void PumpReadWriteEvents(); |
| 151 | |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 152 | int BufferSend(); |
| 153 | int BufferRecv(); |
| 154 | void BufferSendComplete(int result); |
| 155 | void BufferRecvComplete(int result); |
| 156 | void TransportWriteComplete(int result); |
[email protected] | 3e5c692 | 2014-02-06 02:42:16 | [diff] [blame] | 157 | int TransportReadComplete(int result); |
rsleevi | 4a6ca8c | 2016-06-24 03:05:22 | [diff] [blame] | 158 | int VerifyCT(); |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 159 | |
[email protected] | 821e3bb | 2013-11-08 01:06:01 | [diff] [blame] | 160 | // Callback from the SSL layer that indicates the remote server is requesting |
| 161 | // a certificate for this client. |
[email protected] | 82c5902 | 2014-08-15 09:38:27 | [diff] [blame] | 162 | int ClientCertRequestCallback(SSL* ssl); |
[email protected] | 821e3bb | 2013-11-08 01:06:01 | [diff] [blame] | 163 | |
[email protected] | b051cdb6 | 2014-02-28 02:20:16 | [diff] [blame] | 164 | // CertVerifyCallback is called to verify the server's certificates. We do |
| 165 | // verification after the handshake so this function only enforces that the |
| 166 | // certificates don't change during renegotiation. |
svaldez | e83af29 | 2016-04-26 14:33:37 | [diff] [blame] | 167 | int CertVerifyCallback(X509_STORE_CTX* store_ctx); |
[email protected] | b051cdb6 | 2014-02-28 02:20:16 | [diff] [blame] | 168 | |
[email protected] | 821e3bb | 2013-11-08 01:06:01 | [diff] [blame] | 169 | // Callback from the SSL layer to check which NPN protocol we are supporting |
svaldez | e83af29 | 2016-04-26 14:33:37 | [diff] [blame] | 170 | int SelectNextProtoCallback(unsigned char** out, |
| 171 | unsigned char* outlen, |
| 172 | const unsigned char* in, |
| 173 | unsigned int inlen); |
[email protected] | 821e3bb | 2013-11-08 01:06:01 | [diff] [blame] | 174 | |
[email protected] | 5aea7918 | 2014-07-14 20:43:41 | [diff] [blame] | 175 | // Called during an operation on |transport_bio_|'s peer. Checks saved |
| 176 | // transport error state and, if appropriate, returns an error through |
| 177 | // OpenSSL's error system. |
svaldez | e83af29 | 2016-04-26 14:33:37 | [diff] [blame] | 178 | long MaybeReplayTransportError(BIO* bio, |
[email protected] | 5aea7918 | 2014-07-14 20:43:41 | [diff] [blame] | 179 | int cmd, |
svaldez | e83af29 | 2016-04-26 14:33:37 | [diff] [blame] | 180 | const char* argp, |
| 181 | int argi, |
| 182 | long argl, |
[email protected] | 5aea7918 | 2014-07-14 20:43:41 | [diff] [blame] | 183 | long retvalue); |
| 184 | |
| 185 | // Callback from the SSL layer when an operation is performed on |
| 186 | // |transport_bio_|'s peer. |
svaldez | e83af29 | 2016-04-26 14:33:37 | [diff] [blame] | 187 | static long BIOCallback(BIO* bio, |
[email protected] | 5aea7918 | 2014-07-14 20:43:41 | [diff] [blame] | 188 | int cmd, |
svaldez | e83af29 | 2016-04-26 14:33:37 | [diff] [blame] | 189 | const char* argp, |
| 190 | int argi, |
| 191 | long argl, |
[email protected] | 5aea7918 | 2014-07-14 20:43:41 | [diff] [blame] | 192 | long retvalue); |
| 193 | |
davidben | dafe4e5 | 2015-04-08 22:53:52 | [diff] [blame] | 194 | // Called after the initial handshake completes and after the server |
| 195 | // certificate has been verified. The order of handshake completion and |
| 196 | // certificate verification depends on whether the connection was false |
| 197 | // started. After both have happened (thus calling this twice), the session is |
| 198 | // safe to cache and will be cached. |
| 199 | void MaybeCacheSession(); |
| 200 | |
davidben | 44aeae6 | 2015-06-24 20:47:43 | [diff] [blame] | 201 | // Called from the SSL layer whenever a new session is established. |
| 202 | int NewSessionCallback(SSL_SESSION* session); |
davidben | dafe4e5 | 2015-04-08 22:53:52 | [diff] [blame] | 203 | |
estark | 723b5eeb | 2016-02-18 21:01:12 | [diff] [blame] | 204 | // Adds the Certificate Transparency info from ct_verify_result_ to |
| 205 | // |ssl_info|. |
davidben | eb5f8ef3 | 2014-09-04 14:14:32 | [diff] [blame] | 206 | // SCTs are held in three separate vectors in ct_verify_result, each |
| 207 | // vetor representing a particular verification state, this method associates |
| 208 | // each of the SCTs with the corresponding SCTVerifyStatus as it adds it to |
| 209 | // the |ssl_info|.signed_certificate_timestamps list. |
estark | 723b5eeb | 2016-02-18 21:01:12 | [diff] [blame] | 210 | void AddCTInfoToSSLInfo(SSLInfo* ssl_info) const; |
davidben | eb5f8ef3 | 2014-09-04 14:14:32 | [diff] [blame] | 211 | |
rsleevi | f020edc | 2015-03-16 19:31:24 | [diff] [blame] | 212 | // Returns a unique key string for the SSL session cache for |
| 213 | // this socket. |
| 214 | std::string GetSessionCacheKey() const; |
| 215 | |
davidben | 421116c | 2015-05-12 19:56:51 | [diff] [blame] | 216 | // Returns true if renegotiations are allowed. |
| 217 | bool IsRenegotiationAllowed() const; |
| 218 | |
davidben | 1d48952 | 2015-07-01 18:48:46 | [diff] [blame] | 219 | // Callbacks for operations with the private key. |
| 220 | int PrivateKeyTypeCallback(); |
davidben | 1d48952 | 2015-07-01 18:48:46 | [diff] [blame] | 221 | size_t PrivateKeyMaxSignatureLenCallback(); |
davidben | 0bca07fd | 2016-07-18 15:12:03 | [diff] [blame] | 222 | ssl_private_key_result_t PrivateKeySignDigestCallback(uint8_t* out, |
| 223 | size_t* out_len, |
| 224 | size_t max_out, |
| 225 | const EVP_MD* md, |
| 226 | const uint8_t* in, |
| 227 | size_t in_len); |
| 228 | ssl_private_key_result_t PrivateKeyCompleteCallback(uint8_t* out, |
| 229 | size_t* out_len, |
| 230 | size_t max_out); |
davidben | 1d48952 | 2015-07-01 18:48:46 | [diff] [blame] | 231 | |
davidben | 0bca07fd | 2016-07-18 15:12:03 | [diff] [blame] | 232 | void OnPrivateKeyComplete(Error error, const std::vector<uint8_t>& signature); |
davidben | 1d48952 | 2015-07-01 18:48:46 | [diff] [blame] | 233 | |
nharper | 736ceda | 2015-11-07 00:16:59 | [diff] [blame] | 234 | int TokenBindingAdd(const uint8_t** out, |
| 235 | size_t* out_len, |
| 236 | int* out_alert_value); |
| 237 | int TokenBindingParse(const uint8_t* contents, |
| 238 | size_t contents_len, |
| 239 | int* out_alert_value); |
| 240 | |
davidben | 281d13f0 | 2016-04-27 20:43:28 | [diff] [blame] | 241 | void LogConnectEndEvent(int rv); |
| 242 | |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame^] | 243 | // Record which TLS extension was used to negotiate protocol and protocol |
| 244 | // chosen in a UMA histogram. |
| 245 | void RecordNegotiationExtension() const; |
| 246 | |
| 247 | // Records histograms for channel id support during full handshakes - resumed |
| 248 | // handshakes are ignored. |
| 249 | void RecordChannelIDSupport() const; |
| 250 | |
| 251 | // Returns whether TLS channel ID is enabled. |
| 252 | bool IsChannelIDEnabled() const; |
| 253 | |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 254 | bool transport_send_busy_; |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 255 | bool transport_recv_busy_; |
[email protected] | 4b76856 | 2013-02-16 04:10:07 | [diff] [blame] | 256 | |
svaldez | e83af29 | 2016-04-26 14:33:37 | [diff] [blame] | 257 | // Buffers which are shared by BoringSSL and SSLClientSocketImpl. |
haavardm | 2d92e72 | 2014-12-19 13:45:44 | [diff] [blame] | 258 | // GrowableIOBuffer is used to keep ownership and setting offset. |
| 259 | scoped_refptr<GrowableIOBuffer> send_buffer_; |
| 260 | scoped_refptr<GrowableIOBuffer> recv_buffer_; |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 261 | |
[email protected] | dbf036f | 2011-12-06 23:33:24 | [diff] [blame] | 262 | CompletionCallback user_connect_callback_; |
[email protected] | 3f55aa1 | 2011-12-07 02:03:33 | [diff] [blame] | 263 | CompletionCallback user_read_callback_; |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 264 | CompletionCallback user_write_callback_; |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 265 | |
| 266 | // Used by Read function. |
| 267 | scoped_refptr<IOBuffer> user_read_buf_; |
| 268 | int user_read_buf_len_; |
| 269 | |
| 270 | // Used by Write function. |
| 271 | scoped_refptr<IOBuffer> user_write_buf_; |
| 272 | int user_write_buf_len_; |
| 273 | |
[email protected] | 4b76856 | 2013-02-16 04:10:07 | [diff] [blame] | 274 | // Used by DoPayloadRead() when attempting to fill the caller's buffer with |
| 275 | // as much data as possible without blocking. |
| 276 | // If DoPayloadRead() encounters an error after having read some data, stores |
| 277 | // the result to return on the *next* call to DoPayloadRead(). A value > 0 |
| 278 | // indicates there is no pending result, otherwise 0 indicates EOF and < 0 |
| 279 | // indicates an error. |
| 280 | int pending_read_error_; |
| 281 | |
davidben | b8c2321 | 2014-10-28 00:12:16 | [diff] [blame] | 282 | // If there is a pending read result, the OpenSSL result code (output of |
| 283 | // SSL_get_error) associated with it. |
| 284 | int pending_read_ssl_error_; |
| 285 | |
| 286 | // If there is a pending read result, the OpenSSLErrorInfo associated with it. |
| 287 | OpenSSLErrorInfo pending_read_error_info_; |
| 288 | |
[email protected] | 5aea7918 | 2014-07-14 20:43:41 | [diff] [blame] | 289 | // Used by TransportReadComplete() to signify an error reading from the |
| 290 | // transport socket. A value of OK indicates the socket is still |
| 291 | // readable. EOFs are mapped to ERR_CONNECTION_CLOSED. |
| 292 | int transport_read_error_; |
| 293 | |
[email protected] | 3e5c692 | 2014-02-06 02:42:16 | [diff] [blame] | 294 | // Used by TransportWriteComplete() and TransportReadComplete() to signify an |
| 295 | // error writing to the transport socket. A value of OK indicates no error. |
| 296 | int transport_write_error_; |
| 297 | |
[email protected] | 64b5c89 | 2014-08-08 09:39:26 | [diff] [blame] | 298 | // Set when Connect finishes. |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 299 | std::unique_ptr<PeerCertificateChain> server_cert_chain_; |
[email protected] | 170e76c | 2010-10-04 15:04:20 | [diff] [blame] | 300 | scoped_refptr<X509Certificate> server_cert_; |
| 301 | CertVerifyResult server_cert_verify_result_; |
dadrian | d476e65 | 2016-07-26 21:33:24 | [diff] [blame] | 302 | std::string ocsp_response_; |
[email protected] | 64b5c89 | 2014-08-08 09:39:26 | [diff] [blame] | 303 | bool completed_connect_; |
[email protected] | 170e76c | 2010-10-04 15:04:20 | [diff] [blame] | 304 | |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 305 | // Set when Read() or Write() successfully reads or writes data to or from the |
| 306 | // network. |
| 307 | bool was_ever_used_; |
| 308 | |
[email protected] | 515adc2 | 2013-01-09 16:01:23 | [diff] [blame] | 309 | // List of DER-encoded X.509 DistinguishedName of certificate authorities |
| 310 | // allowed by the server. |
| 311 | std::vector<std::string> cert_authorities_; |
[email protected] | c078770 | 2014-05-20 21:51:44 | [diff] [blame] | 312 | // List of SSLClientCertType values for client certificates allowed by the |
| 313 | // server. |
| 314 | std::vector<SSLClientCertType> cert_key_types_; |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 315 | |
[email protected] | 822581d | 2010-12-16 17:27:15 | [diff] [blame] | 316 | CertVerifier* const cert_verifier_; |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 317 | std::unique_ptr<CertVerifier::Request> cert_verifier_request_; |
davidben | 09c3d07 | 2014-08-25 20:33:58 | [diff] [blame] | 318 | base::TimeTicks start_cert_verification_time_; |
[email protected] | 170e76c | 2010-10-04 15:04:20 | [diff] [blame] | 319 | |
davidben | eb5f8ef3 | 2014-09-04 14:14:32 | [diff] [blame] | 320 | // Certificate Transparency: Verifier and result holder. |
| 321 | ct::CTVerifyResult ct_verify_result_; |
| 322 | CTVerifier* cert_transparency_verifier_; |
| 323 | |
[email protected] | ee0f2aa8 | 2013-10-25 11:59:26 | [diff] [blame] | 324 | // The service for retrieving Channel ID keys. May be NULL. |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 325 | ChannelIDService* channel_id_service_; |
nharper | 736ceda | 2015-11-07 00:16:59 | [diff] [blame] | 326 | bool tb_was_negotiated_; |
| 327 | TokenBindingParam tb_negotiated_param_; |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 328 | SignedEkmMap tb_signed_ekm_map_; |
[email protected] | ee0f2aa8 | 2013-10-25 11:59:26 | [diff] [blame] | 329 | |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 330 | // OpenSSL stuff |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 331 | SSL* ssl_; |
| 332 | BIO* transport_bio_; |
| 333 | |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 334 | std::unique_ptr<ClientSocketHandle> transport_; |
[email protected] | 055d7f2 | 2010-11-15 12:03:12 | [diff] [blame] | 335 | const HostPortPair host_and_port_; |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 336 | SSLConfig ssl_config_; |
[email protected] | c3456bb | 2011-12-12 22:22:19 | [diff] [blame] | 337 | // ssl_session_cache_shard_ is an opaque string that partitions the SSL |
| 338 | // session cache. i.e. sessions created with one value will not attempt to |
| 339 | // resume on the socket with a different value. |
| 340 | const std::string ssl_session_cache_shard_; |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 341 | |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 342 | enum State { |
| 343 | STATE_NONE, |
| 344 | STATE_HANDSHAKE, |
davidben | c4212c0 | 2015-05-12 22:30:18 | [diff] [blame] | 345 | STATE_HANDSHAKE_COMPLETE, |
[email protected] | faff985 | 2014-06-21 06:13:46 | [diff] [blame] | 346 | STATE_CHANNEL_ID_LOOKUP, |
| 347 | STATE_CHANNEL_ID_LOOKUP_COMPLETE, |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 348 | STATE_VERIFY_CERT, |
| 349 | STATE_VERIFY_CERT_COMPLETE, |
| 350 | }; |
| 351 | State next_handshake_state_; |
svaldez | 4af14d2 | 2015-08-20 13:48:24 | [diff] [blame] | 352 | |
| 353 | // True if the socket has been disconnected. |
| 354 | bool disconnected_; |
| 355 | |
[email protected] | ea4a1c6a | 2010-12-09 13:33:28 | [diff] [blame] | 356 | NextProtoStatus npn_status_; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame^] | 357 | NextProto negotiated_protocol_; |
| 358 | // Protocol negotiation extension used. |
| 359 | SSLNegotiationExtension negotiation_extension_; |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 360 | // Written by the |channel_id_service_|. |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 361 | std::unique_ptr<crypto::ECPrivateKey> channel_id_key_; |
davidben | 52053b38 | 2015-04-27 19:22:29 | [diff] [blame] | 362 | // True if a channel ID was sent. |
| 363 | bool channel_id_sent_; |
davidben | c269cc4b | 2016-07-27 14:55:03 | [diff] [blame] | 364 | // If non-null, the newly-established to be inserted into the session cache |
| 365 | // once certificate verification is done. |
| 366 | ScopedSSL_SESSION pending_session_; |
davidben | dafe4e5 | 2015-04-08 22:53:52 | [diff] [blame] | 367 | // True if the initial handshake's certificate has been verified. |
| 368 | bool certificate_verified_; |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 369 | // The request handle for |channel_id_service_|. |
nharper | 75ade89 | 2015-06-10 19:05:35 | [diff] [blame] | 370 | ChannelIDService::Request channel_id_request_; |
[email protected] | 8bd4e7a | 2014-08-09 14:49:17 | [diff] [blame] | 371 | |
davidben | 1d48952 | 2015-07-01 18:48:46 | [diff] [blame] | 372 | int signature_result_; |
| 373 | std::vector<uint8_t> signature_; |
| 374 | |
[email protected] | 8bd4e7a | 2014-08-09 14:49:17 | [diff] [blame] | 375 | TransportSecurityState* transport_security_state_; |
| 376 | |
estark | 6f9b3d8 | 2016-01-12 21:37:05 | [diff] [blame] | 377 | CTPolicyEnforcer* const policy_enforcer_; |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 378 | |
[email protected] | 8bd4e7a | 2014-08-09 14:49:17 | [diff] [blame] | 379 | // pinning_failure_log contains a message produced by |
| 380 | // TransportSecurityState::CheckPublicKeyPins in the event of a |
| 381 | // pinning failure. It is a (somewhat) human-readable string. |
| 382 | std::string pinning_failure_log_; |
| 383 | |
dadrian | df302c4 | 2016-06-10 18:48:59 | [diff] [blame] | 384 | // True if PKP is bypassed due to a local trust anchor. |
| 385 | bool pkp_bypassed_; |
| 386 | |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 387 | BoundNetLog net_log_; |
svaldez | e83af29 | 2016-04-26 14:33:37 | [diff] [blame] | 388 | base::WeakPtrFactory<SSLClientSocketImpl> weak_factory_; |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 389 | }; |
| 390 | |
| 391 | } // namespace net |
| 392 | |
svaldez | e83af29 | 2016-04-26 14:33:37 | [diff] [blame] | 393 | #endif // NET_SOCKET_SSL_CLIENT_SOCKET_IMPL_H_ |