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(
}
// 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.
crypto::ScopedSECKEYPrivateKey GetPrivateKeyOnWorkerThread(
PK11SlotInfo* slot,
const std::string& public_key) {
CHECK(slot);
const uint8* public_key_uint8 =
reinterpret_cast<const uint8*>(public_key.data());
std::vector<uint8> public_key_vector(
public_key_uint8, public_key_uint8 + public_key.size());
// TODO(davidben): This should be equivalent to calling
// FindNSSKeyFromPublicKeyInfoInSlot.
crypto::ScopedSECKEYPrivateKey rsa_key(
crypto::FindNSSKeyFromPublicKeyInfo(public_key_vector));
if (!rsa_key || rsa_key->pkcs11Slot != slot ||
SECKEY_GetPrivateKeyType(rsa_key.get()) != rsaKey) {
crypto::FindNSSKeyFromPublicKeyInfoInSlot(public_key_vector, slot));
if (!rsa_key || SECKEY_GetPrivateKeyType(rsa_key.get()) != rsaKey)
return nullptr;
}
return rsa_key.Pass();
}
......
......@@ -451,14 +451,16 @@ void SignRSAOnWorkerThread(scoped_ptr<SignRSAState> state) {
std::vector<uint8> public_key_vector(
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::FindNSSKeyFromPublicKeyInfo(public_key_vector));
// Fail if the key was not found. If a specific slot was requested, also fail
// if the key was found in the wrong slot.
if (!rsa_key || SECKEY_GetPrivateKeyType(rsa_key.get()) != rsaKey ||
(state->slot_ && rsa_key->pkcs11Slot != state->slot_)) {
crypto::ScopedSECKEYPrivateKey rsa_key;
if (state->slot_) {
rsa_key = crypto::FindNSSKeyFromPublicKeyInfoInSlot(public_key_vector,
state->slot_.get());
} else {
rsa_key = crypto::FindNSSKeyFromPublicKeyInfo(public_key_vector);
}
// 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);
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