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" inopenssl(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 isEnvelopedData.
โ ๏ธ 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-verifyoperation.-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-inor-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 CMSDigestedDatatype.-digest_verifyโ verifies a CMSDigestedDatatype and outputs the content.-compressโ creates a CMSCompressedDatatype. OpenSSL has to be compiled with zlib support for this to work, otherwise it'll just output an error. ๐-uncompressโ uncompresses a CMSCompressedDatatype 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 CMSEncryptedDatatype, and outputs the content.-EncryptedData_decryptโ decrypts content using the supplied symmetric key and algorithm via a CMSEncryptedDatatype, and outputs the content.-data_createโ creates a CMSDatatype.-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 isSMIME. seeopenssl-format-options(1)for details.-outform DER|PEM|SMIMEโ the output format of the CMS structure (if one is being written); default isSMIME. seeopenssl-format-options(1)for details.-rctform DER|PEM|SMIMEโ the signed receipt format used with-receipt_verify; default isSMIME. seeopenssl-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,CRLFis 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,-encryptand-decryptoptions. when used with-encryptor-decrypt, the supplied key is used to wrap or unwrap the content encryption key using an AES key in theKEKRecipientInfotype.-secretkeyid idโ the key identifier for the supplied symmetric key, for theKEKRecipientInfotype. this option must be present if-secretkeyis used with-encrypt. with-decryptoperations, the id is used to locate the relevant key; if it's not supplied, then an attempt is used to decrypt anyKEKRecipientInfostructures.-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-recipor-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, seeopenssl-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. seeopenssl-format-options(1)for details.-provider name-provider-path path-provparam [name:]key=value-propquery propqโ see "Provider Options" inopenssl(1),provider(7), andproperty(7).-rand files,-writerand fileโ see "Random State Options" inopenssl(1)for details.
<div style="display:none"></div>
that's part 1 bestie, more coming ๐
๐ Encryption and decryption options ๐
-originatorfile โ 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 ๐-recipfile โ 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
-recipwhen 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 theEVP_get_cipherbyname()function knows โ can also be used, just slap a dash in front of it, like-aes-128-cbc. Peepopenssl-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-CBCis the default. This option is only used with the-encryptand-EncryptedData_encryptcommands. Know the difference bestie ๐ธ
-kekciphercipher โ 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 ๐-wrapcipher โ 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-wrapmight not be supported at all. It's giving "depends on your build" ๐-debug_decryptโ sets theCMS_DEBUG_DECRYPTflag. 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 takesOSSL_KDF_PARAM_KEYandOSSL_KDF_PARAM_INFOparameters and is otherwise fully defined by its name or OID works here โHKDF-SHA256, for example โจ-recip_ukmโ sets theKEMRecipientInfotype's optional user keying material (UKM) in hexadecimal form. That UKM gets encoded, along with other info, into theOSSL_KDF_PARAM_INFOparameter of theKEMRecipientInfotype's KDF. Very demure, very mindful ๐
๐ Signing options ๐
-mddigest โ 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 (usuallySHA-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 ๐
- Real talk though: if signed attributes are not being used (
-signerfile โ 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 ๐-certfilefile โ 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 inPEM,DER, orPKCS#12format โ three format girlies, we love range ๐-cadesโ when used with-sign, this adds anESS signingCertificateorESS signingCertificateV2signed-attribute to theSignerInfo, 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 typemultipart/signedis 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-certfileoption, 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-signoption, 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_fromis included. Read that again bestie, ignored ๐ฅ-receipt_request_fromemailaddress โ for the-signoption, this includes a signed receipt request. Adds an explicit email address where receipts should be supplied. Name the source, iconic ๐-receipt_request_toemailaddress โ 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 ๐ฆ
-signerfile โ 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 ๐-contentfilename โ names a file containing the detached content for operations that take S/MIME input, like the-verifycommand. 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 themultipart/signedMIME 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-certfileoption 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 ๐ข-CAfilefile,-no-CAfile,-CApathdir,-no-CApath,-CAstoreuri,-no-CAstoreโ peep "Trusted Certificate Options" inopenssl-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-signand-encryptoptions. ID over serial, we stan ๐-econtent_typetype โ sets the encapsulated content type to type. If you don't supply one, theDatatype 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 typetext/plain, an error occurs. Do not forget that part bestie ๐ญ-certsoutfile โ 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 theFrom:address. Match your vibes or get clocked ๐ต๏ธโโ๏ธ
โญ Printing options โญ
-nooutโ for the-cmsoutoperation, 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-cmsoutoperation, prints out all fields of the CMS structure. This implies-noout. It's mainly useful for testing purposes, so, you know โ debug girlie things ๐งช-nameoptoption โ for the-cmsoutoperation, when the-printoption is in use, this specifies printing options for string fields. For most cases,utf8is a reasonable value. Seeopenssl-namedisplay-options(1)for the details ๐-receipt_request_printโ for the-verifyoperation, 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" inopenssl-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-decryptoption 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_decryptoption 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 seeCMS_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-cadesoption applies to the-signor-verifyoperations. With this option, the-verifyoperation 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
-keyidoption with-signor-encrypt. - The
-outform PEMoption uses different headers. - The
-compressoption. - The
-secretkeyoption 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 ๐
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
- ubuntu stonking: openssl 4.0.3-1ubuntu1
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms