| 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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 bool* called) | 198 bool* called) |
| 199 : test_(test), | 199 : test_(test), |
| 200 should_succeed_(should_succeed), | 200 should_succeed_(should_succeed), |
| 201 error_substr_(error_substr), | 201 error_substr_(error_substr), |
| 202 called_(called) { | 202 called_(called) { |
| 203 *called_ = false; | 203 *called_ = false; |
| 204 } | 204 } |
| 205 | 205 |
| 206 void Run(scoped_refptr<Result> result, | 206 void Run(scoped_refptr<Result> result, |
| 207 std::unique_ptr<ProofSource::Details> /* details */) override { | 207 std::unique_ptr<ProofSource::Details> /* details */) override { |
| 208 { | |
| 209 // Ensure that the strike register client lock is not held. | |
| 210 QuicCryptoServerConfigPeer peer(&test_->config_); | |
| 211 base::Lock* m = peer.GetStrikeRegisterClientLock(); | |
| 212 // In Chromium, we will dead lock if the lock is held by the current | |
| 213 // thread. Chromium doesn't have AssertNotHeld API call. | |
| 214 // m->AssertNotHeld(); | |
| 215 base::AutoLock lock(*m); | |
| 216 } | |
| 217 ASSERT_FALSE(*called_); | 208 ASSERT_FALSE(*called_); |
| 218 test_->ProcessValidationResult(std::move(result), should_succeed_, | 209 test_->ProcessValidationResult(std::move(result), should_succeed_, |
| 219 error_substr_); | 210 error_substr_); |
| 220 *called_ = true; | 211 *called_ = true; |
| 221 } | 212 } |
| 222 | 213 |
| 223 private: | 214 private: |
| 224 CryptoServerTest* test_; | 215 CryptoServerTest* test_; |
| 225 const bool should_succeed_; | 216 const bool should_succeed_; |
| 226 const char* const error_substr_; | 217 const char* const error_substr_; |
| (...skipping 927 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1154 // clang-format on | 1145 // clang-format on |
| 1155 // If replay protection isn't disabled, then | 1146 // If replay protection isn't disabled, then |
| 1156 // QuicCryptoServerConfig::EvaluateClientHello will leave info.unique as false | 1147 // QuicCryptoServerConfig::EvaluateClientHello will leave info.unique as false |
| 1157 // and cause ProcessClientHello to exit early (and generate a REJ message). | 1148 // and cause ProcessClientHello to exit early (and generate a REJ message). |
| 1158 config_.set_replay_protection(false); | 1149 config_.set_replay_protection(false); |
| 1159 | 1150 |
| 1160 ShouldSucceed(msg); | 1151 ShouldSucceed(msg); |
| 1161 EXPECT_EQ(kSHLO, out_.tag()); | 1152 EXPECT_EQ(kSHLO, out_.tag()); |
| 1162 } | 1153 } |
| 1163 | 1154 |
| 1164 class AsyncStrikeServerVerificationTest : public CryptoServerTest { | |
| 1165 protected: | |
| 1166 AsyncStrikeServerVerificationTest() {} | |
| 1167 | |
| 1168 void SetUp() override { | |
| 1169 const string kOrbit = "12345678"; | |
| 1170 config_options_.orbit = kOrbit; | |
| 1171 strike_register_client_ = new DelayedVerifyStrikeRegisterClient( | |
| 1172 10000, // strike_register_max_entries | |
| 1173 static_cast<uint32_t>(clock_.WallNow().ToUNIXSeconds()), | |
| 1174 60, // strike_register_window_secs | |
| 1175 reinterpret_cast<const uint8_t*>(kOrbit.c_str()), | |
| 1176 StrikeRegister::NO_STARTUP_PERIOD_NEEDED); | |
| 1177 config_.SetStrikeRegisterClient(strike_register_client_); | |
| 1178 ASSERT_NO_FATAL_FAILURE(CryptoServerTest::SetUp()); | |
| 1179 strike_register_client_->StartDelayingVerification(); | |
| 1180 } | |
| 1181 | |
| 1182 DelayedVerifyStrikeRegisterClient* strike_register_client_; | |
| 1183 }; | |
| 1184 | |
| 1185 TEST_P(AsyncStrikeServerVerificationTest, AsyncReplayProtection) { | |
| 1186 // This tests async validation with a strike register works. | |
| 1187 // clang-format off | |
| 1188 CryptoHandshakeMessage msg = CryptoTestUtils::Message( | |
| 1189 "CHLO", | |
| 1190 "PDMD", "X509", | |
| 1191 "AEAD", "AESG", | |
| 1192 "KEXS", "C255", | |
| 1193 "SCID", scid_hex_.c_str(), | |
| 1194 "#004b5453", srct_hex_.c_str(), | |
| 1195 "PUBS", pub_hex_.c_str(), | |
| 1196 "NONC", nonce_hex_.c_str(), | |
| 1197 "VER\0", client_version_string_.c_str(), | |
| 1198 "$padding", static_cast<int>(kClientHelloMinimumSize), | |
| 1199 nullptr); | |
| 1200 // clang-format on | |
| 1201 | |
| 1202 // Clear the message tag. | |
| 1203 out_.set_tag(0); | |
| 1204 | |
| 1205 bool called = false; | |
| 1206 IPAddress server_ip; | |
| 1207 config_.ValidateClientHello( | |
| 1208 msg, client_address_.address(), server_ip, client_version_, &clock_, | |
| 1209 signed_config_, std::unique_ptr<ValidateCallback>( | |
| 1210 new ValidateCallback(this, true, "", &called))); | |
| 1211 // The verification request was queued. | |
| 1212 ASSERT_FALSE(called); | |
| 1213 EXPECT_EQ(0u, out_.tag()); | |
| 1214 EXPECT_EQ(1, strike_register_client_->PendingVerifications()); | |
| 1215 | |
| 1216 // Continue processing the verification request. | |
| 1217 strike_register_client_->RunPendingVerifications(); | |
| 1218 ASSERT_TRUE(called); | |
| 1219 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); | |
| 1220 // The message should be accepted now. | |
| 1221 EXPECT_EQ(kSHLO, out_.tag()); | |
| 1222 | |
| 1223 // Rejected if replayed. | |
| 1224 config_.ValidateClientHello( | |
| 1225 msg, client_address_.address(), server_ip, client_version_, &clock_, | |
| 1226 signed_config_, std::unique_ptr<ValidateCallback>( | |
| 1227 new ValidateCallback(this, true, "", &called))); | |
| 1228 // The verification request was queued. | |
| 1229 ASSERT_FALSE(called); | |
| 1230 EXPECT_EQ(1, strike_register_client_->PendingVerifications()); | |
| 1231 | |
| 1232 strike_register_client_->RunPendingVerifications(); | |
| 1233 ASSERT_TRUE(called); | |
| 1234 EXPECT_EQ(0, strike_register_client_->PendingVerifications()); | |
| 1235 // The message should be rejected now. | |
| 1236 CheckRejectTag(); | |
| 1237 } | |
| 1238 | |
| 1239 TEST_P(AsyncStrikeServerVerificationTest, RequireHandshakeCofirmationPre33) { | |
| 1240 FLAGS_quic_require_handshake_confirmation = false; | |
| 1241 FLAGS_quic_require_handshake_confirmation_pre33 = true; | |
| 1242 // clang-format off | |
| 1243 CryptoHandshakeMessage msg = CryptoTestUtils::Message( | |
| 1244 "CHLO", | |
| 1245 "PDMD", "X509", | |
| 1246 "AEAD", "AESG", | |
| 1247 "KEXS", "C255", | |
| 1248 "SNI", "foobar1.example.com", | |
| 1249 "SCID", scid_hex_.c_str(), | |
| 1250 "#004b5453", srct_hex_.c_str(), | |
| 1251 "PUBS", pub_hex_.c_str(), | |
| 1252 "NONC", nonce_hex_.c_str(), | |
| 1253 "VER\0", client_version_string_.c_str(), | |
| 1254 "XLCT", XlctHexString().c_str(), | |
| 1255 "$padding", static_cast<int>(kClientHelloMinimumSize), | |
| 1256 nullptr); | |
| 1257 // clang-format on | |
| 1258 | |
| 1259 ShouldSucceed(msg); | |
| 1260 | |
| 1261 ASSERT_EQ(kSHLO, out_.tag()); | |
| 1262 CheckServerHello(out_); | |
| 1263 } | |
| 1264 | |
| 1265 } // namespace test | 1155 } // namespace test |
| 1266 } // namespace net | 1156 } // namespace net |
| OLD | NEW |