| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/rsa_private_key.h" | 5 #include "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 #include <secmod.h> | 10 #include <secmod.h> |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 | 278 |
| 279 scoped_ptr<RSAPrivateKey> result(new RSAPrivateKey); | 279 scoped_ptr<RSAPrivateKey> result(new RSAPrivateKey); |
| 280 | 280 |
| 281 SECItem der_private_key_info; | 281 SECItem der_private_key_info; |
| 282 der_private_key_info.data = const_cast<unsigned char*>(&input.front()); | 282 der_private_key_info.data = const_cast<unsigned char*>(&input.front()); |
| 283 der_private_key_info.len = input.size(); | 283 der_private_key_info.len = input.size(); |
| 284 // Allow the private key to be used for key unwrapping, data decryption, | 284 // Allow the private key to be used for key unwrapping, data decryption, |
| 285 // and signature generation. | 285 // and signature generation. |
| 286 const unsigned int key_usage = KU_KEY_ENCIPHERMENT | KU_DATA_ENCIPHERMENT | | 286 const unsigned int key_usage = KU_KEY_ENCIPHERMENT | KU_DATA_ENCIPHERMENT | |
| 287 KU_DIGITAL_SIGNATURE; | 287 KU_DIGITAL_SIGNATURE; |
| 288 // TODO(davidben): PK11_ImportDERPrivateKeyInfoAndReturnKey calls NSS's |
| 289 // SEC_ASN1DecodeItem which does not enforce that there is no trailing |
| 290 // data. |
| 288 SECStatus rv = PK11_ImportDERPrivateKeyInfoAndReturnKey( | 291 SECStatus rv = PK11_ImportDERPrivateKeyInfoAndReturnKey( |
| 289 slot, &der_private_key_info, NULL, NULL, permanent, sensitive, | 292 slot, &der_private_key_info, NULL, NULL, permanent, sensitive, |
| 290 key_usage, &result->key_, NULL); | 293 key_usage, &result->key_, NULL); |
| 291 if (rv != SECSuccess) { | 294 if (rv != SECSuccess) { |
| 292 NOTREACHED(); | 295 NOTREACHED(); |
| 293 return NULL; | 296 return NULL; |
| 294 } | 297 } |
| 295 | 298 |
| 296 result->public_key_ = SECKEY_ConvertToPublicKey(result->key_); | 299 result->public_key_ = SECKEY_ConvertToPublicKey(result->key_); |
| 297 if (!result->public_key_) { | 300 if (!result->public_key_) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 312 if (!result->public_key_) { | 315 if (!result->public_key_) { |
| 313 NOTREACHED(); | 316 NOTREACHED(); |
| 314 return NULL; | 317 return NULL; |
| 315 } | 318 } |
| 316 | 319 |
| 317 return result.release(); | 320 return result.release(); |
| 318 } | 321 } |
| 319 #endif // defined(USE_NSS) | 322 #endif // defined(USE_NSS) |
| 320 | 323 |
| 321 } // namespace crypto | 324 } // namespace crypto |
| OLD | NEW |