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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 // PrivateKeyInfo because PK11_ImportDERPrivateKeyInfoAndReturnKey doesn't | 238 // PrivateKeyInfo because PK11_ImportDERPrivateKeyInfoAndReturnKey doesn't |
239 // support EC keys. | 239 // support EC keys. |
240 // https://bugzilla.mozilla.org/show_bug.cgi?id=327773 | 240 // https://bugzilla.mozilla.org/show_bug.cgi?id=327773 |
241 SECItem password_item = { | 241 SECItem password_item = { |
242 siBuffer, | 242 siBuffer, |
243 reinterpret_cast<unsigned char*>(const_cast<char*>(password.data())), | 243 reinterpret_cast<unsigned char*>(const_cast<char*>(password.data())), |
244 static_cast<unsigned>(password.size()) | 244 static_cast<unsigned>(password.size()) |
245 }; | 245 }; |
246 | 246 |
247 SECKEYEncryptedPrivateKeyInfo* encrypted = PK11_ExportEncryptedPrivKeyInfo( | 247 SECKEYEncryptedPrivateKeyInfo* encrypted = PK11_ExportEncryptedPrivKeyInfo( |
248 NULL, // Slot, optional. | 248 NULL, // Slot, optional. |
249 SEC_OID_PKCS12_V2_PBE_WITH_SHA1_AND_3KEY_TRIPLE_DES_CBC, | 249 SEC_OID_PKCS12_V2_PBE_WITH_SHA1_AND_3KEY_TRIPLE_DES_CBC, |
250 &password_item, | 250 &password_item, |
251 key_, | 251 key_, |
252 iterations, | 252 iterations, |
253 NULL); // wincx. | 253 NULL); // wincx. |
254 | 254 |
255 if (!encrypted) { | 255 if (!encrypted) { |
256 DLOG(ERROR) << "PK11_ExportEncryptedPrivKeyInfo: " << PORT_GetError(); | 256 DLOG(ERROR) << "PK11_ExportEncryptedPrivKeyInfo: " << PORT_GetError(); |
257 return false; | 257 return false; |
258 } | 258 } |
259 | 259 |
260 ScopedPLArenaPool arena(PORT_NewArena(DER_DEFAULT_CHUNKSIZE)); | 260 ScopedPLArenaPool arena(PORT_NewArena(DER_DEFAULT_CHUNKSIZE)); |
261 SECItem der_key = {siBuffer, NULL, 0}; | 261 SECItem der_key = {siBuffer, NULL, 0}; |
262 SECItem* encoded_item = SEC_ASN1EncodeItem( | 262 SECItem* encoded_item = SEC_ASN1EncodeItem( |
263 arena.get(), | 263 arena.get(), |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 | 396 |
397 if (success) { | 397 if (success) { |
398 CHECK_EQ(ecKey, SECKEY_GetPublicKeyType(result->public_key_)); | 398 CHECK_EQ(ecKey, SECKEY_GetPublicKeyType(result->public_key_)); |
399 return result.release(); | 399 return result.release(); |
400 } | 400 } |
401 | 401 |
402 return NULL; | 402 return NULL; |
403 } | 403 } |
404 | 404 |
405 } // namespace crypto | 405 } // namespace crypto |
OLD | NEW |