OPENSSL-CMS(1SSL)

๐ŸŽ€ OPENSSL-CMS ๐Ÿ’…

okay bestie, welcome to openssl-cms โ€” it's the CMS command from the OpenSSL fam, and she's basically the S/MIME v3.1 email whisperer. this is part 1 of 3, so grab a snack ๐Ÿ“ and let's get into it.


โœจ SYNOPSIS โœจ

openssl cms [-help]

General options:

[-in filename] [-out filename] [-config configfile]

Operation options:

[-encrypt] [-decrypt] [-sign] [-verify] [-resign] [-sign_receipt]
[-verify_receipt receipt] [-digest digest] [-digest_create]
[-digest_verify] [-compress] [-uncompress] [-EncryptedData_encrypt]
[-EncryptedData_decrypt] [-data_create] [-data_out] [-cmsout]

File format options:

[-inform DER|PEM|SMIME] [-outform DER|PEM|SMIME] [-rctform
DER|PEM|SMIME] [-stream] [-indef] [-noindef] [-binary] [-crlfeol]
[-asciicrlf]

Keys and password options:

[-pwri_password password] [-secretkey key] [-secretkeyid id] [-inkey
filename|uri] [-passin arg] [-keyopt name:parameter] [-keyform
DER|PEM|P12] [-provider name] [-provider-path path] [-provparam
[name:]key=value] [-propquery propq] [-rand files] [-writerand file]

Encryption options:

[-originator file] [-recip file] [recipient-cert ...]  [-cipher]
[-kekcipher cipher] [-wrap cipher] [-aes128-wrap] [-aes192-wrap]
[-aes256-wrap] [-des3-wrap] [-debug_decrypt] [-recip_kdf kdf]
[-recip_ukm ukm]

Signing options:

[-md digest] [-signer file] [-certfile file] [-cades] [-nodetach]
[-nocerts] [-noattr] [-nosmimecap] [-no_signing_time]
[-receipt_request_all] [-receipt_request_first] [-receipt_request_from
emailaddress] [-receipt_request_to emailaddress]

Verification options:

[-signer file] [-content filename] [-no_content_verify]
[-no_attr_verify] [-nosigs] [-noverify] [-nointern] [-cades]
[-verify_retcode] [-CAfile file] [-no-CAfile] [-CApath dir] [-no-CApath]
[-CAstore uri] [-no-CAstore]

Output options:

[-keyid] [-econtent_type type] [-text] [-certsout file] [-to addr]
[-from addr] [-subject subj]

Printing options:

[-noout] [-print] [-nameopt option] [-receipt_request_print]

Validation options:

[-allow_proxy_certs] [-attime timestamp] [-no_check_time]
[-check_ss_sig] [-crl_check] [-crl_check_all] [-explicit_policy]
[-extended_crl] [-ignore_critical] [-inhibit_any] [-inhibit_map]
[-partial_chain] [-policy arg] [-policy_check] [-policy_print] [-purpose
purpose] [-suiteB_128] [-suiteB_128_only] [-suiteB_192] [-trusted_first]
[-no_alt_chains] [-use_deltas] [-auth_level num] [-verify_depth num]
[-verify_email email] [-verify_hostname hostname] [-verify_ip ip]
[-verify_name name] [-x509_strict] [-issuer_checks]

๐ŸŒธ DESCRIPTION ๐ŸŒธ

so like, this command handles data in CMS format โ€” think S/MIME v3.1 email messages, that whole vibe. she can encrypt, decrypt, sign, verify, compress, uncompress, and print messages. icon behavior, honestly. ๐Ÿ‘‘


๐Ÿ’– OPTIONS ๐Ÿ’–

okay so there's a whole bunch of operation options that decide what kind of thing you're doing: encrypt, decrypt, sign, verify, resign, sign_receipt, verify_receipt, digest_create, digest_verify, compress, uncompress, EncryptedData_encrypt, EncryptedData_decrypt, data_create, data_out, or cmsout. the other options only make sense depending on which operation you picked, and their meaning can literally shift based on it. iykyk.

  • -help โ€” prints out a usage message, so you're not out here guessing. ๐Ÿซถ

๐ŸŒˆ General options

  • -in filename โ€” the input message: either the thing you're encrypting/signing, or the thing you're decrypting/verifying.
  • -out filename โ€” the output: either the decrypted/verified message text, or the output MIME format message that got signed/verified.
  • -config configfile โ€” peep "Configuration Option" in openssl(1) for the deets.

๐Ÿ”ฅ Operation options

  • -encrypt โ€” encrypts data for the given recipient certificates. input file is the message to encrypt, output file is the encrypted data in MIME format. the actual CMS type here is EnvelopedData.
โš ๏ธ bestie, listen: no revocation check is done for the recipient cert. so if that key has been compromised, other people may be able to decrypt the text. not ideal, be aware. ๐Ÿ˜ญ
  • -decrypt โ€” decrypts data using the supplied certificate and private key. expects encrypted data in MIME format as the input file. the decrypted data goes to the output file.
  • -sign โ€” signs data using the supplied certificate and private key. input file is the message to sign. the signed data in MIME format gets written to the output file. slay. โœ๏ธ
  • -verify โ€” verifies signed data. expects signed data on input and outputs the signed data. both clear text and opaque signing are supported. ๐Ÿ’…

by default, validation of signer certificates and their chain happens w.r.t. the S/MIME signing ("smimesign") purpose. for the nitty gritty, see "Certificate Extensions" in openssl-verification-options(1).

  • -resign โ€” resign a message: take an existing message and one or more new signers. glow up era. โœจ
  • -sign_receipt โ€” generates and outputs a signed receipt for the supplied message. the input message must contain a signed receipt request. other than that, it works just like -sign.
  • -verify_receipt receipt โ€” verifies a signed receipt in filename receipt. the input message must contain the original receipt request. otherwise it's basically the -verify operation.
  • -digest digest โ€” when used with -sign, this provides the digest in hexadecimal form instead of computing it from the original message content. cannot be combined with -in or -nodetach.

this operation is the CMS equivalent of openssl-pkeyutl(1) signing. when signing a pre-computed digest, the security relies on the digest and its computation from the original message being trusted. no pressure or anything. ๐Ÿ™ˆ

  • -digest_create โ€” creates a CMS DigestedData type.
  • -digest_verify โ€” verifies a CMS DigestedData type and outputs the content.
  • -compress โ€” creates a CMS CompressedData type. OpenSSL has to be compiled with zlib support for this to work, otherwise it'll just output an error. ๐Ÿ’€
  • -uncompress โ€” uncompresses a CMS CompressedData type and outputs the content. again, OpenSSL must be compiled with zlib support or it'll error out.
  • -EncryptedData_encrypt โ€” encrypts content using the supplied symmetric key and algorithm via a CMS EncryptedData type, and outputs the content.
  • -EncryptedData_decrypt โ€” decrypts content using the supplied symmetric key and algorithm via a CMS EncryptedData type, and outputs the content.
  • -data_create โ€” creates a CMS Data type.
  • -data_out โ€” Data type and output the content.
  • -cmsout โ€” takes an input message and writes out a PEM encoded CMS structure.

๐Ÿฆ‹ File format options

  • -inform DER|PEM|SMIME โ€” the input format of the CMS structure (if one is being read); default is SMIME. see openssl-format-options(1) for details.
  • -outform DER|PEM|SMIME โ€” the output format of the CMS structure (if one is being written); default is SMIME. see openssl-format-options(1) for details.
  • -rctform DER|PEM|SMIME โ€” the signed receipt format used with -receipt_verify; default is SMIME. see openssl-format-options(1) for details.
  • -stream, -indef โ€” these two are equivalent, and both enable streaming I/O for encoding operations. this lets you process data in a single pass without holding the entire contents in memory, which lowkey supports very large files. streaming is automatically set for S/MIME signing with detached data if the output format is SMIME. currently it's off by default for all other operations.
  • -noindef โ€” disables streaming I/O where it would produce an indefinite length constructed encoding. this option currently has no effect. in the future, streaming will be enabled by default on all relevant operations and this option will disable it. so it's giving very "coming soon" energy. ๐Ÿ”ฎ
  • -binary โ€” normally the input message is converted to "canonical" format, which effectively uses CR and LF as end of line โ€” as required by the S/MIME spec. when this option is present, no translation occurs. super useful when handling binary data that may not be in MIME format.
  • -crlfeol โ€” normally the output file uses a single LF as end of line. when this option is present, CRLF is used instead.
  • -asciicrlf โ€” when signing, use ASCII CRLF format canonicalisation. this strips trailing whitespace from all lines, deletes trailing blank lines at EOF, and sets the encapsulated content type. normally used with detached content and an output signature format of DER. you don't usually need it when verifying, because it gets enabled automatically if the encapsulated content format is detected. ๐ŸŽ€

๐Ÿ‘‘ Keys and password options

  • -pwri_password password โ€” specify password for recipient.
  • -secretkey key โ€” specify the symmetric key to use. the key must be supplied in hex format and must be consistent with the algorithm used. supported by the -EncryptedData_encrypt, -EncryptedData_decrypt, -encrypt and -decrypt options. when used with -encrypt or -decrypt, the supplied key is used to wrap or unwrap the content encryption key using an AES key in the KEKRecipientInfo type.
  • -secretkeyid id โ€” the key identifier for the supplied symmetric key, for the KEKRecipientInfo type. this option must be present if -secretkey is used with -encrypt. with -decrypt operations, the id is used to locate the relevant key; if it's not supplied, then an attempt is used to decrypt any KEKRecipientInfo structures.
  • -inkey filename|uri โ€” the private key to use when signing or decrypting. it has to match the corresponding certificate. if you don't specify this option, then the private key must be included in the certificate file specified with -recip or -signer. when signing, you can use this option multiple times to specify successive keys. ๐Ÿ’–
  • -passin arg โ€” the private key password source. for the format of arg, see openssl-passphrase-options(1).
  • -keyopt name:parameter โ€” for signing and encryption, this can be used multiple times to set customised parameters for the preceding key or certificate. right now it can set RSA-PSS for signing, RSA-OAEP for encryption, or modify the default parameters for ECDH.
  • -keyform DER|PEM|P12 โ€” the format of the private key file; unspecified by default. see openssl-format-options(1) for details.
  • -provider name
  • -provider-path path
  • -provparam [name:]key=value
  • -propquery propq โ€” see "Provider Options" in openssl(1), provider(7), and property(7).
  • -rand files, -writerand file โ€” see "Random State Options" in openssl(1) for details.

<div style="display:none"></div>

that's part 1 bestie, more coming ๐Ÿ’œ

๐Ÿ’– Encryption and decryption options ๐Ÿ’–

  • -originator file โ€” hands over a certificate for whoever โœจoriginatedโœจ the encrypted message. You need this for decryption when Key Agreement is what's being used to build a shared key. As of right now, it's not allowed for encryption, so don't even try bestie ๐Ÿ’…
  • -recip file โ€” okay so this one is a double agent, it means different things depending on the vibe:
    • When you're decrypting a message, this names the certificate of the recipient. The cert must line up with one of the actual recipients of the message, no fake ones ๐Ÿšซ
    • When you're encrypting a message, you can use this option multiple times to name every single recipient. And you must use this form if you need customised parameters (like specifying RSA-OAEP, iykyk)
    • Only certificates carrying RSA, Diffie-Hellman or EC keys are supported by this option. That's the whole list, periodt.
  • recipient-cert ... โ€” the alternative to -recip when you're encrypting. Just hand it one or more certificate filenames, easy ๐ŸŽ€
  • -cipher โ€” the encryption algorithm you wanna use. For example, AES (256 bits) is -aes256, or triple DES (168 bits) is -des3. Any standard algorithm name โ€” the kind the EVP_get_cipherbyname() function knows โ€” can also be used, just slap a dash in front of it, like -aes-128-cbc. Peep openssl-enc(1) for the list of ciphers your build of OpenSSL supports.
    • Currently, the AES variants with GCM mode are the only supported AEAD algorithms. That's it, that's the list.
    • If you don't specify anything, AES-256-CBC is the default. This option is only used with the -encrypt and -EncryptedData_encrypt commands. Know the difference bestie ๐ŸŒธ
  • -kekcipher cipher โ€” the cipher algorithm to use for password key encryption. This one matters when you've given a password for password recipient info via -pwri_password, and you've selected an AEAD encryption algorithm. In that exact situation, you should specify a non-AEAD algorithm with this option instead. Yes it's specific, no it's not optional ๐Ÿ™ˆ
  • -wrap cipher โ€” the cipher algorithm to use for key wrap when you're encrypting the message using Key Agreement for key transport. Whatever algorithm you pick should actually be suitable for key wrap, so pick wisely ๐Ÿงš
  • -aes128-wrap, -aes192-wrap, -aes256-wrap, -des3-wrap โ€” use AES128, AES192, AES256, or 3DES-EDE, respectively, to wrap the key. Heads up though: depending on the OpenSSL build options used, -des3-wrap might not be supported at all. It's giving "depends on your build" ๐Ÿ’€
  • -debug_decrypt โ€” sets the CMS_DEBUG_DECRYPT flag. Use this one with caution, okay? See the NOTES section below for the whole story. Don't come crying to me ๐Ÿ˜ญ
  • -recip_kdf โ€” sets the KDF used to generate the key encryption key in the KEMRecipientInfo type. Any KDF that takes OSSL_KDF_PARAM_KEY and OSSL_KDF_PARAM_INFO parameters and is otherwise fully defined by its name or OID works here โ€” HKDF-SHA256, for example โœจ
  • -recip_ukm โ€” sets the KEMRecipientInfo type's optional user keying material (UKM) in hexadecimal form. That UKM gets encoded, along with other info, into the OSSL_KDF_PARAM_INFO parameter of the KEMRecipientInfo type's KDF. Very demure, very mindful ๐Ÿ’œ

๐ŸŒˆ Signing options ๐ŸŒˆ

  • -md digest โ€” the digest algorithm to use when signing or resigning. If you don't include it, the default digest algorithm for the signing key is used (usually SHA-256).
    • Real talk though: if signed attributes are not being used (-noattr), for some hash-less signing schemes the digest algorithm you gave will be ignored, and the digest algorithm the signing scheme requires gets used instead. That's the case for EdDSA (RFC 8419). For SLH-DSA (RFC 9814) and ML-DSA (RFC 9882), the scheme-suggested digest algorithm is only used if you gave none at all. Not me explaining RFCs in a group chat ๐Ÿ’€
  • -signer file โ€” a signing certificate. When you're signing or resigning a message, you can use this option multiple times if you've got more than one signer. Slay, polycert ๐Ÿ’…
  • -certfile file โ€” lets you add extra certificates. When you're signing, these get included with the message. When you're verifying, they get searched for signer certificates and used for chain building. The input can be in PEM, DER, or PKCS#12 format โ€” three format girlies, we love range ๐ŸŽ€
  • -cades โ€” when used with -sign, this adds an ESS signingCertificate or ESS signingCertificateV2 signed-attribute to the SignerInfo, so the signature complies with the requirements for a CAdES Basic Electronic Signature (CAdES-BES). Fancy gorgeous certified signature energy โœจ
  • -nodetach โ€” when signing a message, this gives you opaque signing: that form is more resistant to translation by mail relays, but it cannot be read by mail agents that don't support S/MIME. Without this option, cleartext signing with the MIME type multipart/signed is used. Tradeoffs, bestie ๐Ÿฆ‹
  • -nocerts โ€” normally when signing a message, the signer's certificate is included. With this option, it's excluded. This shrinks the signed message, but the verifier must have a copy of the signer's certificate available locally โ€” passed using the -certfile option, for example. No cert, no party ๐Ÿšซ
  • -noattr โ€” normally when a message is signed, a set of attributes is included, featuring the signing time and the supported symmetric algorithms. With this option, they are not included. Poof, gone ๐Ÿ’จ
  • -nosmimecap โ€” excludes the list of supported algorithms from the signed attributes. Other options like content type and (optionally) signing time are still included though. Sleepy but not asleep ๐Ÿ˜ด
  • -no_signing_time โ€” excludes the signing time from the signed attributes. Other options like content type are still included. Late to the function, still on the guest list ๐ŸŽŸ๏ธ
  • -receipt_request_all, -receipt_request_first โ€” for the -sign option, these include a signed receipt request. Indicate that requests should be provided by all recipients, or by first tier recipients (those mailed directly and not from a mailing list). This option is ignored if -receipt_request_from is included. Read that again bestie, ignored ๐Ÿ”ฅ
  • -receipt_request_from emailaddress โ€” for the -sign option, this includes a signed receipt request. Adds an explicit email address where receipts should be supplied. Name the source, iconic ๐Ÿ’Œ
  • -receipt_request_to emailaddress โ€” adds an explicit email address where signed receipts should be sent to. This option must be supplied if a signed receipt is requested. No skipping this one, it's mandatory periodt ๐Ÿ’…

๐Ÿฆ‹ Verification options ๐Ÿฆ‹

  • -signer file โ€” yes, it's back, different job. If a message has been verified successfully, the signer's certificate(s) get written to this file when verification succeeded. Same name, new purpose, main character energy ๐Ÿ‘‘
  • -content filename โ€” names a file containing the detached content for operations that take S/MIME input, like the -verify command. This only works if the CMS structure is using the detached signature form where the content isn't included. It will override any content if the input format is S/MIME and it uses the multipart/signed MIME content type. Override era ๐Ÿ˜ค
  • -no_content_verify โ€” do not verify signed content signatures. Skip it, we're moving on ๐Ÿƒโ€โ™€๏ธ
  • -no_attr_verify โ€” do not verify signed attribute signatures. Same energy honestly ๐Ÿ™ˆ
  • -nosigs โ€” don't verify the message signature. At all. Bold of you, but okay ๐Ÿ“
  • -noverify โ€” do not verify the signer's certificate of a signed message. We're trusting blindly today I guess ๐Ÿ˜ญ
  • -nointern โ€” normally when verifying a message, the certificates included in the message (if there are any) are searched for the signing certificate. With this option, only the certificates specified in the -certfile option are used. The supplied certificates can still be used as untrusted CAs though. Local only, no outside vibes ๐Ÿงš
  • -cades โ€” when used with -verify, this requires and checks the signer certificate digest. See the NOTES section for more details. It's not just for signing, okurrr โœจ
  • -verify_retcode โ€” exit nonzero on verification failure. Loud and clear, no silent failures over here ๐Ÿ“ข
  • -CAfile file, -no-CAfile, -CApath dir, -no-CApath, -CAstore uri, -no-CAstore โ€” peep "Trusted Certificate Options" in openssl-verification-options(1) for the details. Whole squad of trust options ๐Ÿ’œ

๐ŸŽ€ Output options ๐ŸŽ€

  • -keyid โ€” use the subject key identifier to identify certificates instead of the issuer name and serial number. The certificate you supply must include a subject key identifier extension. Supported by the -sign and -encrypt options. ID over serial, we stan ๐Ÿ’…
  • -econtent_type type โ€” sets the encapsulated content type to type. If you don't supply one, the Data type is used. The type argument can be any valid OID name in either text or numerical format. Flexible queen โœจ
  • -text โ€” this option adds plain text (text/plain) MIME headers to the supplied message if you're encrypting or signing. If you're decrypting or verifying, it strips off text headers: and if the decrypted or verified message isn't of MIME type text/plain, an error occurs. Do not forget that part bestie ๐Ÿ˜ญ
  • -certsout file โ€” any certificates contained in the input message get written to file. Collect them all ๐ŸŽ
  • -to, -from, -subject โ€” the relevant email headers. These are included outside the signed portion of a message, so they may be included manually. If you're signing, lots of S/MIME mail clients check that the signer's certificate email address matches what's specified in the From: address. Match your vibes or get clocked ๐Ÿ•ต๏ธโ€โ™€๏ธ

โญ Printing options โญ

  • -noout โ€” for the -cmsout operation, this stops the parsed CMS structure from being output. Super useful if you're just checking the syntax of the CMS structure. Silent but useful ๐ŸŒธ
  • -print โ€” for the -cmsout operation, prints out all fields of the CMS structure. This implies -noout. It's mainly useful for testing purposes, so, you know โ€” debug girlie things ๐Ÿงช
  • -nameopt option โ€” for the -cmsout operation, when the -print option is in use, this specifies printing options for string fields. For most cases, utf8 is a reasonable value. See openssl-namedisplay-options(1) for the details ๐ŸŽ€
  • -receipt_request_print โ€” for the -verify operation, this prints out the contents of any signed receipt requests. Show me the receipts ๐Ÿ‘€

๐Ÿ’œ Validation options ๐Ÿ’œ

  • -allow_proxy_certs, -attime, -no_check_time, -check_ss_sig, -crl_check, -crl_check_all, -explicit_policy, -extended_crl, -ignore_critical, -inhibit_any, -inhibit_map, -no_alt_chains, -partial_chain, -policy, -policy_check, -policy_print, -purpose, -suiteB_128, -suiteB_128_only, -suiteB_192, -trusted_first, -use_deltas, -auth_level, -verify_depth, -verify_email, -verify_hostname, -verify_ip, -verify_name, -x509_strict, -issuer_checks โ€” this whole gorgeous lineup sets various options of certificate chain verification. See "Verification Options" in openssl-verification-options(1) for the details.
Heads up: any validation errors cause the command to exit. No warnings, no second chances, just bye โœŒ๏ธ

๐Ÿ’Œ NOTES ๐Ÿ’Œ

okay so before you go yeeting mail at people, listen up bestie:

The MIME message must be sent with zero blank lines between the headers and the output. Some mail programs will just helpfully add one for you (rude), so piping the mail directly to sendmail is one way to get the format right.

The message you hand over to be signed or encrypted must include the necessary MIME headers, otherwise a lot of S/MIME clients won't display it properly โ€” if they display it at all ๐Ÿ˜ญ. You can use the -text option to auto-add plain text headers, so that's your bestie there.

A "signed and encrypted" message is literally just a signed message that then gets encrypted. You can make one by encrypting an already-signed message โ€” the examples section has the receipts. โœจ

This version of the program only allows one signer per message, but it will verify multiple signers on messages it receives. Some S/MIME clients choke if a message contains multiple signers, so. It is possible to sign messages "in parallel" by signing an already signed message.

The options -encrypt and -decrypt reflect common usage in S/MIME clients. Strictly speaking these process CMS enveloped data: CMS encrypted data is used for other purposes. iykyk.

The -resign option uses an existing message digest when adding a new signer. Which means attributes must be present in at least one existing signer using the same message digest, or this operation will fail. no cap.

The -stream and -indef options enable streaming I/O support. As a result the encoding is BER using indefinite length constructed encoding and no longer DER. Streaming is supported for the -encrypt operation and the -sign operation if the content is not detached.

Streaming is always used for the -sign operation with detached data, but since the content is no longer part of the CMS structure, the encoding remains DER. slay, consistent.

๐Ÿšจ okay this next one is giving actual hacker movie plot. If the -decrypt option is used without a recipient certificate, then an attempt is made to locate the recipient by trying each potential recipient in turn using the supplied private key. To thwart the MMA attack (Bleichenbacher's attack on PKCS #1 v1.5 RSA padding) all recipients are tried whether they succeed or not, and if no recipients match the message is "decrypted" using a random key โ€” which will typically output garbage. The -debug_decrypt option can be used to disable the MMA attack protection and return an error if no recipient can be found: this option should be used with caution. For a fuller description see CMS_decrypt(3).

๐ŸŽ€ CADES BASIC ELECTRONIC SIGNATURE (CADES-BES) ๐ŸŽ€

A CAdES Basic Electronic Signature (CAdES-BES), as defined in the European Standard ETSI EN 319 122-1 V1.1.1, contains:

  • The signed user data as defined in CMS (RFC 3852);
  • Content-type of the EncapsulatedContentInfo value being signed;
  • Message-digest of the eContent OCTET STRING within encapContentInfo being signed;
  • An ESS signingCertificate or ESS signingCertificateV2 attribute, as defined in Enhanced Security Services (ESS), RFC 2634 and RFC 5035. An ESS signingCertificate attribute only allows for SHA-1 as digest algorithm. An ESS signingCertificateV2 attribute allows for any digest algorithm.
  • The digital signature value computed on the user data and, when present, on the signed attributes.
๐Ÿ’œ NOTE that the -cades option applies to the -sign or -verify operations. With this option, the -verify operation also requires that the signingCertificate attribute is present and checks that the given identifiers match the verification trust chain built during the verification process.

๐ŸŒˆ EXIT CODES ๐ŸŒˆ

  • 0 โ€” The operation was completely successfully. (iconic behaviour ๐Ÿ’…)
  • 1 โ€” An error occurred parsing the command options.
  • 2 โ€” One of the input files could not be read.
  • 3 โ€” An error occurred creating the CMS file or when reading the MIME message.
  • 4 โ€” An error occurred decrypting or verifying the message.
  • 5 โ€” The message was verified correctly but an error occurred writing out the signers certificates. (so close, bestie ๐Ÿ˜ญ)

๐Ÿ’€ COMPATIBILITY WITH PKCS#7 FORMAT ๐Ÿ’€

openssl-smime(1) can only process the older PKCS#7 format. openssl cms supports Cryptographic Message Syntax format. Use of some features will result in messages which cannot be processed by applications which only support the older format. These are detailed below, don't say I didn't warn you:

  • The use of the -keyid option with -sign or -encrypt.
  • The -outform PEM option uses different headers.
  • The -compress option.
  • The -secretkey option when used with -encrypt.
  • The use of PSS with -sign.
  • The use of OAEP or non-RSA keys with -encrypt.

Additionally the -EncryptedData_encrypt and -data_create type cannot be processed by the older openssl-smime(1) command. rip to the legacy apps fr.


โœจ EXAMPLES โœจ

okay bestie this is the fun part, let's go ๐Ÿฆ‹

Create a cleartext signed message:

openssl cms -sign -in message.txt -text -out mail.msg \
       -signer mycert.pem

Create an opaque signed message

openssl cms -sign -in message.txt -text -out mail.msg -nodetach \
       -signer mycert.pem

Create a signed message, include some additional certificates and read the private key from another file:

openssl cms -sign -in in.txt -text -out mail.msg \
       -signer mycert.pem -inkey mykey.pem -certfile mycerts.pem

Create a signed message with two signers, use key identifier:

openssl cms -sign -in message.txt -text -out mail.msg \
       -signer mycert.pem -signer othercert.pem -keyid

Send a signed message under Unix directly to sendmail, including headers:

openssl cms -sign -in in.txt -text -signer mycert.pem \
       -from steve@openssl.org -to someone@somewhere \
       -subject "Signed message" | sendmail someone@somewhere

Verify a message and extract the signer's certificate if successful:

openssl cms -verify -in mail.msg -signer user.pem -out signedtext.txt

Send encrypted mail using triple DES:

openssl cms -encrypt -in in.txt -from steve@openssl.org \
       -to someone@somewhere -subject "Encrypted message" \
       -des3 user.pem -out mail.msg

Sign and encrypt mail:

openssl cms -sign -in ml.txt -signer my.pem -text \
       | openssl cms -encrypt -out mail.msg \
       -from steve@openssl.org -to someone@somewhere \
       -subject "Signed and Encrypted message" -des3 user.pem
๐Ÿ“Œ Note: the encryption command does not include the -text option because the message being encrypted already has MIME headers.

Decrypt a message:

openssl cms -decrypt -in mail.msg -recip mycert.pem -inkey key.pem

The output from Netscape form signing is a PKCS#7 structure with the detached signature format. You can use this program to verify the signature by line wrapping the base64 encoded structure and surrounding it with:

-----BEGIN PKCS7-----
-----END PKCS7-----

and using the command,

openssl cms -verify -inform PEM -in signature.pem -content content.txt

alternatively you can base64 decode the signature and use

openssl cms -verify -inform DER -in signature.der -content content.txt

Create an encrypted message using 128 bit Camellia:

openssl cms -encrypt -in plain.txt -camellia128 -out mail.msg cert.pem

Add a signer to an existing message:

openssl cms -resign -in mail.msg -signer newsign.pem -out mail2.msg

Sign a message using RSA-PSS:

openssl cms -sign -in message.txt -text -out mail.msg \
       -signer mycert.pem -keyopt rsa_padding_mode:pss

Create an encrypted message using RSA-OAEP:

openssl cms -encrypt -in plain.txt -out mail.msg \
       -recip cert.pem -keyopt rsa_padding_mode:oaep

Use SHA256 KDF with an ECDH certificate:

openssl cms -encrypt -in plain.txt -out mail.msg \
       -recip ecdhcert.pem -keyopt ecdh_kdf_md:sha256

Print CMS signed binary data in human-readable form:

openssl cms -in signed.cms -binary -inform DER -cmsout -print

๐Ÿ™ˆ BUGS ๐Ÿ™ˆ

ngl, there's a list. Here's the honest tea:

The MIME parser isn't very clever: it seems to handle most messages that I've thrown at it but it may choke on others. ๐Ÿ˜ฌ

The code currently will only write out the signer's certificate to a file: if the signer has a separate encryption certificate this must be manually extracted. There should be some heuristic that determines the correct encryption certificate. (manifesting that for a future release โœจ)

Ideally a database should be maintained of a certificates for each email address.

The code doesn't currently take note of the permitted symmetric encryption algorithms as supplied in the SMIMECapabilities signed attribute. this means the user has to manually include the correct encryption algorithm. It should store the list of permitted ciphers in a database and only use those.

No revocation checking is done on the signer's certificate. ๐Ÿ’€

Ed448 signing is not supported when using signed-data with signed attributes since OpenSSL does not currently support the digestAlgorithm id-shake256-len as required per RFC 8419.


๐Ÿซถ SEE ALSO ๐Ÿซถ


๐Ÿ‘‘ HISTORY ๐Ÿ‘‘

The default encryption cipher was changed from 3DES to AES-256 in OpenSSL 3.5.

The use of multiple -signer options and the -resign command were first added in OpenSSL 1.0.0.

The -keyopt option was added in OpenSSL 1.0.2.

Support for RSA-OAEP and RSA-PSS was added in OpenSSL 1.0.2.

The use of non-RSA keys with -encrypt and -decrypt was added in OpenSSL 1.0.2.

The -no_alt_chains option was added in OpenSSL 1.0.2b.

The -nameopt option was added in OpenSSL 3.0.0.

The -digest option was added in OpenSSL 3.2.

The -recip_kdf and -recip_ukm options were added in OpenSSL 3.6.

The -engine option was removed in OpenSSL 4.0. (gone but never forgotten ๐Ÿ•Š๏ธ)


Copyright 2008-2026 The OpenSSL Project Authors. All Rights Reserved.

Licensed under the Apache License 2.0 (the "License"). You may not use this file except in compliance with the License. You can obtain a copy in the file LICENSE in the source distribution or at <https://www.openssl.org/source/license.html>.


and that's the whole page bestie, you made it to the end ๐ŸŽ‰ this was OPENSSL-CMS(1SSL) from version 4.0.3, dated 2026-09-29 โ€” go forth and sign your little heart out ๐Ÿ’–๐ŸŒธ๐Ÿฆ‹

๐Ÿ“ฆ where this page comes from