| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "base/crypto/rsa_private_key.h" | 5 #include "base/crypto/rsa_private_key.h" |
| 6 | 6 |
| 7 #include <cryptohi.h> | 7 #include <cryptohi.h> |
| 8 #include <keyhi.h> | 8 #include <keyhi.h> |
| 9 #include <pk11pub.h> | 9 #include <pk11pub.h> |
| 10 | 10 |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 | 216 |
| 217 scoped_ptr<RSAPrivateKey> result(new RSAPrivateKey); | 217 scoped_ptr<RSAPrivateKey> result(new RSAPrivateKey); |
| 218 | 218 |
| 219 PK11SlotInfo *slot = GetDefaultNSSKeySlot(); | 219 PK11SlotInfo *slot = GetDefaultNSSKeySlot(); |
| 220 if (!slot) | 220 if (!slot) |
| 221 return NULL; | 221 return NULL; |
| 222 | 222 |
| 223 SECItem der_private_key_info; | 223 SECItem der_private_key_info; |
| 224 der_private_key_info.data = const_cast<unsigned char*>(&input.front()); | 224 der_private_key_info.data = const_cast<unsigned char*>(&input.front()); |
| 225 der_private_key_info.len = input.size(); | 225 der_private_key_info.len = input.size(); |
| 226 SECStatus rv = PK11_ImportDERPrivateKeyInfoAndReturnKey(slot, | 226 // Allow the private key to be used for key unwrapping, data decryption, |
| 227 &der_private_key_info, NULL, NULL, permanent, sensitive, | 227 // and signature generation. |
| 228 KU_DIGITAL_SIGNATURE, &result->key_, NULL); | 228 const unsigned int key_usage = KU_KEY_ENCIPHERMENT | KU_DATA_ENCIPHERMENT | |
| 229 KU_DIGITAL_SIGNATURE; |
| 230 SECStatus rv = PK11_ImportDERPrivateKeyInfoAndReturnKey( |
| 231 slot, &der_private_key_info, NULL, NULL, permanent, sensitive, |
| 232 key_usage, &result->key_, NULL); |
| 229 PK11_FreeSlot(slot); | 233 PK11_FreeSlot(slot); |
| 230 if (rv != SECSuccess) { | 234 if (rv != SECSuccess) { |
| 231 NOTREACHED(); | 235 NOTREACHED(); |
| 232 return NULL; | 236 return NULL; |
| 233 } | 237 } |
| 234 | 238 |
| 235 result->public_key_ = SECKEY_ConvertToPublicKey(result->key_); | 239 result->public_key_ = SECKEY_ConvertToPublicKey(result->key_); |
| 236 if (!result->public_key_) { | 240 if (!result->public_key_) { |
| 237 NOTREACHED(); | 241 NOTREACHED(); |
| 238 return NULL; | 242 return NULL; |
| 239 } | 243 } |
| 240 | 244 |
| 241 return result.release(); | 245 return result.release(); |
| 242 } | 246 } |
| 243 | 247 |
| 244 } // namespace base | 248 } // namespace base |
| OLD | NEW |