@@ -128,6 +128,37 @@ static int Verify(byte* smime, int smimeSz, byte* ca, int caSz, byte* contentIn,
128128 printf ("\n" );
129129 }
130130
131+ /* print out the signing time attribute if found */
132+ if (ret == 0 ) {
133+ word32 outSz ;
134+ byte * out ;
135+ int err ;
136+ const byte signingTimeOid [] = {
137+ 0x2A , 0x86 , 0x48 , 0x86 , 0xF7 , 0x0D , 0x01 , 0x09 , 0x05
138+ };
139+
140+ err = wc_PKCS7_GetAttributeValue (& pkcs7Compat -> pkcs7 , signingTimeOid ,
141+ sizeof (signingTimeOid ), NULL , & outSz );
142+ if (err == LENGTH_ONLY_E ) {
143+ out = (byte * )XMALLOC (outSz + 1 , NULL , DYNAMIC_TYPE_PKCS7 );
144+ if (out != NULL ) {
145+ err = wc_PKCS7_GetAttributeValue (& pkcs7Compat -> pkcs7 ,
146+ signingTimeOid , sizeof (signingTimeOid ), out , & outSz );
147+ if (err > 0 ) {
148+ word32 i ;
149+ printf ("Signing time attribute is :\n\t" );
150+ for (i = 0 ; i < outSz ; i ++ )
151+ printf ("%02X" , out [i ]);
152+ printf ("\n" );
153+ }
154+ }
155+ XFREE (out , NULL , DYNAMIC_TYPE_PKCS7 );
156+ }
157+ else {
158+ printf ("No signing time attribute found\n" );
159+ }
160+ }
161+
131162 wolfSSL_BIO_free (in );
132163 wolfSSL_BIO_free (content );
133164 wolfSSL_BIO_free (multi );
@@ -145,6 +176,7 @@ static int ReadSmimeAndCert(char* smimeFile, char* certFile, char* contentFile,
145176{
146177 int ret ;
147178 XFILE f ;
179+ * contentSz = 0 ;
148180
149181 f = XFOPEN (smimeFile , "rb" );
150182 if (f == NULL ) {
@@ -188,23 +220,25 @@ static int ReadSmimeAndCert(char* smimeFile, char* certFile, char* contentFile,
188220 }
189221 }
190222
191- f = XFOPEN (contentFile , "rb" );
192- if (f == NULL ) {
193- printf ("Error opening file %s\n" , contentFile );
194- return -1 ;
195- }
196- else {
197- ret = XFREAD (content , 1 , * contentSz , f );
198- if (ret >= 0 ) {
199- if (ret == * contentSz ) {
200- printf ("Cert read in was larger than buffer\n" );
201- XFCLOSE (f );
202- return -1 ;
203- }
204- else {
205- * contentSz = ret ;
206- ret = 0 ;
207- XFCLOSE (f );
223+ if (contentFile != NULL ) {
224+ f = XFOPEN (contentFile , "rb" );
225+ if (f == NULL ) {
226+ printf ("Error opening file %s\n" , contentFile );
227+ return -1 ;
228+ }
229+ else {
230+ ret = XFREAD (content , 1 , * contentSz , f );
231+ if (ret >= 0 ) {
232+ if (ret == * contentSz ) {
233+ printf ("Cert read in was larger than buffer\n" );
234+ XFCLOSE (f );
235+ return -1 ;
236+ }
237+ else {
238+ * contentSz = ret ;
239+ ret = 0 ;
240+ XFCLOSE (f );
241+ }
208242 }
209243 }
210244 }
@@ -225,8 +259,9 @@ int main(int argc, char** argv)
225259
226260 int ret ;
227261
228- if (argc != 4 ) {
229- printf ("Use ./smime-verify <smime file> <der cert file> <content file>\n" );
262+ if (argc < 3 ) {
263+ printf ("Use ./smime-verify <smime file> <der cert file> "
264+ "<optional content file>\n" );
230265 return -1 ;
231266 }
232267
@@ -239,8 +274,14 @@ int main(int argc, char** argv)
239274 return -1 ;
240275 }
241276
242- ret = ReadSmimeAndCert (argv [1 ], argv [2 ], argv [3 ], smime , & smimeSz , cert ,
243- & certSz , content , & contentSz );
277+ if (argc > 3 ) {
278+ ret = ReadSmimeAndCert (argv [1 ], argv [2 ], argv [3 ], smime , & smimeSz , cert ,
279+ & certSz , content , & contentSz );
280+ }
281+ else {
282+ ret = ReadSmimeAndCert (argv [1 ], argv [2 ], NULL , smime , & smimeSz , cert ,
283+ & certSz , content , & contentSz );
284+ }
244285 if (ret == 0 ) {
245286 ret = Verify (smime , smimeSz , cert , certSz , content , contentSz , 0 );
246287 if (ret == 0 ) {
0 commit comments