| 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 "base/files/file_path.h" | 5 #include "base/files/file_path.h" |
| 6 #include "net/base/ip_endpoint.h" | 6 #include "net/base/ip_endpoint.h" |
| 7 #include "net/base/net_errors.h" | 7 #include "net/base/net_errors.h" |
| 8 #include "net/base/test_completion_callback.h" | 8 #include "net/base/test_completion_callback.h" |
| 9 #include "net/base/test_data_directory.h" | 9 #include "net/base/test_data_directory.h" |
| 10 #include "net/cert/cert_status_flags.h" | 10 #include "net/cert/cert_status_flags.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 private: | 49 private: |
| 50 TestCompletionCallback* const comp_callback_; | 50 TestCompletionCallback* const comp_callback_; |
| 51 bool* const ok_; | 51 bool* const ok_; |
| 52 string* const error_details_; | 52 string* const error_details_; |
| 53 }; | 53 }; |
| 54 | 54 |
| 55 // RunVerification runs |verifier->VerifyProof| and asserts that the result | 55 // RunVerification runs |verifier->VerifyProof| and asserts that the result |
| 56 // matches |expected_ok|. | 56 // matches |expected_ok|. |
| 57 void RunVerification(ProofVerifier* verifier, | 57 void RunVerification(ProofVerifier* verifier, |
| 58 const string& hostname, | 58 const string& hostname, |
| 59 const uint16_t port, |
| 59 const string& server_config, | 60 const string& server_config, |
| 60 QuicVersion quic_version, | 61 QuicVersion quic_version, |
| 61 StringPiece chlo_hash, | 62 StringPiece chlo_hash, |
| 62 const vector<string>& certs, | 63 const vector<string>& certs, |
| 63 const string& proof, | 64 const string& proof, |
| 64 bool expected_ok) { | 65 bool expected_ok) { |
| 65 scoped_ptr<ProofVerifyDetails> details; | 66 scoped_ptr<ProofVerifyDetails> details; |
| 66 TestCompletionCallback comp_callback; | 67 TestCompletionCallback comp_callback; |
| 67 bool ok; | 68 bool ok; |
| 68 string error_details; | 69 string error_details; |
| 69 scoped_ptr<ProofVerifyContext> verify_context( | 70 scoped_ptr<ProofVerifyContext> verify_context( |
| 70 CryptoTestUtils::ProofVerifyContextForTesting()); | 71 CryptoTestUtils::ProofVerifyContextForTesting()); |
| 71 TestProofVerifierCallback* callback = | 72 TestProofVerifierCallback* callback = |
| 72 new TestProofVerifierCallback(&comp_callback, &ok, &error_details); | 73 new TestProofVerifierCallback(&comp_callback, &ok, &error_details); |
| 73 | 74 |
| 74 QuicAsyncStatus status = verifier->VerifyProof( | 75 QuicAsyncStatus status = verifier->VerifyProof( |
| 75 hostname, server_config, quic_version, chlo_hash, certs, "", proof, | 76 hostname, port, server_config, quic_version, chlo_hash, certs, "", proof, |
| 76 verify_context.get(), &error_details, &details, callback); | 77 verify_context.get(), &error_details, &details, callback); |
| 77 | 78 |
| 78 switch (status) { | 79 switch (status) { |
| 79 case QUIC_FAILURE: | 80 case QUIC_FAILURE: |
| 80 delete callback; | 81 delete callback; |
| 81 ASSERT_FALSE(expected_ok); | 82 ASSERT_FALSE(expected_ok); |
| 82 ASSERT_NE("", error_details); | 83 ASSERT_NE("", error_details); |
| 83 return; | 84 return; |
| 84 case QUIC_SUCCESS: | 85 case QUIC_SUCCESS: |
| 85 delete callback; | 86 delete callback; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 115 ::testing::ValuesIn(QuicSupportedVersions())); | 116 ::testing::ValuesIn(QuicSupportedVersions())); |
| 116 | 117 |
| 117 // TODO(rtenneti): Enable testing of ProofVerifier. See http://crbug.com/514468. | 118 // TODO(rtenneti): Enable testing of ProofVerifier. See http://crbug.com/514468. |
| 118 TEST_P(ProofTest, DISABLED_Verify) { | 119 TEST_P(ProofTest, DISABLED_Verify) { |
| 119 scoped_ptr<ProofSource> source(CryptoTestUtils::ProofSourceForTesting()); | 120 scoped_ptr<ProofSource> source(CryptoTestUtils::ProofSourceForTesting()); |
| 120 scoped_ptr<ProofVerifier> verifier( | 121 scoped_ptr<ProofVerifier> verifier( |
| 121 CryptoTestUtils::ProofVerifierForTesting()); | 122 CryptoTestUtils::ProofVerifierForTesting()); |
| 122 | 123 |
| 123 const string server_config = "server config bytes"; | 124 const string server_config = "server config bytes"; |
| 124 const string hostname = "test.example.com"; | 125 const string hostname = "test.example.com"; |
| 126 const uint16_t port = 8443; |
| 125 const string first_chlo_hash = "first chlo hash bytes"; | 127 const string first_chlo_hash = "first chlo hash bytes"; |
| 126 const string second_chlo_hash = "first chlo hash bytes"; | 128 const string second_chlo_hash = "first chlo hash bytes"; |
| 127 const QuicVersion quic_version = GetParam(); | 129 const QuicVersion quic_version = GetParam(); |
| 130 |
| 128 scoped_refptr<ProofSource::Chain> chain; | 131 scoped_refptr<ProofSource::Chain> chain; |
| 129 scoped_refptr<ProofSource::Chain> first_chain; | 132 scoped_refptr<ProofSource::Chain> first_chain; |
| 130 string error_details, signature, first_signature, first_cert_sct, cert_sct; | 133 string error_details, signature, first_signature, first_cert_sct, cert_sct; |
| 131 IPAddress server_ip; | 134 IPAddress server_ip; |
| 132 | 135 |
| 133 ASSERT_TRUE(source->GetProof( | 136 ASSERT_TRUE(source->GetProof( |
| 134 server_ip, hostname, server_config, quic_version, first_chlo_hash, | 137 server_ip, hostname, server_config, quic_version, first_chlo_hash, |
| 135 false /* no ECDSA */, &first_chain, &first_signature, &first_cert_sct)); | 138 false /* no ECDSA */, &first_chain, &first_signature, &first_cert_sct)); |
| 136 ASSERT_TRUE(source->GetProof(server_ip, hostname, server_config, quic_version, | 139 ASSERT_TRUE(source->GetProof(server_ip, hostname, server_config, quic_version, |
| 137 second_chlo_hash, false /* no ECDSA */, &chain, | 140 second_chlo_hash, false /* no ECDSA */, &chain, |
| 138 &signature, &cert_sct)); | 141 &signature, &cert_sct)); |
| 139 | 142 |
| 140 // Check that the proof source is caching correctly: | 143 // Check that the proof source is caching correctly: |
| 141 ASSERT_EQ(first_chain->certs, chain->certs); | 144 ASSERT_EQ(first_chain->certs, chain->certs); |
| 142 if (GetParam() < QUIC_VERSION_31) { | 145 if (GetParam() < QUIC_VERSION_31) { |
| 143 ASSERT_EQ(signature, first_signature); | 146 ASSERT_EQ(signature, first_signature); |
| 144 } else { | 147 } else { |
| 145 // QUIC 31 includes the CHLO hash. | 148 // QUIC 31 includes the CHLO hash. |
| 146 ASSERT_NE(signature, first_signature); | 149 ASSERT_NE(signature, first_signature); |
| 147 } | 150 } |
| 148 ASSERT_EQ(first_cert_sct, cert_sct); | 151 ASSERT_EQ(first_cert_sct, cert_sct); |
| 149 | 152 |
| 150 RunVerification(verifier.get(), hostname, server_config, quic_version, | 153 RunVerification(verifier.get(), hostname, port, server_config, quic_version, |
| 151 first_chlo_hash, chain->certs, signature, true); | 154 first_chlo_hash, chain->certs, signature, true); |
| 152 | 155 |
| 153 RunVerification(verifier.get(), "foo.com", server_config, quic_version, | 156 RunVerification(verifier.get(), "foo.com", port, server_config, quic_version, |
| 154 first_chlo_hash, chain->certs, signature, false); | 157 first_chlo_hash, chain->certs, signature, false); |
| 155 | 158 |
| 156 RunVerification(verifier.get(), server_config.substr(1, string::npos), | 159 RunVerification(verifier.get(), server_config.substr(1, string::npos), port, |
| 157 server_config, quic_version, first_chlo_hash, chain->certs, | 160 server_config, quic_version, first_chlo_hash, chain->certs, |
| 158 signature, false); | 161 signature, false); |
| 159 | 162 |
| 160 const string corrupt_signature = "1" + signature; | 163 const string corrupt_signature = "1" + signature; |
| 161 RunVerification(verifier.get(), hostname, server_config, quic_version, | 164 RunVerification(verifier.get(), hostname, port, server_config, quic_version, |
| 162 first_chlo_hash, chain->certs, corrupt_signature, false); | 165 first_chlo_hash, chain->certs, corrupt_signature, false); |
| 163 | 166 |
| 164 vector<string> wrong_certs; | 167 vector<string> wrong_certs; |
| 165 for (size_t i = 1; i < chain->certs.size(); i++) { | 168 for (size_t i = 1; i < chain->certs.size(); i++) { |
| 166 wrong_certs.push_back(chain->certs[i]); | 169 wrong_certs.push_back(chain->certs[i]); |
| 167 } | 170 } |
| 168 RunVerification(verifier.get(), "foo.com", server_config, quic_version, | 171 |
| 172 RunVerification(verifier.get(), "foo.com", port, server_config, quic_version, |
| 169 first_chlo_hash, wrong_certs, corrupt_signature, false); | 173 first_chlo_hash, wrong_certs, corrupt_signature, false); |
| 170 } | 174 } |
| 171 | 175 |
| 172 TEST_P(ProofTest, UseAfterFree) { | 176 TEST_P(ProofTest, UseAfterFree) { |
| 173 ProofSource* source = CryptoTestUtils::ProofSourceForTesting(); | 177 ProofSource* source = CryptoTestUtils::ProofSourceForTesting(); |
| 174 | 178 |
| 175 const string server_config = "server config bytes"; | 179 const string server_config = "server config bytes"; |
| 176 const string hostname = "test.example.com"; | 180 const string hostname = "test.example.com"; |
| 177 const string chlo_hash = "proof nonce bytes"; | 181 const string chlo_hash = "proof nonce bytes"; |
| 178 scoped_refptr<ProofSource::Chain> chain; | 182 scoped_refptr<ProofSource::Chain> chain; |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 0xdc, 0xc5, 0x56, 0x84, 0x8a, 0x31, 0x31, 0x23, 0x61, 0x94, 0x7e, 0x01, | 277 0xdc, 0xc5, 0x56, 0x84, 0x8a, 0x31, 0x31, 0x23, 0x61, 0x94, 0x7e, 0x01, |
| 274 0x22, 0x49, 0xf3, 0xcb, 0x0e, 0x31, 0x03, 0x04, 0x1b, 0x14, 0x43, 0x7c, | 278 0x22, 0x49, 0xf3, 0xcb, 0x0e, 0x31, 0x03, 0x04, 0x1b, 0x14, 0x43, 0x7c, |
| 275 0xad, 0x42, 0xe5, 0x55, | 279 0xad, 0x42, 0xe5, 0x55, |
| 276 }; | 280 }; |
| 277 | 281 |
| 278 scoped_ptr<ProofVerifier> verifier( | 282 scoped_ptr<ProofVerifier> verifier( |
| 279 CryptoTestUtils::RealProofVerifierForTesting()); | 283 CryptoTestUtils::RealProofVerifierForTesting()); |
| 280 | 284 |
| 281 const string server_config = "server config bytes"; | 285 const string server_config = "server config bytes"; |
| 282 const string hostname = "test.example.com"; | 286 const string hostname = "test.example.com"; |
| 287 const uint16_t port = 8443; |
| 283 const string chlo_hash = "proof nonce bytes"; | 288 const string chlo_hash = "proof nonce bytes"; |
| 284 const QuicVersion quic_version = GetParam(); | 289 const QuicVersion quic_version = GetParam(); |
| 285 | 290 |
| 286 vector<string> certs(2); | 291 vector<string> certs(2); |
| 287 certs[0] = LoadTestCert("test.example.com.crt"); | 292 certs[0] = LoadTestCert("test.example.com.crt"); |
| 288 certs[1] = LoadTestCert("intermediate.crt"); | 293 certs[1] = LoadTestCert("intermediate.crt"); |
| 289 | 294 |
| 290 // Signatures are nondeterministic, so we test multiple signatures on the | 295 // Signatures are nondeterministic, so we test multiple signatures on the |
| 291 // same server_config. | 296 // same server_config. |
| 292 vector<string> signatures(3); | 297 vector<string> signatures(3); |
| 293 signatures[0].assign(reinterpret_cast<const char*>(signature_data_0), | 298 signatures[0].assign(reinterpret_cast<const char*>(signature_data_0), |
| 294 sizeof(signature_data_0)); | 299 sizeof(signature_data_0)); |
| 295 signatures[1].assign(reinterpret_cast<const char*>(signature_data_1), | 300 signatures[1].assign(reinterpret_cast<const char*>(signature_data_1), |
| 296 sizeof(signature_data_1)); | 301 sizeof(signature_data_1)); |
| 297 signatures[2].assign(reinterpret_cast<const char*>(signature_data_2), | 302 signatures[2].assign(reinterpret_cast<const char*>(signature_data_2), |
| 298 sizeof(signature_data_2)); | 303 sizeof(signature_data_2)); |
| 299 | 304 |
| 300 for (size_t i = 0; i < signatures.size(); i++) { | 305 for (size_t i = 0; i < signatures.size(); i++) { |
| 301 const string& signature = signatures[i]; | 306 const string& signature = signatures[i]; |
| 302 | 307 |
| 303 RunVerification(verifier.get(), hostname, server_config, quic_version, | 308 RunVerification(verifier.get(), hostname, port, server_config, quic_version, |
| 304 chlo_hash, certs, signature, true); | 309 chlo_hash, certs, signature, true); |
| 305 RunVerification(verifier.get(), "foo.com", server_config, quic_version, | 310 RunVerification(verifier.get(), "foo.com", port, server_config, |
| 306 chlo_hash, certs, signature, false); | 311 quic_version, chlo_hash, certs, signature, false); |
| 307 RunVerification(verifier.get(), hostname, | 312 RunVerification(verifier.get(), hostname, port, |
| 308 server_config.substr(1, string::npos), quic_version, | 313 server_config.substr(1, string::npos), quic_version, |
| 309 chlo_hash, certs, signature, false); | 314 chlo_hash, certs, signature, false); |
| 310 | 315 |
| 311 const string corrupt_signature = "1" + signature; | 316 const string corrupt_signature = "1" + signature; |
| 312 RunVerification(verifier.get(), hostname, server_config, quic_version, | 317 RunVerification(verifier.get(), hostname, port, server_config, quic_version, |
| 313 chlo_hash, certs, corrupt_signature, false); | 318 chlo_hash, certs, corrupt_signature, false); |
| 314 | 319 |
| 315 vector<string> wrong_certs; | 320 vector<string> wrong_certs; |
| 316 for (size_t i = 1; i < certs.size(); i++) { | 321 for (size_t i = 1; i < certs.size(); i++) { |
| 317 wrong_certs.push_back(certs[i]); | 322 wrong_certs.push_back(certs[i]); |
| 318 } | 323 } |
| 319 RunVerification(verifier.get(), hostname, server_config, quic_version, | 324 RunVerification(verifier.get(), hostname, port, server_config, quic_version, |
| 320 chlo_hash, wrong_certs, signature, false); | 325 chlo_hash, wrong_certs, signature, false); |
| 321 } | 326 } |
| 322 } | 327 } |
| 323 | 328 |
| 324 // A known answer test that allows us to test ProofVerifier without a working | 329 // A known answer test that allows us to test ProofVerifier without a working |
| 325 // ProofSource. | 330 // ProofSource. |
| 326 TEST_P(ProofTest, VerifyECDSAKnownAnswerTest) { | 331 TEST_P(ProofTest, VerifyECDSAKnownAnswerTest) { |
| 327 if (GetParam() > QUIC_VERSION_30) { | 332 if (GetParam() > QUIC_VERSION_30) { |
| 328 return; | 333 return; |
| 329 } | 334 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 363 0x02, 0x21, 0x00, 0xc6, 0x20, 0xd4, 0x28, 0xf9, 0x70, 0xb5, 0xb4, 0xff, | 368 0x02, 0x21, 0x00, 0xc6, 0x20, 0xd4, 0x28, 0xf9, 0x70, 0xb5, 0xb4, 0xff, |
| 364 0x4a, 0x35, 0xba, 0xa0, 0xf2, 0x8e, 0x00, 0xf7, 0xcb, 0x43, 0xaf, 0x2d, | 369 0x4a, 0x35, 0xba, 0xa0, 0xf2, 0x8e, 0x00, 0xf7, 0xcb, 0x43, 0xaf, 0x2d, |
| 365 0x1f, 0xce, 0x92, 0x05, 0xca, 0x29, 0xfe, 0xd2, 0x8f, 0xd9, 0x31, | 370 0x1f, 0xce, 0x92, 0x05, 0xca, 0x29, 0xfe, 0xd2, 0x8f, 0xd9, 0x31, |
| 366 }; | 371 }; |
| 367 | 372 |
| 368 scoped_ptr<ProofVerifier> verifier( | 373 scoped_ptr<ProofVerifier> verifier( |
| 369 CryptoTestUtils::RealProofVerifierForTesting()); | 374 CryptoTestUtils::RealProofVerifierForTesting()); |
| 370 | 375 |
| 371 const string server_config = "server config bytes"; | 376 const string server_config = "server config bytes"; |
| 372 const string hostname = "test.example.com"; | 377 const string hostname = "test.example.com"; |
| 378 const uint16_t port = 8443; |
| 373 const string chlo_hash = "chlo_hash nonce bytes"; | 379 const string chlo_hash = "chlo_hash nonce bytes"; |
| 374 const QuicVersion quic_version = GetParam(); | 380 const QuicVersion quic_version = GetParam(); |
| 375 | 381 |
| 376 vector<string> certs(2); | 382 vector<string> certs(2); |
| 377 certs[0] = LoadTestCert("test_ecc.example.com.crt"); | 383 certs[0] = LoadTestCert("test_ecc.example.com.crt"); |
| 378 certs[1] = LoadTestCert("intermediate.crt"); | 384 certs[1] = LoadTestCert("intermediate.crt"); |
| 379 | 385 |
| 380 // Signatures are nondeterministic, so we test multiple signatures on the | 386 // Signatures are nondeterministic, so we test multiple signatures on the |
| 381 // same server_config. | 387 // same server_config. |
| 382 vector<string> signatures(3); | 388 vector<string> signatures(3); |
| 383 signatures[0].assign(reinterpret_cast<const char*>(signature_data_0), | 389 signatures[0].assign(reinterpret_cast<const char*>(signature_data_0), |
| 384 sizeof(signature_data_0)); | 390 sizeof(signature_data_0)); |
| 385 signatures[1].assign(reinterpret_cast<const char*>(signature_data_1), | 391 signatures[1].assign(reinterpret_cast<const char*>(signature_data_1), |
| 386 sizeof(signature_data_1)); | 392 sizeof(signature_data_1)); |
| 387 signatures[2].assign(reinterpret_cast<const char*>(signature_data_2), | 393 signatures[2].assign(reinterpret_cast<const char*>(signature_data_2), |
| 388 sizeof(signature_data_2)); | 394 sizeof(signature_data_2)); |
| 389 | 395 |
| 390 for (size_t i = 0; i < signatures.size(); i++) { | 396 for (size_t i = 0; i < signatures.size(); i++) { |
| 391 LOG(ERROR) << "====================" << i << "======================"; | 397 LOG(ERROR) << "====================" << i << "======================"; |
| 392 const string& signature = signatures[i]; | 398 const string& signature = signatures[i]; |
| 393 | 399 |
| 394 LOG(ERROR) << "=================== expect ok ====================="; | 400 LOG(ERROR) << "=================== expect ok ====================="; |
| 395 RunVerification(verifier.get(), hostname, server_config, quic_version, | 401 RunVerification(verifier.get(), hostname, port, server_config, quic_version, |
| 396 chlo_hash, certs, signature, true); | 402 chlo_hash, certs, signature, true); |
| 397 LOG(ERROR) << "=================== hose_name = foo.com ============="; | 403 LOG(ERROR) << "=================== hose_name = foo.com ============="; |
| 398 RunVerification(verifier.get(), "foo.com", server_config, quic_version, | 404 RunVerification(verifier.get(), "foo.com", port, server_config, |
| 399 chlo_hash, certs, signature, false); | 405 quic_version, chlo_hash, certs, signature, false); |
| 400 LOG(ERROR) << "================== server_config ===================="; | 406 LOG(ERROR) << "================== server_config ===================="; |
| 401 RunVerification(verifier.get(), hostname, | 407 RunVerification(verifier.get(), hostname, port, |
| 402 server_config.substr(1, string::npos), quic_version, | 408 server_config.substr(1, string::npos), quic_version, |
| 403 chlo_hash, certs, signature, false); | 409 chlo_hash, certs, signature, false); |
| 404 | 410 |
| 405 // An ECDSA signature is DER-encoded. Corrupt the last byte so that the | 411 // An ECDSA signature is DER-encoded. Corrupt the last byte so that the |
| 406 // signature can still be DER-decoded correctly. | 412 // signature can still be DER-decoded correctly. |
| 407 string corrupt_signature = signature; | 413 string corrupt_signature = signature; |
| 408 corrupt_signature[corrupt_signature.size() - 1] += 1; | 414 corrupt_signature[corrupt_signature.size() - 1] += 1; |
| 409 LOG(ERROR) << "================= corrupt signature ======================="; | 415 LOG(ERROR) << "================= corrupt signature ======================="; |
| 410 RunVerification(verifier.get(), hostname, server_config, quic_version, | 416 RunVerification(verifier.get(), hostname, port, server_config, quic_version, |
| 411 chlo_hash, certs, corrupt_signature, false); | 417 chlo_hash, certs, corrupt_signature, false); |
| 412 | 418 |
| 413 // Prepending a "1" makes the DER invalid. | 419 // Prepending a "1" makes the DER invalid. |
| 414 const string bad_der_signature1 = "1" + signature; | 420 const string bad_der_signature1 = "1" + signature; |
| 415 LOG(ERROR) << "=========================bad der signature ==============="; | 421 LOG(ERROR) << "=========================bad der signature ==============="; |
| 416 RunVerification(verifier.get(), hostname, server_config, quic_version, | 422 RunVerification(verifier.get(), hostname, port, server_config, quic_version, |
| 417 chlo_hash, certs, bad_der_signature1, false); | 423 chlo_hash, certs, bad_der_signature1, false); |
| 418 | 424 |
| 419 vector<string> wrong_certs; | 425 vector<string> wrong_certs; |
| 420 for (size_t i = 1; i < certs.size(); i++) { | 426 for (size_t i = 1; i < certs.size(); i++) { |
| 421 wrong_certs.push_back(certs[i]); | 427 wrong_certs.push_back(certs[i]); |
| 422 } | 428 } |
| 423 LOG(ERROR) << "==================== wrong certs ========================="; | 429 LOG(ERROR) << "==================== wrong certs ========================="; |
| 424 RunVerification(verifier.get(), hostname, server_config, quic_version, | 430 RunVerification(verifier.get(), hostname, port, server_config, quic_version, |
| 425 chlo_hash, wrong_certs, signature, false); | 431 chlo_hash, wrong_certs, signature, false); |
| 426 } | 432 } |
| 427 } | 433 } |
| 428 | 434 |
| 429 } // namespace test | 435 } // namespace test |
| 430 } // namespace net | 436 } // namespace net |
| OLD | NEW |