Chromium Code Reviews| Index: crypto/rsa_private_key_nss.cc |
| diff --git a/crypto/rsa_private_key_nss.cc b/crypto/rsa_private_key_nss.cc |
| index bac72814fe16d1cc168c637a019ebda082dcd492..03cc254a4ada284957a7ce04b0c46fab00ee995c 100644 |
| --- a/crypto/rsa_private_key_nss.cc |
| +++ b/crypto/rsa_private_key_nss.cc |
| @@ -105,32 +105,41 @@ RSAPrivateKey* RSAPrivateKey::FindFromPublicKeyInfo( |
| return NULL; |
| } |
| - // Now, look for the associated private key in the user's |
| - // hardware-backed NSS DB. If it's not there, consider that an |
| - // error. |
| - PK11SlotInfo *slot = GetPrivateNSSKeySlot(); |
| - if (!slot) { |
| - NOTREACHED(); |
| - return NULL; |
| - } |
| - |
| // Make sure the key is an RSA key. If not, that's an error |
| if (result->public_key_->keyType != rsaKey) { |
| - PK11_FreeSlot(slot); |
| NOTREACHED(); |
| return NULL; |
| } |
| SECItem *ck_id = PK11_MakeIDFromPubKey(&(result->public_key_->u.rsa.modulus)); |
|
Ryan Sleevi
2011/05/25 05:58:25
You can make this a ScopedSECItem (see src/crypto/
Greg Spencer (Chromium)
2011/05/25 17:12:07
Good point. I forgot about the scoped nss types.
|
| if (!ck_id) { |
| - PK11_FreeSlot(slot); |
| NOTREACHED(); |
| return NULL; |
| } |
| + PK11SlotInfo* slot = GetPrivateNSSKeySlot(); |
| + if (!slot) { |
| + NOTREACHED(); |
| + SECITEM_FreeItem(ck_id, PR_TRUE); |
| + return NULL; |
| + } |
| + |
| // Finally...Look for the key! |
| result->key_ = PK11_FindKeyByKeyID(slot, ck_id, NULL); |
| + // If we don't find the matching key in the private slot, then we |
| + // look in the public slot. |
| + if (!result->key_) { |
| + PK11_FreeSlot(slot); |
| + slot = GetPublicNSSKeySlot(); |
|
Ryan Sleevi
2011/05/25 05:58:25
According to the header comments for GetPublicNSSK
Greg Spencer (Chromium)
2011/05/25 17:12:07
Yes, I wrote those comments.
The general policy f
|
| + if (!slot) { |
| + NOTREACHED(); |
| + SECITEM_FreeItem(ck_id, PR_TRUE); |
| + return NULL; |
| + } |
| + result->key_ = PK11_FindKeyByKeyID(slot, ck_id, NULL); |
| + } |
| + |
| // Cleanup... |
| PK11_FreeSlot(slot); |
| SECITEM_FreeItem(ck_id, PR_TRUE); |