2 {- OpenSSL::safe::output_do_not_edit_headers(); -}
6 openssl-cms - CMS command
20 [B<-no_content_verify>]
30 [B<-EncryptedData_decrypt>]
31 [B<-EncryptedData_encrypt>]
33 [B<-verify_receipt> I<receipt>]
36 [B<-inform> B<DER>|B<PEM>|B<SMIME>]
37 [B<-outform> B<DER>|B<PEM>|B<SMIME>]
38 [B<-rctform> B<DER>|B<PEM>|B<SMIME>]
39 [B<-keyform> B<DER>|B<PEM>|B<P12>|B<ENGINE>]
43 [B<-content> I<filename>]
47 [B<-nameopt> I<option>]
64 [B<-certfile> I<file>]
65 [B<-certsout> I<file>]
67 [B<-originator> I<file>]
70 [B<-receipt_request_all>]
71 [B<-receipt_request_first>]
72 [B<-receipt_request_from> I<emailaddress>]
73 [B<-receipt_request_to> I<emailaddress>]
74 [B<-receipt_request_print>]
75 [B<-pwri_password> I<password>]
76 [B<-secretkey> I<key>]
77 [B<-secretkeyid> I<id>]
78 [B<-econtent_type> I<type>]
79 [B<-inkey> I<filename>|I<uri>]
80 [B<-keyopt> I<name>:I<parameter>]
85 {- $OpenSSL::safe::opt_v_synopsis -}
86 {- $OpenSSL::safe::opt_trust_synopsis -}
87 {- $OpenSSL::safe::opt_r_synopsis -}
88 {- $OpenSSL::safe::opt_engine_synopsis -}{- $OpenSSL::safe::opt_provider_synopsis -}
89 {- $OpenSSL::safe::opt_config_synopsis -}
90 [I<recipient-cert> ...]
94 This command handles S/MIME v3.1 mail. It can encrypt, decrypt,
95 sign and verify, compress and uncompress S/MIME messages.
99 There are fourteen operation options that set the type of operation to be
100 performed. The meaning of the other options varies according to the operation
107 Print out a usage message.
111 Encrypt mail for the given recipient certificates. Input file is the message
112 to be encrypted. The output file is the encrypted mail in MIME format. The
113 actual CMS type is B<EnvelopedData>.
115 Note that no revocation check is done for the recipient cert, so if that
116 key has been compromised, others may be able to decrypt the text.
120 Decrypt mail using the supplied certificate and private key. Expects an
121 encrypted mail message in MIME format for the input file. The decrypted mail
122 is written to the output file.
124 =item B<-debug_decrypt>
126 This option sets the B<CMS_DEBUG_DECRYPT> flag. This option should be used
127 with caution: see the notes section below.
131 Sign mail using the supplied certificate and private key. Input file is
132 the message to be signed. The signed message in MIME format is written
137 Verify signed mail. Expects a signed mail message on input and outputs
138 the signed data. Both clear text and opaque signing is supported.
140 =item B<-verify_retcode>
142 Exit nonzero on verification failure.
144 =item B<-no_attr_verify>
146 Do not verify signed attribute signatures.
148 =item B<-no_content_verify>
150 Do not verify signed content signatures.
154 Don't verify message signature.
158 Takes an input message and writes out a PEM encoded CMS structure.
162 Resign a message: take an existing message and one or more new signers.
166 When used with B<-sign>,
167 add an ESS signingCertificate or ESS signingCertificateV2 signed-attribute
168 to the SignerInfo, in order to make the signature comply with the requirements
169 for a CAdES Basic Electronic Signature (CAdES-BES).
170 When used with B<-verify>, require and check signer certificate digest.
171 See the NOTES section for more details.
173 =item B<-data_create>
175 Create a CMS B<Data> type.
179 B<Data> type and output the content.
181 =item B<-digest_create>
183 Create a CMS B<DigestedData> type.
185 =item B<-digest_verify>
187 Verify a CMS B<DigestedData> type and output the content.
191 Create a CMS B<CompressedData> type. OpenSSL must be compiled with B<zlib>
192 support for this option to work, otherwise it will output an error.
196 Uncompress a CMS B<CompressedData> type and output the content. OpenSSL must be
197 compiled with B<zlib> support for this option to work, otherwise it will
200 =item B<-EncryptedData_decrypt>
202 Decrypt content using supplied symmetric key and algorithm using a CMS
203 B<EncryptedData> type and output the content.
205 =item B<-EncryptedData_encrypt>
207 Encrypt content using supplied symmetric key and algorithm using a CMS
208 B<EncryptedData> type and output the content.
210 =item B<-sign_receipt>
212 Generate and output a signed receipt for the supplied message. The input
213 message B<must> contain a signed receipt request. Functionality is otherwise
214 similar to the B<-sign> operation.
216 =item B<-verify_receipt> I<receipt>
218 Verify a signed receipt in filename B<receipt>. The input message B<must>
219 contain the original receipt request. Functionality is otherwise similar
220 to the B<-verify> operation.
222 =item B<-in> I<filename>
224 The input message to be encrypted or signed or the message to be decrypted
227 =item B<-out> I<filename>
229 The message text that has been decrypted or verified or the output MIME
230 format message that has been signed or verified.
232 =item B<-inform> B<DER>|B<PEM>|B<SMIME>
234 The input format of the CMS structure (if one is being read);
235 the default is B<SMIME>.
236 See L<openssl-format-options(1)> for details.
238 =item B<-outform> B<DER>|B<PEM>|B<SMIME>
240 The output format of the CMS structure (if one is being written);
241 the default is B<SMIME>.
242 See L<openssl-format-options(1)> for details.
244 =item B<-keyform> B<DER>|B<PEM>|B<P12>|B<ENGINE>
246 The format of the private key file; unspecified by default.
247 See L<openssl-format-options(1)> for details.
249 =item B<-rctform> B<DER>|B<PEM>|B<SMIME>
251 The signed receipt format for use with the B<-receipt_verify>; the default
253 See L<openssl-format-options(1)> for details.
255 =item B<-stream>, B<-indef>
257 The B<-stream> and B<-indef> options are equivalent and enable streaming I/O
258 for encoding operations. This permits single pass processing of data without
259 the need to hold the entire contents in memory, potentially supporting very
260 large files. Streaming is automatically set for S/MIME signing with detached
261 data if the output format is B<SMIME> it is currently off by default for all
266 Disable streaming I/O where it would produce and indefinite length constructed
267 encoding. This option currently has no effect. In future streaming will be
268 enabled by default on all relevant operations and this option will disable it.
270 =item B<-content> I<filename>
272 This specifies a file containing the detached content, this is only
273 useful with the B<-verify> command. This is only usable if the CMS
274 structure is using the detached signature form where the content is
275 not included. This option will override any content if the input format
276 is S/MIME and it uses the multipart/signed MIME content type.
280 This option adds plain text (text/plain) MIME headers to the supplied
281 message if encrypting or signing. If decrypting or verifying it strips
282 off text headers: if the decrypted or verified message is not of MIME
283 type text/plain then an error occurs.
287 For the B<-cmsout> operation do not output the parsed CMS structure. This
288 is useful when combined with the B<-print> option or if the syntax of the CMS
289 structure is being checked.
293 For the B<-cmsout> operation print out all fields of the CMS structure. This
294 is mainly useful for testing purposes.
296 =item B<-nameopt> I<option>
298 For the B<-cmsout> operation when B<-print> option is in use, specifies
299 printing options for string fields. For most cases B<utf8> is reasonable value.
300 See L<openssl-namedisplay-options(1)> for details.
302 =item B<-md> I<digest>
304 Digest algorithm to use when signing or resigning. If not present then the
305 default digest algorithm for the signing key will be used (usually SHA1).
309 The encryption algorithm to use. For example triple DES (168 bits) - B<-des3>
310 or 256 bit AES - B<-aes256>. Any standard algorithm name (as used by the
311 EVP_get_cipherbyname() function) can also be used preceded by a dash, for
312 example B<-aes-128-cbc>. See L<openssl-enc(1)> for a list of ciphers
313 supported by your version of OpenSSL.
315 Currently the AES variants with GCM mode are the only supported AEAD
318 If not specified triple DES is used. Only used with B<-encrypt> and
319 B<-EncryptedData_create> commands.
321 =item B<-wrap> I<cipher>
323 Cipher algorithm to use for key wrap when encrypting the message using Key
324 Agreement for key transport. The algorithm specified should be suitable for key
327 =item B<-aes128-wrap>, B<-aes192-wrap>, B<-aes256-wrap>, B<-des3-wrap>
329 Use AES128, AES192, AES256, or 3DES-EDE, respectively, to wrap key.
333 When verifying a message normally certificates (if any) included in
334 the message are searched for the signing certificate. With this option
335 only the certificates specified in the B<-certfile> option are used.
336 The supplied certificates can still be used as untrusted CAs however.
340 Do not verify the signers certificate of a signed message.
344 When signing a message the signer's certificate is normally included
345 with this option it is excluded. This will reduce the size of the
346 signed message but the verifier must have a copy of the signers certificate
347 available locally (passed using the B<-certfile> option for example).
351 Normally when a message is signed a set of attributes are included which
352 include the signing time and supported symmetric algorithms. With this
353 option they are not included.
357 Exclude the list of supported algorithms from signed attributes, other options
358 such as signing time and content type are still included.
362 Normally the input message is converted to "canonical" format which is
363 effectively using CR and LF as end of line: as required by the S/MIME
364 specification. When this option is present no translation occurs. This
365 is useful when handling binary data which may not be in MIME format.
369 Normally the output file uses a single B<LF> as end of line. When this
370 option is present B<CRLF> is used instead.
374 When signing use ASCII CRLF format canonicalisation. This strips trailing
375 whitespace from all lines, deletes trailing blank lines at EOF and sets
376 the encapsulated content type. This option is normally used with detached
377 content and an output signature format of DER. This option is not normally
378 needed when verifying as it is enabled automatically if the encapsulated
379 content format is detected.
383 When signing a message use opaque signing: this form is more resistant
384 to translation by mail relays but it cannot be read by mail agents that
385 do not support S/MIME. Without this option cleartext signing with
386 the MIME type multipart/signed is used.
388 =item B<-certfile> I<file>
390 Allows additional certificates to be specified. When signing these will
391 be included with the message. When verifying these will be searched for
392 the signers certificates.
393 The input can be in PEM, DER, or PKCS#12 format.
395 =item B<-certsout> I<file>
397 Any certificates contained in the message are written to I<file>.
399 =item B<-signer> I<file>
401 A signing certificate when signing or resigning a message, this option can be
402 used multiple times if more than one signer is required. If a message is being
403 verified then the signers certificates will be written to this file if the
404 verification was successful.
406 =item B<-originator> I<file>
408 A certificate of the originator of the encrypted message. Necessary for
409 decryption when Key Agreement is in use for a shared key.
411 =item B<-recip> I<file>
413 When decrypting a message this specifies the recipients certificate. The
414 certificate must match one of the recipients of the message or an error
417 When encrypting a message this option may be used multiple times to specify
418 each recipient. This form B<must> be used if customised parameters are
419 required (for example to specify RSA-OAEP).
421 Only certificates carrying RSA, Diffie-Hellman or EC keys are supported by this
426 Use subject key identifier to identify certificates instead of issuer name and
427 serial number. The supplied certificate B<must> include a subject key
428 identifier extension. Supported by B<-sign> and B<-encrypt> options.
430 =item B<-receipt_request_all>, B<-receipt_request_first>
432 For B<-sign> option include a signed receipt request. Indicate requests should
433 be provided by all recipient or first tier recipients (those mailed directly
434 and not from a mailing list). Ignored it B<-receipt_request_from> is included.
436 =item B<-receipt_request_from> I<emailaddress>
438 For B<-sign> option include a signed receipt request. Add an explicit email
439 address where receipts should be supplied.
441 =item B<-receipt_request_to> I<emailaddress>
443 Add an explicit email address where signed receipts should be sent to. This
444 option B<must> but supplied if a signed receipt it requested.
446 =item B<-receipt_request_print>
448 For the B<-verify> operation print out the contents of any signed receipt
451 =item B<-pwri_password> I<password>
453 Specify password for recipient.
455 =item B<-secretkey> I<key>
457 Specify symmetric key to use. The key must be supplied in hex format and be
458 consistent with the algorithm used. Supported by the B<-EncryptedData_encrypt>
459 B<-EncryptedData_decrypt>, B<-encrypt> and B<-decrypt> options. When used
460 with B<-encrypt> or B<-decrypt> the supplied key is used to wrap or unwrap the
461 content encryption key using an AES key in the B<KEKRecipientInfo> type.
463 =item B<-secretkeyid> I<id>
465 The key identifier for the supplied symmetric key for B<KEKRecipientInfo> type.
466 This option B<must> be present if the B<-secretkey> option is used with
467 B<-encrypt>. With B<-decrypt> operations the I<id> is used to locate the
468 relevant key if it is not supplied then an attempt is used to decrypt any
469 B<KEKRecipientInfo> structures.
471 =item B<-econtent_type> I<type>
473 Set the encapsulated content type to I<type> if not supplied the B<Data> type
474 is used. The I<type> argument can be any valid OID name in either text or
477 =item B<-inkey> I<filename>|I<uri>
479 The private key to use when signing or decrypting. This must match the
480 corresponding certificate. If this option is not specified then the
481 private key must be included in the certificate file specified with
482 the B<-recip> or B<-signer> file. When signing this option can be used
483 multiple times to specify successive keys.
485 =item B<-keyopt> I<name>:I<parameter>
487 For signing and encryption this option can be used multiple times to
488 set customised parameters for the preceding key or certificate. It can
489 currently be used to set RSA-PSS for signing, RSA-OAEP for encryption
490 or to modify default parameters for ECDH.
492 =item B<-passin> I<arg>
494 The private key password source. For more information about the format of B<arg>
495 see L<openssl-passphrase-options(1)>.
497 =item B<-to>, B<-from>, B<-subject>
499 The relevant mail headers. These are included outside the signed
500 portion of a message so they may be included manually. If signing
501 then many S/MIME mail clients check the signers certificate's email
502 address matches that specified in the From: address.
504 {- $OpenSSL::safe::opt_v_item -}
506 Any verification errors cause the command to exit.
508 {- $OpenSSL::safe::opt_trust_item -}
510 {- $OpenSSL::safe::opt_r_item -}
512 {- $OpenSSL::safe::opt_engine_item -}
514 {- $OpenSSL::safe::opt_provider_item -}
516 {- $OpenSSL::safe::opt_config_item -}
518 =item I<recipient-cert> ...
520 One or more certificates of message recipients: used when encrypting
527 The MIME message must be sent without any blank lines between the
528 headers and the output. Some mail programs will automatically add
529 a blank line. Piping the mail directly to sendmail is one way to
530 achieve the correct format.
532 The supplied message to be signed or encrypted must include the
533 necessary MIME headers or many S/MIME clients won't display it
534 properly (if at all). You can use the B<-text> option to automatically
535 add plain text headers.
537 A "signed and encrypted" message is one where a signed message is
538 then encrypted. This can be produced by encrypting an already signed
539 message: see the examples section.
541 This version of the program only allows one signer per message but it
542 will verify multiple signers on received messages. Some S/MIME clients
543 choke if a message contains multiple signers. It is possible to sign
544 messages "in parallel" by signing an already signed message.
546 The options B<-encrypt> and B<-decrypt> reflect common usage in S/MIME
547 clients. Strictly speaking these process CMS enveloped data: CMS
548 encrypted data is used for other purposes.
550 The B<-resign> option uses an existing message digest when adding a new
551 signer. This means that attributes must be present in at least one existing
552 signer using the same message digest or this operation will fail.
554 The B<-stream> and B<-indef> options enable streaming I/O support.
555 As a result the encoding is BER using indefinite length constructed encoding
556 and no longer DER. Streaming is supported for the B<-encrypt> operation and the
557 B<-sign> operation if the content is not detached.
559 Streaming is always used for the B<-sign> operation with detached data but
560 since the content is no longer part of the CMS structure the encoding
563 If the B<-decrypt> option is used without a recipient certificate then an
564 attempt is made to locate the recipient by trying each potential recipient
565 in turn using the supplied private key. To thwart the MMA attack
566 (Bleichenbacher's attack on PKCS #1 v1.5 RSA padding) all recipients are
567 tried whether they succeed or not and if no recipients match the message
568 is "decrypted" using a random key which will typically output garbage.
569 The B<-debug_decrypt> option can be used to disable the MMA attack protection
570 and return an error if no recipient can be found: this option should be used
571 with caution. For a fuller description see L<CMS_decrypt(3)>).
573 =head1 CADES BASIC ELECTRONIC SIGNATURE (CADES-BES)
575 A CAdES Basic Electronic Signature (CAdES-BES),
576 as defined in the European Standard ETSI EN 319 122-1 V1.1.1, contains:
582 The signed user data as defined in CMS (RFC 3852);
586 Content-type of the EncapsulatedContentInfo value being signed;
590 Message-digest of the eContent OCTET STRING within encapContentInfo being signed;
594 An ESS signingCertificate or ESS signingCertificateV2 attribute,
595 as defined in Enhanced Security Services (ESS), RFC 2634 and RFC 5035.
596 An ESS signingCertificate attribute only allows for SHA-1 as digest algorithm.
597 An ESS signingCertificateV2 attribute allows for any digest algorithm.
601 The digital signature value computed on the user data and, when present, on the signed attributes.
603 NOTE that the B<-cades> option applies to the B<-sign> or B<-verify> operations.
604 With this option, the B<-verify> operation also requires that the
605 signingCertificate attribute is present and checks that the given identifiers
606 match the verification trust chain built during the verification process.
616 The operation was completely successfully.
620 An error occurred parsing the command options.
624 One of the input files could not be read.
628 An error occurred creating the CMS file or when reading the MIME
633 An error occurred decrypting or verifying the message.
637 The message was verified correctly but an error occurred writing out
638 the signers certificates.
642 =head1 COMPATIBILITY WITH PKCS#7 FORMAT
644 L<openssl-smime(1)> can only process the older B<PKCS#7> format.
645 B<openssl cms> supports Cryptographic Message Syntax format.
646 Use of some features will result in messages which cannot be processed by
647 applications which only support the older format. These are detailed below.
649 The use of the B<-keyid> option with B<-sign> or B<-encrypt>.
651 The B<-outform> I<PEM> option uses different headers.
653 The B<-compress> option.
655 The B<-secretkey> option when used with B<-encrypt>.
657 The use of PSS with B<-sign>.
659 The use of OAEP or non-RSA keys with B<-encrypt>.
661 Additionally the B<-EncryptedData_create> and B<-data_create> type cannot
662 be processed by the older L<openssl-smime(1)> command.
666 Create a cleartext signed message:
668 openssl cms -sign -in message.txt -text -out mail.msg \
671 Create an opaque signed message
673 openssl cms -sign -in message.txt -text -out mail.msg -nodetach \
676 Create a signed message, include some additional certificates and
677 read the private key from another file:
679 openssl cms -sign -in in.txt -text -out mail.msg \
680 -signer mycert.pem -inkey mykey.pem -certfile mycerts.pem
682 Create a signed message with two signers, use key identifier:
684 openssl cms -sign -in message.txt -text -out mail.msg \
685 -signer mycert.pem -signer othercert.pem -keyid
687 Send a signed message under Unix directly to sendmail, including headers:
689 openssl cms -sign -in in.txt -text -signer mycert.pem \
690 -from steve@openssl.org -to someone@somewhere \
691 -subject "Signed message" | sendmail someone@somewhere
693 Verify a message and extract the signer's certificate if successful:
695 openssl cms -verify -in mail.msg -signer user.pem -out signedtext.txt
697 Send encrypted mail using triple DES:
699 openssl cms -encrypt -in in.txt -from steve@openssl.org \
700 -to someone@somewhere -subject "Encrypted message" \
701 -des3 user.pem -out mail.msg
703 Sign and encrypt mail:
705 openssl cms -sign -in ml.txt -signer my.pem -text \
706 | openssl cms -encrypt -out mail.msg \
707 -from steve@openssl.org -to someone@somewhere \
708 -subject "Signed and Encrypted message" -des3 user.pem
710 Note: the encryption command does not include the B<-text> option because the
711 message being encrypted already has MIME headers.
715 openssl cms -decrypt -in mail.msg -recip mycert.pem -inkey key.pem
717 The output from Netscape form signing is a PKCS#7 structure with the
718 detached signature format. You can use this program to verify the
719 signature by line wrapping the base64 encoded structure and surrounding
722 -----BEGIN PKCS7-----
725 and using the command,
727 openssl cms -verify -inform PEM -in signature.pem -content content.txt
729 alternatively you can base64 decode the signature and use
731 openssl cms -verify -inform DER -in signature.der -content content.txt
733 Create an encrypted message using 128 bit Camellia:
735 openssl cms -encrypt -in plain.txt -camellia128 -out mail.msg cert.pem
737 Add a signer to an existing message:
739 openssl cms -resign -in mail.msg -signer newsign.pem -out mail2.msg
741 Sign mail using RSA-PSS:
743 openssl cms -sign -in message.txt -text -out mail.msg \
744 -signer mycert.pem -keyopt rsa_padding_mode:pss
746 Create encrypted mail using RSA-OAEP:
748 openssl cms -encrypt -in plain.txt -out mail.msg \
749 -recip cert.pem -keyopt rsa_padding_mode:oaep
751 Use SHA256 KDF with an ECDH certificate:
753 openssl cms -encrypt -in plain.txt -out mail.msg \
754 -recip ecdhcert.pem -keyopt ecdh_kdf_md:sha256
758 The MIME parser isn't very clever: it seems to handle most messages that I've
759 thrown at it but it may choke on others.
761 The code currently will only write out the signer's certificate to a file: if
762 the signer has a separate encryption certificate this must be manually
763 extracted. There should be some heuristic that determines the correct
764 encryption certificate.
766 Ideally a database should be maintained of a certificates for each email
769 The code doesn't currently take note of the permitted symmetric encryption
770 algorithms as supplied in the SMIMECapabilities signed attribute. this means the
771 user has to manually include the correct encryption algorithm. It should store
772 the list of permitted ciphers in a database and only use those.
774 No revocation checking is done on the signer's certificate.
778 L<ossl_store-file(7)>
782 The use of multiple B<-signer> options and the B<-resign> command were first
783 added in OpenSSL 1.0.0.
785 The B<-keyopt> option was added in OpenSSL 1.0.2.
787 Support for RSA-OAEP and RSA-PSS was added in OpenSSL 1.0.2.
789 The use of non-RSA keys with B<-encrypt> and B<-decrypt>
790 was added in OpenSSL 1.0.2.
792 The -no_alt_chains option was added in OpenSSL 1.0.2b.
794 The B<-nameopt> option was added in OpenSSL 3.0.0.
796 The B<-engine> option was deprecated in OpenSSL 3.0.
800 Copyright 2008-2021 The OpenSSL Project Authors. All Rights Reserved.
802 Licensed under the Apache License 2.0 (the "License"). You may not use
803 this file except in compliance with the License. You can obtain a copy
804 in the file LICENSE in the source distribution or at
805 L<https://www.openssl.org/source/license.html>.