2 /* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
5 /* ====================================================================
6 * Copyright (c) 2008 The OpenSSL Project. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in
17 * the documentation and/or other materials provided with the
20 * 3. All advertising materials mentioning features or use of this
21 * software must display the following acknowledgment:
22 * "This product includes software developed by the OpenSSL Project
23 * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
25 * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
26 * endorse or promote products derived from this software without
27 * prior written permission. For written permission, please contact
28 * licensing@OpenSSL.org.
30 * 5. Products derived from this software may not be called "OpenSSL"
31 * nor may "OpenSSL" appear in their names without prior written
32 * permission of the OpenSSL Project.
34 * 6. Redistributions of any form whatsoever must retain the following
36 * "This product includes software developed by the OpenSSL Project
37 * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
39 * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
40 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
42 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
43 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
45 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
46 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
48 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
50 * OF THE POSSIBILITY OF SUCH DAMAGE.
51 * ====================================================================
54 /* CMS utility function */
60 #ifndef OPENSSL_NO_CMS
62 #include <openssl/crypto.h>
63 #include <openssl/pem.h>
64 #include <openssl/err.h>
65 #include <openssl/x509_vfy.h>
66 #include <openssl/x509v3.h>
67 #include <openssl/cms.h>
71 static int save_certs(char *signerfile, STACK_OF(X509) *signers);
72 static int smime_cb(int ok, X509_STORE_CTX *ctx);
76 #define SMIME_SIGNERS 0x40
77 #define SMIME_ENCRYPT (1 | SMIME_OP)
78 #define SMIME_DECRYPT (2 | SMIME_IP)
79 #define SMIME_SIGN (3 | SMIME_OP | SMIME_SIGNERS)
80 #define SMIME_VERIFY (4 | SMIME_IP)
81 #define SMIME_CMSOUT (5 | SMIME_IP | SMIME_OP)
82 #define SMIME_RESIGN (6 | SMIME_IP | SMIME_OP | SMIME_SIGNERS)
83 #define SMIME_DATAOUT (7 | SMIME_IP)
84 #define SMIME_DATA_CREATE (8 | SMIME_OP)
85 #define SMIME_DIGEST_VERIFY (9 | SMIME_IP)
86 #define SMIME_DIGEST_CREATE (10 | SMIME_OP)
87 #define SMIME_UNCOMPRESS (11 | SMIME_IP)
88 #define SMIME_COMPRESS (12 | SMIME_OP)
89 #define SMIME_ENCRYPTED_DECRYPT (13 | SMIME_IP)
91 int MAIN(int, char **);
93 int MAIN(int argc, char **argv)
99 const char *inmode = "r", *outmode = "w";
100 char *infile = NULL, *outfile = NULL;
101 char *signerfile = NULL, *recipfile = NULL;
102 STACK *sksigners = NULL, *skkeys = NULL;
103 char *certfile = NULL, *keyfile = NULL, *contfile=NULL;
104 const EVP_CIPHER *cipher = NULL;
105 CMS_ContentInfo *cms = NULL;
106 X509_STORE *store = NULL;
107 X509 *cert = NULL, *recip = NULL, *signer = NULL;
108 EVP_PKEY *key = NULL;
109 STACK_OF(X509) *encerts = NULL, *other = NULL;
110 BIO *in = NULL, *out = NULL, *indata = NULL;
112 int flags = CMS_DETACHED;
113 char *to = NULL, *from = NULL, *subject = NULL;
114 char *CAfile = NULL, *CApath = NULL;
115 char *passargin = NULL, *passin = NULL;
119 const EVP_MD *sign_md = NULL;
120 int informat = FORMAT_SMIME, outformat = FORMAT_SMIME;
121 int keyform = FORMAT_PEM;
122 #ifndef OPENSSL_NO_ENGINE
125 unsigned char *secret_key = NULL;
126 size_t secret_keylen;
128 X509_VERIFY_PARAM *vpm = NULL;
137 if ((bio_err = BIO_new(BIO_s_file())) != NULL)
138 BIO_set_fp(bio_err, stderr, BIO_NOCLOSE|BIO_FP_TEXT);
141 if (!load_config(bio_err, NULL))
144 while (!badarg && *args && *args[0] == '-')
146 if (!strcmp (*args, "-encrypt"))
147 operation = SMIME_ENCRYPT;
148 else if (!strcmp (*args, "-decrypt"))
149 operation = SMIME_DECRYPT;
150 else if (!strcmp (*args, "-sign"))
151 operation = SMIME_SIGN;
152 else if (!strcmp (*args, "-resign"))
153 operation = SMIME_RESIGN;
154 else if (!strcmp (*args, "-verify"))
155 operation = SMIME_VERIFY;
156 else if (!strcmp (*args, "-cmsout"))
157 operation = SMIME_CMSOUT;
158 else if (!strcmp (*args, "-data_out"))
159 operation = SMIME_DATAOUT;
160 else if (!strcmp (*args, "-data_create"))
161 operation = SMIME_DATA_CREATE;
162 else if (!strcmp (*args, "-digest_verify"))
163 operation = SMIME_DIGEST_VERIFY;
164 else if (!strcmp (*args, "-digest_create"))
165 operation = SMIME_DIGEST_CREATE;
166 else if (!strcmp (*args, "-compress"))
167 operation = SMIME_COMPRESS;
168 else if (!strcmp (*args, "-uncompress"))
169 operation = SMIME_UNCOMPRESS;
170 else if (!strcmp (*args, "-EncrypedData_decrypt"))
171 operation = SMIME_ENCRYPTED_DECRYPT;
172 #ifndef OPENSSL_NO_DES
173 else if (!strcmp (*args, "-des3"))
174 cipher = EVP_des_ede3_cbc();
175 else if (!strcmp (*args, "-des"))
176 cipher = EVP_des_cbc();
178 #ifndef OPENSSL_NO_SEED
179 else if (!strcmp (*args, "-seed"))
180 cipher = EVP_seed_cbc();
182 #ifndef OPENSSL_NO_RC2
183 else if (!strcmp (*args, "-rc2-40"))
184 cipher = EVP_rc2_40_cbc();
185 else if (!strcmp (*args, "-rc2-128"))
186 cipher = EVP_rc2_cbc();
187 else if (!strcmp (*args, "-rc2-64"))
188 cipher = EVP_rc2_64_cbc();
190 #ifndef OPENSSL_NO_AES
191 else if (!strcmp(*args,"-aes128"))
192 cipher = EVP_aes_128_cbc();
193 else if (!strcmp(*args,"-aes192"))
194 cipher = EVP_aes_192_cbc();
195 else if (!strcmp(*args,"-aes256"))
196 cipher = EVP_aes_256_cbc();
198 #ifndef OPENSSL_NO_CAMELLIA
199 else if (!strcmp(*args,"-camellia128"))
200 cipher = EVP_camellia_128_cbc();
201 else if (!strcmp(*args,"-camellia192"))
202 cipher = EVP_camellia_192_cbc();
203 else if (!strcmp(*args,"-camellia256"))
204 cipher = EVP_camellia_256_cbc();
206 else if (!strcmp (*args, "-text"))
208 else if (!strcmp (*args, "-nointern"))
209 flags |= CMS_NOINTERN;
210 else if (!strcmp (*args, "-noverify")
211 || !strcmp (*args, "-no_signer_cert_verify"))
212 flags |= CMS_NO_SIGNER_CERT_VERIFY;
213 else if (!strcmp (*args, "-nocerts"))
214 flags |= CMS_NOCERTS;
215 else if (!strcmp (*args, "-noattr"))
217 else if (!strcmp (*args, "-nodetach"))
218 flags &= ~CMS_DETACHED;
219 else if (!strcmp (*args, "-nosmimecap"))
220 flags |= CMS_NOSMIMECAP;
221 else if (!strcmp (*args, "-binary"))
223 else if (!strcmp (*args, "-keyid"))
224 flags |= CMS_USE_KEYID;
225 else if (!strcmp (*args, "-nosigs"))
227 else if (!strcmp (*args, "-no_content_verify"))
228 flags |= CMS_NO_CONTENT_VERIFY;
229 else if (!strcmp (*args, "-no_attr_verify"))
230 flags |= CMS_NO_ATTR_VERIFY;
231 else if (!strcmp (*args, "-stream"))
233 else if (!strcmp (*args, "-indef"))
235 else if (!strcmp (*args, "-noindef"))
237 else if (!strcmp (*args, "-nooldmime"))
238 flags |= CMS_NOOLDMIMETYPE;
239 else if (!strcmp (*args, "-crlfeol"))
240 flags |= CMS_CRLFEOL;
241 else if (!strcmp(*args,"-secretkey"))
247 secret_key = string_to_hex(*args, <mp);
250 BIO_printf(bio_err, "Invalid key %s\n", *args);
253 secret_keylen = (size_t)ltmp;
255 else if (!strcmp(*args,"-rand"))
263 #ifndef OPENSSL_NO_ENGINE
264 else if (!strcmp(*args,"-engine"))
271 else if (!strcmp(*args,"-passin"))
277 else if (!strcmp (*args, "-to"))
283 else if (!strcmp (*args, "-from"))
289 else if (!strcmp (*args, "-subject"))
295 else if (!strcmp (*args, "-signer"))
299 /* If previous -signer argument add signer to list */
304 sksigners = sk_new_null();
305 sk_push(sksigners, signerfile);
307 keyfile = signerfile;
309 skkeys = sk_new_null();
310 sk_push(skkeys, keyfile);
313 signerfile = *++args;
315 else if (!strcmp (*args, "-recip"))
321 else if (!strcmp (*args, "-md"))
325 sign_md = EVP_get_digestbyname(*++args);
328 BIO_printf(bio_err, "Unknown digest %s\n",
333 else if (!strcmp (*args, "-inkey"))
337 /* If previous -inkey arument add signer to list */
342 BIO_puts(bio_err, "Illegal -inkey without -signer\n");
346 sksigners = sk_new_null();
347 sk_push(sksigners, signerfile);
350 skkeys = sk_new_null();
351 sk_push(skkeys, keyfile);
355 else if (!strcmp (*args, "-keyform"))
359 keyform = str2fmt(*++args);
361 else if (!strcmp (*args, "-certfile"))
367 else if (!strcmp (*args, "-CAfile"))
373 else if (!strcmp (*args, "-CApath"))
379 else if (!strcmp (*args, "-in"))
385 else if (!strcmp (*args, "-inform"))
389 informat = str2fmt(*++args);
391 else if (!strcmp (*args, "-outform"))
395 outformat = str2fmt(*++args);
397 else if (!strcmp (*args, "-out"))
403 else if (!strcmp (*args, "-content"))
409 else if (args_verify(&args, NULL, &badarg, bio_err, &vpm))
411 else if ((cipher = EVP_get_cipherbyname(*args + 1)) == NULL)
416 if (!(operation & SMIME_SIGNERS) && (skkeys || sksigners))
418 BIO_puts(bio_err, "Multiple signers or keys not allowed\n");
422 if (operation & SMIME_SIGNERS)
424 /* Check to see if any final signer needs to be appended */
425 if (keyfile && !signerfile)
427 BIO_puts(bio_err, "Illegal -inkey without -signer\n");
433 sksigners = sk_new_null();
434 sk_push(sksigners, signerfile);
436 skkeys = sk_new_null();
438 keyfile = signerfile;
439 sk_push(skkeys, keyfile);
443 BIO_printf(bio_err, "No signer certificate specified\n");
450 else if (operation == SMIME_DECRYPT)
452 if (!recipfile && !keyfile)
454 BIO_printf(bio_err, "No recipient certificate or key specified\n");
458 else if (operation == SMIME_ENCRYPT)
462 BIO_printf(bio_err, "No recipient(s) certificate(s) specified\n");
473 BIO_printf (bio_err, "Usage smime [options] cert.pem ...\n");
474 BIO_printf (bio_err, "where options are\n");
475 BIO_printf (bio_err, "-encrypt encrypt message\n");
476 BIO_printf (bio_err, "-decrypt decrypt encrypted message\n");
477 BIO_printf (bio_err, "-sign sign message\n");
478 BIO_printf (bio_err, "-verify verify signed message\n");
479 BIO_printf (bio_err, "-cmsout output CMS structure\n");
480 #ifndef OPENSSL_NO_DES
481 BIO_printf (bio_err, "-des3 encrypt with triple DES\n");
482 BIO_printf (bio_err, "-des encrypt with DES\n");
484 #ifndef OPENSSL_NO_SEED
485 BIO_printf (bio_err, "-seed encrypt with SEED\n");
487 #ifndef OPENSSL_NO_RC2
488 BIO_printf (bio_err, "-rc2-40 encrypt with RC2-40 (default)\n");
489 BIO_printf (bio_err, "-rc2-64 encrypt with RC2-64\n");
490 BIO_printf (bio_err, "-rc2-128 encrypt with RC2-128\n");
492 #ifndef OPENSSL_NO_AES
493 BIO_printf (bio_err, "-aes128, -aes192, -aes256\n");
494 BIO_printf (bio_err, " encrypt PEM output with cbc aes\n");
496 #ifndef OPENSSL_NO_CAMELLIA
497 BIO_printf (bio_err, "-camellia128, -camellia192, -camellia256\n");
498 BIO_printf (bio_err, " encrypt PEM output with cbc camellia\n");
500 BIO_printf (bio_err, "-nointern don't search certificates in message for signer\n");
501 BIO_printf (bio_err, "-nosigs don't verify message signature\n");
502 BIO_printf (bio_err, "-noverify don't verify signers certificate\n");
503 BIO_printf (bio_err, "-nocerts don't include signers certificate when signing\n");
504 BIO_printf (bio_err, "-nodetach use opaque signing\n");
505 BIO_printf (bio_err, "-noattr don't include any signed attributes\n");
506 BIO_printf (bio_err, "-binary don't translate message to text\n");
507 BIO_printf (bio_err, "-certfile file other certificates file\n");
508 BIO_printf (bio_err, "-signer file signer certificate file\n");
509 BIO_printf (bio_err, "-recip file recipient certificate file for decryption\n");
510 BIO_printf (bio_err, "-skeyid use subject key identifier\n");
511 BIO_printf (bio_err, "-in file input file\n");
512 BIO_printf (bio_err, "-inform arg input format SMIME (default), PEM or DER\n");
513 BIO_printf (bio_err, "-inkey file input private key (if not signer or recipient)\n");
514 BIO_printf (bio_err, "-keyform arg input private key format (PEM or ENGINE)\n");
515 BIO_printf (bio_err, "-out file output file\n");
516 BIO_printf (bio_err, "-outform arg output format SMIME (default), PEM or DER\n");
517 BIO_printf (bio_err, "-content file supply or override content for detached signature\n");
518 BIO_printf (bio_err, "-to addr to address\n");
519 BIO_printf (bio_err, "-from ad from address\n");
520 BIO_printf (bio_err, "-subject s subject\n");
521 BIO_printf (bio_err, "-text include or delete text MIME headers\n");
522 BIO_printf (bio_err, "-CApath dir trusted certificates directory\n");
523 BIO_printf (bio_err, "-CAfile file trusted certificates file\n");
524 BIO_printf (bio_err, "-crl_check check revocation status of signer's certificate using CRLs\n");
525 BIO_printf (bio_err, "-crl_check_all check revocation status of signer's certificate chain using CRLs\n");
526 #ifndef OPENSSL_NO_ENGINE
527 BIO_printf (bio_err, "-engine e use engine e, possibly a hardware device.\n");
529 BIO_printf (bio_err, "-passin arg input file pass phrase source\n");
530 BIO_printf(bio_err, "-rand file%cfile%c...\n", LIST_SEPARATOR_CHAR, LIST_SEPARATOR_CHAR);
531 BIO_printf(bio_err, " load the file (or the files in the directory) into\n");
532 BIO_printf(bio_err, " the random number generator\n");
533 BIO_printf (bio_err, "cert.pem recipient certificate(s) for encryption\n");
537 #ifndef OPENSSL_NO_ENGINE
538 e = setup_engine(bio_err, engine, 0);
541 if (!app_passwd(bio_err, passargin, NULL, &passin, NULL))
543 BIO_printf(bio_err, "Error getting password\n");
549 app_RAND_load_file(NULL, bio_err, (inrand != NULL));
551 BIO_printf(bio_err,"%ld semi-random bytes loaded\n",
552 app_RAND_load_files(inrand));
557 if (!(operation & SMIME_SIGNERS))
558 flags &= ~CMS_DETACHED;
560 if (operation & SMIME_OP)
562 if (outformat == FORMAT_ASN1)
567 if (flags & CMS_BINARY)
571 if (operation & SMIME_IP)
573 if (informat == FORMAT_ASN1)
578 if (flags & CMS_BINARY)
582 if (operation == SMIME_ENCRYPT)
586 #ifndef OPENSSL_NO_RC2
587 cipher = EVP_rc2_40_cbc();
589 BIO_printf(bio_err, "No cipher selected\n");
593 encerts = sk_X509_new_null();
596 if (!(cert = load_cert(bio_err,*args,FORMAT_PEM,
597 NULL, e, "recipient certificate file")))
599 #if 0 /* An appropriate message is already printed */
600 BIO_printf(bio_err, "Can't read recipient certificate file %s\n", *args);
604 sk_X509_push(encerts, cert);
612 if (!(other = load_certs(bio_err,certfile,FORMAT_PEM, NULL,
613 e, "certificate file")))
615 ERR_print_errors(bio_err);
620 if (recipfile && (operation == SMIME_DECRYPT))
622 if (!(recip = load_cert(bio_err,recipfile,FORMAT_PEM,NULL,
623 e, "recipient certificate file")))
625 ERR_print_errors(bio_err);
630 if (operation == SMIME_DECRYPT)
635 else if (operation == SMIME_SIGN)
638 keyfile = signerfile;
644 key = load_key(bio_err, keyfile, keyform, 0, passin, e,
652 if (!(in = BIO_new_file(infile, inmode)))
655 "Can't open input file %s\n", infile);
660 in = BIO_new_fp(stdin, BIO_NOCLOSE);
662 if (operation & SMIME_IP)
664 if (informat == FORMAT_SMIME)
665 cms = SMIME_read_CMS(in, &indata);
666 else if (informat == FORMAT_PEM)
667 cms = PEM_read_bio_CMS(in, NULL, NULL, NULL);
668 else if (informat == FORMAT_ASN1)
669 cms = d2i_CMS_bio(in, NULL);
672 BIO_printf(bio_err, "Bad input format for CMS file\n");
678 BIO_printf(bio_err, "Error reading S/MIME message\n");
684 if (!(indata = BIO_new_file(contfile, "rb")))
686 BIO_printf(bio_err, "Can't read content file %s\n", contfile);
694 if (!(out = BIO_new_file(outfile, outmode)))
697 "Can't open output file %s\n", outfile);
703 out = BIO_new_fp(stdout, BIO_NOCLOSE);
704 #ifdef OPENSSL_SYS_VMS
706 BIO *tmpbio = BIO_new(BIO_f_linebuffer());
707 out = BIO_push(tmpbio, out);
712 if (operation == SMIME_VERIFY)
714 if (!(store = setup_verify(bio_err, CAfile, CApath)))
716 X509_STORE_set_verify_cb_func(store, smime_cb);
718 X509_STORE_set1_param(store, vpm);
724 if (operation == SMIME_DATA_CREATE)
728 cms = CMS_data_create(in, flags);
730 else if (operation == SMIME_DIGEST_CREATE)
734 cms = CMS_digest_create(in, sign_md, flags);
736 else if (operation == SMIME_COMPRESS)
740 cms = CMS_compress(in, -1, flags);
742 else if (operation == SMIME_ENCRYPT)
746 cms = CMS_encrypt(encerts, in, cipher, flags);
748 else if (operation & SMIME_SIGNERS)
751 /* If detached data content we only enable streaming if
752 * S/MIME output format.
754 if (operation == SMIME_SIGN)
756 if (flags & CMS_DETACHED)
758 if (outformat == FORMAT_SMIME)
763 flags |= CMS_PARTIAL;
764 cms = CMS_sign(NULL, NULL, other, in, flags);
769 flags |= CMS_REUSE_DIGEST;
770 for (i = 0; i < sk_num(sksigners); i++)
772 signerfile = sk_value(sksigners, i);
773 keyfile = sk_value(skkeys, i);
774 signer = load_cert(bio_err, signerfile,FORMAT_PEM, NULL,
775 e, "signer certificate");
778 key = load_key(bio_err, keyfile, keyform, 0, passin, e,
782 if (!CMS_add1_signer(cms, signer, key, sign_md, flags))
789 /* If not streaming or resigning finalize structure */
790 if ((operation == SMIME_SIGN) && !(flags & CMS_STREAM))
792 if (!CMS_final(cms, in, flags))
799 BIO_printf(bio_err, "Error creating CMS structure\n");
804 if (operation == SMIME_DECRYPT)
806 if (!CMS_decrypt(cms, key, recip, out, flags))
808 BIO_printf(bio_err, "Error decrypting CMS structure\n");
812 else if (operation == SMIME_DATAOUT)
814 if (!CMS_data(cms, out, flags))
817 else if (operation == SMIME_UNCOMPRESS)
819 if (!CMS_uncompress(cms, indata, out, flags))
822 else if (operation == SMIME_DIGEST_VERIFY)
824 if (CMS_digest_verify(cms, indata, out, flags) > 0)
825 BIO_printf(bio_err, "Verification successful\n");
828 BIO_printf(bio_err, "Verification failure\n");
832 else if (operation == SMIME_ENCRYPTED_DECRYPT)
834 if (!CMS_EncryptedData_decrypt(cms, secret_key, secret_keylen,
838 else if (operation == SMIME_VERIFY)
840 if (CMS_verify(cms, other, store, indata, out, flags) > 0)
841 BIO_printf(bio_err, "Verification successful\n");
844 BIO_printf(bio_err, "Verification failure\n");
849 STACK_OF(X509) *signers;
850 signers = CMS_get0_signers(cms);
851 if (!save_certs(signerfile, signers))
854 "Error writing signers to %s\n",
859 sk_X509_free(signers);
864 if (outformat == FORMAT_SMIME)
867 BIO_printf(out, "To: %s\n", to);
869 BIO_printf(out, "From: %s\n", from);
871 BIO_printf(out, "Subject: %s\n", subject);
872 if (operation == SMIME_RESIGN)
873 ret = SMIME_write_CMS(out, cms, indata, flags);
875 ret = SMIME_write_CMS(out, cms, in, flags);
877 else if (outformat == FORMAT_PEM)
878 ret = PEM_write_bio_CMS_stream(out, cms, in, flags);
879 else if (outformat == FORMAT_ASN1)
880 ret = i2d_CMS_bio_stream(out,cms, in, flags);
883 BIO_printf(bio_err, "Bad output format for CMS file\n");
895 ERR_print_errors(bio_err);
897 app_RAND_write_file(NULL, bio_err);
898 sk_X509_pop_free(encerts, X509_free);
899 sk_X509_pop_free(other, X509_free);
901 X509_VERIFY_PARAM_free(vpm);
907 OPENSSL_free(secret_key);
908 X509_STORE_free(store);
913 CMS_ContentInfo_free(cms);
917 if (passin) OPENSSL_free(passin);
921 static int save_certs(char *signerfile, STACK_OF(X509) *signers)
927 tmp = BIO_new_file(signerfile, "w");
929 for(i = 0; i < sk_X509_num(signers); i++)
930 PEM_write_bio_X509(tmp, sk_X509_value(signers, i));
936 /* Minimal callback just to output policy info (if any) */
938 static int smime_cb(int ok, X509_STORE_CTX *ctx)
942 error = X509_STORE_CTX_get_error(ctx);
944 if ((error != X509_V_ERR_NO_EXPLICIT_POLICY)
945 && ((error != X509_V_OK) || (ok != 2)))
948 policies_print(NULL, ctx);