| 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 "crypto/ec_private_key.h" | 5 #include "crypto/ec_private_key.h" |
| 6 | 6 |
| 7 extern "C" { | 7 extern "C" { |
| 8 // Work around NSS missing SEC_BEGIN_PROTOS in secmodt.h. This must come before | 8 // Work around NSS missing SEC_BEGIN_PROTOS in secmodt.h. This must come before |
| 9 // other NSS headers. | 9 // other NSS headers. |
| 10 #include <secmodt.h> | 10 #include <secmodt.h> |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 // static | 107 // static |
| 108 bool ECPrivateKey::ImportFromEncryptedPrivateKeyInfo( | 108 bool ECPrivateKey::ImportFromEncryptedPrivateKeyInfo( |
| 109 const std::string& password, | 109 const std::string& password, |
| 110 const uint8* encrypted_private_key_info, | 110 const uint8* encrypted_private_key_info, |
| 111 size_t encrypted_private_key_info_len, | 111 size_t encrypted_private_key_info_len, |
| 112 CERTSubjectPublicKeyInfo* decoded_spki, | 112 CERTSubjectPublicKeyInfo* decoded_spki, |
| 113 bool permanent, | 113 bool permanent, |
| 114 bool sensitive, | 114 bool sensitive, |
| 115 SECKEYPrivateKey** key, | 115 SECKEYPrivateKey** key, |
| 116 SECKEYPublicKey** public_key) { | 116 SECKEYPublicKey** public_key) { |
| 117 ScopedPK11Slot slot(GetPublicNSSKeySlot()); | 117 ScopedPK11Slot slot(GetKeySlot()); |
| 118 if (!slot.get()) | 118 if (!slot.get()) |
| 119 return false; | 119 return false; |
| 120 | 120 |
| 121 *public_key = SECKEY_ExtractPublicKey(decoded_spki); | 121 *public_key = SECKEY_ExtractPublicKey(decoded_spki); |
| 122 | 122 |
| 123 if (!*public_key) { | 123 if (!*public_key) { |
| 124 DLOG(ERROR) << "SECKEY_ExtractPublicKey: " << PORT_GetError(); | 124 DLOG(ERROR) << "SECKEY_ExtractPublicKey: " << PORT_GetError(); |
| 125 return false; | 125 return false; |
| 126 } | 126 } |
| 127 | 127 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 DLOG(ERROR) << "ImportEncryptedECPrivateKeyInfoAndReturnKey: " | 167 DLOG(ERROR) << "ImportEncryptedECPrivateKeyInfoAndReturnKey: " |
| 168 << PORT_GetError(); | 168 << PORT_GetError(); |
| 169 SECKEY_DestroyPublicKey(*public_key); | 169 SECKEY_DestroyPublicKey(*public_key); |
| 170 *public_key = NULL; | 170 *public_key = NULL; |
| 171 return false; | 171 return false; |
| 172 } | 172 } |
| 173 | 173 |
| 174 return true; | 174 return true; |
| 175 } | 175 } |
| 176 | 176 |
| 177 // static |
| 178 PK11SlotInfo* ECPrivateKey::GetKeySlot() { |
| 179 return GetPublicNSSKeySlot(); |
| 180 } |
| 181 |
| 177 bool ECPrivateKey::ExportEncryptedPrivateKey( | 182 bool ECPrivateKey::ExportEncryptedPrivateKey( |
| 178 const std::string& password, | 183 const std::string& password, |
| 179 int iterations, | 184 int iterations, |
| 180 std::vector<uint8>* output) { | 185 std::vector<uint8>* output) { |
| 181 // We export as an EncryptedPrivateKeyInfo bundle instead of a plain PKCS #8 | 186 // We export as an EncryptedPrivateKeyInfo bundle instead of a plain PKCS #8 |
| 182 // PrivateKeyInfo because PK11_ImportDERPrivateKeyInfoAndReturnKey doesn't | 187 // PrivateKeyInfo because PK11_ImportDERPrivateKeyInfoAndReturnKey doesn't |
| 183 // support EC keys. | 188 // support EC keys. |
| 184 // https://bugzilla.mozilla.org/show_bug.cgi?id=327773 | 189 // https://bugzilla.mozilla.org/show_bug.cgi?id=327773 |
| 185 SECItem password_item = { | 190 SECItem password_item = { |
| 186 siBuffer, | 191 siBuffer, |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 | 245 |
| 241 ECPrivateKey::ECPrivateKey() : key_(NULL), public_key_(NULL) {} | 246 ECPrivateKey::ECPrivateKey() : key_(NULL), public_key_(NULL) {} |
| 242 | 247 |
| 243 // static | 248 // static |
| 244 ECPrivateKey* ECPrivateKey::CreateWithParams(bool permanent, | 249 ECPrivateKey* ECPrivateKey::CreateWithParams(bool permanent, |
| 245 bool sensitive) { | 250 bool sensitive) { |
| 246 EnsureNSSInit(); | 251 EnsureNSSInit(); |
| 247 | 252 |
| 248 scoped_ptr<ECPrivateKey> result(new ECPrivateKey); | 253 scoped_ptr<ECPrivateKey> result(new ECPrivateKey); |
| 249 | 254 |
| 250 ScopedPK11Slot slot(GetPrivateNSSKeySlot()); | 255 ScopedPK11Slot slot(GetKeySlot()); |
| 251 if (!slot.get()) | 256 if (!slot.get()) |
| 252 return NULL; | 257 return NULL; |
| 253 | 258 |
| 254 SECOidData* oid_data = SECOID_FindOIDByTag(SEC_OID_SECG_EC_SECP256R1); | 259 SECOidData* oid_data = SECOID_FindOIDByTag(SEC_OID_SECG_EC_SECP256R1); |
| 255 if (!oid_data) { | 260 if (!oid_data) { |
| 256 DLOG(ERROR) << "SECOID_FindOIDByTag: " << PORT_GetError(); | 261 DLOG(ERROR) << "SECOID_FindOIDByTag: " << PORT_GetError(); |
| 257 return NULL; | 262 return NULL; |
| 258 } | 263 } |
| 259 | 264 |
| 260 // SECKEYECParams is a SECItem containing the DER encoded ASN.1 ECParameters | 265 // SECKEYECParams is a SECItem containing the DER encoded ASN.1 ECParameters |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 | 327 |
| 323 SECKEY_DestroySubjectPublicKeyInfo(decoded_spki); | 328 SECKEY_DestroySubjectPublicKeyInfo(decoded_spki); |
| 324 | 329 |
| 325 if (success) | 330 if (success) |
| 326 return result.release(); | 331 return result.release(); |
| 327 | 332 |
| 328 return NULL; | 333 return NULL; |
| 329 } | 334 } |
| 330 | 335 |
| 331 } // namespace crypto | 336 } // namespace crypto |
| OLD | NEW |