Fix to support PKCS11 without RSA key generation. Fixed Pkcs11Rsa where ret failure could be ignored.

This commit is contained in:
David Garske
2024-07-10 11:17:02 -07:00
parent d4741de5dc
commit 28db1b19e1

View File

@ -947,7 +947,7 @@ static int Pkcs11CreateSecretKey(CK_OBJECT_HANDLE* key, Pkcs11Session* session,
} }
#endif #endif
#ifndef NO_RSA #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
/** /**
* Create a PKCS#11 object containing the RSA private key data. * Create a PKCS#11 object containing the RSA private key data.
* *
@ -1024,7 +1024,7 @@ static int Pkcs11CreateRsaPrivateKey(CK_OBJECT_HANDLE* privateKey,
return ret; return ret;
} }
#endif #endif /* !NO_RSA && WOLFSSL_KEY_GEN */
#ifdef HAVE_ECC #ifdef HAVE_ECC
/** /**
@ -1380,7 +1380,7 @@ int wc_Pkcs11StoreKey(Pkcs11Token* token, int type, int clear, void* key)
break; break;
} }
#endif #endif
#ifndef NO_RSA #if !defined(NO_RSA) && defined(WOLFSSL_KEY_GEN)
case PKCS11_KEY_TYPE_RSA: { case PKCS11_KEY_TYPE_RSA: {
RsaKey* rsaKey = (RsaKey*)key; RsaKey* rsaKey = (RsaKey*)key;
@ -1774,7 +1774,12 @@ static int Pkcs11RsaPrivateKey(Pkcs11Session* session, RsaKey* rsaKey,
int ret; int ret;
if (sessionKey) { if (sessionKey) {
#ifdef WOLFSSL_KEY_GEN
ret = Pkcs11CreateRsaPrivateKey(privateKey, session, rsaKey, 0); ret = Pkcs11CreateRsaPrivateKey(privateKey, session, rsaKey, 0);
#else
/* RSA Key Generation support not compiled in */
ret = NOT_COMPILED_IN;
#endif
} }
else if (rsaKey->labelLen > 0) { else if (rsaKey->labelLen > 0) {
ret = Pkcs11FindKeyByLabel(privateKey, CKO_PRIVATE_KEY, CKK_RSA, ret = Pkcs11FindKeyByLabel(privateKey, CKO_PRIVATE_KEY, CKK_RSA,
@ -1996,7 +2001,8 @@ static int Pkcs11Rsa(Pkcs11Session* session, wc_CryptoInfo* info)
/* Make a handle to a private key. */ /* Make a handle to a private key. */
ret = Pkcs11RsaPrivateKey(session, rsaKey, sessionKey, &key); ret = Pkcs11RsaPrivateKey(session, rsaKey, sessionKey, &key);
} }
}
if (ret == 0) {
if (type == RSA_PUBLIC_ENCRYPT) { if (type == RSA_PUBLIC_ENCRYPT) {
WOLFSSL_MSG("PKCS#11: Public Encrypt"); WOLFSSL_MSG("PKCS#11: Public Encrypt");
if ((mechInfo.flags & CKF_ENCRYPT) != 0) { if ((mechInfo.flags & CKF_ENCRYPT) != 0) {