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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/pickle.h" | 12 #include "base/pickle.h" |
13 #include "base/sha1.h" | 13 #include "base/sha1.h" |
14 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
15 #include "base/strings/string_split.h" | 15 #include "base/strings/string_split.h" |
16 #include "base/strings/string_util.h" | 16 #include "base/strings/string_util.h" |
17 #include "crypto/rsa_private_key.h" | 17 #include "crypto/rsa_private_key.h" |
18 #include "net/base/net_errors.h" | 18 #include "net/base/net_errors.h" |
19 #include "net/base/test_data_directory.h" | 19 #include "net/base/test_data_directory.h" |
20 #include "net/cert/asn1_util.h" | 20 #include "net/cert/asn1_util.h" |
21 #include "net/cert/x509_util_nss.h" | 21 #include "net/cert/x509_util_nss.h" |
22 #include "net/test/cert_test_util.h" | 22 #include "net/test/cert_test_util.h" |
23 #include "net/test/test_certificate_data.h" | 23 #include "net/test/test_certificate_data.h" |
24 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
25 | 25 |
26 #if defined(USE_NSS_CERTS) | 26 #if defined(USE_NSS_CERTS) |
27 #include <cert.h> | 27 #include <cert.h> |
28 #endif | 28 #endif |
29 | 29 |
30 #if defined(OS_WIN) | |
31 #include "base/win/windows_version.h" | |
32 #endif | |
33 | |
34 using base::HexEncode; | 30 using base::HexEncode; |
35 using base::Time; | 31 using base::Time; |
36 | 32 |
37 namespace net { | 33 namespace net { |
38 | 34 |
39 // Certificates for test data. They're obtained with: | 35 // Certificates for test data. They're obtained with: |
40 // | 36 // |
41 // $ openssl s_client -connect [host]:443 -showcerts > /tmp/host.pem < /dev/null | 37 // $ openssl s_client -connect [host]:443 -showcerts > /tmp/host.pem < /dev/null |
42 // $ openssl x509 -inform PEM -outform DER < /tmp/host.pem > /tmp/host.der | 38 // $ openssl x509 -inform PEM -outform DER < /tmp/host.pem > /tmp/host.der |
43 // | 39 // |
(...skipping 1160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1204 #endif | 1200 #endif |
1205 }; | 1201 }; |
1206 | 1202 |
1207 class X509CertificatePublicKeyInfoTest | 1203 class X509CertificatePublicKeyInfoTest |
1208 : public testing::TestWithParam<PublicKeyInfoTestData> { | 1204 : public testing::TestWithParam<PublicKeyInfoTestData> { |
1209 }; | 1205 }; |
1210 | 1206 |
1211 TEST_P(X509CertificatePublicKeyInfoTest, GetPublicKeyInfo) { | 1207 TEST_P(X509CertificatePublicKeyInfoTest, GetPublicKeyInfo) { |
1212 PublicKeyInfoTestData data = GetParam(); | 1208 PublicKeyInfoTestData data = GetParam(); |
1213 | 1209 |
1214 #if defined(OS_WIN) | |
1215 if (base::win::GetVersion() < base::win::VERSION_VISTA && | |
1216 data.expected_type == X509Certificate::kPublicKeyTypeECDSA) { | |
1217 // ECC is only supported on Vista+. Skip the test. | |
1218 return; | |
1219 } | |
1220 #endif | |
1221 | |
1222 scoped_refptr<X509Certificate> cert( | 1210 scoped_refptr<X509Certificate> cert( |
1223 ImportCertFromFile(GetTestCertsDirectory(), data.cert_file)); | 1211 ImportCertFromFile(GetTestCertsDirectory(), data.cert_file)); |
1224 ASSERT_TRUE(cert.get()); | 1212 ASSERT_TRUE(cert.get()); |
1225 | 1213 |
1226 size_t actual_bits = 0; | 1214 size_t actual_bits = 0; |
1227 X509Certificate::PublicKeyType actual_type = | 1215 X509Certificate::PublicKeyType actual_type = |
1228 X509Certificate::kPublicKeyTypeUnknown; | 1216 X509Certificate::kPublicKeyTypeUnknown; |
1229 | 1217 |
1230 X509Certificate::GetPublicKeyInfo(cert->os_cert_handle(), &actual_bits, | 1218 X509Certificate::GetPublicKeyInfo(cert->os_cert_handle(), &actual_bits, |
1231 &actual_type); | 1219 &actual_type); |
1232 | 1220 |
1233 EXPECT_EQ(data.expected_bits, actual_bits); | 1221 EXPECT_EQ(data.expected_bits, actual_bits); |
1234 EXPECT_EQ(data.expected_type, actual_type); | 1222 EXPECT_EQ(data.expected_type, actual_type); |
1235 } | 1223 } |
1236 | 1224 |
1237 INSTANTIATE_TEST_CASE_P(, X509CertificatePublicKeyInfoTest, | 1225 INSTANTIATE_TEST_CASE_P(, X509CertificatePublicKeyInfoTest, |
1238 testing::ValuesIn(kPublicKeyInfoTestData)); | 1226 testing::ValuesIn(kPublicKeyInfoTestData)); |
1239 | 1227 |
1240 } // namespace net | 1228 } // namespace net |
OLD | NEW |