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 8 #include "absl/strings/string_view.h" 9 #include "quiche/quic/core/crypto/quic_crypto_server_config.h" 10 11 namespace quic { 12 namespace test { 13 14 // Peer for accessing otherwise private members of a QuicCryptoServerConfig. 15 class QuicCryptoServerConfigPeer { 16 public: QuicCryptoServerConfigPeer(QuicCryptoServerConfig * server_config)17 explicit QuicCryptoServerConfigPeer(QuicCryptoServerConfig* server_config) 18 : server_config_(server_config) {} 19 20 // Returns the primary config. 21 quiche::QuicheReferenceCountedPointer<QuicCryptoServerConfig::Config> 22 GetPrimaryConfig(); 23 24 // Returns the config associated with |config_id|. 25 quiche::QuicheReferenceCountedPointer<QuicCryptoServerConfig::Config> 26 GetConfig(std::string config_id); 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. 35 std::string NewSourceAddressToken( 36 std::string config_id, SourceAddressTokens previous_tokens, 37 const QuicIpAddress& ip, QuicRandom* rand, QuicWallTime now, 38 CachedNetworkParameters* cached_network_params); 39 40 // Attempts to validate the tokens in |srct|. 41 HandshakeFailureReason ValidateSourceAddressTokens( 42 std::string config_id, absl::string_view srct, const QuicIpAddress& ip, 43 QuicWallTime now, CachedNetworkParameters* cached_network_params); 44 45 // Attempts to validate the single source address token in |token|. 46 HandshakeFailureReason ValidateSingleSourceAddressToken( 47 absl::string_view token, const QuicIpAddress& ip, QuicWallTime now); 48 49 // CheckConfigs compares the state of the Configs in |server_config_| to the 50 // description given as arguments. 51 // The first of each pair is the server config ID of a Config. The second is a 52 // boolean describing whether the config is the primary. For example: 53 // CheckConfigs(std::vector<std::pair<ServerConfigID, bool>>()); // checks 54 // that no Configs are loaded. 55 // 56 // // Checks that exactly three Configs are loaded with the given IDs and 57 // // status. 58 // CheckConfigs( 59 // {{"id1", false}, 60 // {"id2", true}, 61 // {"id3", false}}); 62 void CheckConfigs( 63 std::vector<std::pair<ServerConfigID, bool>> expected_ids_and_status); 64 65 // ConfigsDebug returns a std::string that contains debugging information 66 // about the set of Configs loaded in |server_config_| and their status. 67 std::string ConfigsDebug() 68 QUIC_SHARED_LOCKS_REQUIRED(server_config_->configs_lock_); 69 70 void SelectNewPrimaryConfig(int seconds); 71 72 static std::string CompressChain( 73 QuicCompressedCertsCache* compressed_certs_cache, 74 const quiche::QuicheReferenceCountedPointer<ProofSource::Chain>& chain, 75 const std::string& client_cached_cert_hashes); 76 77 uint32_t source_address_token_future_secs(); 78 79 uint32_t source_address_token_lifetime_secs(); 80 81 private: 82 QuicCryptoServerConfig* server_config_; 83 }; 84 85 } // namespace test 86 } // namespace quic 87 88 #endif // QUICHE_QUIC_TEST_TOOLS_QUIC_CRYPTO_SERVER_CONFIG_PEER_H_ 89