71 #define PROG smime_main
72 static int save_certs(
char *signerfile,
STACK_OF(
X509) *signers);
77 #define SMIME_SIGNERS 0x40
78 #define SMIME_ENCRYPT (1 | SMIME_OP)
79 #define SMIME_DECRYPT (2 | SMIME_IP)
80 #define SMIME_SIGN (3 | SMIME_OP | SMIME_SIGNERS)
81 #define SMIME_VERIFY (4 | SMIME_IP)
82 #define SMIME_PK7OUT (5 | SMIME_IP | SMIME_OP)
83 #define SMIME_RESIGN (6 | SMIME_IP | SMIME_OP | SMIME_SIGNERS)
85 int MAIN(
int,
char **);
87 int MAIN(
int argc,
char **argv)
93 const char *inmode =
"r", *outmode =
"w";
94 char *infile = NULL, *outfile = NULL;
95 char *signerfile = NULL, *recipfile = NULL;
97 char *certfile = NULL, *keyfile = NULL, *contfile=NULL;
101 X509 *cert = NULL, *recip = NULL, *signer = NULL;
104 BIO *
in = NULL, *
out = NULL, *indata = NULL;
107 char *to = NULL, *from = NULL, *subject = NULL;
108 char *CAfile = NULL, *CApath = NULL;
109 char *passargin = NULL, *passin = NULL;
113 const EVP_MD *sign_md = NULL;
116 #ifndef OPENSSL_NO_ENGINE
136 while (!badarg && *args && *args[0] ==
'-')
138 if (!strcmp (*args,
"-encrypt"))
140 else if (!strcmp (*args,
"-decrypt"))
142 else if (!strcmp (*args,
"-sign"))
144 else if (!strcmp (*args,
"-resign"))
146 else if (!strcmp (*args,
"-verify"))
148 else if (!strcmp (*args,
"-pk7out"))
150 #ifndef OPENSSL_NO_DES
151 else if (!strcmp (*args,
"-des3"))
153 else if (!strcmp (*args,
"-des"))
156 #ifndef OPENSSL_NO_SEED
157 else if (!strcmp (*args,
"-seed"))
160 #ifndef OPENSSL_NO_RC2
161 else if (!strcmp (*args,
"-rc2-40"))
163 else if (!strcmp (*args,
"-rc2-128"))
165 else if (!strcmp (*args,
"-rc2-64"))
168 #ifndef OPENSSL_NO_AES
169 else if (!strcmp(*args,
"-aes128"))
171 else if (!strcmp(*args,
"-aes192"))
173 else if (!strcmp(*args,
"-aes256"))
176 #ifndef OPENSSL_NO_CAMELLIA
177 else if (!strcmp(*args,
"-camellia128"))
179 else if (!strcmp(*args,
"-camellia192"))
181 else if (!strcmp(*args,
"-camellia256"))
184 else if (!strcmp (*args,
"-text"))
186 else if (!strcmp (*args,
"-nointern"))
188 else if (!strcmp (*args,
"-noverify"))
190 else if (!strcmp (*args,
"-nochain"))
192 else if (!strcmp (*args,
"-nocerts"))
194 else if (!strcmp (*args,
"-noattr"))
196 else if (!strcmp (*args,
"-nodetach"))
198 else if (!strcmp (*args,
"-nosmimecap"))
200 else if (!strcmp (*args,
"-binary"))
202 else if (!strcmp (*args,
"-nosigs"))
204 else if (!strcmp (*args,
"-stream"))
206 else if (!strcmp (*args,
"-indef"))
208 else if (!strcmp (*args,
"-noindef"))
210 else if (!strcmp (*args,
"-nooldmime"))
212 else if (!strcmp (*args,
"-crlfeol"))
214 else if (!strcmp(*args,
"-rand"))
222 #ifndef OPENSSL_NO_ENGINE
223 else if (!strcmp(*args,
"-engine"))
230 else if (!strcmp(*args,
"-passin"))
236 else if (!strcmp (*args,
"-to"))
242 else if (!strcmp (*args,
"-from"))
248 else if (!strcmp (*args,
"-subject"))
254 else if (!strcmp (*args,
"-signer"))
266 keyfile = signerfile;
272 signerfile = *++args;
274 else if (!strcmp (*args,
"-recip"))
280 else if (!strcmp (*args,
"-md"))
292 else if (!strcmp (*args,
"-inkey"))
314 else if (!strcmp (*args,
"-keyform"))
320 else if (!strcmp (*args,
"-certfile"))
326 else if (!strcmp (*args,
"-CAfile"))
332 else if (!strcmp (*args,
"-CApath"))
338 else if (!strcmp (*args,
"-in"))
344 else if (!strcmp (*args,
"-inform"))
350 else if (!strcmp (*args,
"-outform"))
356 else if (!strcmp (*args,
"-out"))
362 else if (!strcmp (*args,
"-content"))
381 if (operation & SMIME_SIGNERS)
384 if (keyfile && !signerfile)
397 keyfile = signerfile;
411 if (!recipfile && !keyfile)
439 #ifndef OPENSSL_NO_DES
443 #ifndef OPENSSL_NO_SEED
446 #ifndef OPENSSL_NO_RC2
451 #ifndef OPENSSL_NO_AES
455 #ifndef OPENSSL_NO_CAMELLIA
459 BIO_printf (
bio_err,
"-nointern don't search certificates in message for signer\n");
462 BIO_printf (
bio_err,
"-nocerts don't include signers certificate when signing\n");
471 BIO_printf (
bio_err,
"-inkey file input private key (if not signer or recipient)\n");
474 BIO_printf (
bio_err,
"-outform arg output format SMIME (default), PEM or DER\n");
475 BIO_printf (
bio_err,
"-content file supply or override content for detached signature\n");
482 BIO_printf (
bio_err,
"-crl_check check revocation status of signer's certificate using CRLs\n");
483 BIO_printf (
bio_err,
"-crl_check_all check revocation status of signer's certificate chain using CRLs\n");
484 #ifndef OPENSSL_NO_ENGINE
495 #ifndef OPENSSL_NO_ENGINE
515 if (!(operation & SMIME_SIGNERS))
544 #ifndef OPENSSL_NO_RC2
555 NULL, e,
"recipient certificate file")))
571 e,
"certificate file")))
581 e,
"recipient certificate file")))
596 keyfile = signerfile;
613 "Can't open input file %s\n", infile);
620 if (operation & SMIME_IP)
625 p7 = PEM_read_bio_PKCS7(in, NULL, NULL, NULL);
655 "Can't open output file %s\n", outfile);
662 #ifdef OPENSSL_SYS_VMS
688 else if (operation & SMIME_SIGNERS)
704 p7 =
PKCS7_sign(NULL, NULL, other, in, flags);
715 e,
"signer certificate");
763 signers = PKCS7_get0_signers(p7, other, flags);
764 if (!save_certs(signerfile, signers))
774 PEM_write_bio_PKCS7(out, p7);
826 static int save_certs(
char *signerfile,
STACK_OF(
X509) *signers)