blob: 3f5a9840a33e23941f90c7f010959f2679598751 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// 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 "net/third_party/quiche/src/quic/core/crypto/quic_crypto_server_config.h"
9#include "net/third_party/quiche/src/quic/platform/api/quic_string_piece.h"
10
11namespace quic {
12namespace test {
13
14// Peer for accessing otherwise private members of a QuicCryptoServerConfig.
15class 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(
vasilvvc48c8712019-03-11 13:38:16 -070026 std::string config_id);
QUICHE teama6ef0a62019-03-07 20:34:33 -050027
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.
vasilvvc48c8712019-03-11 13:38:16 -070035 std::string NewSourceAddressToken(
36 std::string config_id,
QUICHE teama6ef0a62019-03-07 20:34:33 -050037 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(
vasilvvc48c8712019-03-11 13:38:16 -070045 std::string config_id,
QUICHE teama6ef0a62019-03-07 20:34:33 -050046 QuicStringPiece tokens,
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(
53 QuicStringPiece token,
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
vasilvvc48c8712019-03-11 13:38:16 -070073 // 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()
QUICHE teama6ef0a62019-03-07 20:34:33 -050076 SHARED_LOCKS_REQUIRED(server_config_->configs_lock_);
77
78 void SelectNewPrimaryConfig(int seconds);
79
vasilvvc48c8712019-03-11 13:38:16 -070080 static std::string CompressChain(
QUICHE teama6ef0a62019-03-07 20:34:33 -050081 QuicCompressedCertsCache* compressed_certs_cache,
82 const QuicReferenceCountedPointer<ProofSource::Chain>& chain,
vasilvvc48c8712019-03-11 13:38:16 -070083 const std::string& client_common_set_hashes,
84 const std::string& client_cached_cert_hashes,
QUICHE teama6ef0a62019-03-07 20:34:33 -050085 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_