| 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_SERVER_CONFIG_H_ | 5 #ifndef NET_QUIC_CRYPTO_QUIC_CRYPTO_SERVER_CONFIG_H_ |
| 6 #define NET_QUIC_CRYPTO_QUIC_CRYPTO_SERVER_CONFIG_H_ | 6 #define NET_QUIC_CRYPTO_QUIC_CRYPTO_SERVER_CONFIG_H_ |
| 7 | 7 |
| 8 #include <map> | 8 #include <map> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 316 // primary_time contains the timestamp when this config should become the | 316 // primary_time contains the timestamp when this config should become the |
| 317 // primary config. A value of QuicWallTime::Zero() means that this config | 317 // primary config. A value of QuicWallTime::Zero() means that this config |
| 318 // will not be promoted at a specific time. | 318 // will not be promoted at a specific time. |
| 319 QuicWallTime primary_time; | 319 QuicWallTime primary_time; |
| 320 | 320 |
| 321 // Secondary sort key for use when selecting primary configs and | 321 // Secondary sort key for use when selecting primary configs and |
| 322 // there are multiple configs with the same primary time. | 322 // there are multiple configs with the same primary time. |
| 323 // Smaller numbers mean higher priority. | 323 // Smaller numbers mean higher priority. |
| 324 uint64 priority; | 324 uint64 priority; |
| 325 | 325 |
| 326 // source_address_token_boxer_ is used to protect the |
| 327 // source-address tokens that are given to clients. |
| 328 // Points to either source_address_token_boxer_storage or the |
| 329 // default boxer provided by QuicCryptoServerConfig. |
| 330 const CryptoSecretBoxer* source_address_token_boxer; |
| 331 |
| 332 // Holds the override source_address_token_boxer instance if the |
| 333 // Config is not using the default source address token boxer |
| 334 // instance provided by QuicCryptoServerConfig. |
| 335 scoped_ptr<CryptoSecretBoxer> source_address_token_boxer_storage; |
| 336 |
| 326 private: | 337 private: |
| 327 friend class base::RefCounted<Config>; | 338 friend class base::RefCounted<Config>; |
| 339 |
| 328 virtual ~Config(); | 340 virtual ~Config(); |
| 329 | 341 |
| 330 DISALLOW_COPY_AND_ASSIGN(Config); | 342 DISALLOW_COPY_AND_ASSIGN(Config); |
| 331 }; | 343 }; |
| 332 | 344 |
| 333 typedef std::map<ServerConfigID, scoped_refptr<Config> > ConfigMap; | 345 typedef std::map<ServerConfigID, scoped_refptr<Config> > ConfigMap; |
| 334 | 346 |
| 347 // Get a ref to the config with a given server config id. |
| 348 scoped_refptr<Config> GetConfigWithScid( |
| 349 base::StringPiece requested_scid) const; |
| 350 |
| 335 // ConfigPrimaryTimeLessThan returns true if a->primary_time < | 351 // ConfigPrimaryTimeLessThan returns true if a->primary_time < |
| 336 // b->primary_time. | 352 // b->primary_time. |
| 337 static bool ConfigPrimaryTimeLessThan(const scoped_refptr<Config>& a, | 353 static bool ConfigPrimaryTimeLessThan(const scoped_refptr<Config>& a, |
| 338 const scoped_refptr<Config>& b); | 354 const scoped_refptr<Config>& b); |
| 339 | 355 |
| 340 // SelectNewPrimaryConfig reevaluates the primary config based on the | 356 // SelectNewPrimaryConfig reevaluates the primary config based on the |
| 341 // "primary_time" deadlines contained in each. | 357 // "primary_time" deadlines contained in each. |
| 342 void SelectNewPrimaryConfig(QuicWallTime now) const; | 358 void SelectNewPrimaryConfig(QuicWallTime now) const; |
| 343 | 359 |
| 344 // EvaluateClientHello checks |client_hello| for gross errors and determines | 360 // EvaluateClientHello checks |client_hello| for gross errors and determines |
| 345 // whether it can be shown to be fresh (i.e. not a replay). The results are | 361 // whether it can be shown to be fresh (i.e. not a replay). The results are |
| 346 // written to |info|. | 362 // written to |info|. |
| 347 void EvaluateClientHello( | 363 void EvaluateClientHello( |
| 348 const uint8* primary_orbit, | 364 const uint8* primary_orbit, |
| 365 scoped_refptr<Config> requested_config, |
| 349 ValidateClientHelloResultCallback::Result* client_hello_state, | 366 ValidateClientHelloResultCallback::Result* client_hello_state, |
| 350 ValidateClientHelloResultCallback* done_cb) const; | 367 ValidateClientHelloResultCallback* done_cb) const; |
| 351 | 368 |
| 352 // BuildRejection sets |out| to be a REJ message in reply to |client_hello|. | 369 // BuildRejection sets |out| to be a REJ message in reply to |client_hello|. |
| 353 void BuildRejection( | 370 void BuildRejection( |
| 354 const scoped_refptr<Config>& config, | 371 const Config& config, |
| 355 const CryptoHandshakeMessage& client_hello, | 372 const CryptoHandshakeMessage& client_hello, |
| 356 const ClientHelloInfo& info, | 373 const ClientHelloInfo& info, |
| 357 QuicRandom* rand, | 374 QuicRandom* rand, |
| 358 CryptoHandshakeMessage* out) const; | 375 CryptoHandshakeMessage* out) const; |
| 359 | 376 |
| 360 // ParseConfigProtobuf parses the given config protobuf and returns a | 377 // ParseConfigProtobuf parses the given config protobuf and returns a |
| 361 // scoped_refptr<Config> if successful. The caller adopts the reference to the | 378 // scoped_refptr<Config> if successful. The caller adopts the reference to the |
| 362 // Config. On error, ParseConfigProtobuf returns NULL. | 379 // Config. On error, ParseConfigProtobuf returns NULL. |
| 363 scoped_refptr<Config> ParseConfigProtobuf(QuicServerConfigProtobuf* protobuf); | 380 scoped_refptr<Config> ParseConfigProtobuf(QuicServerConfigProtobuf* protobuf); |
| 364 | 381 |
| 365 // NewSourceAddressToken returns a fresh source address token for the given | 382 // NewSourceAddressToken returns a fresh source address token for the given |
| 366 // IP address. | 383 // IP address. |
| 367 std::string NewSourceAddressToken(const IPEndPoint& ip, | 384 std::string NewSourceAddressToken( |
| 368 QuicRandom* rand, | 385 const Config& config, |
| 369 QuicWallTime now) const; | 386 const IPEndPoint& ip, |
| 387 QuicRandom* rand, |
| 388 QuicWallTime now) const; |
| 370 | 389 |
| 371 // ValidateSourceAddressToken returns true if the source address token in | 390 // ValidateSourceAddressToken returns true if the source address token in |
| 372 // |token| is a valid and timely token for the IP address |ip| given that the | 391 // |token| is a valid and timely token for the IP address |ip| given that the |
| 373 // current time is |now|. | 392 // current time is |now|. |
| 374 bool ValidateSourceAddressToken(base::StringPiece token, | 393 bool ValidateSourceAddressToken( |
| 375 const IPEndPoint& ip, | 394 const Config& config, |
| 376 QuicWallTime now) const; | 395 base::StringPiece token, |
| 396 const IPEndPoint& ip, |
| 397 QuicWallTime now) const; |
| 377 | 398 |
| 378 // NewServerNonce generates and encrypts a random nonce. | 399 // NewServerNonce generates and encrypts a random nonce. |
| 379 std::string NewServerNonce(QuicRandom* rand, QuicWallTime now) const; | 400 std::string NewServerNonce(QuicRandom* rand, QuicWallTime now) const; |
| 380 | 401 |
| 381 // ValidateServerNonce decrypts |token| and verifies that it hasn't been | 402 // ValidateServerNonce decrypts |token| and verifies that it hasn't been |
| 382 // previously used and is recent enough that it is plausible that it was part | 403 // previously used and is recent enough that it is plausible that it was part |
| 383 // of a very recently provided rejection ("recent" will be on the order of | 404 // of a very recently provided rejection ("recent" will be on the order of |
| 384 // 10-30 seconds). If so, it records that it has been used and returns true. | 405 // 10-30 seconds). If so, it records that it has been used and returns true. |
| 385 // Otherwise it returns false. | 406 // Otherwise it returns false. |
| 386 bool ValidateServerNonce(base::StringPiece echoed_server_nonce, | 407 bool ValidateServerNonce(base::StringPiece echoed_server_nonce, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 406 mutable QuicWallTime next_config_promotion_time_; | 427 mutable QuicWallTime next_config_promotion_time_; |
| 407 // Callback to invoke when the primary config changes. | 428 // Callback to invoke when the primary config changes. |
| 408 scoped_ptr<PrimaryConfigChangedCallback> primary_config_changed_cb_; | 429 scoped_ptr<PrimaryConfigChangedCallback> primary_config_changed_cb_; |
| 409 | 430 |
| 410 // Protects access to the pointer held by strike_register_client_. | 431 // Protects access to the pointer held by strike_register_client_. |
| 411 mutable base::Lock strike_register_client_lock_; | 432 mutable base::Lock strike_register_client_lock_; |
| 412 // strike_register_ contains a data structure that keeps track of previously | 433 // strike_register_ contains a data structure that keeps track of previously |
| 413 // observed client nonces in order to prevent replay attacks. | 434 // observed client nonces in order to prevent replay attacks. |
| 414 mutable scoped_ptr<StrikeRegisterClient> strike_register_client_; | 435 mutable scoped_ptr<StrikeRegisterClient> strike_register_client_; |
| 415 | 436 |
| 416 // source_address_token_boxer_ is used to protect the source-address tokens | 437 // Default source_address_token_boxer_ used to protect the |
| 417 // that are given to clients. | 438 // source-address tokens that are given to clients. Individual |
| 418 CryptoSecretBoxer source_address_token_boxer_; | 439 // configs may use boxers with alternate secrets. |
| 440 CryptoSecretBoxer default_source_address_token_boxer_; |
| 419 | 441 |
| 420 // server_nonce_boxer_ is used to encrypt and validate suggested server | 442 // server_nonce_boxer_ is used to encrypt and validate suggested server |
| 421 // nonces. | 443 // nonces. |
| 422 CryptoSecretBoxer server_nonce_boxer_; | 444 CryptoSecretBoxer server_nonce_boxer_; |
| 423 | 445 |
| 424 // server_nonce_orbit_ contains the random, per-server orbit values that this | 446 // server_nonce_orbit_ contains the random, per-server orbit values that this |
| 425 // server will use to generate server nonces (the moral equivalent of a SYN | 447 // server will use to generate server nonces (the moral equivalent of a SYN |
| 426 // cookies). | 448 // cookies). |
| 427 uint8 server_nonce_orbit_[8]; | 449 uint8 server_nonce_orbit_[8]; |
| 428 | 450 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 449 uint32 source_address_token_lifetime_secs_; | 471 uint32 source_address_token_lifetime_secs_; |
| 450 uint32 server_nonce_strike_register_max_entries_; | 472 uint32 server_nonce_strike_register_max_entries_; |
| 451 uint32 server_nonce_strike_register_window_secs_; | 473 uint32 server_nonce_strike_register_window_secs_; |
| 452 | 474 |
| 453 DISALLOW_COPY_AND_ASSIGN(QuicCryptoServerConfig); | 475 DISALLOW_COPY_AND_ASSIGN(QuicCryptoServerConfig); |
| 454 }; | 476 }; |
| 455 | 477 |
| 456 } // namespace net | 478 } // namespace net |
| 457 | 479 |
| 458 #endif // NET_QUIC_CRYPTO_QUIC_CRYPTO_SERVER_CONFIG_H_ | 480 #endif // NET_QUIC_CRYPTO_QUIC_CRYPTO_SERVER_CONFIG_H_ |
| OLD | NEW |