| 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 |
| (...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 | 275 |
| 276 static const uint8_t google_serial[16] = { | 276 static const uint8_t google_serial[16] = { |
| 277 0x01,0x2a,0x39,0x76,0x0d,0x3f,0x4f,0xc9, | 277 0x01,0x2a,0x39,0x76,0x0d,0x3f,0x4f,0xc9, |
| 278 0x0b,0xe7,0xbd,0x2b,0xcf,0x95,0x2e,0x7a, | 278 0x0b,0xe7,0xbd,0x2b,0xcf,0x95,0x2e,0x7a, |
| 279 }; | 279 }; |
| 280 | 280 |
| 281 ASSERT_EQ(sizeof(google_serial), google_cert->serial_number().size()); | 281 ASSERT_EQ(sizeof(google_serial), google_cert->serial_number().size()); |
| 282 EXPECT_TRUE(memcmp(google_cert->serial_number().data(), google_serial, | 282 EXPECT_TRUE(memcmp(google_cert->serial_number().data(), google_serial, |
| 283 sizeof(google_serial)) == 0); | 283 sizeof(google_serial)) == 0); |
| 284 | 284 |
| 285 // TODO(mattm): Creating the X509Certificate fails on windows due to the null | 285 // TODO(mattm): Creating the X509Certificate fails on some platforms due to the |
| 286 // in the subject. Generate a new test cert specifically for this case rather | 286 // null in the subject. Generate a new test cert specifically for this case |
| 287 // than reusing paypal_null_cert. | 287 // rather than reusing paypal_null_cert. |
| 288 #if !defined(OS_WIN) | 288 #if !defined(OS_WIN) && !BUILDFLAG(USE_BYTE_CERTS) |
| 289 // Check a serial number where the first byte is >= 0x80, the DER returned by | 289 // Check a serial number where the first byte is >= 0x80, the DER returned by |
| 290 // serial() should contain the leading 0 padding byte. | 290 // serial() should contain the leading 0 padding byte. |
| 291 scoped_refptr<X509Certificate> paypal_null_cert( | 291 scoped_refptr<X509Certificate> paypal_null_cert( |
| 292 X509Certificate::CreateFromBytes( | 292 X509Certificate::CreateFromBytes( |
| 293 reinterpret_cast<const char*>(paypal_null_der), | 293 reinterpret_cast<const char*>(paypal_null_der), |
| 294 sizeof(paypal_null_der))); | 294 sizeof(paypal_null_der))); |
| 295 ASSERT_TRUE(paypal_null_cert); | 295 ASSERT_TRUE(paypal_null_cert); |
| 296 | 296 |
| 297 static const uint8_t paypal_null_serial[3] = {0x00, 0xf0, 0x9b}; | 297 static const uint8_t paypal_null_serial[3] = {0x00, 0xf0, 0x9b}; |
| 298 ASSERT_EQ(sizeof(paypal_null_serial), | 298 ASSERT_EQ(sizeof(paypal_null_serial), |
| (...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1194 } | 1194 } |
| 1195 | 1195 |
| 1196 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest, | 1196 INSTANTIATE_TEST_CASE_P(, X509CertificateNameVerifyTest, |
| 1197 testing::ValuesIn(kNameVerifyTestData)); | 1197 testing::ValuesIn(kNameVerifyTestData)); |
| 1198 | 1198 |
| 1199 const struct PublicKeyInfoTestData { | 1199 const struct PublicKeyInfoTestData { |
| 1200 const char* cert_file; | 1200 const char* cert_file; |
| 1201 size_t expected_bits; | 1201 size_t expected_bits; |
| 1202 X509Certificate::PublicKeyType expected_type; | 1202 X509Certificate::PublicKeyType expected_type; |
| 1203 } kPublicKeyInfoTestData[] = { | 1203 } kPublicKeyInfoTestData[] = { |
| 1204 {"768-rsa-ee-by-768-rsa-intermediate.pem", | 1204 {"768-rsa-ee-by-768-rsa-intermediate.pem", 768, |
| 1205 768, | |
| 1206 X509Certificate::kPublicKeyTypeRSA}, | 1205 X509Certificate::kPublicKeyTypeRSA}, |
| 1207 {"1024-rsa-ee-by-768-rsa-intermediate.pem", | 1206 {"1024-rsa-ee-by-768-rsa-intermediate.pem", 1024, |
| 1208 1024, | |
| 1209 X509Certificate::kPublicKeyTypeRSA}, | 1207 X509Certificate::kPublicKeyTypeRSA}, |
| 1210 {"prime256v1-ecdsa-ee-by-1024-rsa-intermediate.pem", | 1208 {"prime256v1-ecdsa-ee-by-1024-rsa-intermediate.pem", 256, |
| 1211 256, | |
| 1212 X509Certificate::kPublicKeyTypeECDSA}, | 1209 X509Certificate::kPublicKeyTypeECDSA}, |
| 1213 #if defined(OS_MACOSX) && !defined(OS_IOS) | 1210 #if defined(OS_MACOSX) && !defined(OS_IOS) && !BUILDFLAG(USE_BYTE_CERTS) |
| 1214 // OS X has an key length limit of 4096 bits. This should manifest as an | 1211 // OS X has an key length limit of 4096 bits. This should manifest as an |
| 1215 // unknown key. If a future version of OS X changes this, large_key.pem may | 1212 // unknown key. If a future version of OS X changes this, large_key.pem may |
| 1216 // need to be renegerated with a larger key. See https://crbug.com/472291. | 1213 // need to be renegerated with a larger key. See https://crbug.com/472291. |
| 1217 {"large_key.pem", 0, X509Certificate::kPublicKeyTypeUnknown}, | 1214 {"large_key.pem", 0, X509Certificate::kPublicKeyTypeUnknown}, |
| 1218 #else | 1215 #else |
| 1219 {"large_key.pem", 8200, X509Certificate::kPublicKeyTypeRSA}, | 1216 {"large_key.pem", 8200, X509Certificate::kPublicKeyTypeRSA}, |
| 1220 #endif | 1217 #endif |
| 1221 }; | 1218 }; |
| 1222 | 1219 |
| 1223 class X509CertificatePublicKeyInfoTest | 1220 class X509CertificatePublicKeyInfoTest |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1239 &actual_type); | 1236 &actual_type); |
| 1240 | 1237 |
| 1241 EXPECT_EQ(data.expected_bits, actual_bits); | 1238 EXPECT_EQ(data.expected_bits, actual_bits); |
| 1242 EXPECT_EQ(data.expected_type, actual_type); | 1239 EXPECT_EQ(data.expected_type, actual_type); |
| 1243 } | 1240 } |
| 1244 | 1241 |
| 1245 INSTANTIATE_TEST_CASE_P(, X509CertificatePublicKeyInfoTest, | 1242 INSTANTIATE_TEST_CASE_P(, X509CertificatePublicKeyInfoTest, |
| 1246 testing::ValuesIn(kPublicKeyInfoTestData)); | 1243 testing::ValuesIn(kPublicKeyInfoTestData)); |
| 1247 | 1244 |
| 1248 } // namespace net | 1245 } // namespace net |
| OLD | NEW |