Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(301)

Side by Side Diff: net/base/cert_verify_proc_unittest.cc

Issue 10826257: Implement SHA-256 fingerprint support (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/base/cert_verify_proc.h" 5 #include "net/base/cert_verify_proc.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/file_path.h" 9 #include "base/file_path.h"
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } 113 }
114 114
115 TEST_F(CertVerifyProcTest, PaypalNullCertParsing) { 115 TEST_F(CertVerifyProcTest, PaypalNullCertParsing) {
116 scoped_refptr<X509Certificate> paypal_null_cert( 116 scoped_refptr<X509Certificate> paypal_null_cert(
117 X509Certificate::CreateFromBytes( 117 X509Certificate::CreateFromBytes(
118 reinterpret_cast<const char*>(paypal_null_der), 118 reinterpret_cast<const char*>(paypal_null_der),
119 sizeof(paypal_null_der))); 119 sizeof(paypal_null_der)));
120 120
121 ASSERT_NE(static_cast<X509Certificate*>(NULL), paypal_null_cert); 121 ASSERT_NE(static_cast<X509Certificate*>(NULL), paypal_null_cert);
122 122
123 const SHA1Fingerprint& fingerprint = 123 const SHA1HashValue& fingerprint =
124 paypal_null_cert->fingerprint(); 124 paypal_null_cert->fingerprint();
125 for (size_t i = 0; i < 20; ++i) 125 for (size_t i = 0; i < 20; ++i)
126 EXPECT_EQ(paypal_null_fingerprint[i], fingerprint.data[i]); 126 EXPECT_EQ(paypal_null_fingerprint[i], fingerprint.data[i]);
127 127
128 int flags = 0; 128 int flags = 0;
129 CertVerifyResult verify_result; 129 CertVerifyResult verify_result;
130 int error = Verify(paypal_null_cert, "www.paypal.com", flags, NULL, 130 int error = Verify(paypal_null_cert, "www.paypal.com", flags, NULL,
131 &verify_result); 131 &verify_result);
132 #if defined(USE_NSS) 132 #if defined(USE_NSS)
133 EXPECT_EQ(ERR_CERT_COMMON_NAME_INVALID, error); 133 EXPECT_EQ(ERR_CERT_COMMON_NAME_INVALID, error);
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
390 ImportCertFromFile(certs_dir, kDigiNotarFilenames[i]); 390 ImportCertFromFile(certs_dir, kDigiNotarFilenames[i]);
391 std::string der_bytes; 391 std::string der_bytes;
392 ASSERT_TRUE(X509Certificate::GetDEREncoded( 392 ASSERT_TRUE(X509Certificate::GetDEREncoded(
393 diginotar_cert->os_cert_handle(), &der_bytes)); 393 diginotar_cert->os_cert_handle(), &der_bytes));
394 394
395 base::StringPiece spki; 395 base::StringPiece spki;
396 ASSERT_TRUE(asn1::ExtractSPKIFromDERCert(der_bytes, &spki)); 396 ASSERT_TRUE(asn1::ExtractSPKIFromDERCert(der_bytes, &spki));
397 397
398 std::string spki_sha1 = base::SHA1HashString(spki.as_string()); 398 std::string spki_sha1 = base::SHA1HashString(spki.as_string());
399 399
400 std::vector<SHA1Fingerprint> public_keys; 400 HashValueVector public_keys;
401 SHA1Fingerprint fingerprint; 401 HashValue fingerprint;
402 ASSERT_EQ(sizeof(fingerprint.data), spki_sha1.size()); 402 fingerprint.tag = HASH_VALUE_SHA1;
403 memcpy(fingerprint.data, spki_sha1.data(), spki_sha1.size()); 403 ASSERT_EQ(fingerprint.size(), spki_sha1.size());
404 memcpy(fingerprint.data(), spki_sha1.data(), spki_sha1.size());
404 public_keys.push_back(fingerprint); 405 public_keys.push_back(fingerprint);
405 406
406 EXPECT_TRUE(CertVerifyProc::IsPublicKeyBlacklisted(public_keys)) << 407 EXPECT_TRUE(CertVerifyProc::IsPublicKeyBlacklisted(public_keys)) <<
407 "Public key not blocked for " << kDigiNotarFilenames[i]; 408 "Public key not blocked for " << kDigiNotarFilenames[i];
408 } 409 }
409 } 410 }
410 411
411 TEST_F(CertVerifyProcTest, TestKnownRoot) { 412 TEST_F(CertVerifyProcTest, TestKnownRoot) {
412 FilePath certs_dir = GetTestCertsDirectory(); 413 FilePath certs_dir = GetTestCertsDirectory();
413 CertificateList certs = CreateCertificateListFromFile( 414 CertificateList certs = CreateCertificateListFromFile(
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 intermediates); 448 intermediates);
448 int flags = 0; 449 int flags = 0;
449 CertVerifyResult verify_result; 450 CertVerifyResult verify_result;
450 451
451 // This will blow up, June 8th, 2014. Sorry! Please disable and file a bug 452 // This will blow up, June 8th, 2014. Sorry! Please disable and file a bug
452 // against agl. See also TestKnownRoot. 453 // against agl. See also TestKnownRoot.
453 int error = Verify(cert_chain, "cert.se", flags, NULL, &verify_result); 454 int error = Verify(cert_chain, "cert.se", flags, NULL, &verify_result);
454 EXPECT_EQ(OK, error); 455 EXPECT_EQ(OK, error);
455 EXPECT_EQ(0U, verify_result.cert_status); 456 EXPECT_EQ(0U, verify_result.cert_status);
456 ASSERT_LE(3u, verify_result.public_key_hashes.size()); 457 ASSERT_LE(3u, verify_result.public_key_hashes.size());
457 for (unsigned i = 0; i < 3; i++) { 458
459 HashValueVector sha1_hashes;
460 for (unsigned i = 0; i < verify_result.public_key_hashes.size(); ++i) {
461 if (verify_result.public_key_hashes[i].tag != HASH_VALUE_SHA1)
462 continue;
463 sha1_hashes.push_back(verify_result.public_key_hashes[i]);
464 }
465 ASSERT_LE(3u, sha1_hashes.size());
466
467 for (unsigned i = 0; i < 3; ++i) {
458 EXPECT_EQ(HexEncode(kCertSESPKIs[i], base::kSHA1Length), 468 EXPECT_EQ(HexEncode(kCertSESPKIs[i], base::kSHA1Length),
459 HexEncode(verify_result.public_key_hashes[i].data, base::kSHA1Length)); 469 HexEncode(sha1_hashes[i].data(), base::kSHA1Length));
460 } 470 }
461 } 471 }
462 472
463 // A regression test for http://crbug.com/70293. 473 // A regression test for http://crbug.com/70293.
464 // The Key Usage extension in this RSA SSL server certificate does not have 474 // The Key Usage extension in this RSA SSL server certificate does not have
465 // the keyEncipherment bit. 475 // the keyEncipherment bit.
466 TEST_F(CertVerifyProcTest, InvalidKeyUsage) { 476 TEST_F(CertVerifyProcTest, InvalidKeyUsage) {
467 FilePath certs_dir = GetTestCertsDirectory(); 477 FilePath certs_dir = GetTestCertsDirectory();
468 478
469 scoped_refptr<X509Certificate> server_cert = 479 scoped_refptr<X509Certificate> server_cert =
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
964 #define MAYBE_VerifyMixed DISABLED_VerifyMixed 974 #define MAYBE_VerifyMixed DISABLED_VerifyMixed
965 #else 975 #else
966 #define MAYBE_VerifyMixed VerifyMixed 976 #define MAYBE_VerifyMixed VerifyMixed
967 #endif 977 #endif
968 WRAPPED_INSTANTIATE_TEST_CASE_P( 978 WRAPPED_INSTANTIATE_TEST_CASE_P(
969 MAYBE_VerifyMixed, 979 MAYBE_VerifyMixed,
970 CertVerifyProcWeakDigestTest, 980 CertVerifyProcWeakDigestTest,
971 testing::ValuesIn(kVerifyMixedTestData)); 981 testing::ValuesIn(kVerifyMixedTestData));
972 982
973 } // namespace net 983 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698