Commit 67840e51 authored by davidben's avatar davidben Committed by Commit bot

Use FindNSSKeyFromPublicKeyInfoInSlot when a slot is known.

Follow-up to https://codereview.chromium.org/1128153003/. Rather than query all
keys and checking the slot afterwards, just look up keys in the slot directly.

BUG=478777

Review URL: https://codereview.chromium.org/1139533002

Cr-Commit-Position: refs/heads/master@{#329498}
parent f97970c1
...@@ -79,24 +79,22 @@ void EnsureUserTPMInitializedOnIOThread( ...@@ -79,24 +79,22 @@ void EnsureUserTPMInitializedOnIOThread(
} }
// Checks if a private RSA key associated with |public_key| can be found in // Checks if a private RSA key associated with |public_key| can be found in
// |slot|. // |slot|. |slot| must be non-null.
// Must be called on a worker thread. // Must be called on a worker thread.
crypto::ScopedSECKEYPrivateKey GetPrivateKeyOnWorkerThread( crypto::ScopedSECKEYPrivateKey GetPrivateKeyOnWorkerThread(
PK11SlotInfo* slot, PK11SlotInfo* slot,
const std::string& public_key) { const std::string& public_key) {
CHECK(slot);
const uint8* public_key_uint8 = const uint8* public_key_uint8 =
reinterpret_cast<const uint8*>(public_key.data()); reinterpret_cast<const uint8*>(public_key.data());
std::vector<uint8> public_key_vector( std::vector<uint8> public_key_vector(
public_key_uint8, public_key_uint8 + public_key.size()); public_key_uint8, public_key_uint8 + public_key.size());
// TODO(davidben): This should be equivalent to calling
// FindNSSKeyFromPublicKeyInfoInSlot.
crypto::ScopedSECKEYPrivateKey rsa_key( crypto::ScopedSECKEYPrivateKey rsa_key(
crypto::FindNSSKeyFromPublicKeyInfo(public_key_vector)); crypto::FindNSSKeyFromPublicKeyInfoInSlot(public_key_vector, slot));
if (!rsa_key || rsa_key->pkcs11Slot != slot || if (!rsa_key || SECKEY_GetPrivateKeyType(rsa_key.get()) != rsaKey)
SECKEY_GetPrivateKeyType(rsa_key.get()) != rsaKey) {
return nullptr; return nullptr;
}
return rsa_key.Pass(); return rsa_key.Pass();
} }
......
...@@ -451,14 +451,16 @@ void SignRSAOnWorkerThread(scoped_ptr<SignRSAState> state) { ...@@ -451,14 +451,16 @@ void SignRSAOnWorkerThread(scoped_ptr<SignRSAState> state) {
std::vector<uint8> public_key_vector( std::vector<uint8> public_key_vector(
public_key_uint8, public_key_uint8 + state->public_key_.size()); public_key_uint8, public_key_uint8 + state->public_key_.size());
// TODO(pneubeck): This searches all slots. Change to look only at |slot_|. crypto::ScopedSECKEYPrivateKey rsa_key;
crypto::ScopedSECKEYPrivateKey rsa_key( if (state->slot_) {
crypto::FindNSSKeyFromPublicKeyInfo(public_key_vector)); rsa_key = crypto::FindNSSKeyFromPublicKeyInfoInSlot(public_key_vector,
state->slot_.get());
// Fail if the key was not found. If a specific slot was requested, also fail } else {
// if the key was found in the wrong slot. rsa_key = crypto::FindNSSKeyFromPublicKeyInfo(public_key_vector);
if (!rsa_key || SECKEY_GetPrivateKeyType(rsa_key.get()) != rsaKey || }
(state->slot_ && rsa_key->pkcs11Slot != state->slot_)) {
// Fail if the key was not found or is of the wrong type.
if (!rsa_key || SECKEY_GetPrivateKeyType(rsa_key.get()) != rsaKey) {
state->OnError(FROM_HERE, kErrorKeyNotFound); state->OnError(FROM_HERE, kErrorKeyNotFound);
return; return;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment