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 RunImpl(const CryptoHandshakeMessage& client_hello, | 204 void Run(std::unique_ptr<Result> result, |
205 const Result& result, | 205 std::unique_ptr<ProofSource::Details> /* details */) override { |
206 std::unique_ptr<ProofSource::Details> /* details */) override { | |
207 { | 206 { |
208 // Ensure that the strike register client lock is not held. | 207 // Ensure that the strike register client lock is not held. |
209 QuicCryptoServerConfigPeer peer(&test_->config_); | 208 QuicCryptoServerConfigPeer peer(&test_->config_); |
210 base::Lock* m = peer.GetStrikeRegisterClientLock(); | 209 base::Lock* m = peer.GetStrikeRegisterClientLock(); |
211 // 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 |
212 // thread. Chromium doesn't have AssertNotHeld API call. | 211 // thread. Chromium doesn't have AssertNotHeld API call. |
213 // m->AssertNotHeld(); | 212 // m->AssertNotHeld(); |
214 base::AutoLock lock(*m); | 213 base::AutoLock lock(*m); |
215 } | 214 } |
216 ASSERT_FALSE(*called_); | 215 ASSERT_FALSE(*called_); |
217 test_->ProcessValidationResult(client_hello, result, should_succeed_, | 216 test_->ProcessValidationResult(*result, should_succeed_, error_substr_); |
218 error_substr_); | |
219 *called_ = true; | 217 *called_ = true; |
220 } | 218 } |
221 | 219 |
222 private: | 220 private: |
223 CryptoServerTest* test_; | 221 CryptoServerTest* test_; |
224 bool should_succeed_; | 222 bool should_succeed_; |
225 const char* error_substr_; | 223 const char* error_substr_; |
226 bool* called_; | 224 bool* called_; |
227 }; | 225 }; |
228 | 226 |
(...skipping 10 matching lines...) Expand all Loading... |
239 ASSERT_TRUE(server_hello.GetStringPiece(kCADR, &address)); | 237 ASSERT_TRUE(server_hello.GetStringPiece(kCADR, &address)); |
240 QuicSocketAddressCoder decoder; | 238 QuicSocketAddressCoder decoder; |
241 ASSERT_TRUE(decoder.Decode(address.data(), address.size())); | 239 ASSERT_TRUE(decoder.Decode(address.data(), address.size())); |
242 EXPECT_EQ(client_address_.address(), decoder.ip()); | 240 EXPECT_EQ(client_address_.address(), decoder.ip()); |
243 EXPECT_EQ(client_address_.port(), decoder.port()); | 241 EXPECT_EQ(client_address_.port(), decoder.port()); |
244 } | 242 } |
245 | 243 |
246 void ShouldSucceed(const CryptoHandshakeMessage& message) { | 244 void ShouldSucceed(const CryptoHandshakeMessage& message) { |
247 bool called = false; | 245 bool called = false; |
248 IPAddress server_ip; | 246 IPAddress server_ip; |
249 config_.ValidateClientHello(message, client_address_.address(), server_ip, | 247 config_.ValidateClientHello( |
250 supported_versions_.front(), &clock_, | 248 message, client_address_.address(), server_ip, |
251 &crypto_proof_, | 249 supported_versions_.front(), &clock_, &crypto_proof_, |
252 new ValidateCallback(this, true, "", &called)); | 250 std::unique_ptr<ValidateCallback>( |
| 251 new ValidateCallback(this, true, "", &called))); |
253 EXPECT_TRUE(called); | 252 EXPECT_TRUE(called); |
254 } | 253 } |
255 | 254 |
256 void ShouldFailMentioning(const char* error_substr, | 255 void ShouldFailMentioning(const char* error_substr, |
257 const CryptoHandshakeMessage& message) { | 256 const CryptoHandshakeMessage& message) { |
258 bool called = false; | 257 bool called = false; |
259 ShouldFailMentioning(error_substr, message, &called); | 258 ShouldFailMentioning(error_substr, message, &called); |
260 EXPECT_TRUE(called); | 259 EXPECT_TRUE(called); |
261 } | 260 } |
262 | 261 |
263 void ShouldFailMentioning(const char* error_substr, | 262 void ShouldFailMentioning(const char* error_substr, |
264 const CryptoHandshakeMessage& message, | 263 const CryptoHandshakeMessage& message, |
265 bool* called) { | 264 bool* called) { |
266 IPAddress server_ip; | 265 IPAddress server_ip; |
267 config_.ValidateClientHello( | 266 config_.ValidateClientHello( |
268 message, client_address_.address(), server_ip, | 267 message, client_address_.address(), server_ip, |
269 supported_versions_.front(), &clock_, &crypto_proof_, | 268 supported_versions_.front(), &clock_, &crypto_proof_, |
270 new ValidateCallback(this, false, error_substr, called)); | 269 std::unique_ptr<ValidateCallback>( |
| 270 new ValidateCallback(this, false, error_substr, called))); |
271 } | 271 } |
272 | 272 |
273 void ProcessValidationResult(const CryptoHandshakeMessage& message, | 273 void ProcessValidationResult(const ValidateCallback::Result& result, |
274 const ValidateCallback::Result& result, | |
275 bool should_succeed, | 274 bool should_succeed, |
276 const char* error_substr) { | 275 const char* error_substr) { |
277 IPAddress server_ip; | 276 IPAddress server_ip; |
278 DiversificationNonce diversification_nonce; | 277 DiversificationNonce diversification_nonce; |
279 string error_details; | 278 string error_details; |
280 QuicConnectionId server_designated_connection_id = | 279 QuicConnectionId server_designated_connection_id = |
281 rand_for_id_generation_.RandUint64(); | 280 rand_for_id_generation_.RandUint64(); |
282 QuicErrorCode error = config_.ProcessClientHello( | 281 QuicErrorCode error = config_.ProcessClientHello( |
283 result, /*reject_only=*/false, /*connection_id=*/1, server_ip, | 282 result, /*reject_only=*/false, /*connection_id=*/1, server_ip, |
284 client_address_, supported_versions_.front(), supported_versions_, | 283 client_address_, supported_versions_.front(), supported_versions_, |
285 use_stateless_rejects_, server_designated_connection_id, &clock_, rand_, | 284 use_stateless_rejects_, server_designated_connection_id, &clock_, rand_, |
286 &compressed_certs_cache_, ¶ms_, &crypto_proof_, | 285 &compressed_certs_cache_, ¶ms_, &crypto_proof_, |
287 /*total_framing_overhead=*/50, chlo_packet_size_, &out_, | 286 /*total_framing_overhead=*/50, chlo_packet_size_, &out_, |
288 &diversification_nonce, &error_details); | 287 &diversification_nonce, &error_details); |
289 | 288 |
290 if (should_succeed) { | 289 if (should_succeed) { |
291 ASSERT_EQ(error, QUIC_NO_ERROR) << "Message failed with error " | 290 ASSERT_EQ(error, QUIC_NO_ERROR) << "Message failed with error " |
292 << error_details << ": " | 291 << error_details << ": " |
293 << message.DebugString(); | 292 << result.client_hello.DebugString(); |
294 } else { | 293 } else { |
295 ASSERT_NE(error, QUIC_NO_ERROR) << "Message didn't fail: " | 294 ASSERT_NE(error, QUIC_NO_ERROR) << "Message didn't fail: " |
296 << message.DebugString(); | 295 << result.client_hello.DebugString(); |
297 | 296 |
298 EXPECT_TRUE(error_details.find(error_substr) != string::npos) | 297 EXPECT_TRUE(error_details.find(error_substr) != string::npos) |
299 << error_substr << " not in " << error_details; | 298 << error_substr << " not in " << error_details; |
300 } | 299 } |
301 } | 300 } |
302 | 301 |
303 string GenerateNonce() { | 302 string GenerateNonce() { |
304 string nonce; | 303 string nonce; |
305 CryptoUtils::GenerateNonce( | 304 CryptoUtils::GenerateNonce( |
306 clock_.WallNow(), rand_, | 305 clock_.WallNow(), rand_, |
(...skipping 868 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1175 "VER\0", client_version_string_.c_str(), | 1174 "VER\0", client_version_string_.c_str(), |
1176 "$padding", static_cast<int>(kClientHelloMinimumSize), | 1175 "$padding", static_cast<int>(kClientHelloMinimumSize), |
1177 nullptr); | 1176 nullptr); |
1178 // clang-format on | 1177 // clang-format on |
1179 | 1178 |
1180 // Clear the message tag. | 1179 // Clear the message tag. |
1181 out_.set_tag(0); | 1180 out_.set_tag(0); |
1182 | 1181 |
1183 bool called = false; | 1182 bool called = false; |
1184 IPAddress server_ip; | 1183 IPAddress server_ip; |
1185 config_.ValidateClientHello(msg, client_address_.address(), server_ip, | 1184 config_.ValidateClientHello( |
1186 client_version_, &clock_, &crypto_proof_, | 1185 msg, client_address_.address(), server_ip, client_version_, &clock_, |
1187 new ValidateCallback(this, true, "", &called)); | 1186 &crypto_proof_, std::unique_ptr<ValidateCallback>( |
| 1187 new ValidateCallback(this, true, "", &called))); |
1188 // The verification request was queued. | 1188 // The verification request was queued. |
1189 ASSERT_FALSE(called); | 1189 ASSERT_FALSE(called); |
1190 EXPECT_EQ(0u, out_.tag()); | 1190 EXPECT_EQ(0u, out_.tag()); |
1191 EXPECT_EQ(1, strike_register_client_->PendingVerifications()); | 1191 EXPECT_EQ(1, strike_register_client_->PendingVerifications()); |
1192 | 1192 |
1193 // Continue processing the verification request. | 1193 // Continue processing the verification request. |
1194 strike_register_client_->RunPendingVerifications(); | 1194 strike_register_client_->RunPendingVerifications(); |
1195 ASSERT_TRUE(called); | 1195 ASSERT_TRUE(called); |
1196 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); | 1196 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); |
1197 // The message should be accepted now. | 1197 // The message should be accepted now. |
1198 EXPECT_EQ(kSHLO, out_.tag()); | 1198 EXPECT_EQ(kSHLO, out_.tag()); |
1199 | 1199 |
1200 // Rejected if replayed. | 1200 // Rejected if replayed. |
1201 config_.ValidateClientHello(msg, client_address_.address(), server_ip, | 1201 config_.ValidateClientHello( |
1202 client_version_, &clock_, &crypto_proof_, | 1202 msg, client_address_.address(), server_ip, client_version_, &clock_, |
1203 new ValidateCallback(this, true, "", &called)); | 1203 &crypto_proof_, std::unique_ptr<ValidateCallback>( |
| 1204 new ValidateCallback(this, true, "", &called))); |
1204 // The verification request was queued. | 1205 // The verification request was queued. |
1205 ASSERT_FALSE(called); | 1206 ASSERT_FALSE(called); |
1206 EXPECT_EQ(1, strike_register_client_->PendingVerifications()); | 1207 EXPECT_EQ(1, strike_register_client_->PendingVerifications()); |
1207 | 1208 |
1208 strike_register_client_->RunPendingVerifications(); | 1209 strike_register_client_->RunPendingVerifications(); |
1209 ASSERT_TRUE(called); | 1210 ASSERT_TRUE(called); |
1210 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); | 1211 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); |
1211 // The message should be rejected now. | 1212 // The message should be rejected now. |
1212 CheckRejectTag(); | 1213 CheckRejectTag(); |
1213 } | 1214 } |
(...skipping 30 matching lines...) Expand all Loading... |
1244 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); | 1245 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); |
1245 } else { | 1246 } else { |
1246 // version 33. | 1247 // version 33. |
1247 ASSERT_EQ(kSHLO, out_.tag()); | 1248 ASSERT_EQ(kSHLO, out_.tag()); |
1248 CheckServerHello(out_); | 1249 CheckServerHello(out_); |
1249 } | 1250 } |
1250 } | 1251 } |
1251 | 1252 |
1252 } // namespace test | 1253 } // namespace test |
1253 } // namespace net | 1254 } // namespace net |
OLD | NEW |