| OLD | NEW |
| 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 Loading... |
| 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(X509Certificate::CreateFromBytes( | |
| 328 reinterpret_cast<const char*>(google_der), sizeof(google_der))); | |
| 329 | |
| 330 static const uint8 google_sha256_fingerprint[32] = { | |
| 331 0x21, 0xaf, 0x58, 0x74, 0xea, 0x6b, 0xad, 0xbd, 0xe4, 0xb3, 0xb1, | |
| 332 0xaa, 0x53, 0x32, 0x80, 0x8f, 0xbf, 0x8a, 0x24, 0x7d, 0x98, 0xec, | |
| 333 0x7f, 0x77, 0x49, 0x38, 0x42, 0x81, 0x26, 0x7f, 0xed, 0x38}; | |
| 334 | |
| 335 SHA256HashValue fingerprint = | |
| 336 X509Certificate::CalculateFingerprint256(google_cert->os_cert_handle()); | |
| 337 | |
| 338 for (size_t i = 0; i < 32; ++i) | |
| 339 EXPECT_EQ(google_sha256_fingerprint[i], fingerprint.data[i]); | |
| 340 } | |
| 341 | |
| 342 TEST(X509CertificateTest, CAFingerprints) { | 326 TEST(X509CertificateTest, CAFingerprints) { |
| 343 base::FilePath certs_dir = GetTestCertsDirectory(); | 327 base::FilePath certs_dir = GetTestCertsDirectory(); |
| 344 | 328 |
| 345 scoped_refptr<X509Certificate> server_cert = | 329 scoped_refptr<X509Certificate> server_cert = |
| 346 ImportCertFromFile(certs_dir, "salesforce_com_test.pem"); | 330 ImportCertFromFile(certs_dir, "salesforce_com_test.pem"); |
| 347 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get()); | 331 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get()); |
| 348 | 332 |
| 349 scoped_refptr<X509Certificate> intermediate_cert1 = | 333 scoped_refptr<X509Certificate> intermediate_cert1 = |
| 350 ImportCertFromFile(certs_dir, "verisign_intermediate_ca_2011.pem"); | 334 ImportCertFromFile(certs_dir, "verisign_intermediate_ca_2011.pem"); |
| 351 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert1.get()); | 335 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert1.get()); |
| (...skipping 931 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1283 &actual_type); | 1267 &actual_type); |
| 1284 | 1268 |
| 1285 EXPECT_EQ(data.expected_bits, actual_bits); | 1269 EXPECT_EQ(data.expected_bits, actual_bits); |
| 1286 EXPECT_EQ(data.expected_type, actual_type); | 1270 EXPECT_EQ(data.expected_type, actual_type); |
| 1287 } | 1271 } |
| 1288 | 1272 |
| 1289 INSTANTIATE_TEST_CASE_P(, X509CertificatePublicKeyInfoTest, | 1273 INSTANTIATE_TEST_CASE_P(, X509CertificatePublicKeyInfoTest, |
| 1290 testing::ValuesIn(kPublicKeyInfoTestData)); | 1274 testing::ValuesIn(kPublicKeyInfoTestData)); |
| 1291 | 1275 |
| 1292 } // namespace net | 1276 } // namespace net |
| OLD | NEW |