Skip to content

Commit 2bf882c

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 2bf882c

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

wolfcrypt/src/pkcs7.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5437,9 +5437,7 @@ static int wc_PKCS7_ParseSignerInfo(wc_PKCS7* pkcs7, byte* in, word32 inSz,
54375437
/* Only parse params when still inside the AlgorithmIdentifier;
54385438
* when optional params are absent, idx is already past the sequence. */
54395439
else if (algoContentStart + (word32)algoSeqLen > idx) {
5440-
#if defined(WC_RSA_PSS) && !defined(NO_RSA)
54415440
word32 paramsStart = idx;
5442-
#endif
54435441
byte paramTag;
54445442
int paramLen = 0;
54455443
if (GetASNTag(in, &idx, &paramTag, inSz) != 0 ||
@@ -8344,7 +8342,11 @@ int wc_PKCS7_AddRecipient_KTRI(wc_PKCS7* pkcs7, const byte* cert, word32 certSz,
83448342
pkcs7->publicKeyOID = decoded->keyOID;
83458343

83468344
/* KeyEncryptionAlgorithmIdentifier, only support RSA now */
8347-
if (pkcs7->publicKeyOID != RSAk) {
8345+
if (pkcs7->publicKeyOID != RSAk
8346+
#ifdef WC_RSA_PSS
8347+
&& pkcs7->publicKeyOID != RSAPSSk
8348+
#endif
8349+
) {
83488350
FreeDecodedCert(decoded);
83498351
WC_FREE_VAR_EX(serial, pkcs7->heap, DYNAMIC_TYPE_TMP_BUFFER);
83508352
WC_FREE_VAR_EX(keyAlgArray, pkcs7->heap, DYNAMIC_TYPE_TMP_BUFFER);
@@ -8354,8 +8356,7 @@ int wc_PKCS7_AddRecipient_KTRI(wc_PKCS7* pkcs7, const byte* cert, word32 certSz,
83548356
return ALGO_ID_E;
83558357
}
83568358

8357-
keyEncAlgSz = (int)SetAlgoID((int)pkcs7->publicKeyOID, keyAlgArray,
8358-
oidKeyType, 0);
8359+
keyEncAlgSz = (int)SetAlgoID(RSAk, keyAlgArray, oidKeyType, 0);
83598360
if (keyEncAlgSz == 0) {
83608361
FreeDecodedCert(decoded);
83618362
WC_FREE_VAR_EX(serial, pkcs7->heap, DYNAMIC_TYPE_TMP_BUFFER);
@@ -10230,6 +10231,10 @@ int wc_PKCS7_EncodeEnvelopedData(wc_PKCS7* pkcs7, byte* output, word32 outputSz)
1023010231
if (pkcs7->singleCert != NULL && pkcs7->singleCertSz > 0) {
1023110232
switch (pkcs7->publicKeyOID) {
1023210233
#ifndef NO_RSA
10234+
#ifdef WC_RSA_PSS
10235+
case RSAPSSk:
10236+
FALL_THROUGH;
10237+
#endif
1023310238
case RSAk:
1023410239
ret = wc_PKCS7_AddRecipient_KTRI(pkcs7, pkcs7->singleCert,
1023510240
pkcs7->singleCertSz, 0);
@@ -13547,6 +13552,10 @@ int wc_PKCS7_EncodeAuthEnvelopedData(wc_PKCS7* pkcs7, byte* output,
1354713552
if (pkcs7->singleCert != NULL && pkcs7->singleCertSz > 0) {
1354813553
switch (pkcs7->publicKeyOID) {
1354913554
#ifndef NO_RSA
13555+
#ifdef WC_RSA_PSS
13556+
case RSAPSSk:
13557+
FALL_THROUGH;
13558+
#endif
1355013559
case RSAk:
1355113560
ret = wc_PKCS7_AddRecipient_KTRI(pkcs7, pkcs7->singleCert,
1355213561
pkcs7->singleCertSz, 0);

0 commit comments

Comments
 (0)