2 * Copyright 2008-2020 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 /* CMS utility function */
17 #ifndef OPENSSL_NO_CMS
19 # include <openssl/crypto.h>
20 # include <openssl/pem.h>
21 # include <openssl/err.h>
22 # include <openssl/x509_vfy.h>
23 # include <openssl/x509v3.h>
24 # include <openssl/cms.h>
26 DEFINE_STACK_OF(CMS_SignerInfo
)
28 static int save_certs(char *signerfile
, STACK_OF(X509
) *signers
);
29 static int cms_cb(int ok
, X509_STORE_CTX
*ctx
);
30 static void receipt_request_print(CMS_ContentInfo
*cms
);
31 static CMS_ReceiptRequest
*make_receipt_request(
32 STACK_OF(OPENSSL_STRING
) *rr_to
, int rr_allorfirst
,
33 STACK_OF(OPENSSL_STRING
) *rr_from
, OPENSSL_CTX
*libctx
, const char *propq
);
34 static int cms_set_pkey_param(EVP_PKEY_CTX
*pctx
,
35 STACK_OF(OPENSSL_STRING
) *param
);
37 # define SMIME_OP 0x10
38 # define SMIME_IP 0x20
39 # define SMIME_SIGNERS 0x40
40 # define SMIME_ENCRYPT (1 | SMIME_OP)
41 # define SMIME_DECRYPT (2 | SMIME_IP)
42 # define SMIME_SIGN (3 | SMIME_OP | SMIME_SIGNERS)
43 # define SMIME_VERIFY (4 | SMIME_IP)
44 # define SMIME_CMSOUT (5 | SMIME_IP | SMIME_OP)
45 # define SMIME_RESIGN (6 | SMIME_IP | SMIME_OP | SMIME_SIGNERS)
46 # define SMIME_DATAOUT (7 | SMIME_IP)
47 # define SMIME_DATA_CREATE (8 | SMIME_OP)
48 # define SMIME_DIGEST_VERIFY (9 | SMIME_IP)
49 # define SMIME_DIGEST_CREATE (10 | SMIME_OP)
50 # define SMIME_UNCOMPRESS (11 | SMIME_IP)
51 # define SMIME_COMPRESS (12 | SMIME_OP)
52 # define SMIME_ENCRYPTED_DECRYPT (13 | SMIME_IP)
53 # define SMIME_ENCRYPTED_ENCRYPT (14 | SMIME_OP)
54 # define SMIME_SIGN_RECEIPT (15 | SMIME_IP | SMIME_OP)
55 # define SMIME_VERIFY_RECEIPT (16 | SMIME_IP)
57 static int verify_err
= 0;
59 typedef struct cms_key_param_st cms_key_param
;
61 struct cms_key_param_st
{
63 STACK_OF(OPENSSL_STRING
) *param
;
67 typedef enum OPTION_choice
{
68 OPT_ERR
= -1, OPT_EOF
= 0, OPT_HELP
,
69 OPT_INFORM
, OPT_OUTFORM
, OPT_IN
, OPT_OUT
, OPT_ENCRYPT
,
70 OPT_DECRYPT
, OPT_SIGN
, OPT_CADES
, OPT_SIGN_RECEIPT
, OPT_RESIGN
,
71 OPT_VERIFY
, OPT_VERIFY_RETCODE
, OPT_VERIFY_RECEIPT
,
72 OPT_CMSOUT
, OPT_DATA_OUT
, OPT_DATA_CREATE
, OPT_DIGEST_VERIFY
,
73 OPT_DIGEST_CREATE
, OPT_COMPRESS
, OPT_UNCOMPRESS
,
74 OPT_ED_DECRYPT
, OPT_ED_ENCRYPT
, OPT_DEBUG_DECRYPT
, OPT_TEXT
,
75 OPT_ASCIICRLF
, OPT_NOINTERN
, OPT_NOVERIFY
, OPT_NOCERTS
,
76 OPT_NOATTR
, OPT_NODETACH
, OPT_NOSMIMECAP
, OPT_BINARY
, OPT_KEYID
,
77 OPT_NOSIGS
, OPT_NO_CONTENT_VERIFY
, OPT_NO_ATTR_VERIFY
, OPT_INDEF
,
78 OPT_NOINDEF
, OPT_CRLFEOL
, OPT_NOOUT
, OPT_RR_PRINT
,
79 OPT_RR_ALL
, OPT_RR_FIRST
, OPT_RCTFORM
, OPT_CERTFILE
, OPT_CAFILE
,
80 OPT_CAPATH
, OPT_CASTORE
, OPT_NOCAPATH
, OPT_NOCAFILE
, OPT_NOCASTORE
,
81 OPT_CONTENT
, OPT_PRINT
, OPT_NAMEOPT
,
82 OPT_SECRETKEY
, OPT_SECRETKEYID
, OPT_PWRI_PASSWORD
, OPT_ECONTENT_TYPE
,
83 OPT_PASSIN
, OPT_TO
, OPT_FROM
, OPT_SUBJECT
, OPT_SIGNER
, OPT_RECIP
,
84 OPT_CERTSOUT
, OPT_MD
, OPT_INKEY
, OPT_KEYFORM
, OPT_KEYOPT
, OPT_RR_FROM
,
85 OPT_RR_TO
, OPT_AES128_WRAP
, OPT_AES192_WRAP
, OPT_AES256_WRAP
,
86 OPT_3DES_WRAP
, OPT_WRAP
, OPT_ENGINE
,
88 OPT_PROV_ENUM
, OPT_CONFIG
,
94 const OPTIONS cms_options
[] = {
95 {OPT_HELP_STR
, 1, '-', "Usage: %s [options] [cert...]\n"},
97 OPT_SECTION("General"),
98 {"help", OPT_HELP
, '-', "Display this summary"},
99 {"inform", OPT_INFORM
, 'c', "Input format SMIME (default), PEM or DER"},
100 {"outform", OPT_OUTFORM
, 'c',
101 "Output format SMIME (default), PEM or DER"},
102 {"in", OPT_IN
, '<', "Input file"},
103 {"out", OPT_OUT
, '>', "Output file"},
104 {"debug_decrypt", OPT_DEBUG_DECRYPT
, '-',
105 "Disable MMA protection and return an error if no recipient found"
106 " (see documentation)"},
107 {"stream", OPT_INDEF
, '-', "Enable CMS streaming"},
108 {"indef", OPT_INDEF
, '-', "Same as -stream"},
109 {"noindef", OPT_NOINDEF
, '-', "Disable CMS streaming"},
110 {"crlfeol", OPT_CRLFEOL
, '-', "Use CRLF as EOL termination instead of CR only" },
111 {"CAfile", OPT_CAFILE
, '<', "Trusted certificates file"},
112 {"CApath", OPT_CAPATH
, '/', "trusted certificates directory"},
113 {"CAstore", OPT_CASTORE
, ':', "trusted certificates store URI"},
114 {"no-CAfile", OPT_NOCAFILE
, '-',
115 "Do not load the default certificates file"},
116 {"no-CApath", OPT_NOCAPATH
, '-',
117 "Do not load certificates from the default certificates directory"},
118 {"no-CAstore", OPT_NOCASTORE
, '-',
119 "Do not load certificates from the default certificates store"},
120 # ifndef OPENSSL_NO_ENGINE
121 {"engine", OPT_ENGINE
, 's', "Use engine e, possibly a hardware device"},
125 OPT_SECTION("Action"),
126 {"encrypt", OPT_ENCRYPT
, '-', "Encrypt message"},
127 {"decrypt", OPT_DECRYPT
, '-', "Decrypt encrypted message"},
128 {"sign", OPT_SIGN
, '-', "Sign message"},
129 {"sign_receipt", OPT_SIGN_RECEIPT
, '-', "Generate a signed receipt for the message"},
130 {"resign", OPT_RESIGN
, '-', "Resign a signed message"},
131 {"cades", OPT_CADES
, '-', "Include signer certificate digest"},
132 {"verify", OPT_VERIFY
, '-', "Verify signed message"},
133 {"verify_retcode", OPT_VERIFY_RETCODE
, '-',
134 "Exit non-zero on verification failure"},
135 {"verify_receipt", OPT_VERIFY_RECEIPT
, '<',
136 "Verify receipts; exit if receipt signatures do not verify"},
137 {"digest_verify", OPT_DIGEST_VERIFY
, '-',
138 "Verify a CMS \"DigestedData\" object and output it"},
139 {"digest_create", OPT_DIGEST_CREATE
, '-',
140 "Create a CMS \"DigestedData\" object"},
141 {"compress", OPT_COMPRESS
, '-', "Create a CMS \"CompressedData\" object"},
142 {"uncompress", OPT_UNCOMPRESS
, '-',
143 "Uncompress a CMS \"CompressedData\" object"},
144 {"EncryptedData_decrypt", OPT_ED_DECRYPT
, '-',
145 "Decrypt CMS \"EncryptedData\" object using symmetric key"},
146 {"EncryptedData_encrypt", OPT_ED_ENCRYPT
, '-',
147 "Create CMS \"EncryptedData\" object using symmetric key"},
148 {"data_out", OPT_DATA_OUT
, '-', "Copy CMS \"Data\" object to output"},
149 {"data_create", OPT_DATA_CREATE
, '-', "Create a CMS \"Data\" object"},
150 {"cmsout", OPT_CMSOUT
, '-', "Output CMS structure"},
151 {"no_content_verify", OPT_NO_CONTENT_VERIFY
, '-',
152 "Do not verify signed content signatures"},
153 {"no_attr_verify", OPT_NO_ATTR_VERIFY
, '-',
154 "Do not verify signed attribute signatures"},
155 {"nointern", OPT_NOINTERN
, '-',
156 "Don't search certificates in message for signer"},
157 {"noverify", OPT_NOVERIFY
, '-', "Don't verify signers certificate"},
159 OPT_SECTION("Formatting"),
160 {"text", OPT_TEXT
, '-', "Include or delete text MIME headers"},
161 {"asciicrlf", OPT_ASCIICRLF
, '-',
162 "Perform CRLF canonicalisation when signing"},
163 {"nodetach", OPT_NODETACH
, '-', "Use opaque signing"},
164 {"nosmimecap", OPT_NOSMIMECAP
, '-', "Omit the SMIMECapabilities attribute"},
165 {"noattr", OPT_NOATTR
, '-', "Don't include any signed attributes"},
166 {"binary", OPT_BINARY
, '-', "Don't translate message to text"},
167 {"keyid", OPT_KEYID
, '-', "Use subject key identifier"},
168 {"nosigs", OPT_NOSIGS
, '-', "Don't verify message signature"},
169 {"nocerts", OPT_NOCERTS
, '-',
170 "Don't include signers certificate when signing"},
171 {"noout", OPT_NOOUT
, '-',
172 "For the -cmsout operation do not output the parsed CMS structure"},
173 {"receipt_request_print", OPT_RR_PRINT
, '-', "Print CMS Receipt Request" },
174 {"receipt_request_all", OPT_RR_ALL
, '-',
175 "When signing, create a receipt request for all recipients"},
176 {"receipt_request_first", OPT_RR_FIRST
, '-',
177 "When signing, create a receipt request for first recipient"},
178 {"rctform", OPT_RCTFORM
, 'F', "Receipt file format"},
179 {"certfile", OPT_CERTFILE
, '<', "Other certificates file"},
180 {"content", OPT_CONTENT
, '<',
181 "Supply or override content for detached signature"},
182 {"print", OPT_PRINT
, '-',
183 "For the -cmsout operation print out all fields of the CMS structure"},
184 {"nameopt", OPT_NAMEOPT
, 's',
185 "For the -print option specifies various strings printing options"},
186 {"certsout", OPT_CERTSOUT
, '>', "Certificate output file"},
188 OPT_SECTION("Keying"),
189 {"secretkey", OPT_SECRETKEY
, 's',
190 "Use specified hex-encoded key to decrypt/encrypt recipients or content"},
191 {"secretkeyid", OPT_SECRETKEYID
, 's',
192 "Identity of the -secretkey for CMS \"KEKRecipientInfo\" object"},
193 {"pwri_password", OPT_PWRI_PASSWORD
, 's',
194 "Specific password for recipient"},
195 {"passin", OPT_PASSIN
, 's', "Input file pass phrase source"},
196 {"inkey", OPT_INKEY
, 's',
197 "Input private key (if not signer or recipient)"},
198 {"keyform", OPT_KEYFORM
, 'f', "Input private key format (ENGINE, other values ignored)"},
199 {"keyopt", OPT_KEYOPT
, 's', "Set public key parameters as n:v pairs"},
201 OPT_SECTION("Mail header"),
202 {"econtent_type", OPT_ECONTENT_TYPE
, 's', "OID for external content"},
203 {"to", OPT_TO
, 's', "To address"},
204 {"from", OPT_FROM
, 's', "From address"},
205 {"subject", OPT_SUBJECT
, 's', "Subject"},
206 {"signer", OPT_SIGNER
, 's', "Signer certificate file"},
207 {"originator", OPT_ORIGINATOR
, 's', "Originator certificate file"},
208 {"recip", OPT_RECIP
, '<', "Recipient cert file for decryption"},
209 {"receipt_request_from", OPT_RR_FROM
, 's',
210 "Create signed receipt request with specified email address"},
211 {"receipt_request_to", OPT_RR_TO
, 's',
212 "Create signed receipt targeted to specified address"},
214 OPT_SECTION("Encryption"),
215 {"md", OPT_MD
, 's', "Digest algorithm to use when signing or resigning"},
216 {"", OPT_CIPHER
, '-', "Any supported cipher"},
218 OPT_SECTION("Key-wrapping"),
219 {"aes128-wrap", OPT_AES128_WRAP
, '-', "Use AES128 to wrap key"},
220 {"aes192-wrap", OPT_AES192_WRAP
, '-', "Use AES192 to wrap key"},
221 {"aes256-wrap", OPT_AES256_WRAP
, '-', "Use AES256 to wrap key"},
222 # ifndef OPENSSL_NO_DES
223 {"des3-wrap", OPT_3DES_WRAP
, '-', "Use 3DES-EDE to wrap key"},
225 {"wrap", OPT_WRAP
, 's', "Any wrap cipher to wrap key"},
232 {"cert", 0, 0, "Recipient certs (optional; used only when encrypting)"},
236 static CMS_ContentInfo
*load_content_info(int informat
, BIO
*in
, BIO
**indata
,
238 OPENSSL_CTX
*libctx
, const char *propq
)
240 CMS_ContentInfo
*ret
, *ci
;
242 ret
= CMS_ContentInfo_new_with_libctx(libctx
, propq
);
244 BIO_printf(bio_err
, "Error allocating CMS_contentinfo\n");
249 ci
= SMIME_read_CMS_ex(in
, indata
, &ret
);
252 ci
= PEM_read_bio_CMS(in
, &ret
, NULL
, NULL
);
255 ci
= d2i_CMS_bio(in
, &ret
);
258 BIO_printf(bio_err
, "Bad input format for %s\n", name
);
262 BIO_printf(bio_err
, "Error reading %s Content Info\n", name
);
267 CMS_ContentInfo_free(ret
);
271 int cms_main(int argc
, char **argv
)
274 ASN1_OBJECT
*econtent_type
= NULL
;
275 BIO
*in
= NULL
, *out
= NULL
, *indata
= NULL
, *rctin
= NULL
;
276 CMS_ContentInfo
*cms
= NULL
, *rcms
= NULL
;
277 CMS_ReceiptRequest
*rr
= NULL
;
279 EVP_PKEY
*key
= NULL
;
280 const EVP_CIPHER
*cipher
= NULL
, *wrap_cipher
= NULL
;
281 const EVP_MD
*sign_md
= NULL
;
282 STACK_OF(OPENSSL_STRING
) *rr_to
= NULL
, *rr_from
= NULL
;
283 STACK_OF(OPENSSL_STRING
) *sksigners
= NULL
, *skkeys
= NULL
;
284 STACK_OF(X509
) *encerts
= NULL
, *other
= NULL
;
285 X509
*cert
= NULL
, *recip
= NULL
, *signer
= NULL
, *originator
= NULL
;
286 X509_STORE
*store
= NULL
;
287 X509_VERIFY_PARAM
*vpm
= NULL
;
288 char *certfile
= NULL
, *keyfile
= NULL
, *contfile
= NULL
;
289 const char *CAfile
= NULL
, *CApath
= NULL
, *CAstore
= NULL
;
290 char *certsoutfile
= NULL
;
291 int noCAfile
= 0, noCApath
= 0, noCAstore
= 0;
292 char *infile
= NULL
, *outfile
= NULL
, *rctfile
= NULL
;
293 char *passinarg
= NULL
, *passin
= NULL
, *signerfile
= NULL
, *originatorfile
= NULL
, *recipfile
= NULL
;
294 char *to
= NULL
, *from
= NULL
, *subject
= NULL
, *prog
;
295 cms_key_param
*key_first
= NULL
, *key_param
= NULL
;
296 int flags
= CMS_DETACHED
, noout
= 0, print
= 0, keyidx
= -1, vpmtouched
= 0;
297 int informat
= FORMAT_SMIME
, outformat
= FORMAT_SMIME
;
298 int operation
= 0, ret
= 1, rr_print
= 0, rr_allorfirst
= -1;
299 int verify_retcode
= 0, rctformat
= FORMAT_SMIME
, keyform
= FORMAT_PEM
;
300 size_t secret_keylen
= 0, secret_keyidlen
= 0;
301 unsigned char *pwri_pass
= NULL
, *pwri_tmp
= NULL
;
302 unsigned char *secret_key
= NULL
, *secret_keyid
= NULL
;
304 const char *mime_eol
= "\n";
306 OPENSSL_CTX
*libctx
= app_get0_libctx();
307 const char *propq
= app_get0_propq();
309 if ((vpm
= X509_VERIFY_PARAM_new()) == NULL
)
312 prog
= opt_init(argc
, argv
, cms_options
);
313 while ((o
= opt_next()) != OPT_EOF
) {
318 BIO_printf(bio_err
, "%s: Use -help for summary.\n", prog
);
321 opt_help(cms_options
);
325 if (!opt_format(opt_arg(), OPT_FMT_PDS
, &informat
))
329 if (!opt_format(opt_arg(), OPT_FMT_PDS
, &outformat
))
336 operation
= SMIME_ENCRYPT
;
339 operation
= SMIME_DECRYPT
;
342 operation
= SMIME_SIGN
;
344 case OPT_SIGN_RECEIPT
:
345 operation
= SMIME_SIGN_RECEIPT
;
348 operation
= SMIME_RESIGN
;
351 operation
= SMIME_VERIFY
;
353 case OPT_VERIFY_RETCODE
:
356 case OPT_VERIFY_RECEIPT
:
357 operation
= SMIME_VERIFY_RECEIPT
;
361 operation
= SMIME_CMSOUT
;
364 operation
= SMIME_DATAOUT
;
366 case OPT_DATA_CREATE
:
367 operation
= SMIME_DATA_CREATE
;
369 case OPT_DIGEST_VERIFY
:
370 operation
= SMIME_DIGEST_VERIFY
;
372 case OPT_DIGEST_CREATE
:
373 operation
= SMIME_DIGEST_CREATE
;
376 operation
= SMIME_COMPRESS
;
379 operation
= SMIME_UNCOMPRESS
;
382 operation
= SMIME_ENCRYPTED_DECRYPT
;
385 operation
= SMIME_ENCRYPTED_ENCRYPT
;
387 case OPT_DEBUG_DECRYPT
:
388 flags
|= CMS_DEBUG_DECRYPT
;
394 flags
|= CMS_ASCIICRLF
;
397 flags
|= CMS_NOINTERN
;
400 flags
|= CMS_NO_SIGNER_CERT_VERIFY
;
403 flags
|= CMS_NOCERTS
;
409 flags
&= ~CMS_DETACHED
;
412 flags
|= CMS_NOSMIMECAP
;
421 flags
|= CMS_USE_KEYID
;
426 case OPT_NO_CONTENT_VERIFY
:
427 flags
|= CMS_NO_CONTENT_VERIFY
;
429 case OPT_NO_ATTR_VERIFY
:
430 flags
|= CMS_NO_ATTR_VERIFY
;
436 flags
&= ~CMS_STREAM
;
440 flags
|= CMS_CRLFEOL
;
455 if (rctformat
== FORMAT_ASN1
) {
456 if (!opt_format(opt_arg(),
457 OPT_FMT_PEMDER
| OPT_FMT_SMIME
, &rctformat
))
460 rcms
= load_content_info(rctformat
, rctin
, NULL
, "recipient",
465 certfile
= opt_arg();
489 contfile
= opt_arg();
493 && (rr_from
= sk_OPENSSL_STRING_new_null()) == NULL
)
495 sk_OPENSSL_STRING_push(rr_from
, opt_arg());
499 && (rr_to
= sk_OPENSSL_STRING_new_null()) == NULL
)
501 sk_OPENSSL_STRING_push(rr_to
, opt_arg());
507 if (!set_nameopt(opt_arg()))
511 if (secret_key
!= NULL
) {
512 BIO_printf(bio_err
, "Invalid key (supplied twice) %s\n",
516 secret_key
= OPENSSL_hexstr2buf(opt_arg(), <mp
);
517 if (secret_key
== NULL
) {
518 BIO_printf(bio_err
, "Invalid key %s\n", opt_arg());
521 secret_keylen
= (size_t)ltmp
;
523 case OPT_SECRETKEYID
:
524 if (secret_keyid
!= NULL
) {
525 BIO_printf(bio_err
, "Invalid id (supplied twice) %s\n",
529 secret_keyid
= OPENSSL_hexstr2buf(opt_arg(), <mp
);
530 if (secret_keyid
== NULL
) {
531 BIO_printf(bio_err
, "Invalid id %s\n", opt_arg());
534 secret_keyidlen
= (size_t)ltmp
;
536 case OPT_PWRI_PASSWORD
:
537 pwri_pass
= (unsigned char *)opt_arg();
539 case OPT_ECONTENT_TYPE
:
540 if (econtent_type
!= NULL
) {
541 BIO_printf(bio_err
, "Invalid OID (supplied twice) %s\n",
545 econtent_type
= OBJ_txt2obj(opt_arg(), 0);
546 if (econtent_type
== NULL
) {
547 BIO_printf(bio_err
, "Invalid OID %s\n", opt_arg());
552 e
= setup_engine(opt_arg(), 0);
555 passinarg
= opt_arg();
567 certsoutfile
= opt_arg();
570 if (!opt_md(opt_arg(), &sign_md
))
574 /* If previous -signer argument add signer to list */
575 if (signerfile
!= NULL
) {
576 if (sksigners
== NULL
577 && (sksigners
= sk_OPENSSL_STRING_new_null()) == NULL
)
579 sk_OPENSSL_STRING_push(sksigners
, signerfile
);
581 keyfile
= signerfile
;
583 && (skkeys
= sk_OPENSSL_STRING_new_null()) == NULL
)
585 sk_OPENSSL_STRING_push(skkeys
, keyfile
);
588 signerfile
= opt_arg();
591 originatorfile
= opt_arg();
594 /* If previous -inkey argument add signer to list */
595 if (keyfile
!= NULL
) {
596 if (signerfile
== NULL
) {
597 BIO_puts(bio_err
, "Illegal -inkey without -signer\n");
600 if (sksigners
== NULL
601 && (sksigners
= sk_OPENSSL_STRING_new_null()) == NULL
)
603 sk_OPENSSL_STRING_push(sksigners
, signerfile
);
606 && (skkeys
= sk_OPENSSL_STRING_new_null()) == NULL
)
608 sk_OPENSSL_STRING_push(skkeys
, keyfile
);
613 if (!opt_format(opt_arg(), OPT_FMT_ANY
, &keyform
))
617 if (operation
== SMIME_ENCRYPT
) {
618 if (encerts
== NULL
&& (encerts
= sk_X509_new_null()) == NULL
)
620 cert
= load_cert(opt_arg(), FORMAT_UNDEF
,
621 "recipient certificate file");
624 sk_X509_push(encerts
, cert
);
627 recipfile
= opt_arg();
631 if (!opt_cipher(opt_unknown(), &cipher
))
636 if (operation
== SMIME_ENCRYPT
) {
638 keyidx
+= sk_X509_num(encerts
);
640 if (keyfile
!= NULL
|| signerfile
!= NULL
)
643 keyidx
+= sk_OPENSSL_STRING_num(skkeys
);
646 BIO_printf(bio_err
, "No key specified\n");
649 if (key_param
== NULL
|| key_param
->idx
!= keyidx
) {
650 cms_key_param
*nparam
;
651 nparam
= app_malloc(sizeof(*nparam
), "key param buffer");
652 nparam
->idx
= keyidx
;
653 if ((nparam
->param
= sk_OPENSSL_STRING_new_null()) == NULL
)
656 if (key_first
== NULL
)
659 key_param
->next
= nparam
;
662 sk_OPENSSL_STRING_push(key_param
->param
, opt_arg());
665 if (!opt_verify(o
, vpm
))
674 if (!opt_provider(o
))
678 conf
= app_load_config_modules(opt_arg());
683 # ifndef OPENSSL_NO_DES
684 wrap_cipher
= EVP_des_ede3_wrap();
687 case OPT_AES128_WRAP
:
688 wrap_cipher
= EVP_aes_128_wrap();
690 case OPT_AES192_WRAP
:
691 wrap_cipher
= EVP_aes_192_wrap();
693 case OPT_AES256_WRAP
:
694 wrap_cipher
= EVP_aes_256_wrap();
697 if (!opt_cipher(opt_unknown(), &wrap_cipher
))
702 argc
= opt_num_rest();
705 if ((rr_allorfirst
!= -1 || rr_from
!= NULL
) && rr_to
== NULL
) {
706 BIO_puts(bio_err
, "No Signed Receipts Recipients\n");
710 if (!(operation
& SMIME_SIGNERS
) && (rr_to
!= NULL
|| rr_from
!= NULL
)) {
711 BIO_puts(bio_err
, "Signed receipts only allowed with -sign\n");
714 if (!(operation
& SMIME_SIGNERS
) && (skkeys
!= NULL
|| sksigners
!= NULL
)) {
715 BIO_puts(bio_err
, "Multiple signers or keys not allowed\n");
719 if ((flags
& CMS_CADES
) != 0) {
720 if ((flags
& CMS_NOATTR
) != 0) {
721 BIO_puts(bio_err
, "Incompatible options: "
722 "CAdES required signed attributes\n");
725 if (operation
== SMIME_VERIFY
726 && (flags
& (CMS_NO_SIGNER_CERT_VERIFY
| CMS_NO_ATTR_VERIFY
)) != 0) {
727 BIO_puts(bio_err
, "Incompatible options: CAdES validation require"
728 " certs and signed attributes validations\n");
733 if (operation
& SMIME_SIGNERS
) {
734 if (keyfile
!= NULL
&& signerfile
== NULL
) {
735 BIO_puts(bio_err
, "Illegal -inkey without -signer\n");
738 /* Check to see if any final signer needs to be appended */
739 if (signerfile
!= NULL
) {
740 if (sksigners
== NULL
741 && (sksigners
= sk_OPENSSL_STRING_new_null()) == NULL
)
743 sk_OPENSSL_STRING_push(sksigners
, signerfile
);
744 if (skkeys
== NULL
&& (skkeys
= sk_OPENSSL_STRING_new_null()) == NULL
)
747 keyfile
= signerfile
;
748 sk_OPENSSL_STRING_push(skkeys
, keyfile
);
750 if (sksigners
== NULL
) {
751 BIO_printf(bio_err
, "No signer certificate specified\n");
756 } else if (operation
== SMIME_DECRYPT
) {
757 if (recipfile
== NULL
&& keyfile
== NULL
758 && secret_key
== NULL
&& pwri_pass
== NULL
) {
760 "No recipient certificate or key specified\n");
763 } else if (operation
== SMIME_ENCRYPT
) {
764 if (*argv
== NULL
&& secret_key
== NULL
765 && pwri_pass
== NULL
&& encerts
== NULL
) {
766 BIO_printf(bio_err
, "No recipient(s) certificate(s) specified\n");
769 } else if (!operation
) {
770 BIO_printf(bio_err
, "No operation option (-encrypt|-decrypt|-sign|-verify|...) specified.\n");
774 if (!app_passwd(passinarg
, NULL
, &passin
, NULL
)) {
775 BIO_printf(bio_err
, "Error getting password\n");
781 if (!(operation
& SMIME_SIGNERS
))
782 flags
&= ~CMS_DETACHED
;
784 if (!(operation
& SMIME_OP
))
785 if (flags
& CMS_BINARY
)
786 outformat
= FORMAT_BINARY
;
788 if (!(operation
& SMIME_IP
))
789 if (flags
& CMS_BINARY
)
790 informat
= FORMAT_BINARY
;
792 if (operation
== SMIME_ENCRYPT
) {
794 # ifndef OPENSSL_NO_DES
795 cipher
= EVP_des_ede3_cbc();
797 BIO_printf(bio_err
, "No cipher selected\n");
802 if (secret_key
&& !secret_keyid
) {
803 BIO_printf(bio_err
, "No secret key id\n");
807 if (*argv
&& encerts
== NULL
)
808 if ((encerts
= sk_X509_new_null()) == NULL
)
811 if ((cert
= load_cert(*argv
, FORMAT_UNDEF
,
812 "recipient certificate file")) == NULL
)
814 sk_X509_push(encerts
, cert
);
820 if (certfile
!= NULL
) {
821 if (!load_certs(certfile
, &other
, NULL
, "certificate file")) {
822 ERR_print_errors(bio_err
);
827 if (recipfile
!= NULL
&& (operation
== SMIME_DECRYPT
)) {
828 if ((recip
= load_cert(recipfile
, FORMAT_UNDEF
,
829 "recipient certificate file")) == NULL
) {
830 ERR_print_errors(bio_err
);
835 if (originatorfile
!= NULL
) {
836 if ((originator
= load_cert(originatorfile
, FORMAT_UNDEF
,
837 "originator certificate file")) == NULL
) {
838 ERR_print_errors(bio_err
);
843 if (operation
== SMIME_SIGN_RECEIPT
) {
844 if ((signer
= load_cert(signerfile
, FORMAT_UNDEF
,
845 "receipt signer certificate file")) == NULL
) {
846 ERR_print_errors(bio_err
);
851 if ((operation
== SMIME_DECRYPT
) || (operation
== SMIME_ENCRYPT
)) {
854 } else if ((operation
== SMIME_SIGN
) || (operation
== SMIME_SIGN_RECEIPT
)) {
856 keyfile
= signerfile
;
861 if (keyfile
!= NULL
) {
862 key
= load_key(keyfile
, keyform
, 0, passin
, e
, "signing key file");
867 * TODO: Remove this when CMS has full support for provider-native
870 if (EVP_PKEY_get0(key
) == NULL
)
874 in
= bio_open_default(infile
, 'r', informat
);
878 if (operation
& SMIME_IP
) {
879 cms
= load_content_info(informat
, in
, &indata
, "SMIME", libctx
, propq
);
882 if (contfile
!= NULL
) {
884 if ((indata
= BIO_new_file(contfile
, "rb")) == NULL
) {
885 BIO_printf(bio_err
, "Can't read content file %s\n", contfile
);
889 if (certsoutfile
!= NULL
) {
890 STACK_OF(X509
) *allcerts
;
891 allcerts
= CMS_get1_certs(cms
);
892 if (!save_certs(certsoutfile
, allcerts
)) {
894 "Error writing certs to %s\n", certsoutfile
);
898 sk_X509_pop_free(allcerts
, X509_free
);
902 if (rctfile
!= NULL
) {
903 char *rctmode
= (rctformat
== FORMAT_ASN1
) ? "rb" : "r";
904 if ((rctin
= BIO_new_file(rctfile
, rctmode
)) == NULL
) {
905 BIO_printf(bio_err
, "Can't open receipt file %s\n", rctfile
);
909 rcms
= load_content_info(rctformat
, rctin
, NULL
, "recipient", libctx
,
915 out
= bio_open_default(outfile
, 'w', outformat
);
919 if ((operation
== SMIME_VERIFY
) || (operation
== SMIME_VERIFY_RECEIPT
)) {
920 if ((store
= setup_verify(CAfile
, noCAfile
, CApath
, noCApath
,
921 CAstore
, noCAstore
)) == NULL
)
923 X509_STORE_set_verify_cb(store
, cms_cb
);
925 X509_STORE_set1_param(store
, vpm
);
930 if (operation
== SMIME_DATA_CREATE
) {
931 cms
= CMS_data_create_with_libctx(in
, flags
, libctx
, propq
);
932 } else if (operation
== SMIME_DIGEST_CREATE
) {
933 cms
= CMS_digest_create_with_libctx(in
, sign_md
, flags
, libctx
, propq
);
934 } else if (operation
== SMIME_COMPRESS
) {
935 cms
= CMS_compress(in
, -1, flags
);
936 } else if (operation
== SMIME_ENCRYPT
) {
938 flags
|= CMS_PARTIAL
;
939 cms
= CMS_encrypt_with_libctx(NULL
, in
, cipher
, flags
, libctx
, propq
);
942 for (i
= 0; i
< sk_X509_num(encerts
); i
++) {
943 CMS_RecipientInfo
*ri
;
944 cms_key_param
*kparam
;
945 int tflags
= flags
| CMS_KEY_PARAM
; /* This flag enforces allocating the EVP_PKEY_CTX for the recipient here */
947 X509
*x
= sk_X509_value(encerts
, i
);
950 for (kparam
= key_first
; kparam
; kparam
= kparam
->next
) {
951 if (kparam
->idx
== i
) {
955 ri
= CMS_add1_recipient(cms
, x
, key
, originator
, tflags
);
959 pctx
= CMS_RecipientInfo_get0_pkey_ctx(ri
);
960 if (kparam
!= NULL
) {
961 if (!cms_set_pkey_param(pctx
, kparam
->param
))
965 res
= EVP_PKEY_CTX_ctrl(pctx
, -1, -1,
966 EVP_PKEY_CTRL_CIPHER
,
967 EVP_CIPHER_nid(cipher
), NULL
);
968 if (res
<= 0 && res
!= -2)
971 if (CMS_RecipientInfo_type(ri
) == CMS_RECIPINFO_AGREE
973 EVP_CIPHER_CTX
*wctx
;
974 wctx
= CMS_RecipientInfo_kari_get0_ctx(ri
);
975 EVP_EncryptInit_ex(wctx
, wrap_cipher
, NULL
, NULL
, NULL
);
979 if (secret_key
!= NULL
) {
980 if (!CMS_add0_recipient_key(cms
, NID_undef
,
981 secret_key
, secret_keylen
,
982 secret_keyid
, secret_keyidlen
,
985 /* NULL these because call absorbs them */
989 if (pwri_pass
!= NULL
) {
990 pwri_tmp
= (unsigned char *)OPENSSL_strdup((char *)pwri_pass
);
991 if (pwri_tmp
== NULL
)
993 if (CMS_add0_recipient_password(cms
,
994 -1, NID_undef
, NID_undef
,
995 pwri_tmp
, -1, NULL
) == NULL
)
999 if (!(flags
& CMS_STREAM
)) {
1000 if (!CMS_final(cms
, in
, NULL
, flags
))
1003 } else if (operation
== SMIME_ENCRYPTED_ENCRYPT
) {
1004 cms
= CMS_EncryptedData_encrypt_with_libctx(in
, cipher
, secret_key
,
1005 secret_keylen
, flags
,
1008 } else if (operation
== SMIME_SIGN_RECEIPT
) {
1009 CMS_ContentInfo
*srcms
= NULL
;
1010 STACK_OF(CMS_SignerInfo
) *sis
;
1012 sis
= CMS_get0_SignerInfos(cms
);
1015 si
= sk_CMS_SignerInfo_value(sis
, 0);
1016 srcms
= CMS_sign_receipt(si
, signer
, key
, other
, flags
);
1019 CMS_ContentInfo_free(cms
);
1021 } else if (operation
& SMIME_SIGNERS
) {
1024 * If detached data content we enable streaming if S/MIME output
1027 if (operation
== SMIME_SIGN
) {
1029 if (flags
& CMS_DETACHED
) {
1030 if (outformat
== FORMAT_SMIME
)
1031 flags
|= CMS_STREAM
;
1033 flags
|= CMS_PARTIAL
;
1034 cms
= CMS_sign_with_libctx(NULL
, NULL
, other
, in
, flags
, libctx
, propq
);
1037 if (econtent_type
!= NULL
)
1038 CMS_set1_eContentType(cms
, econtent_type
);
1040 if (rr_to
!= NULL
) {
1041 rr
= make_receipt_request(rr_to
, rr_allorfirst
, rr_from
, libctx
,
1045 "Signed Receipt Request Creation Error\n");
1050 flags
|= CMS_REUSE_DIGEST
;
1052 for (i
= 0; i
< sk_OPENSSL_STRING_num(sksigners
); i
++) {
1054 cms_key_param
*kparam
;
1056 signerfile
= sk_OPENSSL_STRING_value(sksigners
, i
);
1057 keyfile
= sk_OPENSSL_STRING_value(skkeys
, i
);
1059 signer
= load_cert(signerfile
, FORMAT_UNDEF
,
1060 "signer certificate");
1061 if (signer
== NULL
) {
1065 key
= load_key(keyfile
, keyform
, 0, passin
, e
, "signing key file");
1072 * TODO: Remove this when CMS has full support for provider-native
1075 if (EVP_PKEY_get0(key
) == NULL
)
1078 for (kparam
= key_first
; kparam
; kparam
= kparam
->next
) {
1079 if (kparam
->idx
== i
) {
1080 tflags
|= CMS_KEY_PARAM
;
1084 si
= CMS_add1_signer(cms
, signer
, key
, sign_md
, tflags
);
1087 if (kparam
!= NULL
) {
1089 pctx
= CMS_SignerInfo_get0_pkey_ctx(si
);
1090 if (!cms_set_pkey_param(pctx
, kparam
->param
))
1093 if (rr
!= NULL
&& !CMS_add1_ReceiptRequest(si
, rr
))
1100 /* If not streaming or resigning finalize structure */
1101 if ((operation
== SMIME_SIGN
) && !(flags
& CMS_STREAM
)) {
1102 if (!CMS_final(cms
, in
, NULL
, flags
))
1108 BIO_printf(bio_err
, "Error creating CMS structure\n");
1113 if (operation
== SMIME_DECRYPT
) {
1114 if (flags
& CMS_DEBUG_DECRYPT
)
1115 CMS_decrypt(cms
, NULL
, NULL
, NULL
, NULL
, flags
);
1117 if (secret_key
!= NULL
) {
1118 if (!CMS_decrypt_set1_key(cms
,
1119 secret_key
, secret_keylen
,
1120 secret_keyid
, secret_keyidlen
)) {
1121 BIO_puts(bio_err
, "Error decrypting CMS using secret key\n");
1127 if (!CMS_decrypt_set1_pkey_and_peer(cms
, key
, recip
, originator
)) {
1128 BIO_puts(bio_err
, "Error decrypting CMS using private key\n");
1133 if (pwri_pass
!= NULL
) {
1134 if (!CMS_decrypt_set1_password(cms
, pwri_pass
, -1)) {
1135 BIO_puts(bio_err
, "Error decrypting CMS using password\n");
1140 if (!CMS_decrypt(cms
, NULL
, NULL
, indata
, out
, flags
)) {
1141 BIO_printf(bio_err
, "Error decrypting CMS structure\n");
1144 } else if (operation
== SMIME_DATAOUT
) {
1145 if (!CMS_data(cms
, out
, flags
))
1147 } else if (operation
== SMIME_UNCOMPRESS
) {
1148 if (!CMS_uncompress(cms
, indata
, out
, flags
))
1150 } else if (operation
== SMIME_DIGEST_VERIFY
) {
1151 if (CMS_digest_verify(cms
, indata
, out
, flags
) > 0) {
1152 BIO_printf(bio_err
, "Verification successful\n");
1154 BIO_printf(bio_err
, "Verification failure\n");
1157 } else if (operation
== SMIME_ENCRYPTED_DECRYPT
) {
1158 if (!CMS_EncryptedData_decrypt(cms
, secret_key
, secret_keylen
,
1159 indata
, out
, flags
))
1161 } else if (operation
== SMIME_VERIFY
) {
1162 if (CMS_verify(cms
, other
, store
, indata
, out
, flags
) > 0) {
1163 BIO_printf(bio_err
, "%s Verification successful\n",
1164 (flags
& CMS_CADES
) ? "CAdES" : "CMS");
1166 BIO_printf(bio_err
, "Verification failure\n");
1168 ret
= verify_err
+ 32;
1171 if (signerfile
!= NULL
) {
1172 STACK_OF(X509
) *signers
;
1173 signers
= CMS_get0_signers(cms
);
1174 if (!save_certs(signerfile
, signers
)) {
1176 "Error writing signers to %s\n", signerfile
);
1180 sk_X509_free(signers
);
1183 receipt_request_print(cms
);
1185 } else if (operation
== SMIME_VERIFY_RECEIPT
) {
1186 if (CMS_verify_receipt(rcms
, cms
, other
, store
, flags
) > 0) {
1187 BIO_printf(bio_err
, "Verification successful\n");
1189 BIO_printf(bio_err
, "Verification failure\n");
1195 ASN1_PCTX
*pctx
= NULL
;
1196 if (get_nameopt() != XN_FLAG_ONELINE
) {
1197 pctx
= ASN1_PCTX_new();
1198 if (pctx
!= NULL
) { /* Print anyway if malloc failed */
1199 ASN1_PCTX_set_flags(pctx
, ASN1_PCTX_FLAGS_SHOW_ABSENT
);
1200 ASN1_PCTX_set_str_flags(pctx
, get_nameopt());
1201 ASN1_PCTX_set_nm_flags(pctx
, get_nameopt());
1204 CMS_ContentInfo_print_ctx(out
, cms
, 0, pctx
);
1205 ASN1_PCTX_free(pctx
);
1207 } else if (outformat
== FORMAT_SMIME
) {
1209 BIO_printf(out
, "To: %s%s", to
, mime_eol
);
1211 BIO_printf(out
, "From: %s%s", from
, mime_eol
);
1213 BIO_printf(out
, "Subject: %s%s", subject
, mime_eol
);
1214 if (operation
== SMIME_RESIGN
)
1215 ret
= SMIME_write_CMS(out
, cms
, indata
, flags
);
1217 ret
= SMIME_write_CMS(out
, cms
, in
, flags
);
1218 } else if (outformat
== FORMAT_PEM
) {
1219 ret
= PEM_write_bio_CMS_stream(out
, cms
, in
, flags
);
1220 } else if (outformat
== FORMAT_ASN1
) {
1221 ret
= i2d_CMS_bio_stream(out
, cms
, in
, flags
);
1223 BIO_printf(bio_err
, "Bad output format for CMS file\n");
1234 ERR_print_errors(bio_err
);
1235 sk_X509_pop_free(encerts
, X509_free
);
1236 sk_X509_pop_free(other
, X509_free
);
1237 X509_VERIFY_PARAM_free(vpm
);
1238 sk_OPENSSL_STRING_free(sksigners
);
1239 sk_OPENSSL_STRING_free(skkeys
);
1240 OPENSSL_free(secret_key
);
1241 OPENSSL_free(secret_keyid
);
1242 OPENSSL_free(pwri_tmp
);
1243 ASN1_OBJECT_free(econtent_type
);
1244 CMS_ReceiptRequest_free(rr
);
1245 sk_OPENSSL_STRING_free(rr_to
);
1246 sk_OPENSSL_STRING_free(rr_from
);
1247 for (key_param
= key_first
; key_param
;) {
1248 cms_key_param
*tparam
;
1249 sk_OPENSSL_STRING_free(key_param
->param
);
1250 tparam
= key_param
->next
;
1251 OPENSSL_free(key_param
);
1254 X509_STORE_free(store
);
1259 CMS_ContentInfo_free(cms
);
1260 CMS_ContentInfo_free(rcms
);
1266 OPENSSL_free(passin
);
1271 static int save_certs(char *signerfile
, STACK_OF(X509
) *signers
)
1275 if (signerfile
== NULL
)
1277 tmp
= BIO_new_file(signerfile
, "w");
1280 for (i
= 0; i
< sk_X509_num(signers
); i
++)
1281 PEM_write_bio_X509(tmp
, sk_X509_value(signers
, i
));
1286 /* Minimal callback just to output policy info (if any) */
1288 static int cms_cb(int ok
, X509_STORE_CTX
*ctx
)
1292 error
= X509_STORE_CTX_get_error(ctx
);
1296 if ((error
!= X509_V_ERR_NO_EXPLICIT_POLICY
)
1297 && ((error
!= X509_V_OK
) || (ok
!= 2)))
1300 policies_print(ctx
);
1306 static void gnames_stack_print(STACK_OF(GENERAL_NAMES
) *gns
)
1308 STACK_OF(GENERAL_NAME
) *gens
;
1312 for (i
= 0; i
< sk_GENERAL_NAMES_num(gns
); i
++) {
1313 gens
= sk_GENERAL_NAMES_value(gns
, i
);
1314 for (j
= 0; j
< sk_GENERAL_NAME_num(gens
); j
++) {
1315 gen
= sk_GENERAL_NAME_value(gens
, j
);
1316 BIO_puts(bio_err
, " ");
1317 GENERAL_NAME_print(bio_err
, gen
);
1318 BIO_puts(bio_err
, "\n");
1324 static void receipt_request_print(CMS_ContentInfo
*cms
)
1326 STACK_OF(CMS_SignerInfo
) *sis
;
1328 CMS_ReceiptRequest
*rr
;
1330 STACK_OF(GENERAL_NAMES
) *rto
, *rlist
;
1333 sis
= CMS_get0_SignerInfos(cms
);
1334 for (i
= 0; i
< sk_CMS_SignerInfo_num(sis
); i
++) {
1335 si
= sk_CMS_SignerInfo_value(sis
, i
);
1336 rv
= CMS_get1_ReceiptRequest(si
, &rr
);
1337 BIO_printf(bio_err
, "Signer %d:\n", i
+ 1);
1339 BIO_puts(bio_err
, " No Receipt Request\n");
1340 } else if (rv
< 0) {
1341 BIO_puts(bio_err
, " Receipt Request Parse Error\n");
1342 ERR_print_errors(bio_err
);
1346 CMS_ReceiptRequest_get0_values(rr
, &scid
, &allorfirst
,
1348 BIO_puts(bio_err
, " Signed Content ID:\n");
1349 idlen
= ASN1_STRING_length(scid
);
1350 id
= (const char *)ASN1_STRING_get0_data(scid
);
1351 BIO_dump_indent(bio_err
, id
, idlen
, 4);
1352 BIO_puts(bio_err
, " Receipts From");
1353 if (rlist
!= NULL
) {
1354 BIO_puts(bio_err
, " List:\n");
1355 gnames_stack_print(rlist
);
1356 } else if (allorfirst
== 1) {
1357 BIO_puts(bio_err
, ": First Tier\n");
1358 } else if (allorfirst
== 0) {
1359 BIO_puts(bio_err
, ": All\n");
1361 BIO_printf(bio_err
, " Unknown (%d)\n", allorfirst
);
1363 BIO_puts(bio_err
, " Receipts To:\n");
1364 gnames_stack_print(rto
);
1366 CMS_ReceiptRequest_free(rr
);
1370 static STACK_OF(GENERAL_NAMES
) *make_names_stack(STACK_OF(OPENSSL_STRING
) *ns
)
1373 STACK_OF(GENERAL_NAMES
) *ret
;
1374 GENERAL_NAMES
*gens
= NULL
;
1375 GENERAL_NAME
*gen
= NULL
;
1376 ret
= sk_GENERAL_NAMES_new_null();
1379 for (i
= 0; i
< sk_OPENSSL_STRING_num(ns
); i
++) {
1380 char *str
= sk_OPENSSL_STRING_value(ns
, i
);
1381 gen
= a2i_GENERAL_NAME(NULL
, NULL
, NULL
, GEN_EMAIL
, str
, 0);
1384 gens
= GENERAL_NAMES_new();
1387 if (!sk_GENERAL_NAME_push(gens
, gen
))
1390 if (!sk_GENERAL_NAMES_push(ret
, gens
))
1398 sk_GENERAL_NAMES_pop_free(ret
, GENERAL_NAMES_free
);
1399 GENERAL_NAMES_free(gens
);
1400 GENERAL_NAME_free(gen
);
1404 static CMS_ReceiptRequest
*make_receipt_request(
1405 STACK_OF(OPENSSL_STRING
) *rr_to
, int rr_allorfirst
,
1406 STACK_OF(OPENSSL_STRING
) *rr_from
,
1407 OPENSSL_CTX
*libctx
, const char *propq
)
1409 STACK_OF(GENERAL_NAMES
) *rct_to
= NULL
, *rct_from
= NULL
;
1410 CMS_ReceiptRequest
*rr
;
1411 rct_to
= make_names_stack(rr_to
);
1414 if (rr_from
!= NULL
) {
1415 rct_from
= make_names_stack(rr_from
);
1416 if (rct_from
== NULL
)
1421 rr
= CMS_ReceiptRequest_create0_with_libctx(NULL
, -1, rr_allorfirst
,
1422 rct_from
, rct_to
, libctx
, propq
);
1425 sk_GENERAL_NAMES_pop_free(rct_to
, GENERAL_NAMES_free
);
1429 static int cms_set_pkey_param(EVP_PKEY_CTX
*pctx
,
1430 STACK_OF(OPENSSL_STRING
) *param
)
1434 if (sk_OPENSSL_STRING_num(param
) <= 0)
1436 for (i
= 0; i
< sk_OPENSSL_STRING_num(param
); i
++) {
1437 keyopt
= sk_OPENSSL_STRING_value(param
, i
);
1438 if (pkey_ctrl_string(pctx
, keyopt
) <= 0) {
1439 BIO_printf(bio_err
, "parameter error \"%s\"\n", keyopt
);
1440 ERR_print_errors(bio_err
);