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/platform/api/quic_text_utils.h" |
9 #include "net/quic/test_tools/mock_clock.h" | 10 #include "net/quic/test_tools/mock_clock.h" |
10 #include "net/test/gtest_util.h" | 11 #include "net/test/gtest_util.h" |
11 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 | 14 |
14 using std::string; | 15 using std::string; |
15 | 16 |
16 namespace net { | 17 namespace net { |
17 namespace test { | 18 namespace test { |
18 | 19 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
84 ShloVerifier* shlo_verifier_; | 85 ShloVerifier* shlo_verifier_; |
85 }; | 86 }; |
86 | 87 |
87 std::unique_ptr<ProcessClientHelloCallback> GetProcessClientHelloCallback() { | 88 std::unique_ptr<ProcessClientHelloCallback> GetProcessClientHelloCallback() { |
88 return std::unique_ptr<ProcessClientHelloCallback>( | 89 return std::unique_ptr<ProcessClientHelloCallback>( |
89 new ProcessClientHelloCallback(this)); | 90 new ProcessClientHelloCallback(this)); |
90 } | 91 } |
91 | 92 |
92 void ProcessClientHelloDone(std::unique_ptr<CryptoHandshakeMessage> message) { | 93 void ProcessClientHelloDone(std::unique_ptr<CryptoHandshakeMessage> message) { |
93 // Verify output is a SHLO. | 94 // Verify output is a SHLO. |
94 EXPECT_EQ(message->tag(), kSHLO) << "Fail to pass validation. Get " | 95 EXPECT_EQ(message->tag(), kSHLO) |
95 << message->DebugString(); | 96 << "Fail to pass validation. Get " << message->DebugString(); |
96 } | 97 } |
97 | 98 |
98 QuicCryptoServerConfig* crypto_config_; | 99 QuicCryptoServerConfig* crypto_config_; |
99 QuicSocketAddress server_addr_; | 100 QuicSocketAddress server_addr_; |
100 QuicSocketAddress client_addr_; | 101 QuicSocketAddress client_addr_; |
101 const QuicClock* clock_; | 102 const QuicClock* clock_; |
102 QuicReferenceCountedPointer<QuicSignedServerConfig> signed_config_; | 103 QuicReferenceCountedPointer<QuicSignedServerConfig> signed_config_; |
103 QuicCompressedCertsCache* compressed_certs_cache_; | 104 QuicCompressedCertsCache* compressed_certs_cache_; |
104 | 105 |
105 QuicReferenceCountedPointer<QuicCryptoNegotiatedParameters> params_; | 106 QuicReferenceCountedPointer<QuicCryptoNegotiatedParameters> params_; |
(...skipping 26 matching lines...) Expand all Loading... |
132 std::unique_ptr<CryptoHandshakeMessage> msg( | 133 std::unique_ptr<CryptoHandshakeMessage> msg( |
133 crypto_config.AddConfig(std::move(primary_config), clock.WallNow())); | 134 crypto_config.AddConfig(std::move(primary_config), clock.WallNow())); |
134 StringPiece orbit; | 135 StringPiece orbit; |
135 ASSERT_TRUE(msg->GetStringPiece(kORBT, &orbit)); | 136 ASSERT_TRUE(msg->GetStringPiece(kORBT, &orbit)); |
136 string nonce; | 137 string nonce; |
137 CryptoUtils::GenerateNonce( | 138 CryptoUtils::GenerateNonce( |
138 clock.WallNow(), QuicRandom::GetInstance(), | 139 clock.WallNow(), QuicRandom::GetInstance(), |
139 StringPiece(reinterpret_cast<const char*>(orbit.data()), | 140 StringPiece(reinterpret_cast<const char*>(orbit.data()), |
140 sizeof(orbit.size())), | 141 sizeof(orbit.size())), |
141 &nonce); | 142 &nonce); |
142 string nonce_hex = "#" + QuicUtils::HexEncode(nonce); | 143 string nonce_hex = "#" + QuicTextUtils::HexEncode(nonce); |
143 | 144 |
144 char public_value[32]; | 145 char public_value[32]; |
145 memset(public_value, 42, sizeof(public_value)); | 146 memset(public_value, 42, sizeof(public_value)); |
146 string pub_hex = | 147 string pub_hex = |
147 "#" + QuicUtils::HexEncode(public_value, sizeof(public_value)); | 148 "#" + QuicTextUtils::HexEncode(public_value, sizeof(public_value)); |
148 | 149 |
149 QuicVersion version(AllSupportedVersions().front()); | 150 QuicVersion version(AllSupportedVersions().front()); |
150 // clang-format off | 151 // clang-format off |
151 CryptoHandshakeMessage inchoate_chlo = CryptoTestUtils::Message( | 152 CryptoHandshakeMessage inchoate_chlo = CryptoTestUtils::Message( |
152 "CHLO", | 153 "CHLO", |
153 "PDMD", "X509", | 154 "PDMD", "X509", |
154 "AEAD", "AESG", | 155 "AEAD", "AESG", |
155 "KEXS", "C255", | 156 "KEXS", "C255", |
156 "COPT", "SREJ", | 157 "COPT", "SREJ", |
157 "PUBS", pub_hex.c_str(), | 158 "PUBS", pub_hex.c_str(), |
158 "NONC", nonce_hex.c_str(), | 159 "NONC", nonce_hex.c_str(), |
159 "VER\0", QuicTagToString(QuicVersionToQuicTag(version)).c_str(), | 160 "VER\0", QuicTagToString(QuicVersionToQuicTag(version)).c_str(), |
160 "$padding", static_cast<int>(kClientHelloMinimumSize), | 161 "$padding", static_cast<int>(kClientHelloMinimumSize), |
161 nullptr); | 162 nullptr); |
162 // clang-format on | 163 // clang-format on |
163 | 164 |
164 CryptoTestUtils::GenerateFullCHLO(inchoate_chlo, &crypto_config, server_addr, | 165 CryptoTestUtils::GenerateFullCHLO(inchoate_chlo, &crypto_config, server_addr, |
165 client_addr, version, &clock, signed_config, | 166 client_addr, version, &clock, signed_config, |
166 &compressed_certs_cache, &full_chlo); | 167 &compressed_certs_cache, &full_chlo); |
167 // Verify that full_chlo can pass crypto_config's verification. | 168 // Verify that full_chlo can pass crypto_config's verification. |
168 ShloVerifier shlo_verifier(&crypto_config, server_addr, client_addr, &clock, | 169 ShloVerifier shlo_verifier(&crypto_config, server_addr, client_addr, &clock, |
169 signed_config, &compressed_certs_cache); | 170 signed_config, &compressed_certs_cache); |
170 crypto_config.ValidateClientHello( | 171 crypto_config.ValidateClientHello( |
171 full_chlo, client_addr.host(), server_addr, version, &clock, | 172 full_chlo, client_addr.host(), server_addr, version, &clock, |
172 signed_config, shlo_verifier.GetValidateClientHelloCallback()); | 173 signed_config, shlo_verifier.GetValidateClientHelloCallback()); |
173 } | 174 } |
174 | 175 |
175 } // namespace test | 176 } // namespace test |
176 } // namespace net | 177 } // namespace net |
OLD | NEW |