| 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_util.h" | 5 #include "net/cert/x509_util.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/memory/ref_counted.h" | 9 #include "base/memory/ref_counted.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 der_cert.data(), der_cert.size())); | 72 der_cert.data(), der_cert.size())); |
| 73 ASSERT_TRUE(cert.get()); | 73 ASSERT_TRUE(cert.get()); |
| 74 | 74 |
| 75 EXPECT_EQ("subject", cert->subject().GetDisplayName()); | 75 EXPECT_EQ("subject", cert->subject().GetDisplayName()); |
| 76 EXPECT_FALSE(cert->HasExpired()); | 76 EXPECT_FALSE(cert->HasExpired()); |
| 77 } | 77 } |
| 78 | 78 |
| 79 // This test creates a self-signed cert from a private key and then verifies the | 79 // This test creates a self-signed cert from a private key and then verifies the |
| 80 // content of the certificate. | 80 // content of the certificate. |
| 81 TEST(X509UtilTest, CreateSelfSigned) { | 81 TEST(X509UtilTest, CreateSelfSigned) { |
| 82 const uint8 private_key_info[] = { | 82 const uint8_t private_key_info[] = { |
| 83 0x30, 0x82, 0x02, 0x78, 0x02, 0x01, 0x00, 0x30, | 83 0x30, 0x82, 0x02, 0x78, 0x02, 0x01, 0x00, 0x30, |
| 84 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, | 84 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, |
| 85 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, | 85 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82, |
| 86 0x02, 0x62, 0x30, 0x82, 0x02, 0x5e, 0x02, 0x01, | 86 0x02, 0x62, 0x30, 0x82, 0x02, 0x5e, 0x02, 0x01, |
| 87 0x00, 0x02, 0x81, 0x81, 0x00, 0xb8, 0x7f, 0x2b, | 87 0x00, 0x02, 0x81, 0x81, 0x00, 0xb8, 0x7f, 0x2b, |
| 88 0x20, 0xdc, 0x7c, 0x9b, 0x0c, 0xdc, 0x51, 0x61, | 88 0x20, 0xdc, 0x7c, 0x9b, 0x0c, 0xdc, 0x51, 0x61, |
| 89 0x99, 0x0d, 0x36, 0x0f, 0xd4, 0x66, 0x88, 0x08, | 89 0x99, 0x0d, 0x36, 0x0f, 0xd4, 0x66, 0x88, 0x08, |
| 90 0x55, 0x84, 0xd5, 0x3a, 0xbf, 0x2b, 0xa4, 0x64, | 90 0x55, 0x84, 0xd5, 0x3a, 0xbf, 0x2b, 0xa4, 0x64, |
| 91 0x85, 0x7b, 0x0c, 0x04, 0x13, 0x3f, 0x8d, 0xf4, | 91 0x85, 0x7b, 0x0c, 0x04, 0x13, 0x3f, 0x8d, 0xf4, |
| 92 0xbc, 0x38, 0x0d, 0x49, 0xfe, 0x6b, 0xc4, 0x5a, | 92 0xbc, 0x38, 0x0d, 0x49, 0xfe, 0x6b, 0xc4, 0x5a, |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 0x76, 0xc4, 0x82, 0xfa, 0x5c, 0xc3, 0x79, 0x35, | 155 0x76, 0xc4, 0x82, 0xfa, 0x5c, 0xc3, 0x79, 0x35, |
| 156 0x3e, 0x70, 0x8a, 0xbf, 0x27, 0x49, 0xb0, 0x99, | 156 0x3e, 0x70, 0x8a, 0xbf, 0x27, 0x49, 0xb0, 0x99, |
| 157 0x63, 0xcb, 0x77, 0x5f, 0xa8, 0x82, 0x65, 0xf6, | 157 0x63, 0xcb, 0x77, 0x5f, 0xa8, 0x82, 0x65, 0xf6, |
| 158 0x03, 0x52, 0x51, 0xf1, 0xae, 0x2e, 0x05, 0xb3, | 158 0x03, 0x52, 0x51, 0xf1, 0xae, 0x2e, 0x05, 0xb3, |
| 159 0xc6, 0xa4, 0x92, 0xd1, 0xce, 0x6c, 0x72, 0xfb, | 159 0xc6, 0xa4, 0x92, 0xd1, 0xce, 0x6c, 0x72, 0xfb, |
| 160 0x21, 0xb3, 0x02, 0x87, 0xe4, 0xfd, 0x61, 0xca, | 160 0x21, 0xb3, 0x02, 0x87, 0xe4, 0xfd, 0x61, 0xca, |
| 161 0x00, 0x42, 0x19, 0xf0, 0xda, 0x5a, 0x53, 0xe3, | 161 0x00, 0x42, 0x19, 0xf0, 0xda, 0x5a, 0x53, 0xe3, |
| 162 0xb1, 0xc5, 0x15, 0xf3 | 162 0xb1, 0xc5, 0x15, 0xf3 |
| 163 }; | 163 }; |
| 164 | 164 |
| 165 std::vector<uint8> input; | 165 std::vector<uint8_t> input; |
| 166 input.resize(sizeof(private_key_info)); | 166 input.resize(sizeof(private_key_info)); |
| 167 memcpy(&input.front(), private_key_info, sizeof(private_key_info)); | 167 memcpy(&input.front(), private_key_info, sizeof(private_key_info)); |
| 168 | 168 |
| 169 scoped_ptr<crypto::RSAPrivateKey> private_key( | 169 scoped_ptr<crypto::RSAPrivateKey> private_key( |
| 170 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(input)); | 170 crypto::RSAPrivateKey::CreateFromPrivateKeyInfo(input)); |
| 171 ASSERT_TRUE(private_key.get()); | 171 ASSERT_TRUE(private_key.get()); |
| 172 | 172 |
| 173 std::string der_cert; | 173 std::string der_cert; |
| 174 ASSERT_TRUE(x509_util::CreateSelfSignedCert( | 174 ASSERT_TRUE(x509_util::CreateSelfSignedCert( |
| 175 private_key.get(), | 175 private_key.get(), |
| 176 x509_util::DIGEST_SHA1, | 176 x509_util::DIGEST_SHA1, |
| 177 "CN=subject", | 177 "CN=subject", |
| 178 1, | 178 1, |
| 179 base::Time::Now(), | 179 base::Time::Now(), |
| 180 base::Time::Now() + base::TimeDelta::FromDays(1), | 180 base::Time::Now() + base::TimeDelta::FromDays(1), |
| 181 &der_cert)); | 181 &der_cert)); |
| 182 | 182 |
| 183 scoped_refptr<X509Certificate> cert = | 183 scoped_refptr<X509Certificate> cert = |
| 184 X509Certificate::CreateFromBytes(der_cert.data(), der_cert.size()); | 184 X509Certificate::CreateFromBytes(der_cert.data(), der_cert.size()); |
| 185 ASSERT_TRUE(cert.get()); | 185 ASSERT_TRUE(cert.get()); |
| 186 | 186 |
| 187 EXPECT_EQ("subject", cert->subject().GetDisplayName()); | 187 EXPECT_EQ("subject", cert->subject().GetDisplayName()); |
| 188 EXPECT_FALSE(cert->HasExpired()); | 188 EXPECT_FALSE(cert->HasExpired()); |
| 189 } | 189 } |
| 190 | 190 |
| 191 } // namespace x509_util | 191 } // namespace x509_util |
| 192 | 192 |
| 193 } // namespace net | 193 } // namespace net |
| OLD | NEW |