]>
git.ipfire.org Git - thirdparty/openssl.git/blob - demos/smime/smsign2.c
5ad86f15f86e1a018505e3812ef5aa353b9a6440
2 * Copyright 2007-2023 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 /* S/MIME signing example: 2 signers */
11 #include <openssl/pem.h>
12 #include <openssl/pkcs7.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
;
21 int ret
= EXIT_FAILURE
;
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
);
33 if (BIO_reset(tbio
) < 0)
36 skey
= PEM_read_bio_PrivateKey(tbio
, NULL
, 0, NULL
);
40 tbio
= BIO_new_file("signer2.pem", "r");
45 scert2
= PEM_read_bio_X509(tbio
, NULL
, 0, NULL
);
47 if (BIO_reset(tbio
) < 0)
50 skey2
= PEM_read_bio_PrivateKey(tbio
, NULL
, 0, NULL
);
52 if (!scert2
|| !skey2
)
55 in
= BIO_new_file("sign.txt", "r");
60 p7
= PKCS7_sign(NULL
, NULL
, NULL
, in
, PKCS7_STREAM
| PKCS7_PARTIAL
);
65 /* Add each signer in turn */
67 if (!PKCS7_sign_add_signer(p7
, scert
, skey
, NULL
, 0))
70 if (!PKCS7_sign_add_signer(p7
, scert2
, skey2
, NULL
, 0))
73 out
= BIO_new_file("smout.txt", "w");
77 /* NB: content included and finalized by SMIME_write_PKCS7 */
79 if (!SMIME_write_PKCS7(out
, p7
, in
, PKCS7_STREAM
))
86 if (ret
!= EXIT_SUCCESS
) {
87 fprintf(stderr
, "Error Signing Data\n");
88 ERR_print_errors_fp(stderr
);