| 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 18 matching lines...) Expand all Loading... |
| 29 class KeyExchange; | 29 class KeyExchange; |
| 30 class ProofSource; | 30 class ProofSource; |
| 31 class QuicClock; | 31 class QuicClock; |
| 32 class QuicDecrypter; | 32 class QuicDecrypter; |
| 33 class QuicEncrypter; | 33 class QuicEncrypter; |
| 34 class QuicRandom; | 34 class QuicRandom; |
| 35 class QuicServerConfigProtobuf; | 35 class QuicServerConfigProtobuf; |
| 36 class StrikeRegister; | 36 class StrikeRegister; |
| 37 class StrikeRegisterClient; | 37 class StrikeRegisterClient; |
| 38 | 38 |
| 39 struct ClientHelloInfo; | 39 // ClientHelloInfo contains information about a client hello message that is |
| 40 // only kept for as long as it's being processed. |
| 41 struct ClientHelloInfo { |
| 42 ClientHelloInfo(const IPEndPoint& in_client_ip, QuicWallTime in_now); |
| 43 ~ClientHelloInfo(); |
| 44 |
| 45 // Inputs to EvaluateClientHello. |
| 46 const IPEndPoint client_ip; |
| 47 const QuicWallTime now; |
| 48 |
| 49 // Outputs from EvaluateClientHello. |
| 50 bool valid_source_address_token; |
| 51 bool client_nonce_well_formed; |
| 52 bool unique; |
| 53 base::StringPiece sni; |
| 54 base::StringPiece client_nonce; |
| 55 base::StringPiece server_nonce; |
| 56 base::StringPiece user_agent_id; |
| 57 |
| 58 // Errors from EvaluateClientHello. |
| 59 std::vector<uint32> reject_reasons; |
| 60 COMPILE_ASSERT(sizeof(QuicTag) == sizeof(uint32), header_out_of_sync); |
| 61 }; |
| 40 | 62 |
| 41 namespace test { | 63 namespace test { |
| 42 class QuicCryptoServerConfigPeer; | 64 class QuicCryptoServerConfigPeer; |
| 43 } // namespace test | 65 } // namespace test |
| 44 | 66 |
| 45 // Hook that allows application code to subscribe to primary config changes. | 67 // Hook that allows application code to subscribe to primary config changes. |
| 46 class PrimaryConfigChangedCallback { | 68 class PrimaryConfigChangedCallback { |
| 47 public: | 69 public: |
| 48 PrimaryConfigChangedCallback(); | 70 PrimaryConfigChangedCallback(); |
| 49 virtual ~PrimaryConfigChangedCallback(); | 71 virtual ~PrimaryConfigChangedCallback(); |
| 50 virtual void Run(const std::string& scid) = 0; | 72 virtual void Run(const std::string& scid) = 0; |
| 51 | 73 |
| 52 private: | 74 private: |
| 53 DISALLOW_COPY_AND_ASSIGN(PrimaryConfigChangedCallback); | 75 DISALLOW_COPY_AND_ASSIGN(PrimaryConfigChangedCallback); |
| 54 }; | 76 }; |
| 55 | 77 |
| 56 // Callback used to accept the result of the |client_hello| validation step. | 78 // Callback used to accept the result of the |client_hello| validation step. |
| 57 class NET_EXPORT_PRIVATE ValidateClientHelloResultCallback { | 79 class NET_EXPORT_PRIVATE ValidateClientHelloResultCallback { |
| 58 public: | 80 public: |
| 59 // Opaque token that holds information about the client_hello and | 81 // Opaque token that holds information about the client_hello and |
| 60 // its validity. Can be interpreted by calling ProcessClientHello. | 82 // its validity. Can be interpreted by calling ProcessClientHello. |
| 61 struct Result; | 83 struct Result { |
| 84 Result(const CryptoHandshakeMessage& in_client_hello, |
| 85 IPEndPoint in_client_ip, |
| 86 QuicWallTime in_now); |
| 87 ~Result(); |
| 88 |
| 89 CryptoHandshakeMessage client_hello; |
| 90 ClientHelloInfo info; |
| 91 QuicErrorCode error_code; |
| 92 std::string error_details; |
| 93 |
| 94 // Populated if the CHLO STK contained a CachedNetworkParameters proto. |
| 95 CachedNetworkParameters cached_network_params; |
| 96 }; |
| 62 | 97 |
| 63 ValidateClientHelloResultCallback(); | 98 ValidateClientHelloResultCallback(); |
| 64 virtual ~ValidateClientHelloResultCallback(); | 99 virtual ~ValidateClientHelloResultCallback(); |
| 65 void Run(const Result* result); | 100 void Run(const Result* result); |
| 66 | 101 |
| 67 protected: | 102 protected: |
| 68 virtual void RunImpl(const CryptoHandshakeMessage& client_hello, | 103 virtual void RunImpl(const CryptoHandshakeMessage& client_hello, |
| 69 const Result& result) = 0; | 104 const Result& result) = 0; |
| 70 | 105 |
| 71 private: | 106 private: |
| (...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 379 const uint8* primary_orbit, | 414 const uint8* primary_orbit, |
| 380 scoped_refptr<Config> requested_config, | 415 scoped_refptr<Config> requested_config, |
| 381 ValidateClientHelloResultCallback::Result* client_hello_state, | 416 ValidateClientHelloResultCallback::Result* client_hello_state, |
| 382 ValidateClientHelloResultCallback* done_cb) const; | 417 ValidateClientHelloResultCallback* done_cb) const; |
| 383 | 418 |
| 384 // BuildRejection sets |out| to be a REJ message in reply to |client_hello|. | 419 // BuildRejection sets |out| to be a REJ message in reply to |client_hello|. |
| 385 void BuildRejection( | 420 void BuildRejection( |
| 386 const Config& config, | 421 const Config& config, |
| 387 const CryptoHandshakeMessage& client_hello, | 422 const CryptoHandshakeMessage& client_hello, |
| 388 const ClientHelloInfo& info, | 423 const ClientHelloInfo& info, |
| 424 const CachedNetworkParameters& cached_network_params, |
| 389 QuicRandom* rand, | 425 QuicRandom* rand, |
| 390 QuicCryptoNegotiatedParameters *params, | 426 QuicCryptoNegotiatedParameters *params, |
| 391 CryptoHandshakeMessage* out) const; | 427 CryptoHandshakeMessage* out) const; |
| 392 | 428 |
| 393 // ParseConfigProtobuf parses the given config protobuf and returns a | 429 // ParseConfigProtobuf parses the given config protobuf and returns a |
| 394 // scoped_refptr<Config> if successful. The caller adopts the reference to the | 430 // scoped_refptr<Config> if successful. The caller adopts the reference to the |
| 395 // Config. On error, ParseConfigProtobuf returns nullptr. | 431 // Config. On error, ParseConfigProtobuf returns nullptr. |
| 396 scoped_refptr<Config> ParseConfigProtobuf(QuicServerConfigProtobuf* protobuf); | 432 scoped_refptr<Config> ParseConfigProtobuf(QuicServerConfigProtobuf* protobuf); |
| 397 | 433 |
| 398 // NewSourceAddressToken returns a fresh source address token for the given | 434 // NewSourceAddressToken returns a fresh source address token for the given |
| 399 // IP address. |cached_network_params| is optional, and can be nullptr. | 435 // IP address. |cached_network_params| is optional, and can be nullptr. |
| 400 std::string NewSourceAddressToken( | 436 std::string NewSourceAddressToken( |
| 401 const Config& config, | 437 const Config& config, |
| 402 const IPEndPoint& ip, | 438 const IPEndPoint& ip, |
| 403 QuicRandom* rand, | 439 QuicRandom* rand, |
| 404 QuicWallTime now, | 440 QuicWallTime now, |
| 405 const CachedNetworkParameters* cached_network_params) const; | 441 const CachedNetworkParameters* cached_network_params) const; |
| 406 | 442 |
| 407 // ValidateSourceAddressToken returns HANDSHAKE_OK if the source address token | 443 // ValidateSourceAddressToken returns HANDSHAKE_OK if the source address token |
| 408 // in |token| is a valid and timely token for the IP address |ip| given that | 444 // in |token| is a valid and timely token for the IP address |ip| given that |
| 409 // the current time is |now|. Otherwise it returns the reason for failure. | 445 // the current time is |now|. Otherwise it returns the reason for failure. |
| 410 HandshakeFailureReason ValidateSourceAddressToken(const Config& config, | 446 // |cached_network_params| is populated if |token| contains a |
| 411 base::StringPiece token, | 447 // CachedNetworkParameters proto. |
| 412 const IPEndPoint& ip, | 448 HandshakeFailureReason ValidateSourceAddressToken( |
| 413 QuicWallTime now) const; | 449 const Config& config, |
| 450 base::StringPiece token, |
| 451 const IPEndPoint& ip, |
| 452 QuicWallTime now, |
| 453 CachedNetworkParameters* cached_network_params) const; |
| 414 | 454 |
| 415 // NewServerNonce generates and encrypts a random nonce. | 455 // NewServerNonce generates and encrypts a random nonce. |
| 416 std::string NewServerNonce(QuicRandom* rand, QuicWallTime now) const; | 456 std::string NewServerNonce(QuicRandom* rand, QuicWallTime now) const; |
| 417 | 457 |
| 418 // ValidateServerNonce decrypts |token| and verifies that it hasn't been | 458 // ValidateServerNonce decrypts |token| and verifies that it hasn't been |
| 419 // previously used and is recent enough that it is plausible that it was part | 459 // previously used and is recent enough that it is plausible that it was part |
| 420 // of a very recently provided rejection ("recent" will be on the order of | 460 // of a very recently provided rejection ("recent" will be on the order of |
| 421 // 10-30 seconds). If so, it records that it has been used and returns | 461 // 10-30 seconds). If so, it records that it has been used and returns |
| 422 // HANDSHAKE_OK. Otherwise it returns the reason for failure. | 462 // HANDSHAKE_OK. Otherwise it returns the reason for failure. |
| 423 HandshakeFailureReason ValidateServerNonce( | 463 HandshakeFailureReason ValidateServerNonce( |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 uint32 source_address_token_lifetime_secs_; | 528 uint32 source_address_token_lifetime_secs_; |
| 489 uint32 server_nonce_strike_register_max_entries_; | 529 uint32 server_nonce_strike_register_max_entries_; |
| 490 uint32 server_nonce_strike_register_window_secs_; | 530 uint32 server_nonce_strike_register_window_secs_; |
| 491 | 531 |
| 492 DISALLOW_COPY_AND_ASSIGN(QuicCryptoServerConfig); | 532 DISALLOW_COPY_AND_ASSIGN(QuicCryptoServerConfig); |
| 493 }; | 533 }; |
| 494 | 534 |
| 495 } // namespace net | 535 } // namespace net |
| 496 | 536 |
| 497 #endif // NET_QUIC_CRYPTO_QUIC_CRYPTO_SERVER_CONFIG_H_ | 537 #endif // NET_QUIC_CRYPTO_QUIC_CRYPTO_SERVER_CONFIG_H_ |
| OLD | NEW |