Skip to content

Commit 3fefe35

Browse files
committed
Add RSA-PSS certificate support for PKCS7 EnvelopedData KTRI
RSA-PSS signed certificates contain a valid RSA public key that can be used for key transport, but wc_PKCS7_AddRecipient_KTRI and the EnvelopedData/AuthEnvelopedData encode paths rejected them because they only checked for RSAk. Allow RSAPSSk to fall through to the RSAk key transport path, and always use RSAk as the KeyEncryptionAlgorithmIdentifier since the operation is RSA encryption, not RSA-PSS signing. Signed-off-by: Sameeh Jubran <sameeh@wolfssl.com>
1 parent 350706d commit 3fefe35

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

wolfcrypt/src/pkcs7.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8344,7 +8344,11 @@ int wc_PKCS7_AddRecipient_KTRI(wc_PKCS7* pkcs7, const byte* cert, word32 certSz,
83448344
pkcs7->publicKeyOID = decoded->keyOID;
83458345

83468346
/* KeyEncryptionAlgorithmIdentifier, only support RSA now */
8347-
if (pkcs7->publicKeyOID != RSAk) {
8347+
if (pkcs7->publicKeyOID != RSAk
8348+
#ifdef WC_RSA_PSS
8349+
&& pkcs7->publicKeyOID != RSAPSSk
8350+
#endif
8351+
) {
83488352
FreeDecodedCert(decoded);
83498353
WC_FREE_VAR_EX(serial, pkcs7->heap, DYNAMIC_TYPE_TMP_BUFFER);
83508354
WC_FREE_VAR_EX(keyAlgArray, pkcs7->heap, DYNAMIC_TYPE_TMP_BUFFER);
@@ -8354,8 +8358,7 @@ int wc_PKCS7_AddRecipient_KTRI(wc_PKCS7* pkcs7, const byte* cert, word32 certSz,
83548358
return ALGO_ID_E;
83558359
}
83568360

8357-
keyEncAlgSz = (int)SetAlgoID((int)pkcs7->publicKeyOID, keyAlgArray,
8358-
oidKeyType, 0);
8361+
keyEncAlgSz = (int)SetAlgoID(RSAk, keyAlgArray, oidKeyType, 0);
83598362
if (keyEncAlgSz == 0) {
83608363
FreeDecodedCert(decoded);
83618364
WC_FREE_VAR_EX(serial, pkcs7->heap, DYNAMIC_TYPE_TMP_BUFFER);
@@ -10230,6 +10233,10 @@ int wc_PKCS7_EncodeEnvelopedData(wc_PKCS7* pkcs7, byte* output, word32 outputSz)
1023010233
if (pkcs7->singleCert != NULL && pkcs7->singleCertSz > 0) {
1023110234
switch (pkcs7->publicKeyOID) {
1023210235
#ifndef NO_RSA
10236+
#ifdef WC_RSA_PSS
10237+
case RSAPSSk:
10238+
FALL_THROUGH;
10239+
#endif
1023310240
case RSAk:
1023410241
ret = wc_PKCS7_AddRecipient_KTRI(pkcs7, pkcs7->singleCert,
1023510242
pkcs7->singleCertSz, 0);
@@ -13547,6 +13554,10 @@ int wc_PKCS7_EncodeAuthEnvelopedData(wc_PKCS7* pkcs7, byte* output,
1354713554
if (pkcs7->singleCert != NULL && pkcs7->singleCertSz > 0) {
1354813555
switch (pkcs7->publicKeyOID) {
1354913556
#ifndef NO_RSA
13557+
#ifdef WC_RSA_PSS
13558+
case RSAPSSk:
13559+
FALL_THROUGH;
13560+
#endif
1355013561
case RSAk:
1355113562
ret = wc_PKCS7_AddRecipient_KTRI(pkcs7, pkcs7->singleCert,
1355213563
pkcs7->singleCertSz, 0);

0 commit comments

Comments
 (0)