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>]
58 [B<-certfile> I<file>]
59 [B<-certsout> I<file>]
63 [B<-receipt_request_all>]
64 [B<-receipt_request_first>]
65 [B<-receipt_request_from> I<emailaddress>]
66 [B<-receipt_request_to> I<emailaddress>]
67 [B<-receipt_request_print>]
68 [B<-pwri_password> I<password>]
69 [B<-secretkey> I<key>]
70 [B<-secretkeyid> I<id>]
71 [B<-econtent_type> I<type>]
73 [B<-keyopt> I<name>:I<parameter>]
78 {- $OpenSSL::safe::opt_v_synopsis -}
79 {- $OpenSSL::safe::opt_trust_synopsis -}
80 {- $OpenSSL::safe::opt_r_synopsis -}
81 {- $OpenSSL::safe::opt_engine_synopsis -}
84 =for openssl ifdef des-wrap engine
88 This command handles S/MIME v3.1 mail. It can encrypt, decrypt,
89 sign and verify, compress and uncompress S/MIME messages.
93 There are fourteen operation options that set the type of operation to be
94 performed. The meaning of the other options varies according to the operation
101 Print out a usage message.
105 Encrypt mail for the given recipient certificates. Input file is the message
106 to be encrypted. The output file is the encrypted mail in MIME format. The
107 actual CMS type is <B>EnvelopedData<B>.
109 Note that no revocation check is done for the recipient cert, so if that
110 key has been compromised, others may be able to decrypt the text.
114 Decrypt mail using the supplied certificate and private key. Expects an
115 encrypted mail message in MIME format for the input file. The decrypted mail
116 is written to the output file.
118 =item B<-debug_decrypt>
120 This option sets the B<CMS_DEBUG_DECRYPT> flag. This option should be used
121 with caution: see the notes section below.
125 Sign mail using the supplied certificate and private key. Input file is
126 the message to be signed. The signed message in MIME format is written
131 Verify signed mail. Expects a signed mail message on input and outputs
132 the signed data. Both clear text and opaque signing is supported.
134 =item B<-verify_retcode>
136 Exit nonzero on verification failure.
138 =item B<-no_attr_verify>
140 Do not verify signed attribute signatures.
142 =item B<-no_content_verify>
144 Do not verify signed content signatures.
148 Don't verify message signature.
152 Takes an input message and writes out a PEM encoded CMS structure.
156 Resign a message: take an existing message and one or more new signers.
160 Add an ESS signing-certificate or ESS signing-certificate-v2 signed-attribute to the SignerInfo, in order to make
161 the signature comply with the requirements for a CAdES Basic Electronic Signature (CAdES-BES). See the NOTES
162 section for more details.
164 =item B<-data_create>
166 Create a CMS B<Data> type.
170 B<Data> type and output the content.
172 =item B<-digest_create>
174 Create a CMS B<DigestedData> type.
176 =item B<-digest_verify>
178 Verify a CMS B<DigestedData> type and output the content.
182 Create a CMS B<CompressedData> type. OpenSSL must be compiled with B<zlib>
183 support for this option to work, otherwise it will output an error.
187 Uncompress a CMS B<CompressedData> type and output the content. OpenSSL must be
188 compiled with B<zlib> support for this option to work, otherwise it will
191 =item B<-EncryptedData_decrypt>
193 Decrypt content using supplied symmetric key and algorithm using a CMS
194 B<EncryptedData> type and output the content.
196 =item B<-EncryptedData_encrypt>
198 Encrypt content using supplied symmetric key and algorithm using a CMS
199 B<EncryptedData> type and output the content.
201 =item B<-sign_receipt>
203 Generate and output a signed receipt for the supplied message. The input
204 message B<must> contain a signed receipt request. Functionality is otherwise
205 similar to the B<-sign> operation.
207 =item B<-verify_receipt> I<receipt>
209 Verify a signed receipt in filename B<receipt>. The input message B<must>
210 contain the original receipt request. Functionality is otherwise similar
211 to the B<-verify> operation.
213 =item B<-in> I<filename>
215 The input message to be encrypted or signed or the message to be decrypted
218 =item B<-out> I<filename>
220 The message text that has been decrypted or verified or the output MIME
221 format message that has been signed or verified.
223 =item B<-inform> B<DER>|B<PEM>|B<SMIME>
225 The input format of the CMS structure (if one is being read);
226 the default is B<SMIME>.
227 See L<openssl(1)/Format Options> for details.
229 =item B<-outform> B<DER>|B<PEM>|B<SMIME>
231 The output format of the CMS structure (if one is being written);
232 the default is B<SMIME>.
233 See L<openssl(1)/Format Options> for details.
235 =item B<-keyform> B<DER>|B<PEM>|B<ENGINE>
237 The format of the private key file; the default is B<PEM>.
238 See L<openssl(1)/Format Options> for details.
240 =item B<-rctform> B<DER>|B<PEM>|B<SMIME>
242 The signed receipt format for use with the B<-receipt_verify>; the default
244 See L<openssl(1)/Format Options> for details.
246 =item B<-stream>, B<-indef>
248 The B<-stream> and B<-indef> options are equivalent and enable streaming I/O
249 for encoding operations. This permits single pass processing of data without
250 the need to hold the entire contents in memory, potentially supporting very
251 large files. Streaming is automatically set for S/MIME signing with detached
252 data if the output format is B<SMIME> it is currently off by default for all
257 Disable streaming I/O where it would produce and indefinite length constructed
258 encoding. This option currently has no effect. In future streaming will be
259 enabled by default on all relevant operations and this option will disable it.
261 =item B<-content> I<filename>
263 This specifies a file containing the detached content, this is only
264 useful with the B<-verify> command. This is only usable if the CMS
265 structure is using the detached signature form where the content is
266 not included. This option will override any content if the input format
267 is S/MIME and it uses the multipart/signed MIME content type.
271 This option adds plain text (text/plain) MIME headers to the supplied
272 message if encrypting or signing. If decrypting or verifying it strips
273 off text headers: if the decrypted or verified message is not of MIME
274 type text/plain then an error occurs.
278 For the B<-cmsout> operation do not output the parsed CMS structure. This
279 is useful when combined with the B<-print> option or if the syntax of the CMS
280 structure is being checked.
284 For the B<-cmsout> operation print out all fields of the CMS structure. This
285 is mainly useful for testing purposes.
287 =item B<-md> I<digest>
289 Digest algorithm to use when signing or resigning. If not present then the
290 default digest algorithm for the signing key will be used (usually SHA1).
294 The encryption algorithm to use. For example triple DES (168 bits) - B<-des3>
295 or 256 bit AES - B<-aes256>. Any standard algorithm name (as used by the
296 EVP_get_cipherbyname() function) can also be used preceded by a dash, for
297 example B<-aes-128-cbc>. See L<openssl-enc(1)> for a list of ciphers
298 supported by your version of OpenSSL.
300 If not specified triple DES is used. Only used with B<-encrypt> and
301 B<-EncryptedData_create> commands.
305 When verifying a message normally certificates (if any) included in
306 the message are searched for the signing certificate. With this option
307 only the certificates specified in the B<-certfile> option are used.
308 The supplied certificates can still be used as untrusted CAs however.
312 Do not verify the signers certificate of a signed message.
316 When signing a message the signer's certificate is normally included
317 with this option it is excluded. This will reduce the size of the
318 signed message but the verifier must have a copy of the signers certificate
319 available locally (passed using the B<-certfile> option for example).
323 Normally when a message is signed a set of attributes are included which
324 include the signing time and supported symmetric algorithms. With this
325 option they are not included.
329 Exclude the list of supported algorithms from signed attributes, other options
330 such as signing time and content type are still included.
334 Normally the input message is converted to "canonical" format which is
335 effectively using CR and LF as end of line: as required by the S/MIME
336 specification. When this option is present no translation occurs. This
337 is useful when handling binary data which may not be in MIME format.
341 Normally the output file uses a single B<LF> as end of line. When this
342 option is present B<CRLF> is used instead.
346 When signing use ASCII CRLF format canonicalisation. This strips trailing
347 whitespace from all lines, deletes trailing blank lines at EOF and sets
348 the encapsulated content type. This option is normally used with detached
349 content and an output signature format of DER. This option is not normally
350 needed when verifying as it is enabled automatically if the encapsulated
351 content format is detected.
355 When signing a message use opaque signing: this form is more resistant
356 to translation by mail relays but it cannot be read by mail agents that
357 do not support S/MIME. Without this option cleartext signing with
358 the MIME type multipart/signed is used.
360 =item B<-certfile> I<file>
362 Allows additional certificates to be specified. When signing these will
363 be included with the message. When verifying these will be searched for
364 the signers certificates. The certificates should be in PEM format.
366 =item B<-certsout> I<file>
368 Any certificates contained in the message are written to I<file>.
370 =item B<-signer> I<file>
372 A signing certificate when signing or resigning a message, this option can be
373 used multiple times if more than one signer is required. If a message is being
374 verified then the signers certificates will be written to this file if the
375 verification was successful.
377 =item B<-recip> I<file>
379 When decrypting a message this specifies the recipients certificate. The
380 certificate must match one of the recipients of the message or an error
383 When encrypting a message this option may be used multiple times to specify
384 each recipient. This form B<must> be used if customised parameters are
385 required (for example to specify RSA-OAEP).
387 Only certificates carrying RSA, Diffie-Hellman or EC keys are supported by this
392 Use subject key identifier to identify certificates instead of issuer name and
393 serial number. The supplied certificate B<must> include a subject key
394 identifier extension. Supported by B<-sign> and B<-encrypt> options.
396 =item B<-receipt_request_all>, B<-receipt_request_first>
398 For B<-sign> option include a signed receipt request. Indicate requests should
399 be provided by all recipient or first tier recipients (those mailed directly
400 and not from a mailing list). Ignored it B<-receipt_request_from> is included.
402 =item B<-receipt_request_from> I<emailaddress>
404 For B<-sign> option include a signed receipt request. Add an explicit email
405 address where receipts should be supplied.
407 =item B<-receipt_request_to> I<emailaddress>
409 Add an explicit email address where signed receipts should be sent to. This
410 option B<must> but supplied if a signed receipt it requested.
412 =item B<-receipt_request_print>
414 For the B<-verify> operation print out the contents of any signed receipt
417 =item B<-pwri_password> I<password>
419 Specify password for recipient.
421 =item B<-secretkey> I<key>
423 Specify symmetric key to use. The key must be supplied in hex format and be
424 consistent with the algorithm used. Supported by the B<-EncryptedData_encrypt>
425 B<-EncryptedData_decrypt>, B<-encrypt> and B<-decrypt> options. When used
426 with B<-encrypt> or B<-decrypt> the supplied key is used to wrap or unwrap the
427 content encryption key using an AES key in the B<KEKRecipientInfo> type.
429 =item B<-secretkeyid> I<id>
431 The key identifier for the supplied symmetric key for B<KEKRecipientInfo> type.
432 This option B<must> be present if the B<-secretkey> option is used with
433 B<-encrypt>. With B<-decrypt> operations the I<id> is used to locate the
434 relevant key if it is not supplied then an attempt is used to decrypt any
435 B<KEKRecipientInfo> structures.
437 =item B<-econtent_type> I<type>
439 Set the encapsulated content type to I<type> if not supplied the B<Data> type
440 is used. The I<type> argument can be any valid OID name in either text or
443 =item B<-inkey> I<file>
445 The private key to use when signing or decrypting. This must match the
446 corresponding certificate. If this option is not specified then the
447 private key must be included in the certificate file specified with
448 the B<-recip> or B<-signer> file. When signing this option can be used
449 multiple times to specify successive keys.
451 =item B<-keyopt> I<name>:I<parameter>
453 For signing and encryption this option can be used multiple times to
454 set customised parameters for the preceding key or certificate. It can
455 currently be used to set RSA-PSS for signing, RSA-OAEP for encryption
456 or to modify default parameters for ECDH.
458 =item B<-passin> I<arg>
460 The private key password source. For more information about the format of B<arg>
461 see L<openssl(1)/Pass Phrase Options>.
463 =item B<-to>, B<-from>, B<-subject>
465 The relevant mail headers. These are included outside the signed
466 portion of a message so they may be included manually. If signing
467 then many S/MIME mail clients check the signers certificate's email
468 address matches that specified in the From: address.
470 {- $OpenSSL::safe::opt_v_item -}
472 Any verification errors cause the command to exit.
474 {- $OpenSSL::safe::opt_trust_item -}
476 {- $OpenSSL::safe::opt_r_item -}
478 {- $OpenSSL::safe::opt_engine_item -}
480 =item I<cert.pem> ...
482 One or more certificates of message recipients: used when encrypting
489 The MIME message must be sent without any blank lines between the
490 headers and the output. Some mail programs will automatically add
491 a blank line. Piping the mail directly to sendmail is one way to
492 achieve the correct format.
494 The supplied message to be signed or encrypted must include the
495 necessary MIME headers or many S/MIME clients won't display it
496 properly (if at all). You can use the B<-text> option to automatically
497 add plain text headers.
499 A "signed and encrypted" message is one where a signed message is
500 then encrypted. This can be produced by encrypting an already signed
501 message: see the examples section.
503 This version of the program only allows one signer per message but it
504 will verify multiple signers on received messages. Some S/MIME clients
505 choke if a message contains multiple signers. It is possible to sign
506 messages "in parallel" by signing an already signed message.
508 The options B<-encrypt> and B<-decrypt> reflect common usage in S/MIME
509 clients. Strictly speaking these process CMS enveloped data: CMS
510 encrypted data is used for other purposes.
512 The B<-resign> option uses an existing message digest when adding a new
513 signer. This means that attributes must be present in at least one existing
514 signer using the same message digest or this operation will fail.
516 The B<-stream> and B<-indef> options enable streaming I/O support.
517 As a result the encoding is BER using indefinite length constructed encoding
518 and no longer DER. Streaming is supported for the B<-encrypt> operation and the
519 B<-sign> operation if the content is not detached.
521 Streaming is always used for the B<-sign> operation with detached data but
522 since the content is no longer part of the CMS structure the encoding
525 If the B<-decrypt> option is used without a recipient certificate then an
526 attempt is made to locate the recipient by trying each potential recipient
527 in turn using the supplied private key. To thwart the MMA attack
528 (Bleichenbacher's attack on PKCS #1 v1.5 RSA padding) all recipients are
529 tried whether they succeed or not and if no recipients match the message
530 is "decrypted" using a random key which will typically output garbage.
531 The B<-debug_decrypt> option can be used to disable the MMA attack protection
532 and return an error if no recipient can be found: this option should be used
533 with caution. For a fuller description see L<CMS_decrypt(3)>).
535 =head1 CADES BASIC ELECTRONIC SIGNATURE (CADES-BES)
537 A CAdES Basic Electronic Signature (CAdES-BES), as defined in the European Standard ETSI EN 319 122-1 V1.1.1, contains:
543 The signed user data as defined in CMS (RFC 3852);
547 Content-type of the EncapsulatedContentInfo value being signed;
551 Message-digest of the eContent OCTET STRING within encapContentInfo being signed;
555 An ESS signing-certificate or ESS signing-certificate-v2 attribute, as defined in Enhanced Security Services (ESS), RFC 2634 and RFC 5035.
556 An ESS signing-certificate attribute only allows for the use of SHA-1 as a digest algorithm.
557 An ESS signing-certificate-v2 attribute allows for the use of any digest algorithm.
561 The digital signature value computed on the user data and, when present, on the signed attributes.
563 Note that currently the B<-cades> option applies only to the B<-sign> operation and is ignored during
564 the B<-verify> operation, i.e. the signing certification is not checked during the verification process.
565 This feature might be added in a future version.
575 The operation was completely successfully.
579 An error occurred parsing the command options.
583 One of the input files could not be read.
587 An error occurred creating the CMS file or when reading the MIME
592 An error occurred decrypting or verifying the message.
596 The message was verified correctly but an error occurred writing out
597 the signers certificates.
601 =head1 COMPATIBILITY WITH PKCS#7 FORMAT
603 L<openssl-smime(1)> can only process the older B<PKCS#7> format.
604 B<openssl cms> supports Cryptographic Message Syntax format.
605 Use of some features will result in messages which cannot be processed by
606 applications which only support the older format. These are detailed below.
608 The use of the B<-keyid> option with B<-sign> or B<-encrypt>.
610 The B<-outform> I<PEM> option uses different headers.
612 The B<-compress> option.
614 The B<-secretkey> option when used with B<-encrypt>.
616 The use of PSS with B<-sign>.
618 The use of OAEP or non-RSA keys with B<-encrypt>.
620 Additionally the B<-EncryptedData_create> and B<-data_create> type cannot
621 be processed by the older L<openssl-smime(1)> command.
625 Create a cleartext signed message:
627 openssl cms -sign -in message.txt -text -out mail.msg \
630 Create an opaque signed message
632 openssl cms -sign -in message.txt -text -out mail.msg -nodetach \
635 Create a signed message, include some additional certificates and
636 read the private key from another file:
638 openssl cms -sign -in in.txt -text -out mail.msg \
639 -signer mycert.pem -inkey mykey.pem -certfile mycerts.pem
641 Create a signed message with two signers, use key identifier:
643 openssl cms -sign -in message.txt -text -out mail.msg \
644 -signer mycert.pem -signer othercert.pem -keyid
646 Send a signed message under Unix directly to sendmail, including headers:
648 openssl cms -sign -in in.txt -text -signer mycert.pem \
649 -from steve@openssl.org -to someone@somewhere \
650 -subject "Signed message" | sendmail someone@somewhere
652 Verify a message and extract the signer's certificate if successful:
654 openssl cms -verify -in mail.msg -signer user.pem -out signedtext.txt
656 Send encrypted mail using triple DES:
658 openssl cms -encrypt -in in.txt -from steve@openssl.org \
659 -to someone@somewhere -subject "Encrypted message" \
660 -des3 user.pem -out mail.msg
662 Sign and encrypt mail:
664 openssl cms -sign -in ml.txt -signer my.pem -text \
665 | openssl cms -encrypt -out mail.msg \
666 -from steve@openssl.org -to someone@somewhere \
667 -subject "Signed and Encrypted message" -des3 user.pem
669 Note: the encryption command does not include the B<-text> option because the
670 message being encrypted already has MIME headers.
674 openssl cms -decrypt -in mail.msg -recip mycert.pem -inkey key.pem
676 The output from Netscape form signing is a PKCS#7 structure with the
677 detached signature format. You can use this program to verify the
678 signature by line wrapping the base64 encoded structure and surrounding
681 -----BEGIN PKCS7-----
684 and using the command,
686 openssl cms -verify -inform PEM -in signature.pem -content content.txt
688 alternatively you can base64 decode the signature and use
690 openssl cms -verify -inform DER -in signature.der -content content.txt
692 Create an encrypted message using 128 bit Camellia:
694 openssl cms -encrypt -in plain.txt -camellia128 -out mail.msg cert.pem
696 Add a signer to an existing message:
698 openssl cms -resign -in mail.msg -signer newsign.pem -out mail2.msg
700 Sign mail using RSA-PSS:
702 openssl cms -sign -in message.txt -text -out mail.msg \
703 -signer mycert.pem -keyopt rsa_padding_mode:pss
705 Create encrypted mail using RSA-OAEP:
707 openssl cms -encrypt -in plain.txt -out mail.msg \
708 -recip cert.pem -keyopt rsa_padding_mode:oaep
710 Use SHA256 KDF with an ECDH certificate:
712 openssl cms -encrypt -in plain.txt -out mail.msg \
713 -recip ecdhcert.pem -keyopt ecdh_kdf_md:sha256
717 The MIME parser isn't very clever: it seems to handle most messages that I've
718 thrown at it but it may choke on others.
720 The code currently will only write out the signer's certificate to a file: if
721 the signer has a separate encryption certificate this must be manually
722 extracted. There should be some heuristic that determines the correct
723 encryption certificate.
725 Ideally a database should be maintained of a certificates for each email
728 The code doesn't currently take note of the permitted symmetric encryption
729 algorithms as supplied in the SMIMECapabilities signed attribute. this means the
730 user has to manually include the correct encryption algorithm. It should store
731 the list of permitted ciphers in a database and only use those.
733 No revocation checking is done on the signer's certificate.
737 L<ossl_store-file(7)>
741 The use of multiple B<-signer> options and the B<-resign> command were first
742 added in OpenSSL 1.0.0.
744 The B<-keyopt> option was added in OpenSSL 1.0.2.
746 Support for RSA-OAEP and RSA-PSS was added in OpenSSL 1.0.2.
748 The use of non-RSA keys with B<-encrypt> and B<-decrypt>
749 was added in OpenSSL 1.0.2.
751 The -no_alt_chains option was added in OpenSSL 1.0.2b.
755 Copyright 2008-2019 The OpenSSL Project Authors. All Rights Reserved.
757 Licensed under the Apache License 2.0 (the "License"). You may not use
758 this file except in compliance with the License. You can obtain a copy
759 in the file LICENSE in the source distribution or at
760 L<https://www.openssl.org/source/license.html>.