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;
11
CMS_ContentInfo *cms = NULL;
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");
28
cacert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
33
if (!X509_STORE_add_cert(st, cacert))
36
/* Open message being verified */
38
in = BIO_new_file("smout.txt", "r");
44
cms = SMIME_read_CMS(in, &cont);
49
/* File to output verified content to */
50
out = BIO_new_file("smver.txt", "w");
54
if (!CMS_verify(cms, NULL, st, cont, out, 0))
56
fprintf(stderr, "Verification Failure\n");
60
fprintf(stderr, "Verification Successful\n");
68
fprintf(stderr, "Error Verifying Data\n");
69
ERR_print_errors_fp(stderr);
73
CMS_ContentInfo_free(cms);