2 * Copyright 2008-2016 The OpenSSL Project Authors. All Rights Reserved.
4 * Licensed under the OpenSSL license (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 /* S/MIME signing example: 2 signers */
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;
18 X509 *scert = NULL, *scert2 = NULL;
19 EVP_PKEY *skey = NULL, *skey2 = NULL;
20 CMS_ContentInfo *cms = NULL;
23 OpenSSL_add_all_algorithms();
24 ERR_load_crypto_strings();
26 tbio = BIO_new_file("signer.pem", "r");
31 scert = PEM_read_bio_X509(tbio, NULL, 0, NULL);
35 skey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);
39 tbio = BIO_new_file("signer2.pem", "r");
44 scert2 = PEM_read_bio_X509(tbio, NULL, 0, NULL);
48 skey2 = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL);
50 if (!scert2 || !skey2)
53 in = BIO_new_file("sign.txt", "r");
58 cms = CMS_sign(NULL, NULL, NULL, in, CMS_STREAM | CMS_PARTIAL);
63 /* Add each signer in turn */
65 if (!CMS_add1_signer(cms, scert, skey, NULL, 0))
68 if (!CMS_add1_signer(cms, scert2, skey2, NULL, 0))
71 out = BIO_new_file("smout.txt", "w");
75 /* NB: content included and finalized by SMIME_write_CMS */
77 if (!SMIME_write_CMS(out, cms, in, CMS_STREAM))
85 fprintf(stderr, "Error Signing Data\n");
86 ERR_print_errors_fp(stderr);
89 CMS_ContentInfo_free(cms);