25 [B<-EncryptedData_encrypt>]
27 [B<-verify_receipt receipt>]
29 [B<-inform SMIME|PEM|DER>]
30 [B<-rctform SMIME|PEM|DER>]
32 [B<-outform SMIME|PEM|DER>]
33 [B<-stream -indef -noindef>]
35 [B<-content filename>]
43 [B<-attime timestamp>]
65 [B<-verify_depth num>]
66 [B<-verify_email email>]
67 [B<-verify_hostname hostname>]
69 [B<-verify_name name>]
87 [B<-receipt_request_all>]
88 [B<-receipt_request_first>]
89 [B<-receipt_request_from emailaddress>]
90 [B<-receipt_request_to emailaddress>]
91 [B<-receipt_request_print>]
94 [B<-econtent_type type>]
96 [B<-keyopt name:parameter>]
108 The B<cms> command handles S/MIME v3.1 mail. It can encrypt, decrypt, sign and
109 verify, compress and uncompress S/MIME messages.
113 There are fourteen operation options that set the type of operation to be
114 performed. The meaning of the other options varies according to the operation
121 Print out a usage message.
125 Encrypt mail for the given recipient certificates. Input file is the message
126 to be encrypted. The output file is the encrypted mail in MIME format. The
127 actual CMS type is <B>EnvelopedData<B>.
129 Note that no revocation check is done for the recipient cert, so if that
130 key has been compromised, others may be able to decrypt the text.
134 Decrypt mail using the supplied certificate and private key. Expects an
135 encrypted mail message in MIME format for the input file. The decrypted mail
136 is written to the output file.
138 =item B<-debug_decrypt>
140 This option sets the B<CMS_DEBUG_DECRYPT> flag. This option should be used
141 with caution: see the notes section below.
145 Sign mail using the supplied certificate and private key. Input file is
146 the message to be signed. The signed message in MIME format is written
151 Verify signed mail. Expects a signed mail message on input and outputs
152 the signed data. Both clear text and opaque signing is supported.
156 Takes an input message and writes out a PEM encoded CMS structure.
160 Resign a message: take an existing message and one or more new signers.
164 Add an ESS signing-certificate or ESS signing-certificate-v2 signed-attribute to the SignerInfo, in order to make
165 the signature comply with the requirements for a CAdES Basic Electronic Signature (CAdES-BES). See the NOTES
166 section for more details.
168 =item B<-data_create>
170 Create a CMS B<Data> type.
174 B<Data> type and output the content.
176 =item B<-digest_create>
178 Create a CMS B<DigestedData> type.
180 =item B<-digest_verify>
182 Verify a CMS B<DigestedData> type and output the content.
186 Create a CMS B<CompressedData> type. OpenSSL must be compiled with B<zlib>
187 support for this option to work, otherwise it will output an error.
191 Uncompress a CMS B<CompressedData> type and output the content. OpenSSL must be
192 compiled with B<zlib> support for this option to work, otherwise it will
195 =item B<-EncryptedData_encrypt>
197 Encrypt content using supplied symmetric key and algorithm using a CMS
198 B<EncryptedData> type and output the content.
200 =item B<-sign_receipt>
202 Generate and output a signed receipt for the supplied message. The input
203 message B<must> contain a signed receipt request. Functionality is otherwise
204 similar to the B<-sign> operation.
206 =item B<-verify_receipt receipt>
208 Verify a signed receipt in filename B<receipt>. The input message B<must>
209 contain the original receipt request. Functionality is otherwise similar
210 to the B<-verify> operation.
212 =item B<-in filename>
214 The input message to be encrypted or signed or the message to be decrypted
217 =item B<-inform SMIME|PEM|DER>
219 This specifies the input format for the CMS structure. The default
220 is B<SMIME> which reads an S/MIME format message. B<PEM> and B<DER>
221 format change this to expect PEM and DER format CMS structures
222 instead. This currently only affects the input format of the CMS
223 structure, if no CMS structure is being input (for example with
224 B<-encrypt> or B<-sign>) this option has no effect.
226 =item B<-rctform SMIME|PEM|DER>
228 Specify the format for a signed receipt for use with the B<-receipt_verify>
231 =item B<-out filename>
233 The message text that has been decrypted or verified or the output MIME
234 format message that has been signed or verified.
236 =item B<-outform SMIME|PEM|DER>
238 This specifies the output format for the CMS structure. The default
239 is B<SMIME> which writes an S/MIME format message. B<PEM> and B<DER>
240 format change this to write PEM and DER format CMS structures
241 instead. This currently only affects the output format of the CMS
242 structure, if no CMS structure is being output (for example with
243 B<-verify> or B<-decrypt>) this option has no effect.
245 =item B<-stream -indef -noindef>
247 The B<-stream> and B<-indef> options are equivalent and enable streaming I/O
248 for encoding operations. This permits single pass processing of data without
249 the need to hold the entire contents in memory, potentially supporting very
250 large files. Streaming is automatically set for S/MIME signing with detached
251 data if the output format is B<SMIME> it is currently off by default for all
256 Disable streaming I/O where it would produce and indefinite length constructed
257 encoding. This option currently has no effect. In future streaming will be
258 enabled by default on all relevant operations and this option will disable it.
260 =item B<-content filename>
262 This specifies a file containing the detached content, this is only
263 useful with the B<-verify> command. This is only usable if the CMS
264 structure is using the detached signature form where the content is
265 not included. This option will override any content if the input format
266 is S/MIME and it uses the multipart/signed MIME content type.
270 This option adds plain text (text/plain) MIME headers to the supplied
271 message if encrypting or signing. If decrypting or verifying it strips
272 off text headers: if the decrypted or verified message is not of MIME
273 type text/plain then an error occurs.
277 For the B<-cmsout> operation do not output the parsed CMS structure. This
278 is useful when combined with the B<-print> option or if the syntax of the CMS
279 structure is being checked.
283 For the B<-cmsout> operation print out all fields of the CMS structure. This
284 is mainly useful for testing purposes.
286 =item B<-CAfile file>
288 A file containing trusted CA certificates, only used with B<-verify>.
292 A directory containing trusted CA certificates, only used with
293 B<-verify>. This directory must be a standard certificate directory: that
294 is a hash of each subject name (using B<x509 -hash>) should be linked
299 Do not load the trusted CA certificates from the default file location
303 Do not load the trusted CA certificates from the default directory location
307 Digest algorithm to use when signing or resigning. If not present then the
308 default digest algorithm for the signing key will be used (usually SHA1).
312 The encryption algorithm to use. For example triple DES (168 bits) - B<-des3>
313 or 256 bit AES - B<-aes256>. Any standard algorithm name (as used by the
314 EVP_get_cipherbyname() function) can also be used preceded by a dash, for
315 example B<-aes-128-cbc>. See L<enc(1)> for a list of ciphers
316 supported by your version of OpenSSL.
318 If not specified triple DES is used. Only used with B<-encrypt> and
319 B<-EncryptedData_create> commands.
323 When verifying a message normally certificates (if any) included in
324 the message are searched for the signing certificate. With this option
325 only the certificates specified in the B<-certfile> option are used.
326 The supplied certificates can still be used as untrusted CAs however.
330 Do not verify the signers certificate of a signed message.
334 When signing a message the signer's certificate is normally included
335 with this option it is excluded. This will reduce the size of the
336 signed message but the verifier must have a copy of the signers certificate
337 available locally (passed using the B<-certfile> option for example).
341 Normally when a message is signed a set of attributes are included which
342 include the signing time and supported symmetric algorithms. With this
343 option they are not included.
347 Exclude the list of supported algorithms from signed attributes, other options
348 such as signing time and content type are still included.
352 Normally the input message is converted to "canonical" format which is
353 effectively using CR and LF as end of line: as required by the S/MIME
354 specification. When this option is present no translation occurs. This
355 is useful when handling binary data which may not be in MIME format.
359 Normally the output file uses a single B<LF> as end of line. When this
360 option is present B<CRLF> is used instead.
364 When signing use ASCII CRLF format canonicalisation. This strips trailing
365 whitespace from all lines, deletes trailing blank lines at EOF and sets
366 the encapsulated content type. This option is normally used with detached
367 content and an output signature format of DER. This option is not normally
368 needed when verifying as it is enabled automatically if the encapsulated
369 content format is detected.
373 When signing a message use opaque signing: this form is more resistant
374 to translation by mail relays but it cannot be read by mail agents that
375 do not support S/MIME. Without this option cleartext signing with
376 the MIME type multipart/signed is used.
378 =item B<-certfile file>
380 Allows additional certificates to be specified. When signing these will
381 be included with the message. When verifying these will be searched for
382 the signers certificates. The certificates should be in PEM format.
384 =item B<-certsout file>
386 Any certificates contained in the message are written to B<file>.
388 =item B<-signer file>
390 A signing certificate when signing or resigning a message, this option can be
391 used multiple times if more than one signer is required. If a message is being
392 verified then the signers certificates will be written to this file if the
393 verification was successful.
397 When decrypting a message this specifies the recipients certificate. The
398 certificate must match one of the recipients of the message or an error
401 When encrypting a message this option may be used multiple times to specify
402 each recipient. This form B<must> be used if customised parameters are
403 required (for example to specify RSA-OAEP).
405 Only certificates carrying RSA, Diffie-Hellman or EC keys are supported by this
410 Use subject key identifier to identify certificates instead of issuer name and
411 serial number. The supplied certificate B<must> include a subject key
412 identifier extension. Supported by B<-sign> and B<-encrypt> options.
414 =item B<-receipt_request_all>, B<-receipt_request_first>
416 For B<-sign> option include a signed receipt request. Indicate requests should
417 be provided by all recipient or first tier recipients (those mailed directly
418 and not from a mailing list). Ignored it B<-receipt_request_from> is included.
420 =item B<-receipt_request_from emailaddress>
422 For B<-sign> option include a signed receipt request. Add an explicit email
423 address where receipts should be supplied.
425 =item B<-receipt_request_to emailaddress>
427 Add an explicit email address where signed receipts should be sent to. This
428 option B<must> but supplied if a signed receipt it requested.
430 =item B<-receipt_request_print>
432 For the B<-verify> operation print out the contents of any signed receipt
435 =item B<-secretkey key>
437 Specify symmetric key to use. The key must be supplied in hex format and be
438 consistent with the algorithm used. Supported by the B<-EncryptedData_encrypt>
439 B<-EncryptedData_decrypt>, B<-encrypt> and B<-decrypt> options. When used
440 with B<-encrypt> or B<-decrypt> the supplied key is used to wrap or unwrap the
441 content encryption key using an AES key in the B<KEKRecipientInfo> type.
443 =item B<-secretkeyid id>
445 The key identifier for the supplied symmetric key for B<KEKRecipientInfo> type.
446 This option B<must> be present if the B<-secretkey> option is used with
447 B<-encrypt>. With B<-decrypt> operations the B<id> is used to locate the
448 relevant key if it is not supplied then an attempt is used to decrypt any
449 B<KEKRecipientInfo> structures.
451 =item B<-econtent_type type>
453 Set the encapsulated content type to B<type> if not supplied the B<Data> type
454 is used. The B<type> argument can be any valid OID name in either text or
459 The private key to use when signing or decrypting. This must match the
460 corresponding certificate. If this option is not specified then the
461 private key must be included in the certificate file specified with
462 the B<-recip> or B<-signer> file. When signing this option can be used
463 multiple times to specify successive keys.
465 =item B<-keyopt name:opt>
467 For signing and encryption this option can be used multiple times to
468 set customised parameters for the preceding key or certificate. It can
469 currently be used to set RSA-PSS for signing, RSA-OAEP for encryption
470 or to modify default parameters for ECDH.
474 The private key password source. For more information about the format of B<arg>
475 see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)>.
477 =item B<-rand file...>
479 A file or files containing random data used to seed the random number
481 Multiple files can be specified separated by an OS-dependent character.
482 The separator is B<;> for MS-Windows, B<,> for OpenVMS, and B<:> for
485 =item [B<-writerand file>]
487 Writes random data to the specified I<file> upon exit.
488 This can be used with a subsequent B<-rand> flag.
492 One or more certificates of message recipients: used when encrypting
495 =item B<-to, -from, -subject>
497 The relevant mail headers. These are included outside the signed
498 portion of a message so they may be included manually. If signing
499 then many S/MIME mail clients check the signers certificate's email
500 address matches that specified in the From: address.
502 =item B<-attime>, B<-check_ss_sig>, B<-crl_check>, B<-crl_check_all>,
503 B<-explicit_policy>, B<-extended_crl>, B<-ignore_critical>, B<-inhibit_any>,
504 B<-inhibit_map>, B<-no_alt_chains>, B<-no_check_time>, B<-partial_chain>, B<-policy>,
505 B<-policy_check>, B<-policy_print>, B<-purpose>, B<-suiteB_128>,
506 B<-suiteB_128_only>, B<-suiteB_192>, B<-trusted_first>, B<-use_deltas>,
507 B<-auth_level>, B<-verify_depth>, B<-verify_email>, B<-verify_hostname>,
508 B<-verify_ip>, B<-verify_name>, B<-x509_strict>
510 Set various certificate chain validation options. See the
511 L<verify(1)> manual page for details.
517 The MIME message must be sent without any blank lines between the
518 headers and the output. Some mail programs will automatically add
519 a blank line. Piping the mail directly to sendmail is one way to
520 achieve the correct format.
522 The supplied message to be signed or encrypted must include the
523 necessary MIME headers or many S/MIME clients won't display it
524 properly (if at all). You can use the B<-text> option to automatically
525 add plain text headers.
527 A "signed and encrypted" message is one where a signed message is
528 then encrypted. This can be produced by encrypting an already signed
529 message: see the examples section.
531 This version of the program only allows one signer per message but it
532 will verify multiple signers on received messages. Some S/MIME clients
533 choke if a message contains multiple signers. It is possible to sign
534 messages "in parallel" by signing an already signed message.
536 The options B<-encrypt> and B<-decrypt> reflect common usage in S/MIME
537 clients. Strictly speaking these process CMS enveloped data: CMS
538 encrypted data is used for other purposes.
540 The B<-resign> option uses an existing message digest when adding a new
541 signer. This means that attributes must be present in at least one existing
542 signer using the same message digest or this operation will fail.
544 The B<-stream> and B<-indef> options enable streaming I/O support.
545 As a result the encoding is BER using indefinite length constructed encoding
546 and no longer DER. Streaming is supported for the B<-encrypt> operation and the
547 B<-sign> operation if the content is not detached.
549 Streaming is always used for the B<-sign> operation with detached data but
550 since the content is no longer part of the CMS structure the encoding
553 If the B<-decrypt> option is used without a recipient certificate then an
554 attempt is made to locate the recipient by trying each potential recipient
555 in turn using the supplied private key. To thwart the MMA attack
556 (Bleichenbacher's attack on PKCS #1 v1.5 RSA padding) all recipients are
557 tried whether they succeed or not and if no recipients match the message
558 is "decrypted" using a random key which will typically output garbage.
559 The B<-debug_decrypt> option can be used to disable the MMA attack protection
560 and return an error if no recipient can be found: this option should be used
561 with caution. For a fuller description see L<CMS_decrypt(3)>).
563 =head1 CAdES Basic Electronic Signature (CAdES-BES)
565 A CAdES Basic Electronic Signature (CAdES-BES), as defined in the European Standard ETSI EN 319 122-1 V1.1.1, contains:
571 The signed user data as defined in CMS (RFC 3852);
575 Content-type of the EncapsulatedContentInfo value being signed;
579 Message-digest of the eContent OCTET STRING within encapContentInfo being signed;
583 An ESS signing-certificate or ESS signing-certificate-v2 attribute, as defined in Enhanced Security Services (ESS), RFC 2634 and RFC 5035.
584 An ESS signing-certificate attribute only allows for the use of SHA-1 as a digest algorithm.
585 An ESS signing-certificate-v2 attribute allows for the use of any digest algorithm.
589 The digital signature value computed on the user data and, when present, on the signed attributes.
591 Note that currently the B<-cades> option applies only to the B<-sign> operation and is ignored during
592 the B<-verify> operation, i.e. the signing certification is not checked during the verification process.
593 This feature might be added in a future version.
603 The operation was completely successfully.
607 An error occurred parsing the command options.
611 One of the input files could not be read.
615 An error occurred creating the CMS file or when reading the MIME
620 An error occurred decrypting or verifying the message.
624 The message was verified correctly but an error occurred writing out
625 the signers certificates.
629 =head1 COMPATIBILITY WITH PKCS#7 format.
631 The B<smime> utility can only process the older B<PKCS#7> format. The B<cms>
632 utility supports Cryptographic Message Syntax format. Use of some features
633 will result in messages which cannot be processed by applications which only
634 support the older format. These are detailed below.
636 The use of the B<-keyid> option with B<-sign> or B<-encrypt>.
638 The B<-outform PEM> option uses different headers.
640 The B<-compress> option.
642 The B<-secretkey> option when used with B<-encrypt>.
644 The use of PSS with B<-sign>.
646 The use of OAEP or non-RSA keys with B<-encrypt>.
648 Additionally the B<-EncryptedData_create> and B<-data_create> type cannot
649 be processed by the older B<smime> command.
653 Create a cleartext signed message:
655 openssl cms -sign -in message.txt -text -out mail.msg \
658 Create an opaque signed message
660 openssl cms -sign -in message.txt -text -out mail.msg -nodetach \
663 Create a signed message, include some additional certificates and
664 read the private key from another file:
666 openssl cms -sign -in in.txt -text -out mail.msg \
667 -signer mycert.pem -inkey mykey.pem -certfile mycerts.pem
669 Create a signed message with two signers, use key identifier:
671 openssl cms -sign -in message.txt -text -out mail.msg \
672 -signer mycert.pem -signer othercert.pem -keyid
674 Send a signed message under Unix directly to sendmail, including headers:
676 openssl cms -sign -in in.txt -text -signer mycert.pem \
677 -from steve@openssl.org -to someone@somewhere \
678 -subject "Signed message" | sendmail someone@somewhere
680 Verify a message and extract the signer's certificate if successful:
682 openssl cms -verify -in mail.msg -signer user.pem -out signedtext.txt
684 Send encrypted mail using triple DES:
686 openssl cms -encrypt -in in.txt -from steve@openssl.org \
687 -to someone@somewhere -subject "Encrypted message" \
688 -des3 user.pem -out mail.msg
690 Sign and encrypt mail:
692 openssl cms -sign -in ml.txt -signer my.pem -text \
693 | openssl cms -encrypt -out mail.msg \
694 -from steve@openssl.org -to someone@somewhere \
695 -subject "Signed and Encrypted message" -des3 user.pem
697 Note: the encryption command does not include the B<-text> option because the
698 message being encrypted already has MIME headers.
702 openssl cms -decrypt -in mail.msg -recip mycert.pem -inkey key.pem
704 The output from Netscape form signing is a PKCS#7 structure with the
705 detached signature format. You can use this program to verify the
706 signature by line wrapping the base64 encoded structure and surrounding
709 -----BEGIN PKCS7-----
712 and using the command,
714 openssl cms -verify -inform PEM -in signature.pem -content content.txt
716 alternatively you can base64 decode the signature and use
718 openssl cms -verify -inform DER -in signature.der -content content.txt
720 Create an encrypted message using 128 bit Camellia:
722 openssl cms -encrypt -in plain.txt -camellia128 -out mail.msg cert.pem
724 Add a signer to an existing message:
726 openssl cms -resign -in mail.msg -signer newsign.pem -out mail2.msg
728 Sign mail using RSA-PSS:
730 openssl cms -sign -in message.txt -text -out mail.msg \
731 -signer mycert.pem -keyopt rsa_padding_mode:pss
733 Create encrypted mail using RSA-OAEP:
735 openssl cms -encrypt -in plain.txt -out mail.msg \
736 -recip cert.pem -keyopt rsa_padding_mode:oaep
738 Use SHA256 KDF with an ECDH certificate:
740 openssl cms -encrypt -in plain.txt -out mail.msg \
741 -recip ecdhcert.pem -keyopt ecdh_kdf_md:sha256
745 The MIME parser isn't very clever: it seems to handle most messages that I've
746 thrown at it but it may choke on others.
748 The code currently will only write out the signer's certificate to a file: if
749 the signer has a separate encryption certificate this must be manually
750 extracted. There should be some heuristic that determines the correct
751 encryption certificate.
753 Ideally a database should be maintained of a certificates for each email
756 The code doesn't currently take note of the permitted symmetric encryption
757 algorithms as supplied in the SMIMECapabilities signed attribute. this means the
758 user has to manually include the correct encryption algorithm. It should store
759 the list of permitted ciphers in a database and only use those.
761 No revocation checking is done on the signer's certificate.
765 The use of multiple B<-signer> options and the B<-resign> command were first
766 added in OpenSSL 1.0.0.
768 The B<keyopt> option was added in OpenSSL 1.0.2.
770 Support for RSA-OAEP and RSA-PSS was added in OpenSSL 1.0.2.
772 The use of non-RSA keys with B<-encrypt> and B<-decrypt>
773 was added in OpenSSL 1.0.2.
775 The -no_alt_chains option was added in OpenSSL 1.0.2b.
779 Copyright 2008-2018 The OpenSSL Project Authors. All Rights Reserved.
781 Licensed under the Apache License 2.0 (the "License"). You may not use
782 this file except in compliance with the License. You can obtain a copy
783 in the file LICENSE in the source distribution or at
784 L<https://www.openssl.org/source/license.html>.