Chromium Code Reviews| 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 |
| 11 #include <iostream> | 11 #include <iostream> |
| 12 #include <list> | 12 #include <list> |
| 13 | 13 |
| 14 #include "base/leak_annotations.h" | |
| 14 #include "base/logging.h" | 15 #include "base/logging.h" |
| 15 #include "base/nss_util.h" | 16 #include "base/nss_util.h" |
| 16 #include "base/scoped_ptr.h" | 17 #include "base/scoped_ptr.h" |
| 17 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| 18 | 19 |
| 19 // TODO(rafaelw): Consider refactoring common functions and definitions from | 20 // TODO(rafaelw): Consider refactoring common functions and definitions from |
| 20 // rsa_private_key_win.cc or using NSS's ASN.1 encoder. | 21 // rsa_private_key_win.cc or using NSS's ASN.1 encoder. |
| 21 namespace { | 22 namespace { |
| 22 | 23 |
| 23 static bool ReadAttribute(SECKEYPrivateKey* key, | 24 static bool ReadAttribute(SECKEYPrivateKey* key, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 56 PK11_FreeSlot(slot); | 57 PK11_FreeSlot(slot); |
| 57 if (!result->key_) | 58 if (!result->key_) |
| 58 return NULL; | 59 return NULL; |
| 59 | 60 |
| 60 return result.release(); | 61 return result.release(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 // static | 64 // static |
| 64 RSAPrivateKey* RSAPrivateKey::CreateFromPrivateKeyInfo( | 65 RSAPrivateKey* RSAPrivateKey::CreateFromPrivateKeyInfo( |
| 65 const std::vector<uint8>& input) { | 66 const std::vector<uint8>& input) { |
| 67 // This method currently leaks some memory. | |
| 68 // See http://crbug.com/34742. | |
| 69 ANNOTATE_SCOPED_MEMORY_LEAK; | |
| 66 scoped_ptr<RSAPrivateKey> result(new RSAPrivateKey); | 70 scoped_ptr<RSAPrivateKey> result(new RSAPrivateKey); |
| 67 | 71 |
| 68 PK11SlotInfo *slot = PK11_GetInternalSlot(); | 72 PK11SlotInfo *slot = PK11_GetInternalSlot(); |
| 69 if (!slot) | 73 if (!slot) |
| 70 return NULL; | 74 return NULL; |
| 71 | 75 |
| 72 SECItem der_private_key_info; | 76 SECItem der_private_key_info; |
| 73 der_private_key_info.data = const_cast<unsigned char*>(&input.front()); | 77 der_private_key_info.data = const_cast<unsigned char*>(&input.front()); |
| 74 der_private_key_info.len = input.size(); | 78 der_private_key_info.len = input.size(); |
| 75 SECStatus rv = PK11_ImportDERPrivateKeyInfoAndReturnKey(slot, | 79 SECStatus rv = PK11_ImportDERPrivateKeyInfoAndReturnKey(slot, |
|
wtc
2010/03/24 19:17:06
If the annotation doesn't need to be at the beginn
| |
| 76 &der_private_key_info, NULL, NULL, PR_FALSE, PR_FALSE, | 80 &der_private_key_info, NULL, NULL, PR_FALSE, PR_FALSE, |
| 77 KU_DIGITAL_SIGNATURE, &result->key_, NULL); | 81 KU_DIGITAL_SIGNATURE, &result->key_, NULL); |
| 78 PK11_FreeSlot(slot); | 82 PK11_FreeSlot(slot); |
| 79 if (rv != SECSuccess) { | 83 if (rv != SECSuccess) { |
| 80 NOTREACHED(); | 84 NOTREACHED(); |
| 81 return NULL; | 85 return NULL; |
| 82 } | 86 } |
| 83 | 87 |
| 84 result->public_key_ = SECKEY_ConvertToPublicKey(result->key_); | 88 result->public_key_ = SECKEY_ConvertToPublicKey(result->key_); |
| 85 if (!result->public_key_) { | 89 if (!result->public_key_) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 131 } | 135 } |
| 132 | 136 |
| 133 for (size_t i = 0; i < der_pubkey->len; ++i) | 137 for (size_t i = 0; i < der_pubkey->len; ++i) |
| 134 output->push_back(der_pubkey->data[i]); | 138 output->push_back(der_pubkey->data[i]); |
| 135 | 139 |
| 136 SECITEM_FreeItem(der_pubkey, PR_TRUE); | 140 SECITEM_FreeItem(der_pubkey, PR_TRUE); |
| 137 return true; | 141 return true; |
| 138 } | 142 } |
| 139 | 143 |
| 140 } // namespace base | 144 } // namespace base |
| OLD | NEW |