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(std::unique_ptr<Result> result, | 204 void Run(std::unique_ptr<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_); |
(...skipping 24 matching lines...) Expand all Loading... | |
240 EXPECT_EQ(client_address_.address(), decoder.ip()); | 240 EXPECT_EQ(client_address_.address(), decoder.ip()); |
241 EXPECT_EQ(client_address_.port(), decoder.port()); | 241 EXPECT_EQ(client_address_.port(), decoder.port()); |
242 } | 242 } |
243 | 243 |
244 void ShouldSucceed(const CryptoHandshakeMessage& message) { | 244 void ShouldSucceed(const CryptoHandshakeMessage& message) { |
245 bool called = false; | 245 bool called = false; |
246 IPAddress server_ip; | 246 IPAddress server_ip; |
247 config_.ValidateClientHello(message, client_address_.address(), server_ip, | 247 config_.ValidateClientHello(message, client_address_.address(), server_ip, |
248 supported_versions_.front(), &clock_, | 248 supported_versions_.front(), &clock_, |
249 &crypto_proof_, | 249 &crypto_proof_, |
250 new ValidateCallback(this, true, "", &called)); | 250 std::unique_ptr<ValidateCallback>( |
251 new ValidateCallback(this, true, "", &called))); | |
251 EXPECT_TRUE(called); | 252 EXPECT_TRUE(called); |
252 } | 253 } |
253 | 254 |
254 void ShouldFailMentioning(const char* error_substr, | 255 void ShouldFailMentioning(const char* error_substr, |
255 const CryptoHandshakeMessage& message) { | 256 const CryptoHandshakeMessage& message) { |
256 bool called = false; | 257 bool called = false; |
257 ShouldFailMentioning(error_substr, message, &called); | 258 ShouldFailMentioning(error_substr, message, &called); |
258 EXPECT_TRUE(called); | 259 EXPECT_TRUE(called); |
259 } | 260 } |
260 | 261 |
261 void ShouldFailMentioning(const char* error_substr, | 262 void ShouldFailMentioning(const char* error_substr, |
262 const CryptoHandshakeMessage& message, | 263 const CryptoHandshakeMessage& message, |
263 bool* called) { | 264 bool* called) { |
264 IPAddress server_ip; | 265 IPAddress server_ip; |
265 config_.ValidateClientHello( | 266 config_.ValidateClientHello( |
266 message, client_address_.address(), server_ip, | 267 message, client_address_.address(), server_ip, |
267 supported_versions_.front(), &clock_, &crypto_proof_, | 268 supported_versions_.front(), &clock_, &crypto_proof_, |
268 new ValidateCallback(this, false, error_substr, called)); | 269 std::unique_ptr<ValidateCallback>( |
270 new ValidateCallback(this, false, error_substr, called))); | |
269 } | 271 } |
270 | 272 |
271 void ProcessValidationResult(const ValidateCallback::Result& result, | 273 void ProcessValidationResult(const ValidateCallback::Result& result, |
272 bool should_succeed, | 274 bool should_succeed, |
273 const char* error_substr) { | 275 const char* error_substr) { |
274 IPAddress server_ip; | 276 IPAddress server_ip; |
275 DiversificationNonce diversification_nonce; | 277 DiversificationNonce diversification_nonce; |
276 string error_details; | 278 string error_details; |
277 QuicConnectionId server_designated_connection_id = | 279 QuicConnectionId server_designated_connection_id = |
278 rand_for_id_generation_.RandUint64(); | 280 rand_for_id_generation_.RandUint64(); |
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1146 strike_register_client_ = new DelayedVerifyStrikeRegisterClient( | 1148 strike_register_client_ = new DelayedVerifyStrikeRegisterClient( |
1147 10000, // strike_register_max_entries | 1149 10000, // strike_register_max_entries |
1148 static_cast<uint32_t>(clock_.WallNow().ToUNIXSeconds()), | 1150 static_cast<uint32_t>(clock_.WallNow().ToUNIXSeconds()), |
1149 60, // strike_register_window_secs | 1151 60, // strike_register_window_secs |
1150 reinterpret_cast<const uint8_t*>(kOrbit.c_str()), | 1152 reinterpret_cast<const uint8_t*>(kOrbit.c_str()), |
1151 StrikeRegister::NO_STARTUP_PERIOD_NEEDED); | 1153 StrikeRegister::NO_STARTUP_PERIOD_NEEDED); |
1152 config_.SetStrikeRegisterClient(strike_register_client_); | 1154 config_.SetStrikeRegisterClient(strike_register_client_); |
1153 ASSERT_NO_FATAL_FAILURE(CryptoServerTest::SetUp()); | 1155 ASSERT_NO_FATAL_FAILURE(CryptoServerTest::SetUp()); |
1154 strike_register_client_->StartDelayingVerification(); | 1156 strike_register_client_->StartDelayingVerification(); |
1155 } | 1157 } |
1156 | 1158 |
Zhongyi Shi
2016/09/13 21:13:21
This code seems out of sync with internal. ShouldQ
Ryan Hamilton
2016/09/13 21:26:04
Yeah, I noticed that too! No follow-up==bad!
Than
| |
1157 DelayedVerifyStrikeRegisterClient* strike_register_client_; | 1159 DelayedVerifyStrikeRegisterClient* strike_register_client_; |
1158 }; | 1160 }; |
1159 | 1161 |
1160 TEST_P(AsyncStrikeServerVerificationTest, AsyncReplayProtection) { | 1162 TEST_P(AsyncStrikeServerVerificationTest, AsyncReplayProtection) { |
1161 // This tests async validation with a strike register works. | 1163 // This tests async validation with a strike register works. |
1162 // clang-format off | 1164 // clang-format off |
1163 CryptoHandshakeMessage msg = CryptoTestUtils::Message( | 1165 CryptoHandshakeMessage msg = CryptoTestUtils::Message( |
1164 "CHLO", | 1166 "CHLO", |
1165 "PDMD", "X509", | 1167 "PDMD", "X509", |
1166 "AEAD", "AESG", | 1168 "AEAD", "AESG", |
1167 "KEXS", "C255", | 1169 "KEXS", "C255", |
1168 "SCID", scid_hex_.c_str(), | 1170 "SCID", scid_hex_.c_str(), |
1169 "#004b5453", srct_hex_.c_str(), | 1171 "#004b5453", srct_hex_.c_str(), |
1170 "PUBS", pub_hex_.c_str(), | 1172 "PUBS", pub_hex_.c_str(), |
1171 "NONC", nonce_hex_.c_str(), | 1173 "NONC", nonce_hex_.c_str(), |
1172 "VER\0", client_version_string_.c_str(), | 1174 "VER\0", client_version_string_.c_str(), |
1173 "$padding", static_cast<int>(kClientHelloMinimumSize), | 1175 "$padding", static_cast<int>(kClientHelloMinimumSize), |
1174 nullptr); | 1176 nullptr); |
1175 // clang-format on | 1177 // clang-format on |
1176 | 1178 |
1177 // Clear the message tag. | 1179 // Clear the message tag. |
1178 out_.set_tag(0); | 1180 out_.set_tag(0); |
1179 | 1181 |
1180 bool called = false; | 1182 bool called = false; |
1181 IPAddress server_ip; | 1183 IPAddress server_ip; |
1182 config_.ValidateClientHello(msg, client_address_.address(), server_ip, | 1184 config_.ValidateClientHello(msg, client_address_.address(), server_ip, |
1183 client_version_, &clock_, &crypto_proof_, | 1185 client_version_, &clock_, &crypto_proof_, |
1184 new ValidateCallback(this, true, "", &called)); | 1186 std::unique_ptr<ValidateCallback>( |
1187 new ValidateCallback(this, true, "", &called))); | |
1185 // The verification request was queued. | 1188 // The verification request was queued. |
1186 ASSERT_FALSE(called); | 1189 ASSERT_FALSE(called); |
1187 EXPECT_EQ(0u, out_.tag()); | 1190 EXPECT_EQ(0u, out_.tag()); |
1188 EXPECT_EQ(1, strike_register_client_->PendingVerifications()); | 1191 EXPECT_EQ(1, strike_register_client_->PendingVerifications()); |
1189 | 1192 |
1190 // Continue processing the verification request. | 1193 // Continue processing the verification request. |
1191 strike_register_client_->RunPendingVerifications(); | 1194 strike_register_client_->RunPendingVerifications(); |
1192 ASSERT_TRUE(called); | 1195 ASSERT_TRUE(called); |
1193 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); | 1196 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); |
1194 // The message should be accepted now. | 1197 // The message should be accepted now. |
1195 EXPECT_EQ(kSHLO, out_.tag()); | 1198 EXPECT_EQ(kSHLO, out_.tag()); |
1196 | 1199 |
1197 // Rejected if replayed. | 1200 // Rejected if replayed. |
1198 config_.ValidateClientHello(msg, client_address_.address(), server_ip, | 1201 config_.ValidateClientHello(msg, client_address_.address(), server_ip, |
1199 client_version_, &clock_, &crypto_proof_, | 1202 client_version_, &clock_, &crypto_proof_, |
1200 new ValidateCallback(this, true, "", &called)); | 1203 std::unique_ptr<ValidateCallback>( |
1204 new ValidateCallback(this, true, "", &called)) ); | |
1201 // The verification request was queued. | 1205 // The verification request was queued. |
1202 ASSERT_FALSE(called); | 1206 ASSERT_FALSE(called); |
1203 EXPECT_EQ(1, strike_register_client_->PendingVerifications()); | 1207 EXPECT_EQ(1, strike_register_client_->PendingVerifications()); |
1204 | 1208 |
1205 strike_register_client_->RunPendingVerifications(); | 1209 strike_register_client_->RunPendingVerifications(); |
1206 ASSERT_TRUE(called); | 1210 ASSERT_TRUE(called); |
1207 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); | 1211 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); |
1208 // The message should be rejected now. | 1212 // The message should be rejected now. |
1209 CheckRejectTag(); | 1213 CheckRejectTag(); |
1210 } | 1214 } |
(...skipping 30 matching lines...) Expand all Loading... | |
1241 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); | 1245 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); |
1242 } else { | 1246 } else { |
1243 // version 33. | 1247 // version 33. |
1244 ASSERT_EQ(kSHLO, out_.tag()); | 1248 ASSERT_EQ(kSHLO, out_.tag()); |
1245 CheckServerHello(out_); | 1249 CheckServerHello(out_); |
1246 } | 1250 } |
1247 } | 1251 } |
1248 | 1252 |
1249 } // namespace test | 1253 } // namespace test |
1250 } // namespace net | 1254 } // namespace net |
OLD | NEW |