Remove building with NOCRYPTO option
[minix.git] / crypto / external / bsd / openssl / dist / demos / cms / cms_ver.c
blobca935517a7a981645be92316a23588381ecf3577
1 /* Simple S/MIME verification example */
2 #include <openssl/pem.h>
3 #include <openssl/cms.h>
4 #include <openssl/err.h>
6 int main(int argc, char **argv)
8 BIO *in = NULL, *out = NULL, *tbio = NULL, *cont = NULL;
9 X509_STORE *st = NULL;
10 X509 *cacert = NULL;
11 CMS_ContentInfo *cms = NULL;
13 int ret = 1;
15 OpenSSL_add_all_algorithms();
16 ERR_load_crypto_strings();
18 /* Set up trusted CA certificate store */
20 st = X509_STORE_new();
22 /* Read in CA certificate */
23 tbio = BIO_new_file("cacert.pem", "r");
25 if (!tbio)
26 goto err;
28 cacert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
30 if (!cacert)
31 goto err;
33 if (!X509_STORE_add_cert(st, cacert))
34 goto err;
36 /* Open message being verified */
38 in = BIO_new_file("smout.txt", "r");
40 if (!in)
41 goto err;
43 /* parse message */
44 cms = SMIME_read_CMS(in, &cont);
46 if (!cms)
47 goto err;
49 /* File to output verified content to */
50 out = BIO_new_file("smver.txt", "w");
51 if (!out)
52 goto err;
54 if (!CMS_verify(cms, NULL, st, cont, out, 0)) {
55 fprintf(stderr, "Verification Failure\n");
56 goto err;
59 fprintf(stderr, "Verification Successful\n");
61 ret = 0;
63 err:
65 if (ret) {
66 fprintf(stderr, "Error Verifying Data\n");
67 ERR_print_errors_fp(stderr);
70 if (cms)
71 CMS_ContentInfo_free(cms);
73 if (cacert)
74 X509_free(cacert);
76 if (in)
77 BIO_free(in);
78 if (out)
79 BIO_free(out);
80 if (tbio)
81 BIO_free(tbio);
83 return ret;