| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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_QUIC_CRYPTO_CLIENT_CONFIG_H_ | 5 #ifndef NET_QUIC_CRYPTO_QUIC_CRYPTO_CLIENT_CONFIG_H_ |
| 6 #define NET_QUIC_CRYPTO_QUIC_CRYPTO_CLIENT_CONFIG_H_ | 6 #define NET_QUIC_CRYPTO_QUIC_CRYPTO_CLIENT_CONFIG_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <queue> | 9 #include <queue> |
| 10 #include <string> | 10 #include <string> |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 // has expired. | 75 // has expired. |
| 76 ServerConfigState SetServerConfig(base::StringPiece server_config, | 76 ServerConfigState SetServerConfig(base::StringPiece server_config, |
| 77 QuicWallTime now, | 77 QuicWallTime now, |
| 78 std::string* error_details); | 78 std::string* error_details); |
| 79 | 79 |
| 80 // InvalidateServerConfig clears the cached server config (if any). | 80 // InvalidateServerConfig clears the cached server config (if any). |
| 81 void InvalidateServerConfig(); | 81 void InvalidateServerConfig(); |
| 82 | 82 |
| 83 // SetProof stores a certificate chain and signature. | 83 // SetProof stores a certificate chain and signature. |
| 84 void SetProof(const std::vector<std::string>& certs, | 84 void SetProof(const std::vector<std::string>& certs, |
| 85 base::StringPiece cert_sct, |
| 85 base::StringPiece signature); | 86 base::StringPiece signature); |
| 86 | 87 |
| 87 // Clears all the data. | 88 // Clears all the data. |
| 88 void Clear(); | 89 void Clear(); |
| 89 | 90 |
| 90 // Clears the certificate chain and signature and invalidates the proof. | 91 // Clears the certificate chain and signature and invalidates the proof. |
| 91 void ClearProof(); | 92 void ClearProof(); |
| 92 | 93 |
| 93 // SetProofValid records that the certificate chain and signature have been | 94 // SetProofValid records that the certificate chain and signature have been |
| 94 // validated and that it's safe to assume that the server is legitimate. | 95 // validated and that it's safe to assume that the server is legitimate. |
| 95 // (Note: this does not check the chain or signature.) | 96 // (Note: this does not check the chain or signature.) |
| 96 void SetProofValid(); | 97 void SetProofValid(); |
| 97 | 98 |
| 98 // If the server config or the proof has changed then it needs to be | 99 // If the server config or the proof has changed then it needs to be |
| 99 // revalidated. Helper function to keep server_config_valid_ and | 100 // revalidated. Helper function to keep server_config_valid_ and |
| 100 // generation_counter_ in sync. | 101 // generation_counter_ in sync. |
| 101 void SetProofInvalid(); | 102 void SetProofInvalid(); |
| 102 | 103 |
| 103 const std::string& server_config() const; | 104 const std::string& server_config() const; |
| 104 const std::string& source_address_token() const; | 105 const std::string& source_address_token() const; |
| 105 const std::vector<std::string>& certs() const; | 106 const std::vector<std::string>& certs() const; |
| 107 const std::string& cert_sct() const; |
| 106 const std::string& signature() const; | 108 const std::string& signature() const; |
| 107 bool proof_valid() const; | 109 bool proof_valid() const; |
| 108 uint64 generation_counter() const; | 110 uint64 generation_counter() const; |
| 109 const ProofVerifyDetails* proof_verify_details() const; | 111 const ProofVerifyDetails* proof_verify_details() const; |
| 110 | 112 |
| 111 void set_source_address_token(base::StringPiece token); | 113 void set_source_address_token(base::StringPiece token); |
| 112 | 114 |
| 115 void set_cert_sct(base::StringPiece cert_sct); |
| 116 |
| 113 // Adds the connection ID to the queue of server-designated connection-ids. | 117 // Adds the connection ID to the queue of server-designated connection-ids. |
| 114 void add_server_designated_connection_id(QuicConnectionId connection_id); | 118 void add_server_designated_connection_id(QuicConnectionId connection_id); |
| 115 | 119 |
| 116 // If true, the crypto config contains at least one connection ID specified | 120 // If true, the crypto config contains at least one connection ID specified |
| 117 // by the server, and the client should use one of these IDs when initiating | 121 // by the server, and the client should use one of these IDs when initiating |
| 118 // the next connection. | 122 // the next connection. |
| 119 bool has_server_designated_connection_id() const; | 123 bool has_server_designated_connection_id() const; |
| 120 | 124 |
| 121 // This function should only be called when | 125 // This function should only be called when |
| 122 // has_server_designated_connection_id is true. Returns the next | 126 // has_server_designated_connection_id is true. Returns the next |
| (...skipping 20 matching lines...) Expand all Loading... |
| 143 // |server_config_sig_| from the |other|. The remaining fields, | 147 // |server_config_sig_| from the |other|. The remaining fields, |
| 144 // |generation_counter_|, |proof_verify_details_|, and |scfg_| remain | 148 // |generation_counter_|, |proof_verify_details_|, and |scfg_| remain |
| 145 // unchanged. | 149 // unchanged. |
| 146 void InitializeFrom(const CachedState& other); | 150 void InitializeFrom(const CachedState& other); |
| 147 | 151 |
| 148 // Initializes this cached state based on the arguments provided. | 152 // Initializes this cached state based on the arguments provided. |
| 149 // Returns false if there is a problem parsing the server config. | 153 // Returns false if there is a problem parsing the server config. |
| 150 bool Initialize(base::StringPiece server_config, | 154 bool Initialize(base::StringPiece server_config, |
| 151 base::StringPiece source_address_token, | 155 base::StringPiece source_address_token, |
| 152 const std::vector<std::string>& certs, | 156 const std::vector<std::string>& certs, |
| 157 const std::string& cert_sct, |
| 153 base::StringPiece signature, | 158 base::StringPiece signature, |
| 154 QuicWallTime now); | 159 QuicWallTime now); |
| 155 | 160 |
| 156 private: | 161 private: |
| 157 std::string server_config_; // A serialized handshake message. | 162 std::string server_config_; // A serialized handshake message. |
| 158 std::string source_address_token_; // An opaque proof of IP ownership. | 163 std::string source_address_token_; // An opaque proof of IP ownership. |
| 159 std::vector<std::string> certs_; // A list of certificates in leaf-first | 164 std::vector<std::string> certs_; // A list of certificates in leaf-first |
| 160 // order. | 165 // order. |
| 166 std::string cert_sct_; // Signed timestamp of the leaf cert. |
| 161 std::string server_config_sig_; // A signature of |server_config_|. | 167 std::string server_config_sig_; // A signature of |server_config_|. |
| 162 bool server_config_valid_; // True if |server_config_| is correctly | 168 bool server_config_valid_; // True if |server_config_| is correctly |
| 163 // signed and |certs_| has been | 169 // signed and |certs_| has been |
| 164 // validated. | 170 // validated. |
| 165 // Generation counter associated with the |server_config_|, |certs_| and | 171 // Generation counter associated with the |server_config_|, |certs_| and |
| 166 // |server_config_sig_| combination. It is incremented whenever we set | 172 // |server_config_sig_| combination. It is incremented whenever we set |
| 167 // server_config_valid_ to false. | 173 // server_config_valid_ to false. |
| 168 uint64 generation_counter_; | 174 uint64 generation_counter_; |
| 169 | 175 |
| 170 scoped_ptr<ProofVerifyDetails> proof_verify_details_; | 176 scoped_ptr<ProofVerifyDetails> proof_verify_details_; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 | 237 |
| 232 // ProcessRejection processes a REJ message from a server and updates the | 238 // ProcessRejection processes a REJ message from a server and updates the |
| 233 // cached information about that server. After this, |IsComplete| may return | 239 // cached information about that server. After this, |IsComplete| may return |
| 234 // true for that server's CachedState. If the rejection message contains state | 240 // true for that server's CachedState. If the rejection message contains state |
| 235 // about a future handshake (i.e. an nonce value from the server), then it | 241 // about a future handshake (i.e. an nonce value from the server), then it |
| 236 // will be saved in |out_params|. |now| is used to judge whether the server | 242 // will be saved in |out_params|. |now| is used to judge whether the server |
| 237 // config in the rejection message has expired. |is_https| is used to track | 243 // config in the rejection message has expired. |is_https| is used to track |
| 238 // reject reason for secure vs insecure QUIC. | 244 // reject reason for secure vs insecure QUIC. |
| 239 QuicErrorCode ProcessRejection(const CryptoHandshakeMessage& rej, | 245 QuicErrorCode ProcessRejection(const CryptoHandshakeMessage& rej, |
| 240 QuicWallTime now, | 246 QuicWallTime now, |
| 247 QuicVersion version, |
| 241 CachedState* cached, | 248 CachedState* cached, |
| 242 QuicCryptoNegotiatedParameters* out_params, | 249 QuicCryptoNegotiatedParameters* out_params, |
| 243 std::string* error_details); | 250 std::string* error_details); |
| 244 | 251 |
| 245 // ProcessServerHello processes the message in |server_hello|, updates the | 252 // ProcessServerHello processes the message in |server_hello|, updates the |
| 246 // cached information about that server, writes the negotiated parameters to | 253 // cached information about that server, writes the negotiated parameters to |
| 247 // |out_params| and returns QUIC_NO_ERROR. If |server_hello| is unacceptable | 254 // |out_params| and returns QUIC_NO_ERROR. If |server_hello| is unacceptable |
| 248 // then it puts an error message in |error_details| and returns an error | 255 // then it puts an error message in |error_details| and returns an error |
| 249 // code. |version| is the QUIC version for the current connection. | 256 // code. |version| is the QUIC version for the current connection. |
| 250 // |negotiated_versions| contains the list of version, if any, that were | 257 // |negotiated_versions| contains the list of version, if any, that were |
| 251 // present in a version negotiation packet previously recevied from the | 258 // present in a version negotiation packet previously recevied from the |
| 252 // server. The contents of this list will be compared against the list of | 259 // server. The contents of this list will be compared against the list of |
| 253 // versions provided in the VER tag of the server hello. | 260 // versions provided in the VER tag of the server hello. |
| 254 QuicErrorCode ProcessServerHello(const CryptoHandshakeMessage& server_hello, | 261 QuicErrorCode ProcessServerHello(const CryptoHandshakeMessage& server_hello, |
| 255 QuicConnectionId connection_id, | 262 QuicConnectionId connection_id, |
| 256 QuicVersion version, | 263 QuicVersion version, |
| 257 const QuicVersionVector& negotiated_versions, | 264 const QuicVersionVector& negotiated_versions, |
| 258 CachedState* cached, | 265 CachedState* cached, |
| 259 QuicCryptoNegotiatedParameters* out_params, | 266 QuicCryptoNegotiatedParameters* out_params, |
| 260 std::string* error_details); | 267 std::string* error_details); |
| 261 | 268 |
| 262 // Processes the message in |server_update|, updating the cached source | 269 // Processes the message in |server_update|, updating the cached source |
| 263 // address token, and server config. | 270 // address token, and server config. |
| 264 // If |server_update| is invalid then |error_details| will contain an error | 271 // If |server_update| is invalid then |error_details| will contain an error |
| 265 // message, and an error code will be returned. If all has gone well | 272 // message, and an error code will be returned. If all has gone well |
| 266 // QUIC_NO_ERROR is returned. | 273 // QUIC_NO_ERROR is returned. |
| 267 QuicErrorCode ProcessServerConfigUpdate( | 274 QuicErrorCode ProcessServerConfigUpdate( |
| 268 const CryptoHandshakeMessage& server_update, | 275 const CryptoHandshakeMessage& server_update, |
| 269 QuicWallTime now, | 276 QuicWallTime now, |
| 277 const QuicVersion version, |
| 270 CachedState* cached, | 278 CachedState* cached, |
| 271 QuicCryptoNegotiatedParameters* out_params, | 279 QuicCryptoNegotiatedParameters* out_params, |
| 272 std::string* error_details); | 280 std::string* error_details); |
| 273 | 281 |
| 274 ProofVerifier* proof_verifier() const; | 282 ProofVerifier* proof_verifier() const; |
| 275 | 283 |
| 276 ChannelIDSource* channel_id_source() const; | 284 ChannelIDSource* channel_id_source() const; |
| 277 | 285 |
| 278 // SetChannelIDSource sets a ChannelIDSource that will be called, when the | 286 // SetChannelIDSource sets a ChannelIDSource that will be called, when the |
| 279 // server supports channel IDs, to obtain a channel ID for signing a message | 287 // server supports channel IDs, to obtain a channel ID for signing a message |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 315 // Sets the members to reasonable, default values. | 323 // Sets the members to reasonable, default values. |
| 316 void SetDefaults(); | 324 void SetDefaults(); |
| 317 | 325 |
| 318 // CacheNewServerConfig checks for SCFG, STK, PROF, and CRT tags in |message|, | 326 // CacheNewServerConfig checks for SCFG, STK, PROF, and CRT tags in |message|, |
| 319 // verifies them, and stores them in the cached state if they validate. | 327 // verifies them, and stores them in the cached state if they validate. |
| 320 // This is used on receipt of a REJ from a server, or when a server sends | 328 // This is used on receipt of a REJ from a server, or when a server sends |
| 321 // updated server config during a connection. | 329 // updated server config during a connection. |
| 322 QuicErrorCode CacheNewServerConfig( | 330 QuicErrorCode CacheNewServerConfig( |
| 323 const CryptoHandshakeMessage& message, | 331 const CryptoHandshakeMessage& message, |
| 324 QuicWallTime now, | 332 QuicWallTime now, |
| 333 const QuicVersion version, |
| 325 const std::vector<std::string>& cached_certs, | 334 const std::vector<std::string>& cached_certs, |
| 326 CachedState* cached, | 335 CachedState* cached, |
| 327 std::string* error_details); | 336 std::string* error_details); |
| 328 | 337 |
| 329 // If the suffix of the hostname in |server_id| is in |canonical_suffixes_|, | 338 // If the suffix of the hostname in |server_id| is in |canonical_suffixes_|, |
| 330 // then populate |cached| with the canonical cached state from | 339 // then populate |cached| with the canonical cached state from |
| 331 // |canonical_server_map_| for that suffix. Returns true if |cached| is | 340 // |canonical_server_map_| for that suffix. Returns true if |cached| is |
| 332 // initialized with canonical cached state. | 341 // initialized with canonical cached state. |
| 333 bool PopulateFromCanonicalConfig(const QuicServerId& server_id, | 342 bool PopulateFromCanonicalConfig(const QuicServerId& server_id, |
| 334 CachedState* cached); | 343 CachedState* cached); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 355 | 364 |
| 356 // The |user_agent_id_| passed in QUIC's CHLO message. | 365 // The |user_agent_id_| passed in QUIC's CHLO message. |
| 357 std::string user_agent_id_; | 366 std::string user_agent_id_; |
| 358 | 367 |
| 359 DISALLOW_COPY_AND_ASSIGN(QuicCryptoClientConfig); | 368 DISALLOW_COPY_AND_ASSIGN(QuicCryptoClientConfig); |
| 360 }; | 369 }; |
| 361 | 370 |
| 362 } // namespace net | 371 } // namespace net |
| 363 | 372 |
| 364 #endif // NET_QUIC_CRYPTO_QUIC_CRYPTO_CLIENT_CONFIG_H_ | 373 #endif // NET_QUIC_CRYPTO_QUIC_CRYPTO_CLIENT_CONFIG_H_ |
| OLD | NEW |