[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 | |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 8 | #include <stddef.h> |
tbansal | f82cc8e | 2015-10-14 20:05:49 | [diff] [blame] | 9 | #include <stdint.h> |
davidben | 1d48952 | 2015-07-01 18:48:46 | [diff] [blame] | 10 | |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 11 | #include <memory> |
[email protected] | ea4a1c6a | 2010-12-09 13:33:28 | [diff] [blame] | 12 | #include <string> |
davidben | 1d48952 | 2015-07-01 18:48:46 | [diff] [blame] | 13 | #include <vector> |
[email protected] | ea4a1c6a | 2010-12-09 13:33:28 | [diff] [blame] | 14 | |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 15 | #include "base/compiler_specific.h" |
| 16 | #include "base/containers/mru_cache.h" |
David Benjamin | e34d7424 | 2017-06-29 20:35:16 | [diff] [blame^] | 17 | #include "base/macros.h" |
davidben | 2a811e4e | 2015-12-01 10:49:34 | [diff] [blame] | 18 | #include "base/memory/ref_counted.h" |
[email protected] | be90ba3 | 2013-05-13 20:05:25 | [diff] [blame] | 19 | #include "base/memory/weak_ptr.h" |
davidben | 2a811e4e | 2015-12-01 10:49:34 | [diff] [blame] | 20 | #include "build/build_config.h" |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 21 | #include "net/base/completion_callback.h" |
| 22 | #include "net/base/io_buffer.h" |
eroman | 7f9236a | 2015-05-11 21:23:43 | [diff] [blame] | 23 | #include "net/cert/cert_verifier.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 24 | #include "net/cert/cert_verify_result.h" |
davidben | eb5f8ef3 | 2014-09-04 14:14:32 | [diff] [blame] | 25 | #include "net/cert/ct_verify_result.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 26 | #include "net/log/net_log_with_source.h" |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 27 | #include "net/socket/client_socket_handle.h" |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 28 | #include "net/socket/next_proto.h" |
davidben | 3418e81f | 2016-10-19 00:09:45 | [diff] [blame] | 29 | #include "net/socket/socket_bio_adapter.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 30 | #include "net/socket/ssl_client_socket.h" |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 31 | #include "net/ssl/channel_id_service.h" |
davidben | b8c2321 | 2014-10-28 00:12:16 | [diff] [blame] | 32 | #include "net/ssl/openssl_ssl_util.h" |
[email protected] | c078770 | 2014-05-20 21:51:44 | [diff] [blame] | 33 | #include "net/ssl/ssl_client_cert_type.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 34 | #include "net/ssl/ssl_config_service.h" |
tfarina | e8cb8aa | 2016-10-21 02:44:01 | [diff] [blame] | 35 | #include "third_party/boringssl/src/include/openssl/base.h" |
| 36 | #include "third_party/boringssl/src/include/openssl/ssl.h" |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 37 | |
davidben | 2a811e4e | 2015-12-01 10:49:34 | [diff] [blame] | 38 | namespace base { |
| 39 | class FilePath; |
| 40 | class SequencedTaskRunner; |
xunjieli | 9f8c5fb5 | 2016-12-07 22:59:33 | [diff] [blame] | 41 | namespace trace_event { |
| 42 | class ProcessMemoryDump; |
| 43 | } |
davidben | 2a811e4e | 2015-12-01 10:49:34 | [diff] [blame] | 44 | } |
| 45 | |
davidben | fe132d9 | 2016-09-27 18:07:21 | [diff] [blame] | 46 | namespace crypto { |
| 47 | class OpenSSLErrStackTracer; |
| 48 | } |
| 49 | |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 50 | namespace net { |
| 51 | |
[email protected] | 170e76c | 2010-10-04 15:04:20 | [diff] [blame] | 52 | class CertVerifier; |
davidben | eb5f8ef3 | 2014-09-04 14:14:32 | [diff] [blame] | 53 | class CTVerifier; |
davidben | 3418e81f | 2016-10-19 00:09:45 | [diff] [blame] | 54 | class SocketBIOAdapter; |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 55 | class SSLCertRequestInfo; |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 56 | class SSLInfo; |
| 57 | |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 58 | using TokenBindingSignatureMap = |
| 59 | base::MRUCache<std::pair<TokenBindingType, std::string>, |
| 60 | std::vector<uint8_t>>; |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 61 | |
davidben | 3418e81f | 2016-10-19 00:09:45 | [diff] [blame] | 62 | class SSLClientSocketImpl : public SSLClientSocket, |
| 63 | public SocketBIOAdapter::Delegate { |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 64 | public: |
| 65 | // Takes ownership of the transport_socket, which may already be connected. |
| 66 | // The given hostname will be compared with the name(s) in the server's |
| 67 | // certificate during the SSL handshake. ssl_config specifies the SSL |
| 68 | // settings. |
svaldez | e83af29 | 2016-04-26 14:33:37 | [diff] [blame] | 69 | SSLClientSocketImpl(std::unique_ptr<ClientSocketHandle> transport_socket, |
| 70 | const HostPortPair& host_and_port, |
| 71 | const SSLConfig& ssl_config, |
| 72 | const SSLClientSocketContext& context); |
| 73 | ~SSLClientSocketImpl() override; |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 74 | |
[email protected] | fbef1393 | 2010-11-23 12:38:53 | [diff] [blame] | 75 | const HostPortPair& host_and_port() const { return host_and_port_; } |
[email protected] | c3456bb | 2011-12-12 22:22:19 | [diff] [blame] | 76 | const std::string& ssl_session_cache_shard() const { |
| 77 | return ssl_session_cache_shard_; |
| 78 | } |
[email protected] | fbef1393 | 2010-11-23 12:38:53 | [diff] [blame] | 79 | |
davidben | 2a811e4e | 2015-12-01 10:49:34 | [diff] [blame] | 80 | #if !defined(OS_NACL) |
| 81 | // Log SSL key material to |path| on |task_runner|. Must be called before any |
| 82 | // SSLClientSockets are created. |
| 83 | static void SetSSLKeyLogFile( |
| 84 | const base::FilePath& path, |
| 85 | const scoped_refptr<base::SequencedTaskRunner>& task_runner); |
| 86 | #endif |
zhongyi | 81f85c6d9 | 2015-10-16 19:34:14 | [diff] [blame] | 87 | |
[email protected] | dbf036f | 2011-12-06 23:33:24 | [diff] [blame] | 88 | // SSLClientSocket implementation. |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 89 | void GetSSLCertRequestInfo(SSLCertRequestInfo* cert_request_info) override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 90 | ChannelIDService* GetChannelIDService() const override; |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 91 | Error GetTokenBindingSignature(crypto::ECPrivateKey* key, |
| 92 | TokenBindingType tb_type, |
| 93 | std::vector<uint8_t>* out) override; |
nharper | b36644f | 2016-02-22 23:14:43 | [diff] [blame] | 94 | crypto::ECPrivateKey* GetChannelIDKey() const override; |
David Benjamin | e34d7424 | 2017-06-29 20:35:16 | [diff] [blame^] | 95 | SSLErrorDetails GetConnectErrorDetails() const override; |
[email protected] | 81ec7c1 | 2012-07-31 18:32:19 | [diff] [blame] | 96 | |
| 97 | // SSLSocket implementation. |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 98 | int ExportKeyingMaterial(const base::StringPiece& label, |
| 99 | bool has_context, |
| 100 | const base::StringPiece& context, |
| 101 | unsigned char* out, |
| 102 | unsigned int outlen) override; |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 103 | |
[email protected] | dbf036f | 2011-12-06 23:33:24 | [diff] [blame] | 104 | // StreamSocket implementation. |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 105 | int Connect(const CompletionCallback& callback) override; |
| 106 | void Disconnect() override; |
| 107 | bool IsConnected() const override; |
| 108 | bool IsConnectedAndIdle() const override; |
| 109 | int GetPeerAddress(IPEndPoint* address) const override; |
| 110 | int GetLocalAddress(IPEndPoint* address) const override; |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 111 | const NetLogWithSource& NetLog() const override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 112 | void SetSubresourceSpeculation() override; |
| 113 | void SetOmniboxSpeculation() override; |
| 114 | bool WasEverUsed() const override; |
tfarina | 2846404c | 2016-12-25 14:31:37 | [diff] [blame] | 115 | bool WasAlpnNegotiated() const override; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 116 | NextProto GetNegotiatedProtocol() const override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 117 | bool GetSSLInfo(SSLInfo* ssl_info) override; |
ttuttle | 23fdb7b | 2015-05-15 01:28:03 | [diff] [blame] | 118 | void GetConnectionAttempts(ConnectionAttempts* out) const override; |
| 119 | void ClearConnectionAttempts() override {} |
| 120 | void AddConnectionAttempts(const ConnectionAttempts& attempts) override {} |
tbansal | f82cc8e | 2015-10-14 20:05:49 | [diff] [blame] | 121 | int64_t GetTotalReceivedBytes() const override; |
xunjieli | 998d247 | 2017-01-12 01:12:28 | [diff] [blame] | 122 | void DumpMemoryStats(SocketMemoryStats* stats) const override; |
xunjieli | 9f8c5fb5 | 2016-12-07 22:59:33 | [diff] [blame] | 123 | |
| 124 | // Dumps memory allocation stats. |pmd| is the browser process memory dump. |
| 125 | static void DumpSSLClientSessionMemoryStats( |
| 126 | base::trace_event::ProcessMemoryDump* pmd); |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 127 | |
[email protected] | dbf036f | 2011-12-06 23:33:24 | [diff] [blame] | 128 | // Socket implementation. |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 129 | int Read(IOBuffer* buf, |
| 130 | int buf_len, |
| 131 | const CompletionCallback& callback) override; |
xunjieli | 321a96f3 | 2017-03-07 19:42:17 | [diff] [blame] | 132 | int ReadIfReady(IOBuffer* buf, |
| 133 | int buf_len, |
| 134 | const CompletionCallback& callback) override; |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 135 | int Write(IOBuffer* buf, |
| 136 | int buf_len, |
| 137 | const CompletionCallback& callback) override; |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 138 | int SetReceiveBufferSize(int32_t size) override; |
| 139 | int SetSendBufferSize(int32_t size) override; |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 140 | |
davidben | 3418e81f | 2016-10-19 00:09:45 | [diff] [blame] | 141 | // SocketBIOAdapter implementation: |
| 142 | void OnReadReady() override; |
| 143 | void OnWriteReady() override; |
| 144 | |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 145 | private: |
[email protected] | 7f38da8a | 2014-03-17 16:44:26 | [diff] [blame] | 146 | class PeerCertificateChain; |
[email protected] | 821e3bb | 2013-11-08 01:06:01 | [diff] [blame] | 147 | class SSLContext; |
| 148 | friend class SSLClientSocket; |
| 149 | friend class SSLContext; |
| 150 | |
[email protected] | c8a80e9 | 2014-05-17 16:02:08 | [diff] [blame] | 151 | int Init(); |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 152 | void DoReadCallback(int result); |
| 153 | void DoWriteCallback(int result); |
| 154 | |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 155 | int DoHandshake(); |
davidben | c4212c0 | 2015-05-12 22:30:18 | [diff] [blame] | 156 | int DoHandshakeComplete(int result); |
[email protected] | faff985 | 2014-06-21 06:13:46 | [diff] [blame] | 157 | int DoChannelIDLookup(); |
| 158 | int DoChannelIDLookupComplete(int result); |
[email protected] | 170e76c | 2010-10-04 15:04:20 | [diff] [blame] | 159 | int DoVerifyCert(int result); |
| 160 | int DoVerifyCertComplete(int result); |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 161 | void DoConnectCallback(int result); |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 162 | |
| 163 | void OnHandshakeIOComplete(int result); |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 164 | |
| 165 | int DoHandshakeLoop(int last_io_result); |
xunjieli | 321a96f3 | 2017-03-07 19:42:17 | [diff] [blame] | 166 | int DoPayloadRead(IOBuffer* buf, int buf_len); |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 167 | int DoPayloadWrite(); |
| 168 | |
davidben | 1d48952 | 2015-07-01 18:48:46 | [diff] [blame] | 169 | // Called when an asynchronous event completes which may have blocked the |
davidben | 3418e81f | 2016-10-19 00:09:45 | [diff] [blame] | 170 | // pending Connect, Read or Write calls, if any. Retries all state machines |
| 171 | // and, if complete, runs the respective callbacks. |
| 172 | void RetryAllOperations(); |
davidben | 1d48952 | 2015-07-01 18:48:46 | [diff] [blame] | 173 | |
rsleevi | 4a6ca8c | 2016-06-24 03:05:22 | [diff] [blame] | 174 | int VerifyCT(); |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 175 | |
[email protected] | 821e3bb | 2013-11-08 01:06:01 | [diff] [blame] | 176 | // Callback from the SSL layer that indicates the remote server is requesting |
| 177 | // a certificate for this client. |
[email protected] | 82c5902 | 2014-08-15 09:38:27 | [diff] [blame] | 178 | int ClientCertRequestCallback(SSL* ssl); |
[email protected] | 821e3bb | 2013-11-08 01:06:01 | [diff] [blame] | 179 | |
davidben | dafe4e5 | 2015-04-08 22:53:52 | [diff] [blame] | 180 | // Called after the initial handshake completes and after the server |
| 181 | // certificate has been verified. The order of handshake completion and |
| 182 | // certificate verification depends on whether the connection was false |
| 183 | // started. After both have happened (thus calling this twice), the session is |
| 184 | // safe to cache and will be cached. |
| 185 | void MaybeCacheSession(); |
| 186 | |
davidben | 44aeae6 | 2015-06-24 20:47:43 | [diff] [blame] | 187 | // Called from the SSL layer whenever a new session is established. |
| 188 | int NewSessionCallback(SSL_SESSION* session); |
davidben | dafe4e5 | 2015-04-08 22:53:52 | [diff] [blame] | 189 | |
estark | 723b5eeb | 2016-02-18 21:01:12 | [diff] [blame] | 190 | // Adds the Certificate Transparency info from ct_verify_result_ to |
| 191 | // |ssl_info|. |
davidben | eb5f8ef3 | 2014-09-04 14:14:32 | [diff] [blame] | 192 | // SCTs are held in three separate vectors in ct_verify_result, each |
| 193 | // vetor representing a particular verification state, this method associates |
| 194 | // each of the SCTs with the corresponding SCTVerifyStatus as it adds it to |
| 195 | // the |ssl_info|.signed_certificate_timestamps list. |
estark | 723b5eeb | 2016-02-18 21:01:12 | [diff] [blame] | 196 | void AddCTInfoToSSLInfo(SSLInfo* ssl_info) const; |
davidben | eb5f8ef3 | 2014-09-04 14:14:32 | [diff] [blame] | 197 | |
rsleevi | f020edc | 2015-03-16 19:31:24 | [diff] [blame] | 198 | // Returns a unique key string for the SSL session cache for |
| 199 | // this socket. |
| 200 | std::string GetSessionCacheKey() const; |
| 201 | |
davidben | 421116c | 2015-05-12 19:56:51 | [diff] [blame] | 202 | // Returns true if renegotiations are allowed. |
| 203 | bool IsRenegotiationAllowed() const; |
| 204 | |
davidben | 1d48952 | 2015-07-01 18:48:46 | [diff] [blame] | 205 | // Callbacks for operations with the private key. |
davidben | 0bca07fd | 2016-07-18 15:12:03 | [diff] [blame] | 206 | ssl_private_key_result_t PrivateKeySignDigestCallback(uint8_t* out, |
| 207 | size_t* out_len, |
| 208 | size_t max_out, |
| 209 | const EVP_MD* md, |
| 210 | const uint8_t* in, |
| 211 | size_t in_len); |
| 212 | ssl_private_key_result_t PrivateKeyCompleteCallback(uint8_t* out, |
| 213 | size_t* out_len, |
| 214 | size_t max_out); |
davidben | 1d48952 | 2015-07-01 18:48:46 | [diff] [blame] | 215 | |
davidben | 0bca07fd | 2016-07-18 15:12:03 | [diff] [blame] | 216 | void OnPrivateKeyComplete(Error error, const std::vector<uint8_t>& signature); |
davidben | 1d48952 | 2015-07-01 18:48:46 | [diff] [blame] | 217 | |
davidben | cef9e21 | 2017-04-19 15:00:10 | [diff] [blame] | 218 | // Called whenever BoringSSL processes a protocol message. |
| 219 | void MessageCallback(int is_write, |
| 220 | int content_type, |
| 221 | const void* buf, |
| 222 | size_t len); |
| 223 | |
nharper | 736ceda | 2015-11-07 00:16:59 | [diff] [blame] | 224 | int TokenBindingAdd(const uint8_t** out, |
| 225 | size_t* out_len, |
| 226 | int* out_alert_value); |
| 227 | int TokenBindingParse(const uint8_t* contents, |
| 228 | size_t contents_len, |
| 229 | int* out_alert_value); |
| 230 | |
davidben | 281d13f0 | 2016-04-27 20:43:28 | [diff] [blame] | 231 | void LogConnectEndEvent(int rv); |
| 232 | |
bnc | bd442c2 | 2016-09-14 20:49:16 | [diff] [blame] | 233 | // Record whether ALPN was used, and if so, the negotiated protocol, |
| 234 | // in a UMA histogram. |
| 235 | void RecordNegotiatedProtocol() const; |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 236 | |
| 237 | // Records histograms for channel id support during full handshakes - resumed |
| 238 | // handshakes are ignored. |
| 239 | void RecordChannelIDSupport() const; |
| 240 | |
| 241 | // Returns whether TLS channel ID is enabled. |
| 242 | bool IsChannelIDEnabled() const; |
| 243 | |
davidben | fe132d9 | 2016-09-27 18:07:21 | [diff] [blame] | 244 | // Returns the net error corresponding to the most recent OpenSSL |
| 245 | // error. ssl_error is the output of SSL_get_error. |
| 246 | int MapLastOpenSSLError(int ssl_error, |
| 247 | const crypto::OpenSSLErrStackTracer& tracer, |
| 248 | OpenSSLErrorInfo* info); |
| 249 | |
[email protected] | dbf036f | 2011-12-06 23:33:24 | [diff] [blame] | 250 | CompletionCallback user_connect_callback_; |
[email protected] | 3f55aa1 | 2011-12-07 02:03:33 | [diff] [blame] | 251 | CompletionCallback user_read_callback_; |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 252 | CompletionCallback user_write_callback_; |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 253 | |
| 254 | // Used by Read function. |
| 255 | scoped_refptr<IOBuffer> user_read_buf_; |
| 256 | int user_read_buf_len_; |
| 257 | |
| 258 | // Used by Write function. |
| 259 | scoped_refptr<IOBuffer> user_write_buf_; |
| 260 | int user_write_buf_len_; |
| 261 | |
[email protected] | 4b76856 | 2013-02-16 04:10:07 | [diff] [blame] | 262 | // Used by DoPayloadRead() when attempting to fill the caller's buffer with |
| 263 | // as much data as possible without blocking. |
| 264 | // If DoPayloadRead() encounters an error after having read some data, stores |
| 265 | // the result to return on the *next* call to DoPayloadRead(). A value > 0 |
| 266 | // indicates there is no pending result, otherwise 0 indicates EOF and < 0 |
| 267 | // indicates an error. |
| 268 | int pending_read_error_; |
| 269 | |
davidben | b8c2321 | 2014-10-28 00:12:16 | [diff] [blame] | 270 | // If there is a pending read result, the OpenSSL result code (output of |
| 271 | // SSL_get_error) associated with it. |
| 272 | int pending_read_ssl_error_; |
| 273 | |
| 274 | // If there is a pending read result, the OpenSSLErrorInfo associated with it. |
| 275 | OpenSSLErrorInfo pending_read_error_info_; |
| 276 | |
[email protected] | 64b5c89 | 2014-08-08 09:39:26 | [diff] [blame] | 277 | // Set when Connect finishes. |
[email protected] | 170e76c | 2010-10-04 15:04:20 | [diff] [blame] | 278 | scoped_refptr<X509Certificate> server_cert_; |
| 279 | CertVerifyResult server_cert_verify_result_; |
[email protected] | 64b5c89 | 2014-08-08 09:39:26 | [diff] [blame] | 280 | bool completed_connect_; |
[email protected] | 170e76c | 2010-10-04 15:04:20 | [diff] [blame] | 281 | |
[email protected] | 0dc88b3 | 2014-03-26 20:12:28 | [diff] [blame] | 282 | // Set when Read() or Write() successfully reads or writes data to or from the |
| 283 | // network. |
| 284 | bool was_ever_used_; |
| 285 | |
[email protected] | 822581d | 2010-12-16 17:27:15 | [diff] [blame] | 286 | CertVerifier* const cert_verifier_; |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 287 | std::unique_ptr<CertVerifier::Request> cert_verifier_request_; |
davidben | 09c3d07 | 2014-08-25 20:33:58 | [diff] [blame] | 288 | base::TimeTicks start_cert_verification_time_; |
[email protected] | 170e76c | 2010-10-04 15:04:20 | [diff] [blame] | 289 | |
davidben | eb5f8ef3 | 2014-09-04 14:14:32 | [diff] [blame] | 290 | // Certificate Transparency: Verifier and result holder. |
| 291 | ct::CTVerifyResult ct_verify_result_; |
| 292 | CTVerifier* cert_transparency_verifier_; |
| 293 | |
[email protected] | ee0f2aa8 | 2013-10-25 11:59:26 | [diff] [blame] | 294 | // The service for retrieving Channel ID keys. May be NULL. |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 295 | ChannelIDService* channel_id_service_; |
nharper | 736ceda | 2015-11-07 00:16:59 | [diff] [blame] | 296 | bool tb_was_negotiated_; |
| 297 | TokenBindingParam tb_negotiated_param_; |
nharper | 78e6d2b | 2016-09-21 05:42:35 | [diff] [blame] | 298 | TokenBindingSignatureMap tb_signature_map_; |
[email protected] | ee0f2aa8 | 2013-10-25 11:59:26 | [diff] [blame] | 299 | |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 300 | // OpenSSL stuff |
davidben | d80c12c | 2016-10-11 00:13:49 | [diff] [blame] | 301 | bssl::UniquePtr<SSL> ssl_; |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 302 | |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 303 | std::unique_ptr<ClientSocketHandle> transport_; |
davidben | 3418e81f | 2016-10-19 00:09:45 | [diff] [blame] | 304 | std::unique_ptr<SocketBIOAdapter> transport_adapter_; |
[email protected] | 055d7f2 | 2010-11-15 12:03:12 | [diff] [blame] | 305 | const HostPortPair host_and_port_; |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 306 | SSLConfig ssl_config_; |
[email protected] | c3456bb | 2011-12-12 22:22:19 | [diff] [blame] | 307 | // ssl_session_cache_shard_ is an opaque string that partitions the SSL |
| 308 | // session cache. i.e. sessions created with one value will not attempt to |
| 309 | // resume on the socket with a different value. |
| 310 | const std::string ssl_session_cache_shard_; |
nharper | 00d06ff | 2017-01-20 00:55:56 | [diff] [blame] | 311 | int ssl_session_cache_lookup_count_; |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 312 | |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 313 | enum State { |
| 314 | STATE_NONE, |
| 315 | STATE_HANDSHAKE, |
davidben | c4212c0 | 2015-05-12 22:30:18 | [diff] [blame] | 316 | STATE_HANDSHAKE_COMPLETE, |
[email protected] | faff985 | 2014-06-21 06:13:46 | [diff] [blame] | 317 | STATE_CHANNEL_ID_LOOKUP, |
| 318 | STATE_CHANNEL_ID_LOOKUP_COMPLETE, |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 319 | STATE_VERIFY_CERT, |
| 320 | STATE_VERIFY_CERT_COMPLETE, |
| 321 | }; |
| 322 | State next_handshake_state_; |
svaldez | 4af14d2 | 2015-08-20 13:48:24 | [diff] [blame] | 323 | |
| 324 | // True if the socket has been disconnected. |
| 325 | bool disconnected_; |
| 326 | |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 327 | NextProto negotiated_protocol_; |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 328 | // Written by the |channel_id_service_|. |
danakj | 655b66c | 2016-04-16 00:51:38 | [diff] [blame] | 329 | std::unique_ptr<crypto::ECPrivateKey> channel_id_key_; |
davidben | 52053b38 | 2015-04-27 19:22:29 | [diff] [blame] | 330 | // True if a channel ID was sent. |
| 331 | bool channel_id_sent_; |
davidben | c269cc4b | 2016-07-27 14:55:03 | [diff] [blame] | 332 | // If non-null, the newly-established to be inserted into the session cache |
| 333 | // once certificate verification is done. |
davidben | d80c12c | 2016-10-11 00:13:49 | [diff] [blame] | 334 | bssl::UniquePtr<SSL_SESSION> pending_session_; |
davidben | dafe4e5 | 2015-04-08 22:53:52 | [diff] [blame] | 335 | // True if the initial handshake's certificate has been verified. |
| 336 | bool certificate_verified_; |
davidben | fe132d9 | 2016-09-27 18:07:21 | [diff] [blame] | 337 | // Set to true if a CertificateRequest was received. |
| 338 | bool certificate_requested_; |
[email protected] | 6b8a3c74 | 2014-07-25 00:25:35 | [diff] [blame] | 339 | // The request handle for |channel_id_service_|. |
nharper | 75ade89 | 2015-06-10 19:05:35 | [diff] [blame] | 340 | ChannelIDService::Request channel_id_request_; |
[email protected] | 8bd4e7a | 2014-08-09 14:49:17 | [diff] [blame] | 341 | |
davidben | 1d48952 | 2015-07-01 18:48:46 | [diff] [blame] | 342 | int signature_result_; |
| 343 | std::vector<uint8_t> signature_; |
| 344 | |
[email protected] | 8bd4e7a | 2014-08-09 14:49:17 | [diff] [blame] | 345 | TransportSecurityState* transport_security_state_; |
| 346 | |
estark | 6f9b3d8 | 2016-01-12 21:37:05 | [diff] [blame] | 347 | CTPolicyEnforcer* const policy_enforcer_; |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 348 | |
[email protected] | 8bd4e7a | 2014-08-09 14:49:17 | [diff] [blame] | 349 | // pinning_failure_log contains a message produced by |
| 350 | // TransportSecurityState::CheckPublicKeyPins in the event of a |
| 351 | // pinning failure. It is a (somewhat) human-readable string. |
| 352 | std::string pinning_failure_log_; |
| 353 | |
dadrian | df302c4 | 2016-06-10 18:48:59 | [diff] [blame] | 354 | // True if PKP is bypassed due to a local trust anchor. |
| 355 | bool pkp_bypassed_; |
| 356 | |
David Benjamin | e34d7424 | 2017-06-29 20:35:16 | [diff] [blame^] | 357 | SSLErrorDetails connect_error_details_; |
| 358 | |
tfarina | 42834111 | 2016-09-22 13:38:20 | [diff] [blame] | 359 | NetLogWithSource net_log_; |
svaldez | e83af29 | 2016-04-26 14:33:37 | [diff] [blame] | 360 | base::WeakPtrFactory<SSLClientSocketImpl> weak_factory_; |
David Benjamin | e34d7424 | 2017-06-29 20:35:16 | [diff] [blame^] | 361 | |
| 362 | DISALLOW_COPY_AND_ASSIGN(SSLClientSocketImpl); |
[email protected] | d518cd9 | 2010-09-29 12:27:44 | [diff] [blame] | 363 | }; |
| 364 | |
| 365 | } // namespace net |
| 366 | |
svaldez | e83af29 | 2016-04-26 14:33:37 | [diff] [blame] | 367 | #endif // NET_SOCKET_SSL_CLIENT_SOCKET_IMPL_H_ |