|
18 | 18 | * along with this program; if not, write to the Free Software |
19 | 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
20 | 20 | */ |
| 21 | +#ifndef WOLFSSL_USER_SETTINGS |
21 | 22 | #include <wolfssl/options.h> |
| 23 | +#endif |
22 | 24 | #include <wolfssl/wolfcrypt/settings.h> |
23 | 25 | #include <wolfssl/wolfcrypt/pkcs7.h> |
24 | 26 | #include <wolfssl/wolfcrypt/error-crypt.h> |
@@ -65,8 +67,10 @@ int main(int argc, char** argv) |
65 | 67 |
|
66 | 68 | if (rc != fileSz) { |
67 | 69 | printf("Failed to read der file!\n"); |
68 | | - return -1; |
| 70 | + rc = -1; |
| 71 | + goto exit; |
69 | 72 | } |
| 73 | + rc = 0; |
70 | 74 | } |
71 | 75 |
|
72 | 76 | /* PKCS_Init captures/saves this, so make sure |
@@ -95,6 +99,43 @@ int main(int argc, char** argv) |
95 | 99 |
|
96 | 100 | printf("PKCS7 Verify Success\n"); |
97 | 101 |
|
| 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 | + |
98 | 139 | exit: |
99 | 140 |
|
100 | 141 | if (rc != 0) |
|
0 commit comments