OLD | NEW |
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 { | 19 class ShloVerifier { |
20 public: | 20 public: |
21 ShloVerifier(QuicCryptoServerConfig* crypto_config, | 21 ShloVerifier( |
22 QuicSocketAddress server_addr, | 22 QuicCryptoServerConfig* crypto_config, |
23 QuicSocketAddress client_addr, | 23 QuicSocketAddress server_addr, |
24 const QuicClock* clock, | 24 QuicSocketAddress client_addr, |
25 scoped_refptr<QuicSignedServerConfig> signed_config, | 25 const QuicClock* clock, |
26 QuicCompressedCertsCache* compressed_certs_cache) | 26 QuicReferenceCountedPointer<QuicSignedServerConfig> signed_config, |
| 27 QuicCompressedCertsCache* compressed_certs_cache) |
27 : crypto_config_(crypto_config), | 28 : crypto_config_(crypto_config), |
28 server_addr_(server_addr), | 29 server_addr_(server_addr), |
29 client_addr_(client_addr), | 30 client_addr_(client_addr), |
30 clock_(clock), | 31 clock_(clock), |
31 signed_config_(signed_config), | 32 signed_config_(signed_config), |
32 compressed_certs_cache_(compressed_certs_cache), | 33 compressed_certs_cache_(compressed_certs_cache), |
33 params_(new QuicCryptoNegotiatedParameters) {} | 34 params_(new QuicCryptoNegotiatedParameters) {} |
34 | 35 |
35 class ValidateClientHelloCallback : public ValidateClientHelloResultCallback { | 36 class ValidateClientHelloCallback : public ValidateClientHelloResultCallback { |
36 public: | 37 public: |
37 explicit ValidateClientHelloCallback(ShloVerifier* shlo_verifier) | 38 explicit ValidateClientHelloCallback(ShloVerifier* shlo_verifier) |
38 : shlo_verifier_(shlo_verifier) {} | 39 : shlo_verifier_(shlo_verifier) {} |
39 void Run(scoped_refptr<ValidateClientHelloResultCallback::Result> result, | 40 void Run(QuicReferenceCountedPointer< |
| 41 ValidateClientHelloResultCallback::Result> result, |
40 std::unique_ptr<ProofSource::Details> /* details */) override { | 42 std::unique_ptr<ProofSource::Details> /* details */) override { |
41 shlo_verifier_->ValidateClientHelloDone(result); | 43 shlo_verifier_->ValidateClientHelloDone(result); |
42 } | 44 } |
43 | 45 |
44 private: | 46 private: |
45 ShloVerifier* shlo_verifier_; | 47 ShloVerifier* shlo_verifier_; |
46 }; | 48 }; |
47 | 49 |
48 std::unique_ptr<ValidateClientHelloCallback> | 50 std::unique_ptr<ValidateClientHelloCallback> |
49 GetValidateClientHelloCallback() { | 51 GetValidateClientHelloCallback() { |
50 return std::unique_ptr<ValidateClientHelloCallback>( | 52 return std::unique_ptr<ValidateClientHelloCallback>( |
51 new ValidateClientHelloCallback(this)); | 53 new ValidateClientHelloCallback(this)); |
52 } | 54 } |
53 | 55 |
54 private: | 56 private: |
55 void ValidateClientHelloDone( | 57 void ValidateClientHelloDone( |
56 const scoped_refptr<ValidateClientHelloResultCallback::Result>& result) { | 58 const QuicReferenceCountedPointer< |
| 59 ValidateClientHelloResultCallback::Result>& result) { |
57 result_ = result; | 60 result_ = result; |
58 crypto_config_->ProcessClientHello( | 61 crypto_config_->ProcessClientHello( |
59 result_, /*reject_only=*/false, /*connection_id=*/1, server_addr_, | 62 result_, /*reject_only=*/false, /*connection_id=*/1, server_addr_, |
60 client_addr_, AllSupportedVersions().front(), AllSupportedVersions(), | 63 client_addr_, AllSupportedVersions().front(), AllSupportedVersions(), |
61 /*use_stateless_rejects=*/true, /*server_designated_connection_id=*/0, | 64 /*use_stateless_rejects=*/true, /*server_designated_connection_id=*/0, |
62 clock_, QuicRandom::GetInstance(), compressed_certs_cache_, params_, | 65 clock_, QuicRandom::GetInstance(), compressed_certs_cache_, params_, |
63 signed_config_, /*total_framing_overhead=*/50, kDefaultMaxPacketSize, | 66 signed_config_, /*total_framing_overhead=*/50, kDefaultMaxPacketSize, |
64 GetProcessClientHelloCallback()); | 67 GetProcessClientHelloCallback()); |
65 } | 68 } |
66 | 69 |
(...skipping 22 matching lines...) Expand all Loading... |
89 void ProcessClientHelloDone(std::unique_ptr<CryptoHandshakeMessage> message) { | 92 void ProcessClientHelloDone(std::unique_ptr<CryptoHandshakeMessage> message) { |
90 // Verify output is a SHLO. | 93 // Verify output is a SHLO. |
91 EXPECT_EQ(message->tag(), kSHLO) << "Fail to pass validation. Get " | 94 EXPECT_EQ(message->tag(), kSHLO) << "Fail to pass validation. Get " |
92 << message->DebugString(); | 95 << message->DebugString(); |
93 } | 96 } |
94 | 97 |
95 QuicCryptoServerConfig* crypto_config_; | 98 QuicCryptoServerConfig* crypto_config_; |
96 QuicSocketAddress server_addr_; | 99 QuicSocketAddress server_addr_; |
97 QuicSocketAddress client_addr_; | 100 QuicSocketAddress client_addr_; |
98 const QuicClock* clock_; | 101 const QuicClock* clock_; |
99 scoped_refptr<QuicSignedServerConfig> signed_config_; | 102 QuicReferenceCountedPointer<QuicSignedServerConfig> signed_config_; |
100 QuicCompressedCertsCache* compressed_certs_cache_; | 103 QuicCompressedCertsCache* compressed_certs_cache_; |
101 | 104 |
102 scoped_refptr<QuicCryptoNegotiatedParameters> params_; | 105 QuicReferenceCountedPointer<QuicCryptoNegotiatedParameters> params_; |
103 scoped_refptr<ValidateClientHelloResultCallback::Result> result_; | 106 QuicReferenceCountedPointer<ValidateClientHelloResultCallback::Result> |
| 107 result_; |
104 }; | 108 }; |
105 | 109 |
106 TEST(CryptoTestUtilsTest, TestGenerateFullCHLO) { | 110 TEST(CryptoTestUtilsTest, TestGenerateFullCHLO) { |
107 MockClock clock; | 111 MockClock clock; |
108 QuicCryptoServerConfig crypto_config( | 112 QuicCryptoServerConfig crypto_config( |
109 QuicCryptoServerConfig::TESTING, QuicRandom::GetInstance(), | 113 QuicCryptoServerConfig::TESTING, QuicRandom::GetInstance(), |
110 CryptoTestUtils::ProofSourceForTesting()); | 114 CryptoTestUtils::ProofSourceForTesting()); |
111 QuicSocketAddress server_addr; | 115 QuicSocketAddress server_addr; |
112 QuicSocketAddress client_addr(QuicIpAddress::Loopback4(), 1); | 116 QuicSocketAddress client_addr(QuicIpAddress::Loopback4(), 1); |
113 scoped_refptr<QuicSignedServerConfig> signed_config( | 117 QuicReferenceCountedPointer<QuicSignedServerConfig> signed_config( |
114 new QuicSignedServerConfig); | 118 new QuicSignedServerConfig); |
115 QuicCompressedCertsCache compressed_certs_cache( | 119 QuicCompressedCertsCache compressed_certs_cache( |
116 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize); | 120 QuicCompressedCertsCache::kQuicCompressedCertsCacheSize); |
117 CryptoHandshakeMessage full_chlo; | 121 CryptoHandshakeMessage full_chlo; |
118 | 122 |
119 QuicCryptoServerConfig::ConfigOptions old_config_options; | 123 QuicCryptoServerConfig::ConfigOptions old_config_options; |
120 old_config_options.id = "old-config-id"; | 124 old_config_options.id = "old-config-id"; |
121 delete crypto_config.AddDefaultConfig(QuicRandom::GetInstance(), &clock, | 125 delete crypto_config.AddDefaultConfig(QuicRandom::GetInstance(), &clock, |
122 old_config_options); | 126 old_config_options); |
123 QuicCryptoServerConfig::ConfigOptions new_config_options; | 127 QuicCryptoServerConfig::ConfigOptions new_config_options; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 // Verify that full_chlo can pass crypto_config's verification. | 167 // Verify that full_chlo can pass crypto_config's verification. |
164 ShloVerifier shlo_verifier(&crypto_config, server_addr, client_addr, &clock, | 168 ShloVerifier shlo_verifier(&crypto_config, server_addr, client_addr, &clock, |
165 signed_config, &compressed_certs_cache); | 169 signed_config, &compressed_certs_cache); |
166 crypto_config.ValidateClientHello( | 170 crypto_config.ValidateClientHello( |
167 full_chlo, client_addr.host(), server_addr, version, &clock, | 171 full_chlo, client_addr.host(), server_addr, version, &clock, |
168 signed_config, shlo_verifier.GetValidateClientHelloCallback()); | 172 signed_config, shlo_verifier.GetValidateClientHelloCallback()); |
169 } | 173 } |
170 | 174 |
171 } // namespace test | 175 } // namespace test |
172 } // namespace net | 176 } // namespace net |
OLD | NEW |