OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 <algorithm> | 5 #include <algorithm> |
6 #include <cstdint> | 6 #include <cstdint> |
7 #include <memory> | 7 #include <memory> |
8 #include <ostream> | 8 #include <ostream> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 const CryptoHandshakeMessage& message, | 264 const CryptoHandshakeMessage& message, |
265 bool* called) { | 265 bool* called) { |
266 IPAddress server_ip; | 266 IPAddress server_ip; |
267 config_.ValidateClientHello( | 267 config_.ValidateClientHello( |
268 message, client_address_.address(), server_ip, | 268 message, client_address_.address(), server_ip, |
269 supported_versions_.front(), &clock_, &crypto_proof_, | 269 supported_versions_.front(), &clock_, &crypto_proof_, |
270 std::unique_ptr<ValidateCallback>( | 270 std::unique_ptr<ValidateCallback>( |
271 new ValidateCallback(this, false, error_substr, called))); | 271 new ValidateCallback(this, false, error_substr, called))); |
272 } | 272 } |
273 | 273 |
| 274 class ProcessCallback : public ProcessClientHelloResultCallback { |
| 275 public: |
| 276 ProcessCallback(scoped_refptr<ValidateCallback::Result> result, |
| 277 bool should_succeed, |
| 278 const char* error_substr, |
| 279 bool* called, |
| 280 CryptoHandshakeMessage* out) |
| 281 : result_(std::move(result)), |
| 282 should_succeed_(should_succeed), |
| 283 error_substr_(error_substr), |
| 284 called_(called), |
| 285 out_(out) { |
| 286 *called_ = false; |
| 287 } |
| 288 |
| 289 void Run( |
| 290 QuicErrorCode error, |
| 291 const string& error_details, |
| 292 std::unique_ptr<CryptoHandshakeMessage> message, |
| 293 std::unique_ptr<DiversificationNonce> diversification_nonce) override { |
| 294 if (should_succeed_) { |
| 295 ASSERT_EQ(error, QUIC_NO_ERROR) << "Message failed with error " |
| 296 << error_details << ": " |
| 297 << result_->client_hello.DebugString(); |
| 298 } else { |
| 299 ASSERT_NE(error, QUIC_NO_ERROR) << "Message didn't fail: " |
| 300 << result_->client_hello.DebugString(); |
| 301 |
| 302 EXPECT_TRUE(error_details.find(error_substr_) != string::npos) |
| 303 << error_substr_ << " not in " << error_details; |
| 304 } |
| 305 if (message != nullptr) { |
| 306 *out_ = *message; |
| 307 } |
| 308 *called_ = true; |
| 309 } |
| 310 |
| 311 private: |
| 312 const scoped_refptr<ValidateCallback::Result> result_; |
| 313 const bool should_succeed_; |
| 314 const char* const error_substr_; |
| 315 bool* called_; |
| 316 CryptoHandshakeMessage* out_; |
| 317 }; |
| 318 |
274 void ProcessValidationResult(scoped_refptr<ValidateCallback::Result> result, | 319 void ProcessValidationResult(scoped_refptr<ValidateCallback::Result> result, |
275 bool should_succeed, | 320 bool should_succeed, |
276 const char* error_substr) { | 321 const char* error_substr) { |
277 IPAddress server_ip; | 322 IPAddress server_ip; |
278 DiversificationNonce diversification_nonce; | |
279 string error_details; | |
280 QuicConnectionId server_designated_connection_id = | 323 QuicConnectionId server_designated_connection_id = |
281 rand_for_id_generation_.RandUint64(); | 324 rand_for_id_generation_.RandUint64(); |
282 QuicErrorCode error = config_.ProcessClientHello( | 325 bool called; |
| 326 config_.ProcessClientHello( |
283 result, /*reject_only=*/false, /*connection_id=*/1, server_ip, | 327 result, /*reject_only=*/false, /*connection_id=*/1, server_ip, |
284 client_address_, supported_versions_.front(), supported_versions_, | 328 client_address_, supported_versions_.front(), supported_versions_, |
285 use_stateless_rejects_, server_designated_connection_id, &clock_, rand_, | 329 use_stateless_rejects_, server_designated_connection_id, &clock_, rand_, |
286 &compressed_certs_cache_, ¶ms_, &crypto_proof_, | 330 &compressed_certs_cache_, ¶ms_, &crypto_proof_, |
287 /*total_framing_overhead=*/50, chlo_packet_size_, &out_, | 331 /*total_framing_overhead=*/50, chlo_packet_size_, |
288 &diversification_nonce, &error_details); | 332 std::unique_ptr<ProcessCallback>(new ProcessCallback( |
289 | 333 result, should_succeed, error_substr, &called, &out_))); |
290 if (should_succeed) { | 334 EXPECT_TRUE(called); |
291 ASSERT_EQ(error, QUIC_NO_ERROR) << "Message failed with error " | |
292 << error_details << ": " | |
293 << result->client_hello.DebugString(); | |
294 } else { | |
295 ASSERT_NE(error, QUIC_NO_ERROR) << "Message didn't fail: " | |
296 << result->client_hello.DebugString(); | |
297 | |
298 EXPECT_TRUE(error_details.find(error_substr) != string::npos) | |
299 << error_substr << " not in " << error_details; | |
300 } | |
301 } | 335 } |
302 | 336 |
303 string GenerateNonce() { | 337 string GenerateNonce() { |
304 string nonce; | 338 string nonce; |
305 CryptoUtils::GenerateNonce( | 339 CryptoUtils::GenerateNonce( |
306 clock_.WallNow(), rand_, | 340 clock_.WallNow(), rand_, |
307 StringPiece(reinterpret_cast<const char*>(orbit_), sizeof(orbit_)), | 341 StringPiece(reinterpret_cast<const char*>(orbit_), sizeof(orbit_)), |
308 &nonce); | 342 &nonce); |
309 return nonce; | 343 return nonce; |
310 } | 344 } |
(...skipping 934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1245 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); | 1279 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); |
1246 } else { | 1280 } else { |
1247 // version 33. | 1281 // version 33. |
1248 ASSERT_EQ(kSHLO, out_.tag()); | 1282 ASSERT_EQ(kSHLO, out_.tag()); |
1249 CheckServerHello(out_); | 1283 CheckServerHello(out_); |
1250 } | 1284 } |
1251 } | 1285 } |
1252 | 1286 |
1253 } // namespace test | 1287 } // namespace test |
1254 } // namespace net | 1288 } // namespace net |
OLD | NEW |