@@ -1039,6 +1039,85 @@ int test_wc_PKCS7_EncodeSignedData_RSA_PSS(void)
10391039#endif
10401040
10411041
1042+ /*
1043+ * Testing wc_PKCS7_EncodeEnvelopedData() with RSA-PSS signed certificate
1044+ * for KTRI key transport. Uses certs/rsapss/client-rsapss.der.
1045+ * Requires encode and round-trip decode to succeed.
1046+ */
1047+ #if defined(HAVE_PKCS7 ) && defined(WC_RSA_PSS ) && !defined(NO_RSA ) && \
1048+ !defined(NO_FILESYSTEM ) && !defined(NO_SHA256 ) && \
1049+ !defined(NO_AES ) && defined(HAVE_AES_CBC ) && defined(WOLFSSL_AES_256 )
1050+ int test_wc_PKCS7_EnvelopedData_KTRI_RSA_PSS (void )
1051+ {
1052+ EXPECT_DECLS ;
1053+ PKCS7 * pkcs7 = NULL ;
1054+ byte encrypted [FOURK_BUF ];
1055+ byte decrypted [FOURK_BUF ];
1056+ byte cert [FOURK_BUF ];
1057+ byte key [FOURK_BUF ];
1058+ word32 certSz = 0 ;
1059+ word32 keySz = 0 ;
1060+ XFILE fp = XBADFILE ;
1061+ byte data [] = "Test data for RSA-PSS EnvelopedData KTRI." ;
1062+ int encryptedSz = 0 , decryptedSz = 0 ;
1063+
1064+ XMEMSET (cert , 0 , sizeof (cert ));
1065+ XMEMSET (key , 0 , sizeof (key ));
1066+
1067+ /* Load RSA-PSS client cert */
1068+ ExpectTrue ((fp = XFOPEN ("./certs/rsapss/client-rsapss.der" , "rb" ))
1069+ != XBADFILE );
1070+ if (fp != XBADFILE ) {
1071+ ExpectIntGT (certSz = (word32 )XFREAD (cert , 1 , sizeof (cert ), fp ), 0 );
1072+ XFCLOSE (fp );
1073+ fp = XBADFILE ;
1074+ }
1075+
1076+ /* Load RSA-PSS client private key */
1077+ ExpectTrue ((fp = XFOPEN ("./certs/rsapss/client-rsapss-priv.der" , "rb" ))
1078+ != XBADFILE );
1079+ if (fp != XBADFILE ) {
1080+ ExpectIntGT (keySz = (word32 )XFREAD (key , 1 , sizeof (key ), fp ), 0 );
1081+ XFCLOSE (fp );
1082+ fp = XBADFILE ;
1083+ }
1084+
1085+ /* Encode EnvelopedData with KTRI using RSA-PSS cert */
1086+ ExpectNotNull (pkcs7 = wc_PKCS7_New (HEAP_HINT , testDevId ));
1087+ ExpectIntEQ (wc_PKCS7_InitWithCert (pkcs7 , cert , certSz ), 0 );
1088+ if (pkcs7 != NULL ) {
1089+ pkcs7 -> content = data ;
1090+ pkcs7 -> contentSz = (word32 )sizeof (data );
1091+ pkcs7 -> contentOID = DATA ;
1092+ pkcs7 -> encryptOID = AES256CBCb ;
1093+ }
1094+
1095+ ExpectIntGT (encryptedSz = wc_PKCS7_EncodeEnvelopedData (pkcs7 ,
1096+ encrypted , sizeof (encrypted )), 0 );
1097+ wc_PKCS7_Free (pkcs7 );
1098+ pkcs7 = NULL ;
1099+
1100+ /* Decode EnvelopedData */
1101+ ExpectNotNull (pkcs7 = wc_PKCS7_New (HEAP_HINT , testDevId ));
1102+ ExpectIntEQ (wc_PKCS7_InitWithCert (pkcs7 , cert , certSz ), 0 );
1103+ if (pkcs7 != NULL ) {
1104+ pkcs7 -> privateKey = key ;
1105+ pkcs7 -> privateKeySz = keySz ;
1106+ }
1107+
1108+ ExpectIntGT (decryptedSz = wc_PKCS7_DecodeEnvelopedData (pkcs7 ,
1109+ encrypted , (word32 )encryptedSz ,
1110+ decrypted , sizeof (decrypted )), 0 );
1111+ ExpectIntEQ (decryptedSz , (int )sizeof (data ));
1112+ ExpectIntEQ (XMEMCMP (decrypted , data , sizeof (data )), 0 );
1113+
1114+ wc_PKCS7_Free (pkcs7 );
1115+
1116+ return EXPECT_RESULT ();
1117+ } /* END test_wc_PKCS7_EnvelopedData_KTRI_RSA_PSS */
1118+ #endif
1119+
1120+
10421121/*
10431122 * Testing wc_PKCS7_EncodeSignedData_ex() and wc_PKCS7_VerifySignedData_ex()
10441123 */
0 commit comments