2 * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the Apache License 2.0 (the "License"). You may not use
5 * this file except in compliance with the License. You can obtain a copy
6 * in the file LICENSE in the source distribution or at
7 * https://www.openssl.org/source/license.html
10 /* Simple S/MIME verification example */
11 #include <openssl/pem.h>
12 #include <openssl/cms.h>
13 #include <openssl/err.h>
15 int main(int argc, char **argv)
17 BIO *in = NULL, *out = NULL, *tbio = NULL, *cont = NULL;
18 X509_STORE *st = NULL;
20 CMS_ContentInfo *cms = NULL;
24 OpenSSL_add_all_algorithms();
25 ERR_load_crypto_strings();
27 /* Set up trusted CA certificate store */
29 st = X509_STORE_new();
31 /* Read in CA certificate */
32 tbio = BIO_new_file("cacert.pem", "r");
37 cacert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
42 if (!X509_STORE_add_cert(st, cacert))
45 /* Open message being verified */
47 in = BIO_new_file("smout.txt", "r");
53 cms = SMIME_read_CMS(in, &cont);
58 /* File to output verified content to */
59 out = BIO_new_file("smver.txt", "w");
63 if (!CMS_verify(cms, NULL, st, cont, out, 0)) {
64 fprintf(stderr, "Verification Failure\n");
68 fprintf(stderr, "Verification Successful\n");
75 fprintf(stderr, "Error Verifying Data\n");
76 ERR_print_errors_fp(stderr);
79 CMS_ContentInfo_free(cms);