| 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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 bool should_succeed, | 194 bool should_succeed, |
| 195 const char* error_substr, | 195 const char* error_substr, |
| 196 bool* called) | 196 bool* called) |
| 197 : test_(test), | 197 : test_(test), |
| 198 should_succeed_(should_succeed), | 198 should_succeed_(should_succeed), |
| 199 error_substr_(error_substr), | 199 error_substr_(error_substr), |
| 200 called_(called) { | 200 called_(called) { |
| 201 *called_ = false; | 201 *called_ = false; |
| 202 } | 202 } |
| 203 | 203 |
| 204 void Run(std::unique_ptr<Result> result, | 204 void Run(scoped_refptr<Result> result, |
| 205 std::unique_ptr<ProofSource::Details> /* details */) override { | 205 std::unique_ptr<ProofSource::Details> /* details */) override { |
| 206 { | 206 { |
| 207 // Ensure that the strike register client lock is not held. | 207 // Ensure that the strike register client lock is not held. |
| 208 QuicCryptoServerConfigPeer peer(&test_->config_); | 208 QuicCryptoServerConfigPeer peer(&test_->config_); |
| 209 base::Lock* m = peer.GetStrikeRegisterClientLock(); | 209 base::Lock* m = peer.GetStrikeRegisterClientLock(); |
| 210 // In Chromium, we will dead lock if the lock is held by the current | 210 // In Chromium, we will dead lock if the lock is held by the current |
| 211 // thread. Chromium doesn't have AssertNotHeld API call. | 211 // thread. Chromium doesn't have AssertNotHeld API call. |
| 212 // m->AssertNotHeld(); | 212 // m->AssertNotHeld(); |
| 213 base::AutoLock lock(*m); | 213 base::AutoLock lock(*m); |
| 214 } | 214 } |
| 215 ASSERT_FALSE(*called_); | 215 ASSERT_FALSE(*called_); |
| 216 test_->ProcessValidationResult(*result, should_succeed_, error_substr_); | 216 test_->ProcessValidationResult(std::move(result), should_succeed_, |
| 217 error_substr_); |
| 217 *called_ = true; | 218 *called_ = true; |
| 218 } | 219 } |
| 219 | 220 |
| 220 private: | 221 private: |
| 221 CryptoServerTest* test_; | 222 CryptoServerTest* test_; |
| 222 bool should_succeed_; | 223 const bool should_succeed_; |
| 223 const char* error_substr_; | 224 const char* const error_substr_; |
| 224 bool* called_; | 225 bool* called_; |
| 225 }; | 226 }; |
| 226 | 227 |
| 227 void CheckServerHello(const CryptoHandshakeMessage& server_hello) { | 228 void CheckServerHello(const CryptoHandshakeMessage& server_hello) { |
| 228 const QuicTag* versions; | 229 const QuicTag* versions; |
| 229 size_t num_versions; | 230 size_t num_versions; |
| 230 server_hello.GetTaglist(kVER, &versions, &num_versions); | 231 server_hello.GetTaglist(kVER, &versions, &num_versions); |
| 231 ASSERT_EQ(supported_versions_.size(), num_versions); | 232 ASSERT_EQ(supported_versions_.size(), num_versions); |
| 232 for (size_t i = 0; i < num_versions; ++i) { | 233 for (size_t i = 0; i < num_versions; ++i) { |
| 233 EXPECT_EQ(QuicVersionToQuicTag(supported_versions_[i]), versions[i]); | 234 EXPECT_EQ(QuicVersionToQuicTag(supported_versions_[i]), versions[i]); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 263 const CryptoHandshakeMessage& message, | 264 const CryptoHandshakeMessage& message, |
| 264 bool* called) { | 265 bool* called) { |
| 265 IPAddress server_ip; | 266 IPAddress server_ip; |
| 266 config_.ValidateClientHello( | 267 config_.ValidateClientHello( |
| 267 message, client_address_.address(), server_ip, | 268 message, client_address_.address(), server_ip, |
| 268 supported_versions_.front(), &clock_, &crypto_proof_, | 269 supported_versions_.front(), &clock_, &crypto_proof_, |
| 269 std::unique_ptr<ValidateCallback>( | 270 std::unique_ptr<ValidateCallback>( |
| 270 new ValidateCallback(this, false, error_substr, called))); | 271 new ValidateCallback(this, false, error_substr, called))); |
| 271 } | 272 } |
| 272 | 273 |
| 273 void ProcessValidationResult(const ValidateCallback::Result& result, | 274 void ProcessValidationResult(scoped_refptr<ValidateCallback::Result> result, |
| 274 bool should_succeed, | 275 bool should_succeed, |
| 275 const char* error_substr) { | 276 const char* error_substr) { |
| 276 IPAddress server_ip; | 277 IPAddress server_ip; |
| 277 DiversificationNonce diversification_nonce; | 278 DiversificationNonce diversification_nonce; |
| 278 string error_details; | 279 string error_details; |
| 279 QuicConnectionId server_designated_connection_id = | 280 QuicConnectionId server_designated_connection_id = |
| 280 rand_for_id_generation_.RandUint64(); | 281 rand_for_id_generation_.RandUint64(); |
| 281 QuicErrorCode error = config_.ProcessClientHello( | 282 QuicErrorCode error = config_.ProcessClientHello( |
| 282 result, /*reject_only=*/false, /*connection_id=*/1, server_ip, | 283 result, /*reject_only=*/false, /*connection_id=*/1, server_ip, |
| 283 client_address_, supported_versions_.front(), supported_versions_, | 284 client_address_, supported_versions_.front(), supported_versions_, |
| 284 use_stateless_rejects_, server_designated_connection_id, &clock_, rand_, | 285 use_stateless_rejects_, server_designated_connection_id, &clock_, rand_, |
| 285 &compressed_certs_cache_, ¶ms_, &crypto_proof_, | 286 &compressed_certs_cache_, ¶ms_, &crypto_proof_, |
| 286 /*total_framing_overhead=*/50, chlo_packet_size_, &out_, | 287 /*total_framing_overhead=*/50, chlo_packet_size_, &out_, |
| 287 &diversification_nonce, &error_details); | 288 &diversification_nonce, &error_details); |
| 288 | 289 |
| 289 if (should_succeed) { | 290 if (should_succeed) { |
| 290 ASSERT_EQ(error, QUIC_NO_ERROR) << "Message failed with error " | 291 ASSERT_EQ(error, QUIC_NO_ERROR) << "Message failed with error " |
| 291 << error_details << ": " | 292 << error_details << ": " |
| 292 << result.client_hello.DebugString(); | 293 << result->client_hello.DebugString(); |
| 293 } else { | 294 } else { |
| 294 ASSERT_NE(error, QUIC_NO_ERROR) << "Message didn't fail: " | 295 ASSERT_NE(error, QUIC_NO_ERROR) << "Message didn't fail: " |
| 295 << result.client_hello.DebugString(); | 296 << result->client_hello.DebugString(); |
| 296 | 297 |
| 297 EXPECT_TRUE(error_details.find(error_substr) != string::npos) | 298 EXPECT_TRUE(error_details.find(error_substr) != string::npos) |
| 298 << error_substr << " not in " << error_details; | 299 << error_substr << " not in " << error_details; |
| 299 } | 300 } |
| 300 } | 301 } |
| 301 | 302 |
| 302 string GenerateNonce() { | 303 string GenerateNonce() { |
| 303 string nonce; | 304 string nonce; |
| 304 CryptoUtils::GenerateNonce( | 305 CryptoUtils::GenerateNonce( |
| 305 clock_.WallNow(), rand_, | 306 clock_.WallNow(), rand_, |
| (...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1245 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); | 1246 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); |
| 1246 } else { | 1247 } else { |
| 1247 // version 33. | 1248 // version 33. |
| 1248 ASSERT_EQ(kSHLO, out_.tag()); | 1249 ASSERT_EQ(kSHLO, out_.tag()); |
| 1249 CheckServerHello(out_); | 1250 CheckServerHello(out_); |
| 1250 } | 1251 } |
| 1251 } | 1252 } |
| 1252 | 1253 |
| 1253 } // namespace test | 1254 } // namespace test |
| 1254 } // namespace net | 1255 } // namespace net |
| OLD | NEW |