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" |
11 #include "base/sha1.h" | 11 #include "base/sha1.h" |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
| 14 #include "base/strings/string_util.h" |
14 #include "crypto/rsa_private_key.h" | 15 #include "crypto/rsa_private_key.h" |
15 #include "net/base/net_errors.h" | 16 #include "net/base/net_errors.h" |
16 #include "net/base/test_data_directory.h" | 17 #include "net/base/test_data_directory.h" |
17 #include "net/cert/asn1_util.h" | 18 #include "net/cert/asn1_util.h" |
18 #include "net/test/cert_test_util.h" | 19 #include "net/test/cert_test_util.h" |
19 #include "net/test/test_certificate_data.h" | 20 #include "net/test/test_certificate_data.h" |
20 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
21 | 22 |
22 #if defined(USE_NSS) | 23 #if defined(USE_NSS) |
23 #include <cert.h> | 24 #include <cert.h> |
(...skipping 292 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 reinterpret_cast<const char*>(paypal_null_der), | 317 reinterpret_cast<const char*>(paypal_null_der), |
317 sizeof(paypal_null_der))); | 318 sizeof(paypal_null_der))); |
318 | 319 |
319 static const uint8 paypal_null_serial[3] = {0x00, 0xf0, 0x9b}; | 320 static const uint8 paypal_null_serial[3] = {0x00, 0xf0, 0x9b}; |
320 ASSERT_EQ(sizeof(paypal_null_serial), | 321 ASSERT_EQ(sizeof(paypal_null_serial), |
321 paypal_null_cert->serial_number().size()); | 322 paypal_null_cert->serial_number().size()); |
322 EXPECT_TRUE(memcmp(paypal_null_cert->serial_number().data(), | 323 EXPECT_TRUE(memcmp(paypal_null_cert->serial_number().data(), |
323 paypal_null_serial, sizeof(paypal_null_serial)) == 0); | 324 paypal_null_serial, sizeof(paypal_null_serial)) == 0); |
324 } | 325 } |
325 | 326 |
| 327 TEST(X509CertificateTest, SHA256FingerprintsCorrectly) { |
| 328 scoped_refptr<X509Certificate> google_cert(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, |
| 333 0xaa, 0x53, 0x32, 0x80, 0x8f, 0xbf, 0x8a, 0x24, 0x7d, 0x98, 0xec, |
| 334 0x7f, 0x77, 0x49, 0x38, 0x42, 0x81, 0x26, 0x7f, 0xed, 0x38}; |
| 335 |
| 336 SHA256HashValue fingerprint = |
| 337 X509Certificate::CalculateFingerprint256(google_cert->os_cert_handle()); |
| 338 |
| 339 for (size_t i = 0; i < 32; ++i) |
| 340 EXPECT_EQ(google_sha256_fingerprint[i], fingerprint.data[i]); |
| 341 } |
| 342 |
326 TEST(X509CertificateTest, CAFingerprints) { | 343 TEST(X509CertificateTest, CAFingerprints) { |
327 base::FilePath certs_dir = GetTestCertsDirectory(); | 344 base::FilePath certs_dir = GetTestCertsDirectory(); |
328 | 345 |
329 scoped_refptr<X509Certificate> server_cert = | 346 scoped_refptr<X509Certificate> server_cert = |
330 ImportCertFromFile(certs_dir, "salesforce_com_test.pem"); | 347 ImportCertFromFile(certs_dir, "salesforce_com_test.pem"); |
331 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get()); | 348 ASSERT_NE(static_cast<X509Certificate*>(NULL), server_cert.get()); |
332 | 349 |
333 scoped_refptr<X509Certificate> intermediate_cert1 = | 350 scoped_refptr<X509Certificate> intermediate_cert1 = |
334 ImportCertFromFile(certs_dir, "verisign_intermediate_ca_2011.pem"); | 351 ImportCertFromFile(certs_dir, "verisign_intermediate_ca_2011.pem"); |
335 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert1.get()); | 352 ASSERT_NE(static_cast<X509Certificate*>(NULL), intermediate_cert1.get()); |
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1162 &actual_type); | 1179 &actual_type); |
1163 | 1180 |
1164 EXPECT_EQ(data.expected_bits, actual_bits); | 1181 EXPECT_EQ(data.expected_bits, actual_bits); |
1165 EXPECT_EQ(data.expected_type, actual_type); | 1182 EXPECT_EQ(data.expected_type, actual_type); |
1166 } | 1183 } |
1167 | 1184 |
1168 INSTANTIATE_TEST_CASE_P(, X509CertificatePublicKeyInfoTest, | 1185 INSTANTIATE_TEST_CASE_P(, X509CertificatePublicKeyInfoTest, |
1169 testing::ValuesIn(kPublicKeyInfoTestData)); | 1186 testing::ValuesIn(kPublicKeyInfoTestData)); |
1170 | 1187 |
1171 } // namespace net | 1188 } // namespace net |
OLD | NEW |