Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(571)

Side by Side Diff: net/quic/test_tools/crypto_test_utils_test.cc

Issue 2181773002: Add a test helper method to construct a full CHLO. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@127821412
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/test_tools/crypto_test_utils.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #include "net/quic/test_tools/crypto_test_utils.h"
Zhongyi Shi 2016/07/25 22:33:48 Add the license header?
Ryan Hamilton 2016/07/25 23:06:45 Done in final.
2
3 #include "net/quic/crypto/crypto_server_config_protobuf.h"
4 #include "net/quic/quic_utils.h"
5 #include "net/quic/test_tools/mock_clock.h"
6 #include "net/test/gtest_util.h"
7 #include "testing/gmock/include/gmock/gmock.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 using std::string;
11
12 namespace net {
13 namespace test {
14
15 class ShloVerifier : public ValidateClientHelloResultCallback {
16 public:
17 ShloVerifier(QuicCryptoServerConfig* crypto_config,
18 IPAddress server_ip,
19 IPEndPoint client_addr,
20 const QuicClock* clock,
21 QuicCryptoProof* proof,
22 QuicCompressedCertsCache* compressed_certs_cache)
23 : crypto_config_(crypto_config),
24 server_ip_(server_ip),
25 client_addr_(client_addr),
26 clock_(clock),
27 proof_(proof),
28 compressed_certs_cache_(compressed_certs_cache) {}
29
30 // Verify that the output message is a SHLO.
31 void RunImpl(
32 const CryptoHandshakeMessage& chlo,
33 const ValidateClientHelloResultCallback::Result& result) override {
34 QuicCryptoNegotiatedParameters params;
35 string error_details;
36 DiversificationNonce diversification_nonce;
37 CryptoHandshakeMessage out;
38 crypto_config_->ProcessClientHello(
39 result, /*reject_only=*/false, /*connection_id=*/1, server_ip_,
40 client_addr_, QuicSupportedVersions().front(), QuicSupportedVersions(),
41 /*use_stateless_rejects=*/true, /*server_designated_connection_id=*/0,
42 clock_, QuicRandom::GetInstance(), compressed_certs_cache_, &params,
43 proof_, &out, &diversification_nonce, &error_details);
44 // Verify output is a SHLO.
45 EXPECT_EQ(out.tag(), kSHLO) << "Fail to pass validation. Get "
46 << out.DebugString();
47 }
48
49 protected:
50 QuicCryptoServerConfig* crypto_config_;
51 IPAddress server_ip_;
52 IPEndPoint client_addr_;
53 const QuicClock* clock_;
54 QuicCryptoProof* proof_;
55 QuicCompressedCertsCache* compressed_certs_cache_;
56 };
57
58 TEST(CryptoTestUtilsTest, TestGenerateFullCHLO) {
59 MockClock clock;
60 QuicCryptoServerConfig crypto_config(
61 QuicCryptoServerConfig::TESTING, QuicRandom::GetInstance(),
62 CryptoTestUtils::ProofSourceForTesting());
63 IPAddress server_ip;
64 IPEndPoint client_addr(IPAddress::IPv4Localhost(), 1);
65 QuicCryptoProof proof;
66 QuicCompressedCertsCache compressed_certs_cache(
67 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize);
68 CryptoHandshakeMessage full_chlo;
69
70 QuicCryptoServerConfig::ConfigOptions old_config_options;
71 old_config_options.id = "old-config-id";
72 delete crypto_config.AddDefaultConfig(QuicRandom::GetInstance(),
73 &clock, old_config_options);
74 QuicCryptoServerConfig::ConfigOptions new_config_options;
75 std::unique_ptr<QuicServerConfigProtobuf> primary_config(
76 crypto_config.GenerateConfig(QuicRandom::GetInstance(), &clock,
77 new_config_options));
78 primary_config->set_primary_time(clock.WallNow().ToUNIXSeconds());
79 std::unique_ptr<CryptoHandshakeMessage> msg(
80 crypto_config.AddConfig(primary_config.get(), clock.WallNow()));
81 StringPiece orbit;
82 ASSERT_TRUE(msg->GetStringPiece(kORBT, &orbit));
83 string nonce;
84 CryptoUtils::GenerateNonce(
85 clock.WallNow(), QuicRandom::GetInstance(),
86 StringPiece(reinterpret_cast<const char*>(orbit.data()),
87 sizeof(orbit.size())),
88 &nonce);
89 string nonce_hex = "#" + QuicUtils::HexEncode(nonce);
90
91 char public_value[32];
92 memset(public_value, 42, sizeof(public_value));
93 string pub_hex =
94 "#" + QuicUtils::HexEncode(public_value, sizeof(public_value));
95
96 QuicVersion version(QuicSupportedVersions().front());
97 // clang-format off
98 CryptoHandshakeMessage inchoate_chlo = CryptoTestUtils::Message(
99 "CHLO",
100 "PDMD", "X509",
101 "AEAD", "AESG",
102 "KEXS", "C255",
103 "COPT", "SREJ",
104 "PUBS", pub_hex.c_str(),
105 "NONC", nonce_hex.c_str(),
106 "VER\0", QuicUtils::TagToString(QuicVersionToQuicTag(version)).c_str(),
107 "$padding", static_cast<int>(kClientHelloMinimumSize),
108 nullptr);
109 // clang-format on
110
111 CryptoTestUtils::GenerateFullCHLO(inchoate_chlo, &crypto_config, server_ip,
112 client_addr, version, &clock, &proof,
113 &compressed_certs_cache, &full_chlo);
114 // Verify that full_chlo can pass crypto_config's verification.
115 crypto_config.ValidateClientHello(
116 full_chlo, client_addr.address(), server_ip, version, &clock, &proof,
117 new ShloVerifier(&crypto_config, server_ip, client_addr, &clock, &proof,
118 &compressed_certs_cache));
119 }
120
121 } // namespace test
122 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/crypto_test_utils.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698