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> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 } // namespace | 53 } // namespace |
54 | 54 |
55 bool GetFakeCertificateDER(const base::TimeDelta& expiry, | 55 bool GetFakeCertificateDER(const base::TimeDelta& expiry, |
56 std::string* certificate) { | 56 std::string* certificate) { |
57 base::Time valid_start = base::Time::Now() - base::TimeDelta::FromDays(1); | 57 base::Time valid_start = base::Time::Now() - base::TimeDelta::FromDays(1); |
58 base::Time valid_expiry = base::Time::Now() + expiry; | 58 base::Time valid_expiry = base::Time::Now() + expiry; |
59 if (valid_expiry <= valid_start) { | 59 if (valid_expiry <= valid_start) { |
60 valid_start = valid_expiry - base::TimeDelta::FromDays(1); | 60 valid_start = valid_expiry - base::TimeDelta::FromDays(1); |
61 } | 61 } |
62 scoped_ptr<crypto::RSAPrivateKey> test_key( | 62 std::unique_ptr<crypto::RSAPrivateKey> test_key( |
63 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(std::vector<uint8_t>( | 63 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(std::vector<uint8_t>( |
64 &kTestKeyData[0], &kTestKeyData[arraysize(kTestKeyData)]))); | 64 &kTestKeyData[0], &kTestKeyData[arraysize(kTestKeyData)]))); |
65 if (!test_key.get()) { | 65 if (!test_key.get()) { |
66 return false; | 66 return false; |
67 } | 67 } |
68 return net::x509_util::CreateSelfSignedCert( | 68 return net::x509_util::CreateSelfSignedCert( |
69 test_key.get(), net::x509_util::DIGEST_SHA256, "CN=subject", 12345, | 69 test_key.get(), net::x509_util::DIGEST_SHA256, "CN=subject", 12345, |
70 valid_start, valid_expiry, certificate); | 70 valid_start, valid_expiry, certificate); |
71 } | 71 } |
72 | 72 |
73 bool GetFakeCertificatePEM(const base::TimeDelta& expiry, | 73 bool GetFakeCertificatePEM(const base::TimeDelta& expiry, |
74 std::string* certificate) { | 74 std::string* certificate) { |
75 std::string certificate_der; | 75 std::string certificate_der; |
76 if (!GetFakeCertificateDER(expiry, &certificate_der)) { | 76 if (!GetFakeCertificateDER(expiry, &certificate_der)) { |
77 return false; | 77 return false; |
78 } | 78 } |
79 return net::X509Certificate::GetPEMEncodedFromDER(certificate_der, | 79 return net::X509Certificate::GetPEMEncodedFromDER(certificate_der, |
80 certificate); | 80 certificate); |
81 } | 81 } |
82 | 82 |
83 } // namespace attestation | 83 } // namespace attestation |
84 } // namespace chromeos | 84 } // namespace chromeos |
OLD | NEW |