OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef NET_QUIC_CRYPTO_CRYPTO_HANDSHAKE_H_ | 5 #ifndef NET_QUIC_CRYPTO_CRYPTO_HANDSHAKE_H_ |
6 #define NET_QUIC_CRYPTO_CRYPTO_HANDSHAKE_H_ | 6 #define NET_QUIC_CRYPTO_CRYPTO_HANDSHAKE_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.h" |
14 #include "net/base/net_export.h" | 14 #include "net/base/net_export.h" |
15 #include "net/quic/crypto/crypto_protocol.h" | 15 #include "net/quic/crypto/crypto_protocol.h" |
| 16 #include "net/quic/quic_protocol.h" |
16 #include "net/quic/quic_time.h" | 17 #include "net/quic/quic_time.h" |
17 | 18 |
18 namespace net { | 19 namespace net { |
19 | 20 |
20 class KeyExchange; | 21 class KeyExchange; |
| 22 class ProofVerifier; |
21 class QuicClock; | 23 class QuicClock; |
22 class QuicDecrypter; | 24 class QuicDecrypter; |
23 class QuicEncrypter; | 25 class QuicEncrypter; |
24 class QuicRandom; | 26 class QuicRandom; |
25 | 27 |
26 // An intermediate format of a handshake message that's convenient for a | 28 // An intermediate format of a handshake message that's convenient for a |
27 // CryptoFramer to serialize from or parse into. | 29 // CryptoFramer to serialize from or parse into. |
28 class NET_EXPORT_PRIVATE CryptoHandshakeMessage { | 30 class NET_EXPORT_PRIVATE CryptoHandshakeMessage { |
29 public: | 31 public: |
30 CryptoHandshakeMessage(); | 32 CryptoHandshakeMessage(); |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 std::string server_config_id; | 135 std::string server_config_id; |
134 std::string server_nonce; | 136 std::string server_nonce; |
135 }; | 137 }; |
136 | 138 |
137 // QuicCryptoConfig contains common configuration between clients and servers. | 139 // QuicCryptoConfig contains common configuration between clients and servers. |
138 class NET_EXPORT_PRIVATE QuicCryptoConfig { | 140 class NET_EXPORT_PRIVATE QuicCryptoConfig { |
139 public: | 141 public: |
140 enum { | 142 enum { |
141 // CONFIG_VERSION is the one (and, for the moment, only) version number that | 143 // CONFIG_VERSION is the one (and, for the moment, only) version number that |
142 // we implement. | 144 // we implement. |
143 CONFIG_VERSION = 0, | 145 CONFIG_VERSION = 0, |
144 }; | 146 }; |
145 | 147 |
146 // kLabel is constant that is used in key derivation to tie the resulting key | 148 // kLabel is constant that is used in key derivation to tie the resulting key |
147 // to this protocol. | 149 // to this protocol. |
148 static const char kLabel[]; | 150 static const char kLabel[]; |
149 | 151 |
150 QuicCryptoConfig(); | 152 QuicCryptoConfig(); |
151 ~QuicCryptoConfig(); | 153 ~QuicCryptoConfig(); |
152 | 154 |
153 // Protocol version | 155 // Protocol version |
(...skipping 28 matching lines...) Expand all Loading... |
182 // GetServerConfig returns the parsed contents of |server_config|, or NULL | 184 // GetServerConfig returns the parsed contents of |server_config|, or NULL |
183 // if |server_config| is empty. The return value is owned by this object | 185 // if |server_config| is empty. The return value is owned by this object |
184 // and is destroyed when this object is. | 186 // and is destroyed when this object is. |
185 const CryptoHandshakeMessage* GetServerConfig() const; | 187 const CryptoHandshakeMessage* GetServerConfig() const; |
186 | 188 |
187 // SetServerConfig checks that |scfg| parses correctly and stores it in | 189 // SetServerConfig checks that |scfg| parses correctly and stores it in |
188 // |server_config|. It returns true if the parsing succeeds and false | 190 // |server_config|. It returns true if the parsing succeeds and false |
189 // otherwise. | 191 // otherwise. |
190 bool SetServerConfig(base::StringPiece scfg); | 192 bool SetServerConfig(base::StringPiece scfg); |
191 | 193 |
| 194 // SetProof stores a certificate chain and signature. |
| 195 void SetProof(const std::vector<base::StringPiece>& certs, |
| 196 base::StringPiece signature); |
| 197 |
| 198 // SetProofValid records that the certificate chain and signature have been |
| 199 // validated and that it's safe to assume that the server is legitimate. |
| 200 // (Note: this does not check the chain or signature.) |
| 201 void SetProofValid(); |
| 202 |
192 const std::string& server_config() const; | 203 const std::string& server_config() const; |
193 const std::string& source_address_token() const; | 204 const std::string& source_address_token() const; |
| 205 const std::vector<std::string>& certs() const; |
| 206 const std::string& signature() const; |
| 207 bool proof_valid() const; |
194 | 208 |
195 void set_source_address_token(base::StringPiece token); | 209 void set_source_address_token(base::StringPiece token); |
196 | 210 |
197 private: | 211 private: |
198 std::string server_config_id_; // An opaque id from the server. | 212 std::string server_config_id_; // An opaque id from the server. |
199 std::string server_config_; // A serialized handshake message. | 213 std::string server_config_; // A serialized handshake message. |
200 std::string source_address_token_; // An opaque proof of IP ownership. | 214 std::string source_address_token_; // An opaque proof of IP ownership. |
| 215 std::vector<std::string> certs_; // A list of certificates in leaf-first |
| 216 // order. |
| 217 std::string server_config_sig_; // A signature of |server_config_|. |
| 218 bool server_config_valid_; // true if |server_config_| is correctly signed |
| 219 // and |certs_| has been validated. |
201 | 220 |
202 // scfg contains the cached, parsed value of |server_config|. | 221 // scfg contains the cached, parsed value of |server_config|. |
203 mutable scoped_ptr<CryptoHandshakeMessage> scfg_; | 222 mutable scoped_ptr<CryptoHandshakeMessage> scfg_; |
204 }; | 223 }; |
205 | 224 |
206 QuicCryptoClientConfig(); | 225 QuicCryptoClientConfig(); |
207 ~QuicCryptoClientConfig(); | 226 ~QuicCryptoClientConfig(); |
208 | 227 |
209 // Sets the members to reasonable, default values. | 228 // Sets the members to reasonable, default values. |
210 void SetDefaults(); | 229 void SetDefaults(); |
211 | 230 |
212 // Lookup returns a CachedState for the given hostname, or NULL if no | 231 // LookupOrCreate returns a CachedState for the given hostname. If no such |
213 // information is known. | 232 // CachedState currently exists, it will be created and cached. |
214 const CachedState* Lookup(const std::string& server_hostname) const; | 233 CachedState* LookupOrCreate(const std::string& server_hostname); |
215 | 234 |
216 // FillInchoateClientHello sets |out| to be a CHLO message that elicits a | 235 // FillInchoateClientHello sets |out| to be a CHLO message that elicits a |
217 // source-address token or SCFG from a server. If |cached| is non-NULL, the | 236 // source-address token or SCFG from a server. If |cached| is non-NULL, the |
218 // source-address token will be taken from it. | 237 // source-address token will be taken from it. |
219 void FillInchoateClientHello(const std::string& server_hostname, | 238 void FillInchoateClientHello(const std::string& server_hostname, |
220 const CachedState* cached, | 239 const CachedState* cached, |
221 CryptoHandshakeMessage* out) const; | 240 CryptoHandshakeMessage* out) const; |
222 | 241 |
223 // FillClientHello sets |out| to be a CHLO message based on the configuration | 242 // FillClientHello sets |out| to be a CHLO message based on the configuration |
224 // of this object. This object must have cached enough information about | 243 // of this object. This object must have cached enough information about |
(...skipping 10 matching lines...) Expand all Loading... |
235 QuicRandom* rand, | 254 QuicRandom* rand, |
236 QuicCryptoNegotiatedParameters* out_params, | 255 QuicCryptoNegotiatedParameters* out_params, |
237 CryptoHandshakeMessage* out, | 256 CryptoHandshakeMessage* out, |
238 std::string* error_details) const; | 257 std::string* error_details) const; |
239 | 258 |
240 // ProcessRejection processes a REJ message from a server and updates the | 259 // ProcessRejection processes a REJ message from a server and updates the |
241 // cached information about that server. After this, |is_complete| may return | 260 // cached information about that server. After this, |is_complete| may return |
242 // true for that server's CachedState. If the rejection message contains | 261 // true for that server's CachedState. If the rejection message contains |
243 // state about a future handshake (i.e. an nonce value from the server), then | 262 // state about a future handshake (i.e. an nonce value from the server), then |
244 // it will be saved in |out_params|. | 263 // it will be saved in |out_params|. |
245 QuicErrorCode ProcessRejection(const std::string& server_hostname, | 264 QuicErrorCode ProcessRejection(CachedState* cached, |
246 const CryptoHandshakeMessage& rej, | 265 const CryptoHandshakeMessage& rej, |
247 QuicCryptoNegotiatedParameters* out_params, | 266 QuicCryptoNegotiatedParameters* out_params, |
248 std::string* error_details); | 267 std::string* error_details); |
249 | 268 |
250 // ProcessServerHello processes the message in |server_hello|, writes the | 269 // ProcessServerHello processes the message in |server_hello|, writes the |
251 // negotiated parameters to |out_params| and returns QUIC_NO_ERROR. If | 270 // negotiated parameters to |out_params| and returns QUIC_NO_ERROR. If |
252 // |server_hello| is unacceptable then it puts an error message in | 271 // |server_hello| is unacceptable then it puts an error message in |
253 // |error_details| and returns an error code. | 272 // |error_details| and returns an error code. |
254 QuicErrorCode ProcessServerHello(const CryptoHandshakeMessage& server_hello, | 273 QuicErrorCode ProcessServerHello(const CryptoHandshakeMessage& server_hello, |
255 const std::string& nonce, | 274 const std::string& nonce, |
256 QuicCryptoNegotiatedParameters* out_params, | 275 QuicCryptoNegotiatedParameters* out_params, |
257 std::string* error_details); | 276 std::string* error_details); |
258 | 277 |
| 278 const ProofVerifier* proof_verifier() const; |
| 279 |
| 280 // SetProofVerifier takes ownership of a |ProofVerifier| that clients are |
| 281 // free to use in order to verify certificate chains from servers. Setting a |
| 282 // |ProofVerifier| does not alter the behaviour of the |
| 283 // QuicCryptoClientConfig, it's just a place to store it. |
| 284 void SetProofVerifier(ProofVerifier* verifier); |
| 285 |
259 private: | 286 private: |
260 // cached_states_ maps from the server hostname to the cached information | 287 // cached_states_ maps from the server hostname to the cached information |
261 // about that server. | 288 // about that server. |
262 std::map<std::string, CachedState*> cached_states_; | 289 std::map<std::string, CachedState*> cached_states_; |
| 290 |
| 291 scoped_ptr<ProofVerifier> proof_verifier_; |
| 292 |
| 293 DISALLOW_COPY_AND_ASSIGN(QuicCryptoClientConfig); |
263 }; | 294 }; |
264 | 295 |
265 } // namespace net | 296 } // namespace net |
266 | 297 |
267 #endif // NET_QUIC_CRYPTO_CRYPTO_HANDSHAKE_H_ | 298 #endif // NET_QUIC_CRYPTO_CRYPTO_HANDSHAKE_H_ |
OLD | NEW |