Skip to content

Commit 08c24d4

Browse files
committed
Added pkcs7-verify verification of matching output and .p7b
added DER to PEM check wc_DerToPem.
1 parent 4465fe0 commit 08c24d4

2 files changed

Lines changed: 42 additions & 1 deletion

File tree

pkcs7/pkcs7-verify.c

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
* along with this program; if not, write to the Free Software
1919
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
2020
*/
21+
#ifndef WOLFSSL_USER_SETTINGS
2122
#include <wolfssl/options.h>
23+
#endif
2224
#include <wolfssl/wolfcrypt/settings.h>
2325
#include <wolfssl/wolfcrypt/pkcs7.h>
2426
#include <wolfssl/wolfcrypt/error-crypt.h>
@@ -65,8 +67,10 @@ int main(int argc, char** argv)
6567

6668
if (rc != fileSz) {
6769
printf("Failed to read der file!\n");
68-
return -1;
70+
rc = -1;
71+
goto exit;
6972
}
73+
rc = 0;
7074
}
7175

7276
/* PKCS_Init captures/saves this, so make sure
@@ -95,6 +99,43 @@ int main(int argc, char** argv)
9599

96100
printf("PKCS7 Verify Success\n");
97101

102+
#ifdef WOLFSSL_DER_TO_PEM
103+
memset(fileBuf, 0, fileSz);
104+
rc = wc_DerToPem(derBuf, derSz, fileBuf, fileSz, PKCS7_TYPE);
105+
if (rc <= 0) {
106+
printf("DER to PEM failed: %d\n", rc);
107+
goto exit;
108+
}
109+
printf("%s", fileBuf);
110+
#endif
111+
112+
/* load PKCS7 */
113+
derFile = fopen(pkcs7SignedDer, "rb");
114+
if (derFile) {
115+
fseek(derFile, 0, SEEK_END);
116+
fileSz = (int)ftell(derFile);
117+
rewind(derFile);
118+
119+
rc = (int)fread(fileBuf, 1, fileSz, derFile);
120+
fclose(derFile);
121+
122+
if (rc != fileSz) {
123+
printf("Failed to read der file!\n");
124+
rc = -1;
125+
goto exit;
126+
}
127+
rc = 0;
128+
}
129+
130+
/* Verify DER output matches expected output */
131+
if (fileSz != derSz || memcmp(fileBuf, derBuf, derSz) != 0) {
132+
fprintf(stderr, "DER output didn't match expected\n");
133+
rc = -1;
134+
}
135+
else {
136+
printf("DER output matches the original PEM\n");
137+
}
138+
98139
exit:
99140

100141
if (rc != 0)

pkcs7/signed.p7b

1.59 KB
Binary file not shown.

0 commit comments

Comments
 (0)