Report invalid key when key import fails. Do not go on and use invalid

key handle.  Bug 283642.  r=relyea
This commit is contained in:
nelsonb%netscape.com 2005-02-27 15:25:46 +00:00
parent dc41d37763
commit d614d9c9ff

View File

@ -583,6 +583,12 @@ PK11_VerifyRecover(SECKEYPublicKey *key,
PK11_ReferenceSlot(slot);
}
if (id == CK_INVALID_HANDLE) {
PK11_FreeSlot(slot);
PORT_SetError( SEC_ERROR_BAD_KEY );
return SECFailure;
}
session = pk11_GetNewSession(slot,&owner);
if (!owner || !(slot->isThreadSafe)) PK11_EnterSlotMonitor(slot);
crv = PK11_GETTAB(slot)->C_VerifyRecoverInit(session,&mech,id);
@ -636,6 +642,12 @@ PK11_Verify(SECKEYPublicKey *key, SECItem *sig, SECItem *hash, void *wincx)
PK11_ReferenceSlot(slot);
}
if (id == CK_INVALID_HANDLE) {
PK11_FreeSlot(slot);
PORT_SetError( SEC_ERROR_BAD_KEY );
return SECFailure;
}
session = pk11_GetNewSession(slot,&owner);
if (!owner || !(slot->isThreadSafe)) PK11_EnterSlotMonitor(slot);
crv = PK11_GETTAB(slot)->C_VerifyInit(session,&mech,id);
@ -793,6 +805,12 @@ pk11_PubEncryptRaw(SECKEYPublicKey *key, unsigned char *enc,
id = PK11_ImportPublicKey(slot,key,PR_FALSE);
if (id == CK_INVALID_HANDLE) {
PK11_FreeSlot(slot);
PORT_SetError( SEC_ERROR_BAD_KEY );
return SECFailure;
}
session = pk11_GetNewSession(slot,&owner);
if (!owner || !(slot->isThreadSafe)) PK11_EnterSlotMonitor(slot);
crv = PK11_GETTAB(slot)->C_EncryptInit(session, mech, id);