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