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

Side by Side Diff: net/cert/x509_certificate_unittest.cc

Issue 462543002: Certificate Transparency: Code for unpacking EV cert hashes whitelist (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebasing on master Created 6 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
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/cert/x509_certificate.h" 5 #include "net/cert/x509_certificate.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/pickle.h" 10 #include "base/pickle.h"
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 reinterpret_cast<const char*>(paypal_null_der), 316 reinterpret_cast<const char*>(paypal_null_der),
317 sizeof(paypal_null_der))); 317 sizeof(paypal_null_der)));
318 318
319 static const uint8 paypal_null_serial[3] = {0x00, 0xf0, 0x9b}; 319 static const uint8 paypal_null_serial[3] = {0x00, 0xf0, 0x9b};
320 ASSERT_EQ(sizeof(paypal_null_serial), 320 ASSERT_EQ(sizeof(paypal_null_serial),
321 paypal_null_cert->serial_number().size()); 321 paypal_null_cert->serial_number().size());
322 EXPECT_TRUE(memcmp(paypal_null_cert->serial_number().data(), 322 EXPECT_TRUE(memcmp(paypal_null_cert->serial_number().data(),
323 paypal_null_serial, sizeof(paypal_null_serial)) == 0); 323 paypal_null_serial, sizeof(paypal_null_serial)) == 0);
324 } 324 }
325 325
326 TEST(X509CertificateTest, SHA256FingerprintsCorrectly) {
327 scoped_refptr<X509Certificate> google_cert(
328 X509Certificate::CreateFromBytes(
329 reinterpret_cast<const char*>(google_der), sizeof(google_der)));
330
331 static const uint8 google_sha256_fingerprint[32] = {
332 0x21, 0xaf, 0x58, 0x74, 0xea, 0x6b, 0xad, 0xbd, 0xe4, 0xb3, 0xb1, 0xaa,
333 0x53, 0x32, 0x80, 0x8f, 0xbf, 0x8a, 0x24, 0x7d, 0x98, 0xec, 0x7f, 0x77,
334 0x49, 0x38, 0x42, 0x81, 0x26, 0x7f, 0xed, 0x38
335 };
336
337 SHA256HashValue fingerprint = X509Certificate::CalculateFingerprint256(
338 google_cert->os_cert_handle());
339
340 for (size_t i = 0; i < 32; ++i)
341 EXPECT_EQ(google_sha256_fingerprint[i], fingerprint.data[i]);
342 }
343
326 TEST(X509CertificateTest, CAFingerprints) { 344 TEST(X509CertificateTest, CAFingerprints) {
327 base::FilePath certs_dir = GetTestCertsDirectory(); 345 base::FilePath certs_dir = GetTestCertsDirectory();
328 346
329 scoped_refptr<X509Certificate> server_cert = 347 scoped_refptr<X509Certificate> server_cert =
330 ImportCertFromFile(certs_dir, "salesforce_com_test.pem"); 348 ImportCertFromFile(certs_dir, "salesforce_com_test.pem");
331 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert); 349 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert);
332 350
333 scoped_refptr<X509Certificate> intermediate_cert1 = 351 scoped_refptr<X509Certificate> intermediate_cert1 =
334 ImportCertFromFile(certs_dir, "verisign_intermediate_ca_2011.pem"); 352 ImportCertFromFile(certs_dir, "verisign_intermediate_ca_2011.pem");
335 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert1); 353 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert1);
(...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 &actual_type); 1285 &actual_type);
1268 1286
1269 EXPECT_EQ(data.expected_bits, actual_bits); 1287 EXPECT_EQ(data.expected_bits, actual_bits);
1270 EXPECT_EQ(data.expected_type, actual_type); 1288 EXPECT_EQ(data.expected_type, actual_type);
1271 } 1289 }
1272 1290
1273 INSTANTIATE_TEST_CASE_P(, X509CertificatePublicKeyInfoTest, 1291 INSTANTIATE_TEST_CASE_P(, X509CertificatePublicKeyInfoTest,
1274 testing::ValuesIn(kPublicKeyInfoTestData)); 1292 testing::ValuesIn(kPublicKeyInfoTestData));
1275 1293
1276 } // namespace net 1294 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698