@@ -79,7 +79,8 @@ static int write_file_buffer(const char* fileName, byte* in, word32 inSz)
7979}
8080
8181static int signedData_sign_noattrs (byte * cert , word32 certSz , byte * key ,
82- word32 keySz , byte * out , word32 outSz )
82+ word32 keySz , byte * out , word32 outSz ,
83+ byte streamMode , byte noCerts )
8384{
8485 int ret ;
8586 PKCS7 * pkcs7 ;
@@ -118,6 +119,14 @@ static int signedData_sign_noattrs(byte* cert, word32 certSz, byte* key,
118119 pkcs7 -> signedAttribs = NULL ;
119120 pkcs7 -> signedAttribsSz = 0 ;
120121
122+ if (streamMode ) {
123+ wc_PKCS7_SetStreamMode (pkcs7 , 1 );
124+ }
125+
126+ if (noCerts ) {
127+ wc_PKCS7_SetNoCerts (pkcs7 , 1 );
128+ }
129+
121130 /* encode signedData, returns size */
122131 ret = wc_PKCS7_EncodeSignedData (pkcs7 , out , outSz );
123132 if (ret <= 0 ) {
@@ -127,8 +136,8 @@ static int signedData_sign_noattrs(byte* cert, word32 certSz, byte* key,
127136 return -1 ;
128137
129138 } else {
130- printf ("Successfully encoded SignedData bundle (%s)\n" ,
131- encodedFileNoAttrs );
139+ printf ("Successfully encoded SignedData bundle (%s) %s \n" ,
140+ encodedFileNoAttrs , ( noCerts )? "No Certs Added" : "" );
132141
133142#ifdef DEBUG_WOLFSSL
134143 printf ("Encoded DER (%d bytes):\n" , ret );
@@ -244,10 +253,14 @@ static int signedData_verify(byte* in, word32 inSz, byte* cert,
244253
245254 if (ret < 0 || (pkcs7 -> contentSz != sizeof (data )) ||
246255 (XMEMCMP (pkcs7 -> content , data , pkcs7 -> contentSz ) != 0 )) {
247- printf ("ERROR: Failed to verify SignedData bundle, ret = %d\n" , ret );
248- wc_PKCS7_Free (pkcs7 );
249- return -1 ;
250-
256+ if (ret == PKCS7_SIGNEEDS_CHECK ) {
257+ printf ("WARNING: Parsed through bundle but no certificates found to"
258+ " verify signature with\n" );
259+ }
260+ else {
261+ printf ("ERROR: Failed to verify SignedData bundle, ret = %d\n" ,
262+ ret );
263+ }
251264 } else {
252265 printf ("Successfully verified SignedData bundle.\n" );
253266
@@ -287,7 +300,7 @@ int main(int argc, char** argv)
287300
288301 /* no attributes */
289302 encryptedSz = signedData_sign_noattrs (cert , certSz , key , keySz ,
290- encrypted , sizeof (encrypted ));
303+ encrypted , sizeof (encrypted ), 0 , 0 );
291304 if (encryptedSz < 0 )
292305 return -1 ;
293306
@@ -297,6 +310,19 @@ int main(int argc, char** argv)
297310 if (decryptedSz < 0 )
298311 return -1 ;
299312
313+ /* no attributes, stream mode, and no certs */
314+ encryptedSz = signedData_sign_noattrs (cert , certSz , key , keySz ,
315+ encrypted , sizeof (encrypted ), 1 , 1 );
316+ if (encryptedSz < 0 )
317+ return -1 ;
318+
319+ decryptedSz = signedData_verify (encrypted , encryptedSz ,
320+ cert , certSz , key , keySz ,
321+ decrypted , sizeof (decrypted ));
322+ /* should be error to warn that the signature needs checked */
323+ if (decryptedSz != PKCS7_SIGNEEDS_CHECK )
324+ return -1 ;
325+
300326 /* default attributes + messageType attribute */
301327 encryptedSz = signedData_sign_attrs (cert , certSz , key , keySz ,
302328 encrypted , sizeof (encrypted ));
0 commit comments