| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "net/quic/crypto/quic_crypto_client_config.h" | 5 #include "net/quic/crypto/quic_crypto_client_config.h" |
| 6 | 6 |
| 7 #include "net/quic/crypto/proof_verifier.h" | 7 #include "net/quic/crypto/proof_verifier.h" |
| 8 #include "net/quic/quic_server_id.h" | 8 #include "net/quic/quic_server_id.h" |
| 9 #include "net/quic/test_tools/crypto_test_utils.h" | 9 #include "net/quic/test_tools/crypto_test_utils.h" |
| 10 #include "net/quic/test_tools/mock_random.h" | 10 #include "net/quic/test_tools/mock_random.h" |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 EXPECT_EQ(1u, other.generation_counter()); | 148 EXPECT_EQ(1u, other.generation_counter()); |
| 149 EXPECT_FALSE(state.has_server_designated_connection_id()); | 149 EXPECT_FALSE(state.has_server_designated_connection_id()); |
| 150 EXPECT_FALSE(state.has_server_nonce()); | 150 EXPECT_FALSE(state.has_server_nonce()); |
| 151 } | 151 } |
| 152 | 152 |
| 153 TEST(QuicCryptoClientConfigTest, InchoateChlo) { | 153 TEST(QuicCryptoClientConfigTest, InchoateChlo) { |
| 154 QuicCryptoClientConfig::CachedState state; | 154 QuicCryptoClientConfig::CachedState state; |
| 155 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); | 155 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); |
| 156 QuicCryptoNegotiatedParameters params; | 156 QuicCryptoNegotiatedParameters params; |
| 157 CryptoHandshakeMessage msg; | 157 CryptoHandshakeMessage msg; |
| 158 QuicServerId server_id("www.google.com", 80, PRIVACY_MODE_DISABLED); | 158 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED); |
| 159 MockRandom rand; | 159 MockRandom rand; |
| 160 config.FillInchoateClientHello(server_id, QuicVersionMax(), &state, &rand, | 160 config.FillInchoateClientHello(server_id, QuicVersionMax(), &state, &rand, |
| 161 ¶ms, &msg); | 161 ¶ms, &msg); |
| 162 | 162 |
| 163 QuicTag cver; | 163 QuicTag cver; |
| 164 EXPECT_EQ(QUIC_NO_ERROR, msg.GetUint32(kVER, &cver)); | 164 EXPECT_EQ(QUIC_NO_ERROR, msg.GetUint32(kVER, &cver)); |
| 165 EXPECT_EQ(QuicVersionToQuicTag(QuicVersionMax()), cver); | 165 EXPECT_EQ(QuicVersionToQuicTag(QuicVersionMax()), cver); |
| 166 StringPiece proof_nonce; | 166 StringPiece proof_nonce; |
| 167 EXPECT_TRUE(msg.GetStringPiece(kNONP, &proof_nonce)); | 167 EXPECT_TRUE(msg.GetStringPiece(kNONP, &proof_nonce)); |
| 168 EXPECT_EQ(string(32, 'r'), proof_nonce); | 168 EXPECT_EQ(string(32, 'r'), proof_nonce); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 } | 234 } |
| 235 | 235 |
| 236 TEST(QuicCryptoClientConfigTest, FillClientHello) { | 236 TEST(QuicCryptoClientConfigTest, FillClientHello) { |
| 237 QuicCryptoClientConfig::CachedState state; | 237 QuicCryptoClientConfig::CachedState state; |
| 238 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); | 238 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); |
| 239 QuicCryptoNegotiatedParameters params; | 239 QuicCryptoNegotiatedParameters params; |
| 240 QuicConnectionId kConnectionId = 1234; | 240 QuicConnectionId kConnectionId = 1234; |
| 241 string error_details; | 241 string error_details; |
| 242 MockRandom rand; | 242 MockRandom rand; |
| 243 CryptoHandshakeMessage chlo; | 243 CryptoHandshakeMessage chlo; |
| 244 QuicServerId server_id("www.google.com", 80, PRIVACY_MODE_DISABLED); | 244 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED); |
| 245 config.FillClientHello(server_id, kConnectionId, QuicVersionMax(), &state, | 245 config.FillClientHello(server_id, kConnectionId, QuicVersionMax(), &state, |
| 246 QuicWallTime::Zero(), &rand, | 246 QuicWallTime::Zero(), &rand, |
| 247 nullptr, // channel_id_key | 247 nullptr, // channel_id_key |
| 248 ¶ms, &chlo, &error_details); | 248 ¶ms, &chlo, &error_details); |
| 249 | 249 |
| 250 // Verify that certain QuicTags have been set correctly in the CHLO. | 250 // Verify that certain QuicTags have been set correctly in the CHLO. |
| 251 QuicTag cver; | 251 QuicTag cver; |
| 252 EXPECT_EQ(QUIC_NO_ERROR, chlo.GetUint32(kVER, &cver)); | 252 EXPECT_EQ(QUIC_NO_ERROR, chlo.GetUint32(kVER, &cver)); |
| 253 EXPECT_EQ(QuicVersionToQuicTag(QuicVersionMax()), cver); | 253 EXPECT_EQ(QuicVersionToQuicTag(QuicVersionMax()), cver); |
| 254 } | 254 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 274 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); | 274 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); |
| 275 EXPECT_EQ(QUIC_VERSION_NEGOTIATION_MISMATCH, | 275 EXPECT_EQ(QUIC_VERSION_NEGOTIATION_MISMATCH, |
| 276 config.ProcessServerHello(msg, 0, supported_versions.front(), | 276 config.ProcessServerHello(msg, 0, supported_versions.front(), |
| 277 supported_versions, &cached, &out_params, | 277 supported_versions, &cached, &out_params, |
| 278 &error)); | 278 &error)); |
| 279 EXPECT_EQ("Downgrade attack detected", error); | 279 EXPECT_EQ("Downgrade attack detected", error); |
| 280 } | 280 } |
| 281 | 281 |
| 282 TEST(QuicCryptoClientConfigTest, InitializeFrom) { | 282 TEST(QuicCryptoClientConfigTest, InitializeFrom) { |
| 283 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); | 283 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); |
| 284 QuicServerId canonical_server_id("www.google.com", 80, PRIVACY_MODE_DISABLED); | 284 QuicServerId canonical_server_id("www.google.com", 443, |
| 285 PRIVACY_MODE_DISABLED); |
| 285 QuicCryptoClientConfig::CachedState* state = | 286 QuicCryptoClientConfig::CachedState* state = |
| 286 config.LookupOrCreate(canonical_server_id); | 287 config.LookupOrCreate(canonical_server_id); |
| 287 // TODO(rch): Populate other fields of |state|. | 288 // TODO(rch): Populate other fields of |state|. |
| 288 state->set_source_address_token("TOKEN"); | 289 state->set_source_address_token("TOKEN"); |
| 289 state->SetProofValid(); | 290 state->SetProofValid(); |
| 290 | 291 |
| 291 QuicServerId other_server_id("mail.google.com", 80, PRIVACY_MODE_DISABLED); | 292 QuicServerId other_server_id("mail.google.com", 443, PRIVACY_MODE_DISABLED); |
| 292 config.InitializeFrom(other_server_id, canonical_server_id, &config); | 293 config.InitializeFrom(other_server_id, canonical_server_id, &config); |
| 293 QuicCryptoClientConfig::CachedState* other = | 294 QuicCryptoClientConfig::CachedState* other = |
| 294 config.LookupOrCreate(other_server_id); | 295 config.LookupOrCreate(other_server_id); |
| 295 | 296 |
| 296 EXPECT_EQ(state->server_config(), other->server_config()); | 297 EXPECT_EQ(state->server_config(), other->server_config()); |
| 297 EXPECT_EQ(state->source_address_token(), other->source_address_token()); | 298 EXPECT_EQ(state->source_address_token(), other->source_address_token()); |
| 298 EXPECT_EQ(state->certs(), other->certs()); | 299 EXPECT_EQ(state->certs(), other->certs()); |
| 299 EXPECT_EQ(1u, other->generation_counter()); | 300 EXPECT_EQ(1u, other->generation_counter()); |
| 300 } | 301 } |
| 301 | 302 |
| 302 TEST(QuicCryptoClientConfigTest, Canonical) { | 303 TEST(QuicCryptoClientConfigTest, Canonical) { |
| 303 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); | 304 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); |
| 304 config.AddCanonicalSuffix(".google.com"); | 305 config.AddCanonicalSuffix(".google.com"); |
| 305 QuicServerId canonical_id1("www.google.com", 80, PRIVACY_MODE_DISABLED); | 306 QuicServerId canonical_id1("www.google.com", 443, PRIVACY_MODE_DISABLED); |
| 306 QuicServerId canonical_id2("mail.google.com", 80, PRIVACY_MODE_DISABLED); | 307 QuicServerId canonical_id2("mail.google.com", 443, PRIVACY_MODE_DISABLED); |
| 307 QuicCryptoClientConfig::CachedState* state = | 308 QuicCryptoClientConfig::CachedState* state = |
| 308 config.LookupOrCreate(canonical_id1); | 309 config.LookupOrCreate(canonical_id1); |
| 309 // TODO(rch): Populate other fields of |state|. | 310 // TODO(rch): Populate other fields of |state|. |
| 310 state->set_source_address_token("TOKEN"); | 311 state->set_source_address_token("TOKEN"); |
| 311 state->SetProofValid(); | 312 state->SetProofValid(); |
| 312 | 313 |
| 313 QuicCryptoClientConfig::CachedState* other = | 314 QuicCryptoClientConfig::CachedState* other = |
| 314 config.LookupOrCreate(canonical_id2); | 315 config.LookupOrCreate(canonical_id2); |
| 315 | 316 |
| 316 EXPECT_TRUE(state->IsEmpty()); | 317 EXPECT_TRUE(state->IsEmpty()); |
| 317 EXPECT_EQ(state->server_config(), other->server_config()); | 318 EXPECT_EQ(state->server_config(), other->server_config()); |
| 318 EXPECT_EQ(state->source_address_token(), other->source_address_token()); | 319 EXPECT_EQ(state->source_address_token(), other->source_address_token()); |
| 319 EXPECT_EQ(state->certs(), other->certs()); | 320 EXPECT_EQ(state->certs(), other->certs()); |
| 320 EXPECT_EQ(1u, other->generation_counter()); | 321 EXPECT_EQ(1u, other->generation_counter()); |
| 321 | 322 |
| 322 QuicServerId different_id("mail.google.org", 80, PRIVACY_MODE_DISABLED); | 323 QuicServerId different_id("mail.google.org", 443, PRIVACY_MODE_DISABLED); |
| 323 EXPECT_TRUE(config.LookupOrCreate(different_id)->IsEmpty()); | 324 EXPECT_TRUE(config.LookupOrCreate(different_id)->IsEmpty()); |
| 324 } | 325 } |
| 325 | 326 |
| 326 TEST(QuicCryptoClientConfigTest, CanonicalNotUsedIfNotValid) { | 327 TEST(QuicCryptoClientConfigTest, CanonicalNotUsedIfNotValid) { |
| 327 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); | 328 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); |
| 328 config.AddCanonicalSuffix(".google.com"); | 329 config.AddCanonicalSuffix(".google.com"); |
| 329 QuicServerId canonical_id1("www.google.com", 80, PRIVACY_MODE_DISABLED); | 330 QuicServerId canonical_id1("www.google.com", 443, PRIVACY_MODE_DISABLED); |
| 330 QuicServerId canonical_id2("mail.google.com", 80, PRIVACY_MODE_DISABLED); | 331 QuicServerId canonical_id2("mail.google.com", 443, PRIVACY_MODE_DISABLED); |
| 331 QuicCryptoClientConfig::CachedState* state = | 332 QuicCryptoClientConfig::CachedState* state = |
| 332 config.LookupOrCreate(canonical_id1); | 333 config.LookupOrCreate(canonical_id1); |
| 333 // TODO(rch): Populate other fields of |state|. | 334 // TODO(rch): Populate other fields of |state|. |
| 334 state->set_source_address_token("TOKEN"); | 335 state->set_source_address_token("TOKEN"); |
| 335 | 336 |
| 336 // Do not set the proof as valid, and check that it is not used | 337 // Do not set the proof as valid, and check that it is not used |
| 337 // as a canonical entry. | 338 // as a canonical entry. |
| 338 EXPECT_TRUE(config.LookupOrCreate(canonical_id2)->IsEmpty()); | 339 EXPECT_TRUE(config.LookupOrCreate(canonical_id2)->IsEmpty()); |
| 339 } | 340 } |
| 340 | 341 |
| 341 TEST(QuicCryptoClientConfigTest, ClearCachedStates) { | 342 TEST(QuicCryptoClientConfigTest, ClearCachedStates) { |
| 342 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); | 343 QuicCryptoClientConfig config(CryptoTestUtils::ProofVerifierForTesting()); |
| 343 QuicServerId server_id("www.google.com", 80, PRIVACY_MODE_DISABLED); | 344 QuicServerId server_id("www.google.com", 443, PRIVACY_MODE_DISABLED); |
| 344 QuicCryptoClientConfig::CachedState* state = config.LookupOrCreate(server_id); | 345 QuicCryptoClientConfig::CachedState* state = config.LookupOrCreate(server_id); |
| 345 // TODO(rch): Populate other fields of |state|. | 346 // TODO(rch): Populate other fields of |state|. |
| 346 vector<string> certs(1); | 347 vector<string> certs(1); |
| 347 certs[0] = "Hello Cert"; | 348 certs[0] = "Hello Cert"; |
| 348 state->SetProof(certs, "cert_sct", "chlo_hash", "signature"); | 349 state->SetProof(certs, "cert_sct", "chlo_hash", "signature"); |
| 349 state->set_source_address_token("TOKEN"); | 350 state->set_source_address_token("TOKEN"); |
| 350 state->SetProofValid(); | 351 state->SetProofValid(); |
| 351 EXPECT_EQ(1u, state->generation_counter()); | 352 EXPECT_EQ(1u, state->generation_counter()); |
| 352 | 353 |
| 353 // Verify LookupOrCreate returns the same data. | 354 // Verify LookupOrCreate returns the same data. |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 QuicCryptoNegotiatedParameters out_params; | 474 QuicCryptoNegotiatedParameters out_params; |
| 474 string error_details; | 475 string error_details; |
| 475 EXPECT_EQ(QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER, | 476 EXPECT_EQ(QUIC_INVALID_CRYPTO_MESSAGE_PARAMETER, |
| 476 config.ProcessServerHello(msg, 0, version, supported_versions, | 477 config.ProcessServerHello(msg, 0, version, supported_versions, |
| 477 &cached, &out_params, &error_details)); | 478 &cached, &out_params, &error_details)); |
| 478 EXPECT_EQ("server hello missing server nonce", error_details); | 479 EXPECT_EQ("server hello missing server nonce", error_details); |
| 479 } | 480 } |
| 480 | 481 |
| 481 } // namespace test | 482 } // namespace test |
| 482 } // namespace net | 483 } // namespace net |
| OLD | NEW |