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 // We also want to check a serial number where the first byte is >= 0x80 in | 285 // TODO(mattm): Creating the X509Certificate fails on windows due to the null |
286 // case the underlying library tries to pad it. | 286 // in the subject. Generate a new test cert specifically for this case rather |
| 287 // than reusing paypal_null_cert. |
| 288 #if !defined(OS_WIN) |
| 289 // Check a serial number where the first byte is >= 0x80, the DER returned by |
| 290 // serial() should contain the leading 0 padding byte. |
287 scoped_refptr<X509Certificate> paypal_null_cert( | 291 scoped_refptr<X509Certificate> paypal_null_cert( |
288 X509Certificate::CreateFromBytes( | 292 X509Certificate::CreateFromBytes( |
289 reinterpret_cast<const char*>(paypal_null_der), | 293 reinterpret_cast<const char*>(paypal_null_der), |
290 sizeof(paypal_null_der))); | 294 sizeof(paypal_null_der))); |
291 ASSERT_TRUE(paypal_null_cert); | 295 ASSERT_TRUE(paypal_null_cert); |
292 | 296 |
293 static const uint8_t paypal_null_serial[3] = {0x00, 0xf0, 0x9b}; | 297 static const uint8_t paypal_null_serial[3] = {0x00, 0xf0, 0x9b}; |
294 ASSERT_EQ(sizeof(paypal_null_serial), | 298 ASSERT_EQ(sizeof(paypal_null_serial), |
295 paypal_null_cert->serial_number().size()); | 299 paypal_null_cert->serial_number().size()); |
296 EXPECT_TRUE(memcmp(paypal_null_cert->serial_number().data(), | 300 EXPECT_TRUE(memcmp(paypal_null_cert->serial_number().data(), |
297 paypal_null_serial, sizeof(paypal_null_serial)) == 0); | 301 paypal_null_serial, sizeof(paypal_null_serial)) == 0); |
| 302 #endif // !defined(OS_WIN) |
298 } | 303 } |
299 | 304 |
300 TEST(X509CertificateTest, SHA256FingerprintsCorrectly) { | 305 TEST(X509CertificateTest, SHA256FingerprintsCorrectly) { |
301 scoped_refptr<X509Certificate> google_cert(X509Certificate::CreateFromBytes( | 306 scoped_refptr<X509Certificate> google_cert(X509Certificate::CreateFromBytes( |
302 reinterpret_cast<const char*>(google_der), sizeof(google_der))); | 307 reinterpret_cast<const char*>(google_der), sizeof(google_der))); |
303 ASSERT_TRUE(google_cert); | 308 ASSERT_TRUE(google_cert); |
304 | 309 |
305 const SHA256HashValue google_sha256_fingerprint = { | 310 const SHA256HashValue google_sha256_fingerprint = { |
306 {0x21, 0xaf, 0x58, 0x74, 0xea, 0x6b, 0xad, 0xbd, 0xe4, 0xb3, 0xb1, | 311 {0x21, 0xaf, 0x58, 0x74, 0xea, 0x6b, 0xad, 0xbd, 0xe4, 0xb3, 0xb1, |
307 0xaa, 0x53, 0x32, 0x80, 0x8f, 0xbf, 0x8a, 0x24, 0x7d, 0x98, 0xec, | 312 0xaa, 0x53, 0x32, 0x80, 0x8f, 0xbf, 0x8a, 0x24, 0x7d, 0x98, 0xec, |
(...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1234 &actual_type); | 1239 &actual_type); |
1235 | 1240 |
1236 EXPECT_EQ(data.expected_bits, actual_bits); | 1241 EXPECT_EQ(data.expected_bits, actual_bits); |
1237 EXPECT_EQ(data.expected_type, actual_type); | 1242 EXPECT_EQ(data.expected_type, actual_type); |
1238 } | 1243 } |
1239 | 1244 |
1240 INSTANTIATE_TEST_CASE_P(, X509CertificatePublicKeyInfoTest, | 1245 INSTANTIATE_TEST_CASE_P(, X509CertificatePublicKeyInfoTest, |
1241 testing::ValuesIn(kPublicKeyInfoTestData)); | 1246 testing::ValuesIn(kPublicKeyInfoTestData)); |
1242 | 1247 |
1243 } // namespace net | 1248 } // namespace net |
OLD | NEW |