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/crypto/common_cert_set.h" | 7 #include "net/quic/crypto/common_cert_set.h" |
8 #include "net/quic/crypto/crypto_handshake.h" | 8 #include "net/quic/crypto/crypto_handshake.h" |
9 #include "net/quic/crypto/crypto_server_config.h" | 9 #include "net/quic/crypto/crypto_server_config.h" |
10 #include "net/quic/crypto/quic_decrypter.h" | 10 #include "net/quic/crypto/quic_decrypter.h" |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 95 |
96 for (vector<CryptoHandshakeMessage>::const_iterator | 96 for (vector<CryptoHandshakeMessage>::const_iterator |
97 i = crypto_visitor.messages().begin(); | 97 i = crypto_visitor.messages().begin(); |
98 i != crypto_visitor.messages().end(); ++i) { | 98 i != crypto_visitor.messages().end(); ++i) { |
99 dest_stream->OnHandshakeMessage(*i); | 99 dest_stream->OnHandshakeMessage(*i); |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 } // anonymous namespace | 103 } // anonymous namespace |
104 | 104 |
| 105 CryptoTestUtils::FakeClientOptions::FakeClientOptions() |
| 106 : dont_verify_certs(false) { |
| 107 } |
| 108 |
105 // static | 109 // static |
106 void CryptoTestUtils::CommunicateHandshakeMessages( | 110 void CryptoTestUtils::CommunicateHandshakeMessages( |
107 PacketSavingConnection* a_conn, | 111 PacketSavingConnection* a_conn, |
108 QuicCryptoStream* a, | 112 QuicCryptoStream* a, |
109 PacketSavingConnection* b_conn, | 113 PacketSavingConnection* b_conn, |
110 QuicCryptoStream* b) { | 114 QuicCryptoStream* b) { |
111 size_t a_i = 0, b_i = 0; | 115 size_t a_i = 0, b_i = 0; |
112 while (!a->handshake_confirmed()) { | 116 while (!a->handshake_confirmed()) { |
113 ASSERT_GT(a_conn->packets_.size(), a_i); | 117 ASSERT_GT(a_conn->packets_.size(), a_i); |
114 LOG(INFO) << "Processing " << a_conn->packets_.size() - a_i | 118 LOG(INFO) << "Processing " << a_conn->packets_.size() - a_i |
(...skipping 13 matching lines...) Expand all Loading... |
128 // static | 132 // static |
129 int CryptoTestUtils::HandshakeWithFakeServer( | 133 int CryptoTestUtils::HandshakeWithFakeServer( |
130 PacketSavingConnection* client_conn, | 134 PacketSavingConnection* client_conn, |
131 QuicCryptoClientStream* client) { | 135 QuicCryptoClientStream* client) { |
132 QuicGuid guid(1); | 136 QuicGuid guid(1); |
133 IPAddressNumber ip; | 137 IPAddressNumber ip; |
134 CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip)); | 138 CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip)); |
135 IPEndPoint addr = IPEndPoint(ip, 1); | 139 IPEndPoint addr = IPEndPoint(ip, 1); |
136 PacketSavingConnection* server_conn = | 140 PacketSavingConnection* server_conn = |
137 new PacketSavingConnection(guid, addr, true); | 141 new PacketSavingConnection(guid, addr, true); |
138 TestSession server_session(server_conn, true); | 142 TestSession server_session(server_conn, QuicConfig(), true); |
139 | 143 |
140 QuicConfig config; | |
141 QuicCryptoServerConfig crypto_config(QuicCryptoServerConfig::TESTING); | 144 QuicCryptoServerConfig crypto_config(QuicCryptoServerConfig::TESTING); |
142 SetupCryptoServerConfigForTest( | 145 SetupCryptoServerConfigForTest( |
143 server_session.connection()->clock(), | 146 server_session.connection()->clock(), |
144 server_session.connection()->random_generator(), | 147 server_session.connection()->random_generator(), |
145 &config, &crypto_config); | 148 server_session.config(), &crypto_config); |
146 | 149 |
147 QuicCryptoServerStream server(config, crypto_config, &server_session); | 150 QuicCryptoServerStream server(crypto_config, &server_session); |
148 server_session.SetCryptoStream(&server); | 151 server_session.SetCryptoStream(&server); |
149 | 152 |
150 // The client's handshake must have been started already. | 153 // The client's handshake must have been started already. |
151 CHECK_NE(0u, client_conn->packets_.size()); | 154 CHECK_NE(0u, client_conn->packets_.size()); |
152 | 155 |
153 CommunicateHandshakeMessages(client_conn, client, server_conn, &server); | 156 CommunicateHandshakeMessages(client_conn, client, server_conn, &server); |
154 | 157 |
155 CompareClientAndServerKeys(client, &server); | 158 CompareClientAndServerKeys(client, &server); |
156 | 159 |
157 return client->num_sent_client_hellos(); | 160 return client->num_sent_client_hellos(); |
158 } | 161 } |
159 | 162 |
160 // static | 163 // static |
161 int CryptoTestUtils::HandshakeWithFakeClient( | 164 int CryptoTestUtils::HandshakeWithFakeClient( |
162 PacketSavingConnection* server_conn, | 165 PacketSavingConnection* server_conn, |
163 QuicCryptoServerStream* server) { | 166 QuicCryptoServerStream* server, |
| 167 const FakeClientOptions& options) { |
164 QuicGuid guid(1); | 168 QuicGuid guid(1); |
165 IPAddressNumber ip; | 169 IPAddressNumber ip; |
166 CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip)); | 170 CHECK(ParseIPLiteralToNumber("192.0.2.33", &ip)); |
167 IPEndPoint addr = IPEndPoint(ip, 1); | 171 IPEndPoint addr = IPEndPoint(ip, 1); |
168 PacketSavingConnection* client_conn = | 172 PacketSavingConnection* client_conn = |
169 new PacketSavingConnection(guid, addr, false); | 173 new PacketSavingConnection(guid, addr, false); |
170 TestSession client_session(client_conn, true); | 174 TestSession client_session(client_conn, QuicConfig(), false); |
171 QuicConfig config; | |
172 QuicCryptoClientConfig crypto_config; | 175 QuicCryptoClientConfig crypto_config; |
173 | 176 |
174 config.SetDefaults(); | 177 client_session.config()->SetDefaults(); |
175 crypto_config.SetDefaults(); | 178 crypto_config.SetDefaults(); |
176 // TODO(rtenneti): Enable testing of ProofVerifier. | 179 // TODO(rtenneti): Enable testing of ProofVerifier. |
177 // crypto_config.SetProofVerifier(ProofVerifierForTesting()); | 180 // if (!options.dont_verify_certs) { |
178 QuicCryptoClientStream client("test.example.com", config, &client_session, | 181 // crypto_config.SetProofVerifier(ProofVerifierForTesting()); |
| 182 // } |
| 183 QuicCryptoClientStream client("test.example.com", &client_session, |
179 &crypto_config); | 184 &crypto_config); |
180 client_session.SetCryptoStream(&client); | 185 client_session.SetCryptoStream(&client); |
181 | 186 |
182 CHECK(client.CryptoConnect()); | 187 CHECK(client.CryptoConnect()); |
183 CHECK_EQ(1u, client_conn->packets_.size()); | 188 CHECK_EQ(1u, client_conn->packets_.size()); |
184 | 189 |
185 CommunicateHandshakeMessages(client_conn, &client, server_conn, server); | 190 CommunicateHandshakeMessages(client_conn, &client, server_conn, server); |
186 | 191 |
187 CompareClientAndServerKeys(&client, server); | 192 CompareClientAndServerKeys(&client, server); |
188 | 193 |
189 return client.num_sent_client_hellos(); | 194 return client.num_sent_client_hellos(); |
190 } | 195 } |
191 | 196 |
192 // static | 197 // static |
193 void CryptoTestUtils::SetupCryptoServerConfigForTest( | 198 void CryptoTestUtils::SetupCryptoServerConfigForTest( |
194 const QuicClock* clock, | 199 const QuicClock* clock, |
195 QuicRandom* rand, | 200 QuicRandom* rand, |
196 QuicConfig* config, | 201 QuicConfig* config, |
197 QuicCryptoServerConfig* crypto_config) { | 202 QuicCryptoServerConfig* crypto_config) { |
198 config->SetDefaults(); | 203 config->SetDefaults(); |
199 CryptoHandshakeMessage extra_tags; | |
200 config->ToHandshakeMessage(&extra_tags); | |
201 | |
202 scoped_ptr<CryptoHandshakeMessage> scfg( | 204 scoped_ptr<CryptoHandshakeMessage> scfg( |
203 crypto_config->AddDefaultConfig( | 205 crypto_config->AddDefaultConfig( |
204 rand, clock, extra_tags, QuicCryptoServerConfig::kDefaultExpiry)); | 206 rand, clock, QuicCryptoServerConfig::kDefaultExpiry)); |
205 if (!config->SetFromHandshakeMessage(*scfg)) { | |
206 CHECK(false) << "Crypto config could not be parsed by QuicConfig."; | |
207 } | |
208 } | 207 } |
209 | 208 |
210 // static | 209 // static |
211 string CryptoTestUtils::GetValueForTag(const CryptoHandshakeMessage& message, | 210 string CryptoTestUtils::GetValueForTag(const CryptoHandshakeMessage& message, |
212 QuicTag tag) { | 211 QuicTag tag) { |
213 QuicTagValueMap::const_iterator it = message.tag_value_map().find(tag); | 212 QuicTagValueMap::const_iterator it = message.tag_value_map().find(tag); |
214 if (it == message.tag_value_map().end()) { | 213 if (it == message.tag_value_map().end()) { |
215 return string(); | 214 return string(); |
216 } | 215 } |
217 return it->second; | 216 return it->second; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 return true; | 266 return true; |
268 } | 267 } |
269 | 268 |
270 private: | 269 private: |
271 const string cert_; | 270 const string cert_; |
272 const uint64 hash_; | 271 const uint64 hash_; |
273 const uint32 index_; | 272 const uint32 index_; |
274 }; | 273 }; |
275 | 274 |
276 CommonCertSets* CryptoTestUtils::MockCommonCertSets(StringPiece cert, | 275 CommonCertSets* CryptoTestUtils::MockCommonCertSets(StringPiece cert, |
277 uint64 hash, | 276 uint64 hash, |
278 uint32 index) { | 277 uint32 index) { |
279 return new class MockCommonCertSets(cert, hash, index); | 278 return new class MockCommonCertSets(cert, hash, index); |
280 } | 279 } |
281 | 280 |
282 void CryptoTestUtils::CompareClientAndServerKeys( | 281 void CryptoTestUtils::CompareClientAndServerKeys( |
283 QuicCryptoClientStream* client, | 282 QuicCryptoClientStream* client, |
284 QuicCryptoServerStream* server) { | 283 QuicCryptoServerStream* server) { |
285 const QuicEncrypter* client_encrypter( | 284 const QuicEncrypter* client_encrypter( |
286 client->session()->connection()->encrypter(ENCRYPTION_INITIAL)); | 285 client->session()->connection()->encrypter(ENCRYPTION_INITIAL)); |
287 const QuicDecrypter* client_decrypter( | 286 const QuicDecrypter* client_decrypter( |
288 client->session()->connection()->decrypter()); | 287 client->session()->connection()->decrypter()); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
360 client_forward_secure_decrypter_key.data(), | 359 client_forward_secure_decrypter_key.data(), |
361 client_forward_secure_decrypter_key.length()); | 360 client_forward_secure_decrypter_key.length()); |
362 CompareCharArraysWithHexError("server forward secure write IV", | 361 CompareCharArraysWithHexError("server forward secure write IV", |
363 server_forward_secure_encrypter_iv.data(), | 362 server_forward_secure_encrypter_iv.data(), |
364 server_forward_secure_encrypter_iv.length(), | 363 server_forward_secure_encrypter_iv.length(), |
365 client_forward_secure_decrypter_iv.data(), | 364 client_forward_secure_decrypter_iv.data(), |
366 client_forward_secure_decrypter_iv.length()); | 365 client_forward_secure_decrypter_iv.length()); |
367 } | 366 } |
368 } // namespace test | 367 } // namespace test |
369 } // namespace net | 368 } // namespace net |
OLD | NEW |