OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ssl/ssl_platform_key.h" | 5 #include "net/ssl/ssl_platform_key.h" |
6 | 6 |
7 #include <keyhi.h> | 7 #include <keyhi.h> |
8 #include <pk11pub.h> | 8 #include <pk11pub.h> |
9 #include <stdint.h> | 9 #include <stdint.h> |
10 #include <string.h> | 10 #include <string.h> |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 crypto::ScopedTestNSSDB test_db; | 67 crypto::ScopedTestNSSDB test_db; |
68 scoped_refptr<X509Certificate> cert; | 68 scoped_refptr<X509Certificate> cert; |
69 if (SSLPrivateKey::IsECDSAType(test_key.key_type)) { | 69 if (SSLPrivateKey::IsECDSAType(test_key.key_type)) { |
70 // NSS cannot import unencrypted ECDSA keys, so we encrypt it with an empty | 70 // NSS cannot import unencrypted ECDSA keys, so we encrypt it with an empty |
71 // password and import manually. | 71 // password and import manually. |
72 std::vector<uint8_t> pkcs8_vector(pkcs8.begin(), pkcs8.end()); | 72 std::vector<uint8_t> pkcs8_vector(pkcs8.begin(), pkcs8.end()); |
73 std::unique_ptr<crypto::ECPrivateKey> ec_private_key = | 73 std::unique_ptr<crypto::ECPrivateKey> ec_private_key = |
74 crypto::ECPrivateKey::CreateFromPrivateKeyInfo(pkcs8_vector); | 74 crypto::ECPrivateKey::CreateFromPrivateKeyInfo(pkcs8_vector); |
75 ASSERT_TRUE(ec_private_key); | 75 ASSERT_TRUE(ec_private_key); |
76 std::vector<uint8_t> encrypted; | 76 std::vector<uint8_t> encrypted; |
77 ASSERT_TRUE(ec_private_key->ExportEncryptedPrivateKey("", 1, &encrypted)); | 77 ASSERT_TRUE(ec_private_key->ExportEncryptedPrivateKey(&encrypted)); |
78 | 78 |
79 SECItem encrypted_item = {siBuffer, encrypted.data(), | 79 SECItem encrypted_item = {siBuffer, encrypted.data(), |
80 static_cast<unsigned>(encrypted.size())}; | 80 static_cast<unsigned>(encrypted.size())}; |
81 SECKEYEncryptedPrivateKeyInfo epki; | 81 SECKEYEncryptedPrivateKeyInfo epki; |
82 memset(&epki, 0, sizeof(epki)); | 82 memset(&epki, 0, sizeof(epki)); |
83 crypto::ScopedPLArenaPool arena(PORT_NewArena(DER_DEFAULT_CHUNKSIZE)); | 83 crypto::ScopedPLArenaPool arena(PORT_NewArena(DER_DEFAULT_CHUNKSIZE)); |
84 ASSERT_EQ(SECSuccess, | 84 ASSERT_EQ(SECSuccess, |
85 SEC_QuickDERDecodeItem( | 85 SEC_QuickDERDecodeItem( |
86 arena.get(), &epki, | 86 arena.get(), &epki, |
87 SEC_ASN1_GET(SECKEY_EncryptedPrivateKeyInfoTemplate), | 87 SEC_ASN1_GET(SECKEY_EncryptedPrivateKeyInfoTemplate), |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
132 | 132 |
133 TestSSLPrivateKeyMatches(key.get(), pkcs8); | 133 TestSSLPrivateKeyMatches(key.get(), pkcs8); |
134 } | 134 } |
135 | 135 |
136 INSTANTIATE_TEST_CASE_P(, | 136 INSTANTIATE_TEST_CASE_P(, |
137 SSLPlatformKeyNSSTest, | 137 SSLPlatformKeyNSSTest, |
138 testing::ValuesIn(kTestKeys), | 138 testing::ValuesIn(kTestKeys), |
139 TestKeyToString); | 139 TestKeyToString); |
140 | 140 |
141 } // namespace net | 141 } // namespace net |
OLD | NEW |