2 {- OpenSSL::safe::output_do_not_edit_headers(); -}
6 openssl-cms - CMS utility
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<ENGINE>]
43 [B<-content> I<filename>]
59 [B<-certfile> I<file>]
60 [B<-certsout> I<file>]
62 [B<-originator> I<file>]
65 [B<-receipt_request_all>]
66 [B<-receipt_request_first>]
67 [B<-receipt_request_from> I<emailaddress>]
68 [B<-receipt_request_to> I<emailaddress>]
69 [B<-receipt_request_print>]
70 [B<-pwri_password> I<password>]
71 [B<-secretkey> I<key>]
72 [B<-secretkeyid> I<id>]
73 [B<-econtent_type> I<type>]
75 [B<-keyopt> I<name>:I<parameter>]
80 {- $OpenSSL::safe::opt_v_synopsis -}
81 {- $OpenSSL::safe::opt_trust_synopsis -}
82 {- $OpenSSL::safe::opt_r_synopsis -}
83 {- $OpenSSL::safe::opt_engine_synopsis -}
86 =for openssl ifdef des-wrap engine
90 This command handles S/MIME v3.1 mail. It can encrypt, decrypt,
91 sign and verify, compress and uncompress S/MIME messages.
95 There are fourteen operation options that set the type of operation to be
96 performed. The meaning of the other options varies according to the operation
103 Print out a usage message.
107 Encrypt mail for the given recipient certificates. Input file is the message
108 to be encrypted. The output file is the encrypted mail in MIME format. The
109 actual CMS type is <B>EnvelopedData<B>.
111 Note that no revocation check is done for the recipient cert, so if that
112 key has been compromised, others may be able to decrypt the text.
116 Decrypt mail using the supplied certificate and private key. Expects an
117 encrypted mail message in MIME format for the input file. The decrypted mail
118 is written to the output file.
120 =item B<-debug_decrypt>
122 This option sets the B<CMS_DEBUG_DECRYPT> flag. This option should be used
123 with caution: see the notes section below.
127 Sign mail using the supplied certificate and private key. Input file is
128 the message to be signed. The signed message in MIME format is written
133 Verify signed mail. Expects a signed mail message on input and outputs
134 the signed data. Both clear text and opaque signing is supported.
136 =item B<-verify_retcode>
138 Exit nonzero on verification failure.
140 =item B<-no_attr_verify>
142 Do not verify signed attribute signatures.
144 =item B<-no_content_verify>
146 Do not verify signed content signatures.
150 Don't verify message signature.
154 Takes an input message and writes out a PEM encoded CMS structure.
158 Resign a message: take an existing message and one or more new signers.
162 Add an ESS signing-certificate or ESS signing-certificate-v2 signed-attribute to the SignerInfo, in order to make
163 the signature comply with the requirements for a CAdES Basic Electronic Signature (CAdES-BES). See the NOTES
164 section for more details.
166 =item B<-data_create>
168 Create a CMS B<Data> type.
172 B<Data> type and output the content.
174 =item B<-digest_create>
176 Create a CMS B<DigestedData> type.
178 =item B<-digest_verify>
180 Verify a CMS B<DigestedData> type and output the content.
184 Create a CMS B<CompressedData> type. OpenSSL must be compiled with B<zlib>
185 support for this option to work, otherwise it will output an error.
189 Uncompress a CMS B<CompressedData> type and output the content. OpenSSL must be
190 compiled with B<zlib> support for this option to work, otherwise it will
193 =item B<-EncryptedData_decrypt>
195 Decrypt content using supplied symmetric key and algorithm using a CMS
196 B<EncryptedData> type and output the content.
198 =item B<-EncryptedData_encrypt>
200 Encrypt content using supplied symmetric key and algorithm using a CMS
201 B<EncryptedData> type and output the content.
203 =item B<-sign_receipt>
205 Generate and output a signed receipt for the supplied message. The input
206 message B<must> contain a signed receipt request. Functionality is otherwise
207 similar to the B<-sign> operation.
209 =item B<-verify_receipt> I<receipt>
211 Verify a signed receipt in filename B<receipt>. The input message B<must>
212 contain the original receipt request. Functionality is otherwise similar
213 to the B<-verify> operation.
215 =item B<-in> I<filename>
217 The input message to be encrypted or signed or the message to be decrypted
220 =item B<-out> I<filename>
222 The message text that has been decrypted or verified or the output MIME
223 format message that has been signed or verified.
225 =item B<-inform> B<DER>|B<PEM>|B<SMIME>
227 The input format of the CMS structure (if one is being read);
228 the default is B<SMIME>.
229 See L<openssl(1)/Format Options> for details.
231 =item B<-outform> B<DER>|B<PEM>|B<SMIME>
233 The output format of the CMS structure (if one is being written);
234 the default is B<SMIME>.
235 See L<openssl(1)/Format Options> for details.
237 =item B<-keyform> B<DER>|B<PEM>|B<ENGINE>
239 The format of the private key file; the default is B<PEM>.
240 See L<openssl(1)/Format Options> for details.
242 =item B<-rctform> B<DER>|B<PEM>|B<SMIME>
244 The signed receipt format for use with the B<-receipt_verify>; the default
246 See L<openssl(1)/Format Options> for details.
248 =item B<-stream>, B<-indef>
250 The B<-stream> and B<-indef> options are equivalent and enable streaming I/O
251 for encoding operations. This permits single pass processing of data without
252 the need to hold the entire contents in memory, potentially supporting very
253 large files. Streaming is automatically set for S/MIME signing with detached
254 data if the output format is B<SMIME> it is currently off by default for all
259 Disable streaming I/O where it would produce and indefinite length constructed
260 encoding. This option currently has no effect. In future streaming will be
261 enabled by default on all relevant operations and this option will disable it.
263 =item B<-content> I<filename>
265 This specifies a file containing the detached content, this is only
266 useful with the B<-verify> command. This is only usable if the CMS
267 structure is using the detached signature form where the content is
268 not included. This option will override any content if the input format
269 is S/MIME and it uses the multipart/signed MIME content type.
273 This option adds plain text (text/plain) MIME headers to the supplied
274 message if encrypting or signing. If decrypting or verifying it strips
275 off text headers: if the decrypted or verified message is not of MIME
276 type text/plain then an error occurs.
280 For the B<-cmsout> operation do not output the parsed CMS structure. This
281 is useful when combined with the B<-print> option or if the syntax of the CMS
282 structure is being checked.
286 For the B<-cmsout> operation print out all fields of the CMS structure. This
287 is mainly useful for testing purposes.
289 =item B<-md> I<digest>
291 Digest algorithm to use when signing or resigning. If not present then the
292 default digest algorithm for the signing key will be used (usually SHA1).
296 The encryption algorithm to use. For example triple DES (168 bits) - B<-des3>
297 or 256 bit AES - B<-aes256>. Any standard algorithm name (as used by the
298 EVP_get_cipherbyname() function) can also be used preceded by a dash, for
299 example B<-aes-128-cbc>. See L<openssl-enc(1)> for a list of ciphers
300 supported by your version of OpenSSL.
302 If not specified triple DES is used. Only used with B<-encrypt> and
303 B<-EncryptedData_create> commands.
305 =item B<-wrap> I<cipher>
307 Cipher algorithm to use for key wrap when encrypting the message using Key
308 Agreement for key transport. The algorithm specified should be suitable for key
313 When verifying a message normally certificates (if any) included in
314 the message are searched for the signing certificate. With this option
315 only the certificates specified in the B<-certfile> option are used.
316 The supplied certificates can still be used as untrusted CAs however.
320 Do not verify the signers certificate of a signed message.
324 When signing a message the signer's certificate is normally included
325 with this option it is excluded. This will reduce the size of the
326 signed message but the verifier must have a copy of the signers certificate
327 available locally (passed using the B<-certfile> option for example).
331 Normally when a message is signed a set of attributes are included which
332 include the signing time and supported symmetric algorithms. With this
333 option they are not included.
337 Exclude the list of supported algorithms from signed attributes, other options
338 such as signing time and content type are still included.
342 Normally the input message is converted to "canonical" format which is
343 effectively using CR and LF as end of line: as required by the S/MIME
344 specification. When this option is present no translation occurs. This
345 is useful when handling binary data which may not be in MIME format.
349 Normally the output file uses a single B<LF> as end of line. When this
350 option is present B<CRLF> is used instead.
354 When signing use ASCII CRLF format canonicalisation. This strips trailing
355 whitespace from all lines, deletes trailing blank lines at EOF and sets
356 the encapsulated content type. This option is normally used with detached
357 content and an output signature format of DER. This option is not normally
358 needed when verifying as it is enabled automatically if the encapsulated
359 content format is detected.
363 When signing a message use opaque signing: this form is more resistant
364 to translation by mail relays but it cannot be read by mail agents that
365 do not support S/MIME. Without this option cleartext signing with
366 the MIME type multipart/signed is used.
368 =item B<-certfile> I<file>
370 Allows additional certificates to be specified. When signing these will
371 be included with the message. When verifying these will be searched for
372 the signers certificates. The certificates should be in PEM format.
374 =item B<-certsout> I<file>
376 Any certificates contained in the message are written to I<file>.
378 =item B<-signer> I<file>
380 A signing certificate when signing or resigning a message, this option can be
381 used multiple times if more than one signer is required. If a message is being
382 verified then the signers certificates will be written to this file if the
383 verification was successful.
385 =item B<-originator> I<file>
387 A certificate of the originator of the encrypted message. Necessary for
388 decryption when Key Agreement is in use for a shared key.
390 =item B<-recip> I<file>
392 When decrypting a message this specifies the recipients certificate. The
393 certificate must match one of the recipients of the message or an error
396 When encrypting a message this option may be used multiple times to specify
397 each recipient. This form B<must> be used if customised parameters are
398 required (for example to specify RSA-OAEP).
400 Only certificates carrying RSA, Diffie-Hellman or EC keys are supported by this
405 Use subject key identifier to identify certificates instead of issuer name and
406 serial number. The supplied certificate B<must> include a subject key
407 identifier extension. Supported by B<-sign> and B<-encrypt> options.
409 =item B<-receipt_request_all>, B<-receipt_request_first>
411 For B<-sign> option include a signed receipt request. Indicate requests should
412 be provided by all recipient or first tier recipients (those mailed directly
413 and not from a mailing list). Ignored it B<-receipt_request_from> is included.
415 =item B<-receipt_request_from> I<emailaddress>
417 For B<-sign> option include a signed receipt request. Add an explicit email
418 address where receipts should be supplied.
420 =item B<-receipt_request_to> I<emailaddress>
422 Add an explicit email address where signed receipts should be sent to. This
423 option B<must> but supplied if a signed receipt it requested.
425 =item B<-receipt_request_print>
427 For the B<-verify> operation print out the contents of any signed receipt
430 =item B<-pwri_password> I<password>
432 Specify password for recipient.
434 =item B<-secretkey> I<key>
436 Specify symmetric key to use. The key must be supplied in hex format and be
437 consistent with the algorithm used. Supported by the B<-EncryptedData_encrypt>
438 B<-EncryptedData_decrypt>, B<-encrypt> and B<-decrypt> options. When used
439 with B<-encrypt> or B<-decrypt> the supplied key is used to wrap or unwrap the
440 content encryption key using an AES key in the B<KEKRecipientInfo> type.
442 =item B<-secretkeyid> I<id>
444 The key identifier for the supplied symmetric key for B<KEKRecipientInfo> type.
445 This option B<must> be present if the B<-secretkey> option is used with
446 B<-encrypt>. With B<-decrypt> operations the I<id> is used to locate the
447 relevant key if it is not supplied then an attempt is used to decrypt any
448 B<KEKRecipientInfo> structures.
450 =item B<-econtent_type> I<type>
452 Set the encapsulated content type to I<type> if not supplied the B<Data> type
453 is used. The I<type> argument can be any valid OID name in either text or
456 =item B<-inkey> I<file>
458 The private key to use when signing or decrypting. This must match the
459 corresponding certificate. If this option is not specified then the
460 private key must be included in the certificate file specified with
461 the B<-recip> or B<-signer> file. When signing this option can be used
462 multiple times to specify successive keys.
464 =item B<-keyopt> I<name>:I<parameter>
466 For signing and encryption this option can be used multiple times to
467 set customised parameters for the preceding key or certificate. It can
468 currently be used to set RSA-PSS for signing, RSA-OAEP for encryption
469 or to modify default parameters for ECDH.
471 =item B<-passin> I<arg>
473 The private key password source. For more information about the format of B<arg>
474 see L<openssl(1)/Pass Phrase Options>.
476 =item B<-to>, B<-from>, B<-subject>
478 The relevant mail headers. These are included outside the signed
479 portion of a message so they may be included manually. If signing
480 then many S/MIME mail clients check the signers certificate's email
481 address matches that specified in the From: address.
483 {- $OpenSSL::safe::opt_v_item -}
485 Any verification errors cause the command to exit.
487 {- $OpenSSL::safe::opt_trust_item -}
489 {- $OpenSSL::safe::opt_r_item -}
491 {- $OpenSSL::safe::opt_engine_item -}
493 =item I<cert.pem> ...
495 One or more certificates of message recipients: used when encrypting
502 The MIME message must be sent without any blank lines between the
503 headers and the output. Some mail programs will automatically add
504 a blank line. Piping the mail directly to sendmail is one way to
505 achieve the correct format.
507 The supplied message to be signed or encrypted must include the
508 necessary MIME headers or many S/MIME clients won't display it
509 properly (if at all). You can use the B<-text> option to automatically
510 add plain text headers.
512 A "signed and encrypted" message is one where a signed message is
513 then encrypted. This can be produced by encrypting an already signed
514 message: see the examples section.
516 This version of the program only allows one signer per message but it
517 will verify multiple signers on received messages. Some S/MIME clients
518 choke if a message contains multiple signers. It is possible to sign
519 messages "in parallel" by signing an already signed message.
521 The options B<-encrypt> and B<-decrypt> reflect common usage in S/MIME
522 clients. Strictly speaking these process CMS enveloped data: CMS
523 encrypted data is used for other purposes.
525 The B<-resign> option uses an existing message digest when adding a new
526 signer. This means that attributes must be present in at least one existing
527 signer using the same message digest or this operation will fail.
529 The B<-stream> and B<-indef> options enable streaming I/O support.
530 As a result the encoding is BER using indefinite length constructed encoding
531 and no longer DER. Streaming is supported for the B<-encrypt> operation and the
532 B<-sign> operation if the content is not detached.
534 Streaming is always used for the B<-sign> operation with detached data but
535 since the content is no longer part of the CMS structure the encoding
538 If the B<-decrypt> option is used without a recipient certificate then an
539 attempt is made to locate the recipient by trying each potential recipient
540 in turn using the supplied private key. To thwart the MMA attack
541 (Bleichenbacher's attack on PKCS #1 v1.5 RSA padding) all recipients are
542 tried whether they succeed or not and if no recipients match the message
543 is "decrypted" using a random key which will typically output garbage.
544 The B<-debug_decrypt> option can be used to disable the MMA attack protection
545 and return an error if no recipient can be found: this option should be used
546 with caution. For a fuller description see L<CMS_decrypt(3)>).
548 =head1 CADES BASIC ELECTRONIC SIGNATURE (CADES-BES)
550 A CAdES Basic Electronic Signature (CAdES-BES), as defined in the European Standard ETSI EN 319 122-1 V1.1.1, contains:
556 The signed user data as defined in CMS (RFC 3852);
560 Content-type of the EncapsulatedContentInfo value being signed;
564 Message-digest of the eContent OCTET STRING within encapContentInfo being signed;
568 An ESS signing-certificate or ESS signing-certificate-v2 attribute, as defined in Enhanced Security Services (ESS), RFC 2634 and RFC 5035.
569 An ESS signing-certificate attribute only allows for the use of SHA-1 as a digest algorithm.
570 An ESS signing-certificate-v2 attribute allows for the use of any digest algorithm.
574 The digital signature value computed on the user data and, when present, on the signed attributes.
576 Note that currently the B<-cades> option applies only to the B<-sign> operation and is ignored during
577 the B<-verify> operation, i.e. the signing certification is not checked during the verification process.
578 This feature might be added in a future version.
588 The operation was completely successfully.
592 An error occurred parsing the command options.
596 One of the input files could not be read.
600 An error occurred creating the CMS file or when reading the MIME
605 An error occurred decrypting or verifying the message.
609 The message was verified correctly but an error occurred writing out
610 the signers certificates.
614 =head1 COMPATIBILITY WITH PKCS#7 FORMAT
616 L<openssl-smime(1)> can only process the older B<PKCS#7> format.
617 B<openssl cms> supports Cryptographic Message Syntax format.
618 Use of some features will result in messages which cannot be processed by
619 applications which only support the older format. These are detailed below.
621 The use of the B<-keyid> option with B<-sign> or B<-encrypt>.
623 The B<-outform> I<PEM> option uses different headers.
625 The B<-compress> option.
627 The B<-secretkey> option when used with B<-encrypt>.
629 The use of PSS with B<-sign>.
631 The use of OAEP or non-RSA keys with B<-encrypt>.
633 Additionally the B<-EncryptedData_create> and B<-data_create> type cannot
634 be processed by the older L<openssl-smime(1)> command.
638 Create a cleartext signed message:
640 openssl cms -sign -in message.txt -text -out mail.msg \
643 Create an opaque signed message
645 openssl cms -sign -in message.txt -text -out mail.msg -nodetach \
648 Create a signed message, include some additional certificates and
649 read the private key from another file:
651 openssl cms -sign -in in.txt -text -out mail.msg \
652 -signer mycert.pem -inkey mykey.pem -certfile mycerts.pem
654 Create a signed message with two signers, use key identifier:
656 openssl cms -sign -in message.txt -text -out mail.msg \
657 -signer mycert.pem -signer othercert.pem -keyid
659 Send a signed message under Unix directly to sendmail, including headers:
661 openssl cms -sign -in in.txt -text -signer mycert.pem \
662 -from steve@openssl.org -to someone@somewhere \
663 -subject "Signed message" | sendmail someone@somewhere
665 Verify a message and extract the signer's certificate if successful:
667 openssl cms -verify -in mail.msg -signer user.pem -out signedtext.txt
669 Send encrypted mail using triple DES:
671 openssl cms -encrypt -in in.txt -from steve@openssl.org \
672 -to someone@somewhere -subject "Encrypted message" \
673 -des3 user.pem -out mail.msg
675 Sign and encrypt mail:
677 openssl cms -sign -in ml.txt -signer my.pem -text \
678 | openssl cms -encrypt -out mail.msg \
679 -from steve@openssl.org -to someone@somewhere \
680 -subject "Signed and Encrypted message" -des3 user.pem
682 Note: the encryption command does not include the B<-text> option because the
683 message being encrypted already has MIME headers.
687 openssl cms -decrypt -in mail.msg -recip mycert.pem -inkey key.pem
689 The output from Netscape form signing is a PKCS#7 structure with the
690 detached signature format. You can use this program to verify the
691 signature by line wrapping the base64 encoded structure and surrounding
694 -----BEGIN PKCS7-----
697 and using the command,
699 openssl cms -verify -inform PEM -in signature.pem -content content.txt
701 alternatively you can base64 decode the signature and use
703 openssl cms -verify -inform DER -in signature.der -content content.txt
705 Create an encrypted message using 128 bit Camellia:
707 openssl cms -encrypt -in plain.txt -camellia128 -out mail.msg cert.pem
709 Add a signer to an existing message:
711 openssl cms -resign -in mail.msg -signer newsign.pem -out mail2.msg
713 Sign mail using RSA-PSS:
715 openssl cms -sign -in message.txt -text -out mail.msg \
716 -signer mycert.pem -keyopt rsa_padding_mode:pss
718 Create encrypted mail using RSA-OAEP:
720 openssl cms -encrypt -in plain.txt -out mail.msg \
721 -recip cert.pem -keyopt rsa_padding_mode:oaep
723 Use SHA256 KDF with an ECDH certificate:
725 openssl cms -encrypt -in plain.txt -out mail.msg \
726 -recip ecdhcert.pem -keyopt ecdh_kdf_md:sha256
730 The MIME parser isn't very clever: it seems to handle most messages that I've
731 thrown at it but it may choke on others.
733 The code currently will only write out the signer's certificate to a file: if
734 the signer has a separate encryption certificate this must be manually
735 extracted. There should be some heuristic that determines the correct
736 encryption certificate.
738 Ideally a database should be maintained of a certificates for each email
741 The code doesn't currently take note of the permitted symmetric encryption
742 algorithms as supplied in the SMIMECapabilities signed attribute. this means the
743 user has to manually include the correct encryption algorithm. It should store
744 the list of permitted ciphers in a database and only use those.
746 No revocation checking is done on the signer's certificate.
750 L<ossl_store-file(7)>
754 The use of multiple B<-signer> options and the B<-resign> command were first
755 added in OpenSSL 1.0.0.
757 The B<-keyopt> option was added in OpenSSL 1.0.2.
759 Support for RSA-OAEP and RSA-PSS was added in OpenSSL 1.0.2.
761 The use of non-RSA keys with B<-encrypt> and B<-decrypt>
762 was added in OpenSSL 1.0.2.
764 The -no_alt_chains option was added in OpenSSL 1.0.2b.
768 Copyright 2008-2019 The OpenSSL Project Authors. All Rights Reserved.
770 Licensed under the Apache License 2.0 (the "License"). You may not use
771 this file except in compliance with the License. You can obtain a copy
772 in the file LICENSE in the source distribution or at
773 L<https://www.openssl.org/source/license.html>.