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

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

Issue 2397513002: Conversion of a QUIC method to an async signature and resulting fallout. No functional change inten… (Closed)
Patch Set: Add NET_EXPORT_PRIVATE Created 4 years, 2 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "net/quic/test_tools/crypto_test_utils.h" 5 #include "net/quic/test_tools/crypto_test_utils.h"
6 6
7 #include "net/quic/core/crypto/crypto_server_config_protobuf.h" 7 #include "net/quic/core/crypto/crypto_server_config_protobuf.h"
8 #include "net/quic/core/quic_utils.h" 8 #include "net/quic/core/quic_utils.h"
9 #include "net/quic/test_tools/mock_clock.h" 9 #include "net/quic/test_tools/mock_clock.h"
10 #include "net/test/gtest_util.h" 10 #include "net/test/gtest_util.h"
11 #include "testing/gmock/include/gmock/gmock.h" 11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 13
14 using std::string; 14 using std::string;
15 15
16 namespace net { 16 namespace net {
17 namespace test { 17 namespace test {
18 18
19 class ShloVerifier : public ValidateClientHelloResultCallback { 19 class ShloVerifier {
20 public: 20 public:
21 ShloVerifier(QuicCryptoServerConfig* crypto_config, 21 ShloVerifier(QuicCryptoServerConfig* crypto_config,
22 IPAddress server_ip, 22 IPAddress server_ip,
23 IPEndPoint client_addr, 23 IPEndPoint client_addr,
24 const QuicClock* clock, 24 const QuicClock* clock,
25 QuicCryptoProof* proof, 25 QuicCryptoProof* proof,
26 QuicCompressedCertsCache* compressed_certs_cache) 26 QuicCompressedCertsCache* compressed_certs_cache)
27 : crypto_config_(crypto_config), 27 : crypto_config_(crypto_config),
28 server_ip_(server_ip), 28 server_ip_(server_ip),
29 client_addr_(client_addr), 29 client_addr_(client_addr),
30 clock_(clock), 30 clock_(clock),
31 proof_(proof), 31 proof_(proof),
32 compressed_certs_cache_(compressed_certs_cache) {} 32 compressed_certs_cache_(compressed_certs_cache) {}
33 33
34 // Verify that the output message is a SHLO. 34 class ValidateClientHelloCallback : public ValidateClientHelloResultCallback {
35 void Run(scoped_refptr<ValidateClientHelloResultCallback::Result> result, 35 public:
36 std::unique_ptr<ProofSource::Details> /* details */) override { 36 explicit ValidateClientHelloCallback(ShloVerifier* shlo_verifier)
37 QuicCryptoNegotiatedParameters params; 37 : shlo_verifier_(shlo_verifier) {}
38 string error_details; 38 void Run(scoped_refptr<ValidateClientHelloResultCallback::Result> result,
39 DiversificationNonce diversification_nonce; 39 std::unique_ptr<ProofSource::Details> /* details */) override {
40 CryptoHandshakeMessage out; 40 shlo_verifier_->ValidateClientHelloDone(result);
41 }
42
43 private:
44 ShloVerifier* shlo_verifier_;
45 };
46
47 std::unique_ptr<ValidateClientHelloCallback>
48 GetValidateClientHelloCallback() {
49 return std::unique_ptr<ValidateClientHelloCallback>(
50 new ValidateClientHelloCallback(this));
51 }
52
53 private:
54 void ValidateClientHelloDone(
55 const scoped_refptr<ValidateClientHelloResultCallback::Result>& result) {
56 result_ = result;
41 crypto_config_->ProcessClientHello( 57 crypto_config_->ProcessClientHello(
42 result, /*reject_only=*/false, /*connection_id=*/1, server_ip_, 58 result_, /*reject_only=*/false, /*connection_id=*/1, server_ip_,
43 client_addr_, AllSupportedVersions().front(), AllSupportedVersions(), 59 client_addr_, AllSupportedVersions().front(), AllSupportedVersions(),
44 /*use_stateless_rejects=*/true, /*server_designated_connection_id=*/0, 60 /*use_stateless_rejects=*/true, /*server_designated_connection_id=*/0,
45 clock_, QuicRandom::GetInstance(), compressed_certs_cache_, &params, 61 clock_, QuicRandom::GetInstance(), compressed_certs_cache_, &params_,
46 proof_, /*total_framing_overhead=*/50, kDefaultMaxPacketSize, &out, 62 proof_, /*total_framing_overhead=*/50, kDefaultMaxPacketSize,
47 &diversification_nonce, &error_details); 63 GetProcessClientHelloCallback());
48 // Verify output is a SHLO.
49 EXPECT_EQ(out.tag(), kSHLO) << "Fail to pass validation. Get "
50 << out.DebugString();
51 } 64 }
52 65
53 protected: 66 class ProcessClientHelloCallback : public ProcessClientHelloResultCallback {
67 public:
68 explicit ProcessClientHelloCallback(ShloVerifier* shlo_verifier)
69 : shlo_verifier_(shlo_verifier) {}
70 void Run(
71 QuicErrorCode error,
72 const string& error_details,
73 std::unique_ptr<CryptoHandshakeMessage> message,
74 std::unique_ptr<DiversificationNonce> diversification_nonce) override {
75 shlo_verifier_->ProcessClientHelloDone(std::move(message));
76 }
77
78 private:
79 ShloVerifier* shlo_verifier_;
80 };
81
82 std::unique_ptr<ProcessClientHelloCallback> GetProcessClientHelloCallback() {
83 return std::unique_ptr<ProcessClientHelloCallback>(
84 new ProcessClientHelloCallback(this));
85 }
86
87 void ProcessClientHelloDone(std::unique_ptr<CryptoHandshakeMessage> message) {
88 // Verify output is a SHLO.
89 EXPECT_EQ(message->tag(), kSHLO) << "Fail to pass validation. Get "
90 << message->DebugString();
91 }
92
54 QuicCryptoServerConfig* crypto_config_; 93 QuicCryptoServerConfig* crypto_config_;
55 IPAddress server_ip_; 94 IPAddress server_ip_;
56 IPEndPoint client_addr_; 95 IPEndPoint client_addr_;
57 const QuicClock* clock_; 96 const QuicClock* clock_;
58 QuicCryptoProof* proof_; 97 QuicCryptoProof* proof_;
59 QuicCompressedCertsCache* compressed_certs_cache_; 98 QuicCompressedCertsCache* compressed_certs_cache_;
99
100 QuicCryptoNegotiatedParameters params_;
101 scoped_refptr<ValidateClientHelloResultCallback::Result> result_;
60 }; 102 };
61 103
62 TEST(CryptoTestUtilsTest, TestGenerateFullCHLO) { 104 TEST(CryptoTestUtilsTest, TestGenerateFullCHLO) {
63 MockClock clock; 105 MockClock clock;
64 QuicCryptoServerConfig crypto_config( 106 QuicCryptoServerConfig crypto_config(
65 QuicCryptoServerConfig::TESTING, QuicRandom::GetInstance(), 107 QuicCryptoServerConfig::TESTING, QuicRandom::GetInstance(),
66 CryptoTestUtils::ProofSourceForTesting()); 108 CryptoTestUtils::ProofSourceForTesting());
67 IPAddress server_ip; 109 IPAddress server_ip;
68 IPEndPoint client_addr(IPAddress::IPv4Localhost(), 1); 110 IPEndPoint client_addr(IPAddress::IPv4Localhost(), 1);
69 QuicCryptoProof proof; 111 QuicCryptoProof proof;
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 "NONC", nonce_hex.c_str(), 151 "NONC", nonce_hex.c_str(),
110 "VER\0", QuicUtils::TagToString(QuicVersionToQuicTag(version)).c_str(), 152 "VER\0", QuicUtils::TagToString(QuicVersionToQuicTag(version)).c_str(),
111 "$padding", static_cast<int>(kClientHelloMinimumSize), 153 "$padding", static_cast<int>(kClientHelloMinimumSize),
112 nullptr); 154 nullptr);
113 // clang-format on 155 // clang-format on
114 156
115 CryptoTestUtils::GenerateFullCHLO(inchoate_chlo, &crypto_config, server_ip, 157 CryptoTestUtils::GenerateFullCHLO(inchoate_chlo, &crypto_config, server_ip,
116 client_addr, version, &clock, &proof, 158 client_addr, version, &clock, &proof,
117 &compressed_certs_cache, &full_chlo); 159 &compressed_certs_cache, &full_chlo);
118 // Verify that full_chlo can pass crypto_config's verification. 160 // Verify that full_chlo can pass crypto_config's verification.
161 ShloVerifier shlo_verifier(&crypto_config, server_ip, client_addr, &clock,
162 &proof, &compressed_certs_cache);
119 crypto_config.ValidateClientHello( 163 crypto_config.ValidateClientHello(
120 full_chlo, client_addr.address(), server_ip, version, &clock, &proof, 164 full_chlo, client_addr.address(), server_ip, version, &clock, &proof,
121 std::unique_ptr<ShloVerifier>( 165 shlo_verifier.GetValidateClientHelloCallback());
122 new ShloVerifier(&crypto_config, server_ip, client_addr, &clock,
123 &proof, &compressed_certs_cache)));
124 } 166 }
125 167
126 } // namespace test 168 } // namespace test
127 } // namespace net 169 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/test_tools/crypto_test_utils.cc ('k') | net/quic/test_tools/quic_crypto_server_config_peer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698