QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 1 | // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef QUICHE_QUIC_TEST_TOOLS_QUIC_CRYPTO_SERVER_CONFIG_PEER_H_ |
| 6 | #define QUICHE_QUIC_TEST_TOOLS_QUIC_CRYPTO_SERVER_CONFIG_PEER_H_ |
| 7 | |
vasilvv | 5f225b0 | 2020-10-08 11:49:09 -0400 | [diff] [blame] | 8 | #include "absl/strings/string_view.h" |
QUICHE team | 5be974e | 2020-12-29 18:35:24 -0500 | [diff] [blame] | 9 | #include "quic/core/crypto/quic_crypto_server_config.h" |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 10 | |
| 11 | namespace quic { |
| 12 | namespace test { |
| 13 | |
| 14 | // Peer for accessing otherwise private members of a QuicCryptoServerConfig. |
| 15 | class QuicCryptoServerConfigPeer { |
| 16 | public: |
| 17 | explicit QuicCryptoServerConfigPeer(QuicCryptoServerConfig* server_config) |
| 18 | : server_config_(server_config) {} |
| 19 | |
| 20 | // Returns the primary config. |
| 21 | QuicReferenceCountedPointer<QuicCryptoServerConfig::Config> |
| 22 | GetPrimaryConfig(); |
| 23 | |
| 24 | // Returns the config associated with |config_id|. |
| 25 | QuicReferenceCountedPointer<QuicCryptoServerConfig::Config> GetConfig( |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 26 | std::string config_id); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 27 | |
| 28 | // Returns a pointer to the ProofSource object. |
| 29 | ProofSource* GetProofSource() const; |
| 30 | |
| 31 | // Reset the proof_source_ member. |
| 32 | void ResetProofSource(std::unique_ptr<ProofSource> proof_source); |
| 33 | |
| 34 | // Generates a new valid source address token. |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 35 | std::string NewSourceAddressToken( |
| 36 | std::string config_id, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 37 | SourceAddressTokens previous_tokens, |
| 38 | const QuicIpAddress& ip, |
| 39 | QuicRandom* rand, |
| 40 | QuicWallTime now, |
| 41 | CachedNetworkParameters* cached_network_params); |
| 42 | |
| 43 | // Attempts to validate the tokens in |tokens|. |
| 44 | HandshakeFailureReason ValidateSourceAddressTokens( |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 45 | std::string config_id, |
vasilvv | 5f225b0 | 2020-10-08 11:49:09 -0400 | [diff] [blame] | 46 | absl::string_view tokens, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 47 | const QuicIpAddress& ip, |
| 48 | QuicWallTime now, |
| 49 | CachedNetworkParameters* cached_network_params); |
| 50 | |
| 51 | // Attempts to validate the single source address token in |token|. |
| 52 | HandshakeFailureReason ValidateSingleSourceAddressToken( |
vasilvv | 5f225b0 | 2020-10-08 11:49:09 -0400 | [diff] [blame] | 53 | absl::string_view token, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 54 | const QuicIpAddress& ip, |
| 55 | QuicWallTime now); |
| 56 | |
| 57 | // CheckConfigs compares the state of the Configs in |server_config_| to the |
| 58 | // description given as arguments. |
| 59 | // The first of each pair is the server config ID of a Config. The second is a |
| 60 | // boolean describing whether the config is the primary. For example: |
| 61 | // CheckConfigs(std::vector<std::pair<ServerConfigID, bool>>()); // checks |
| 62 | // that no Configs are loaded. |
| 63 | // |
| 64 | // // Checks that exactly three Configs are loaded with the given IDs and |
| 65 | // // status. |
| 66 | // CheckConfigs( |
| 67 | // {{"id1", false}, |
| 68 | // {"id2", true}, |
| 69 | // {"id3", false}}); |
| 70 | void CheckConfigs( |
| 71 | std::vector<std::pair<ServerConfigID, bool>> expected_ids_and_status); |
| 72 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 73 | // ConfigsDebug returns a std::string that contains debugging information |
| 74 | // about the set of Configs loaded in |server_config_| and their status. |
| 75 | std::string ConfigsDebug() |
rch | 52cb79f | 2019-08-30 13:35:57 -0700 | [diff] [blame] | 76 | QUIC_SHARED_LOCKS_REQUIRED(server_config_->configs_lock_); |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 77 | |
| 78 | void SelectNewPrimaryConfig(int seconds); |
| 79 | |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 80 | static std::string CompressChain( |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 81 | QuicCompressedCertsCache* compressed_certs_cache, |
| 82 | const QuicReferenceCountedPointer<ProofSource::Chain>& chain, |
vasilvv | c48c871 | 2019-03-11 13:38:16 -0700 | [diff] [blame] | 83 | const std::string& client_common_set_hashes, |
| 84 | const std::string& client_cached_cert_hashes, |
QUICHE team | a6ef0a6 | 2019-03-07 20:34:33 -0500 | [diff] [blame] | 85 | const CommonCertSets* common_sets); |
| 86 | |
| 87 | uint32_t source_address_token_future_secs(); |
| 88 | |
| 89 | uint32_t source_address_token_lifetime_secs(); |
| 90 | |
| 91 | private: |
| 92 | QuicCryptoServerConfig* server_config_; |
| 93 | }; |
| 94 | |
| 95 | } // namespace test |
| 96 | } // namespace quic |
| 97 | |
| 98 | #endif // QUICHE_QUIC_TEST_TOOLS_QUIC_CRYPTO_SERVER_CONFIG_PEER_H_ |