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