OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "chrome/browser/chromeos/attestation/fake_certificate.h" | 5 #include "chrome/browser/chromeos/attestation/fake_certificate.h" |
6 | 6 |
| 7 #include <stdint.h> |
| 8 |
| 9 #include "base/macros.h" |
7 #include "base/time/time.h" | 10 #include "base/time/time.h" |
8 #include "crypto/rsa_private_key.h" | 11 #include "crypto/rsa_private_key.h" |
9 #include "net/cert/x509_certificate.h" | 12 #include "net/cert/x509_certificate.h" |
10 #include "net/cert/x509_util.h" | 13 #include "net/cert/x509_util.h" |
11 | 14 |
12 namespace chromeos { | 15 namespace chromeos { |
13 namespace attestation { | 16 namespace attestation { |
14 | 17 |
15 namespace { | 18 namespace { |
16 | 19 |
17 // A test key encoded as ASN.1 PrivateKeyInfo from PKCS #8. | 20 // A test key encoded as ASN.1 PrivateKeyInfo from PKCS #8. |
18 const uint8 kTestKeyData[] = { | 21 const uint8_t kTestKeyData[] = { |
19 0x30, 0x82, 0x01, 0x55, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a, | 22 0x30, 0x82, 0x01, 0x55, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a, |
20 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, | 23 0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, |
21 0x01, 0x3f, 0x30, 0x82, 0x01, 0x3b, 0x02, 0x01, 0x00, 0x02, 0x41, 0x00, | 24 0x01, 0x3f, 0x30, 0x82, 0x01, 0x3b, 0x02, 0x01, 0x00, 0x02, 0x41, 0x00, |
22 0xd9, 0xcd, 0xca, 0xcd, 0xc3, 0xea, 0xbe, 0x72, 0x79, 0x1c, 0x29, 0x37, | 25 0xd9, 0xcd, 0xca, 0xcd, 0xc3, 0xea, 0xbe, 0x72, 0x79, 0x1c, 0x29, 0x37, |
23 0x39, 0x99, 0x1f, 0xd4, 0xb3, 0x0e, 0xf0, 0x7b, 0x78, 0x77, 0x0e, 0x05, | 26 0x39, 0x99, 0x1f, 0xd4, 0xb3, 0x0e, 0xf0, 0x7b, 0x78, 0x77, 0x0e, 0x05, |
24 0x3b, 0x65, 0x34, 0x12, 0x62, 0xaf, 0xa6, 0x8d, 0x33, 0xce, 0x78, 0xf8, | 27 0x3b, 0x65, 0x34, 0x12, 0x62, 0xaf, 0xa6, 0x8d, 0x33, 0xce, 0x78, 0xf8, |
25 0x47, 0x05, 0x1d, 0x98, 0xaa, 0x1b, 0x1f, 0x50, 0x05, 0x5b, 0x3c, 0x19, | 28 0x47, 0x05, 0x1d, 0x98, 0xaa, 0x1b, 0x1f, 0x50, 0x05, 0x5b, 0x3c, 0x19, |
26 0x3f, 0x80, 0x83, 0x63, 0x63, 0x3a, 0xec, 0xcb, 0x2e, 0x90, 0x4f, 0xf5, | 29 0x3f, 0x80, 0x83, 0x63, 0x63, 0x3a, 0xec, 0xcb, 0x2e, 0x90, 0x4f, 0xf5, |
27 0x26, 0x76, 0xf1, 0xd5, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x40, 0x64, | 30 0x26, 0x76, 0xf1, 0xd5, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x40, 0x64, |
28 0x29, 0xc2, 0xd9, 0x6b, 0xfe, 0xf9, 0x84, 0x75, 0x73, 0xe0, 0xf4, 0x77, | 31 0x29, 0xc2, 0xd9, 0x6b, 0xfe, 0xf9, 0x84, 0x75, 0x73, 0xe0, 0xf4, 0x77, |
(...skipping 21 matching lines...) Expand all Loading... |
50 } // namespace | 53 } // namespace |
51 | 54 |
52 bool GetFakeCertificateDER(const base::TimeDelta& expiry, | 55 bool GetFakeCertificateDER(const base::TimeDelta& expiry, |
53 std::string* certificate) { | 56 std::string* certificate) { |
54 base::Time valid_start = base::Time::Now() - base::TimeDelta::FromDays(1); | 57 base::Time valid_start = base::Time::Now() - base::TimeDelta::FromDays(1); |
55 base::Time valid_expiry = base::Time::Now() + expiry; | 58 base::Time valid_expiry = base::Time::Now() + expiry; |
56 if (valid_expiry <= valid_start) { | 59 if (valid_expiry <= valid_start) { |
57 valid_start = valid_expiry - base::TimeDelta::FromDays(1); | 60 valid_start = valid_expiry - base::TimeDelta::FromDays(1); |
58 } | 61 } |
59 scoped_ptr<crypto::RSAPrivateKey> test_key( | 62 scoped_ptr<crypto::RSAPrivateKey> test_key( |
60 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo( | 63 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(std::vector<uint8_t>( |
61 std::vector<uint8>(&kTestKeyData[0], | 64 &kTestKeyData[0], &kTestKeyData[arraysize(kTestKeyData)]))); |
62 &kTestKeyData[arraysize(kTestKeyData)]))); | |
63 if (!test_key.get()) { | 65 if (!test_key.get()) { |
64 return false; | 66 return false; |
65 } | 67 } |
66 return net::x509_util::CreateSelfSignedCert( | 68 return net::x509_util::CreateSelfSignedCert( |
67 test_key.get(), net::x509_util::DIGEST_SHA256, "CN=subject", 12345, | 69 test_key.get(), net::x509_util::DIGEST_SHA256, "CN=subject", 12345, |
68 valid_start, valid_expiry, certificate); | 70 valid_start, valid_expiry, certificate); |
69 } | 71 } |
70 | 72 |
71 bool GetFakeCertificatePEM(const base::TimeDelta& expiry, | 73 bool GetFakeCertificatePEM(const base::TimeDelta& expiry, |
72 std::string* certificate) { | 74 std::string* certificate) { |
73 std::string certificate_der; | 75 std::string certificate_der; |
74 if (!GetFakeCertificateDER(expiry, &certificate_der)) { | 76 if (!GetFakeCertificateDER(expiry, &certificate_der)) { |
75 return false; | 77 return false; |
76 } | 78 } |
77 return net::X509Certificate::GetPEMEncodedFromDER(certificate_der, | 79 return net::X509Certificate::GetPEMEncodedFromDER(certificate_der, |
78 certificate); | 80 certificate); |
79 } | 81 } |
80 | 82 |
81 } // namespace attestation | 83 } // namespace attestation |
82 } // namespace chromeos | 84 } // namespace chromeos |
OLD | NEW |