1 /* S/MIME signing example: 2 signers */
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
;
9 X509
*scert
= NULL
, *scert2
= NULL
;
10 EVP_PKEY
*skey
= NULL
, *skey2
= NULL
;
11 CMS_ContentInfo
*cms
= NULL
;
14 OpenSSL_add_all_algorithms();
15 ERR_load_crypto_strings();
17 tbio
= BIO_new_file("signer.pem", "r");
22 scert
= PEM_read_bio_X509(tbio
, NULL
, 0, NULL
);
26 skey
= PEM_read_bio_PrivateKey(tbio
, NULL
, 0, NULL
);
30 tbio
= BIO_new_file("signer2.pem", "r");
35 scert2
= PEM_read_bio_X509(tbio
, NULL
, 0, NULL
);
39 skey2
= PEM_read_bio_PrivateKey(tbio
, NULL
, 0, NULL
);
41 if (!scert2
|| !skey2
)
44 in
= BIO_new_file("sign.txt", "r");
49 cms
= CMS_sign(NULL
, NULL
, NULL
, in
, CMS_STREAM
| CMS_PARTIAL
);
54 /* Add each signer in turn */
56 if (!CMS_add1_signer(cms
, scert
, skey
, NULL
, 0))
59 if (!CMS_add1_signer(cms
, scert2
, skey2
, NULL
, 0))
62 out
= BIO_new_file("smout.txt", "w");
66 /* NB: content included and finalized by SMIME_write_CMS */
68 if (!SMIME_write_CMS(out
, cms
, in
, CMS_STREAM
))
76 fprintf(stderr
, "Error Signing Data\n");
77 ERR_print_errors_fp(stderr
);
81 CMS_ContentInfo_free(cms
);