openssl-cms.pod.in 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925
  1. =pod
  2. {- OpenSSL::safe::output_do_not_edit_headers(); -}
  3. =head1 NAME
  4. openssl-cms - CMS command
  5. =head1 SYNOPSIS
  6. B<openssl> B<cms>
  7. [B<-help>]
  8. General options:
  9. [B<-in> I<filename>]
  10. [B<-out> I<filename>]
  11. {- $OpenSSL::safe::opt_config_synopsis -}
  12. Operation options:
  13. [B<-encrypt>]
  14. [B<-decrypt>]
  15. [B<-sign>]
  16. [B<-verify>]
  17. [B<-resign>]
  18. [B<-sign_receipt>]
  19. [B<-verify_receipt> I<receipt>]
  20. [B<-digest> I<digest>]
  21. [B<-digest_create>]
  22. [B<-digest_verify>]
  23. [B<-compress>]
  24. [B<-uncompress>]
  25. [B<-EncryptedData_encrypt>]
  26. [B<-EncryptedData_decrypt>]
  27. [B<-data_create>]
  28. [B<-data_out>]
  29. [B<-cmsout>]
  30. File format options:
  31. [B<-inform> B<DER>|B<PEM>|B<SMIME>]
  32. [B<-outform> B<DER>|B<PEM>|B<SMIME>]
  33. [B<-rctform> B<DER>|B<PEM>|B<SMIME>]
  34. [B<-stream>]
  35. [B<-indef>]
  36. [B<-noindef>]
  37. [B<-binary>]
  38. [B<-crlfeol>]
  39. [B<-asciicrlf>]
  40. Keys and password options:
  41. [B<-pwri_password> I<password>]
  42. [B<-secretkey> I<key>]
  43. [B<-secretkeyid> I<id>]
  44. [B<-inkey> I<filename>|I<uri>]
  45. [B<-passin> I<arg>]
  46. [B<-keyopt> I<name>:I<parameter>]
  47. [B<-keyform> B<DER>|B<PEM>|B<P12>|B<ENGINE>]
  48. {- $OpenSSL::safe::opt_engine_synopsis -}{- $OpenSSL::safe::opt_provider_synopsis -}
  49. {- $OpenSSL::safe::opt_r_synopsis -}
  50. Encryption options:
  51. [B<-originator> I<file>]
  52. [B<-recip> I<file>]
  53. [I<recipient-cert> ...]
  54. [B<-I<cipher>>]
  55. [B<-wrap> I<cipher>]
  56. [B<-aes128-wrap>]
  57. [B<-aes192-wrap>]
  58. [B<-aes256-wrap>]
  59. [B<-des3-wrap>]
  60. [B<-debug_decrypt>]
  61. Signing options:
  62. [B<-md> I<digest>]
  63. [B<-signer> I<file>]
  64. [B<-certfile> I<file>]
  65. [B<-cades>]
  66. [B<-nodetach>]
  67. [B<-nocerts>]
  68. [B<-noattr>]
  69. [B<-nosmimecap>]
  70. [B<-receipt_request_all>]
  71. [B<-receipt_request_first>]
  72. [B<-receipt_request_from> I<emailaddress>]
  73. [B<-receipt_request_to> I<emailaddress>]
  74. Verification options:
  75. [B<-signer> I<file>]
  76. [B<-content> I<filename>]
  77. [B<-no_content_verify>]
  78. [B<-no_attr_verify>]
  79. [B<-nosigs>]
  80. [B<-noverify>]
  81. [B<-nointern>]
  82. [B<-cades>]
  83. [B<-verify_retcode>]
  84. {- $OpenSSL::safe::opt_trust_synopsis -}
  85. Output options:
  86. [B<-keyid>]
  87. [B<-econtent_type> I<type>]
  88. [B<-text>]
  89. [B<-certsout> I<file>]
  90. [B<-to> I<addr>]
  91. [B<-from> I<addr>]
  92. [B<-subject> I<subj>]
  93. Printing options:
  94. [B<-noout>]
  95. [B<-print>]
  96. [B<-nameopt> I<option>]
  97. [B<-receipt_request_print>]
  98. Validation options:
  99. {- $OpenSSL::safe::opt_v_synopsis -}
  100. =head1 DESCRIPTION
  101. This command handles data in CMS format such as S/MIME v3.1 email messages.
  102. It can encrypt, decrypt, sign, verify, compress, uncompress, and print messages.
  103. =head1 OPTIONS
  104. There are a number of operation options that set the type of operation to be
  105. performed: encrypt, decrypt, sign, verify, resign, sign_receipt, verify_receipt,
  106. digest_create, digest_verify, compress, uncompress,
  107. EncryptedData_encrypt, EncryptedData_decrypt, data_create, data_out, or cmsout.
  108. The relevance of the other options depends on the operation type
  109. and their meaning may vary according to it.
  110. =over 4
  111. =item B<-help>
  112. Print out a usage message.
  113. =back
  114. =head2 General options
  115. =over 4
  116. =item B<-in> I<filename>
  117. The input message to be encrypted or signed or the message to be decrypted
  118. or verified.
  119. =item B<-out> I<filename>
  120. The message text that has been decrypted or verified or the output MIME
  121. format message that has been signed or verified.
  122. {- $OpenSSL::safe::opt_config_item -}
  123. =back
  124. =head2 Operation options
  125. =over 4
  126. =item B<-encrypt>
  127. Encrypt data for the given recipient certificates. Input file is the message
  128. to be encrypted. The output file is the encrypted data in MIME format. The
  129. actual CMS type is B<EnvelopedData>.
  130. Note that no revocation check is done for the recipient cert, so if that
  131. key has been compromised, others may be able to decrypt the text.
  132. =item B<-decrypt>
  133. Decrypt data using the supplied certificate and private key. Expects
  134. encrypted datain MIME format for the input file. The decrypted data
  135. is written to the output file.
  136. =item B<-sign>
  137. Sign data using the supplied certificate and private key. Input file is
  138. the message to be signed. The signed data in MIME format is written
  139. to the output file.
  140. =item B<-verify>
  141. Verify signed data. Expects a signed data on input and outputs
  142. the signed data. Both clear text and opaque signing is supported.
  143. =item B<-resign>
  144. Resign a message: take an existing message and one or more new signers.
  145. =item B<-sign_receipt>
  146. Generate and output a signed receipt for the supplied message. The input
  147. message B<must> contain a signed receipt request. Functionality is otherwise
  148. similar to the B<-sign> operation.
  149. =item B<-verify_receipt> I<receipt>
  150. Verify a signed receipt in filename B<receipt>. The input message B<must>
  151. contain the original receipt request. Functionality is otherwise similar
  152. to the B<-verify> operation.
  153. =item B<-digest> I<digest>
  154. When used with B<-sign>, provides the digest in hexadecimal form instead of
  155. computing it from the original message content. Cannot be combined with B<-in>
  156. or B<-nodetach>.
  157. This operation is the CMS equivalent of L<openssl-pkeyutl(1)> signing.
  158. When signing a pre-computed digest, the security relies on the digest and its
  159. computation from the original message being trusted.
  160. =item B<-digest_create>
  161. Create a CMS B<DigestedData> type.
  162. =item B<-digest_verify>
  163. Verify a CMS B<DigestedData> type and output the content.
  164. =item B<-compress>
  165. Create a CMS B<CompressedData> type. OpenSSL must be compiled with B<zlib>
  166. support for this option to work, otherwise it will output an error.
  167. =item B<-uncompress>
  168. Uncompress a CMS B<CompressedData> type and output the content. OpenSSL must be
  169. compiled with B<zlib> support for this option to work, otherwise it will
  170. output an error.
  171. =item B<-EncryptedData_encrypt>
  172. Encrypt content using supplied symmetric key and algorithm using a CMS
  173. B<EncryptedData> type and output the content.
  174. =item B<-EncryptedData_decrypt>
  175. Decrypt content using supplied symmetric key and algorithm using a CMS
  176. B<EncryptedData> type and output the content.
  177. =item B<-data_create>
  178. Create a CMS B<Data> type.
  179. =item B<-data_out>
  180. B<Data> type and output the content.
  181. =item B<-cmsout>
  182. Takes an input message and writes out a PEM encoded CMS structure.
  183. =back
  184. =head2 File format options
  185. =over 4
  186. =item B<-inform> B<DER>|B<PEM>|B<SMIME>
  187. The input format of the CMS structure (if one is being read);
  188. the default is B<SMIME>.
  189. See L<openssl-format-options(1)> for details.
  190. =item B<-outform> B<DER>|B<PEM>|B<SMIME>
  191. The output format of the CMS structure (if one is being written);
  192. the default is B<SMIME>.
  193. See L<openssl-format-options(1)> for details.
  194. =item B<-rctform> B<DER>|B<PEM>|B<SMIME>
  195. The signed receipt format for use with the B<-receipt_verify>; the default
  196. is B<SMIME>.
  197. See L<openssl-format-options(1)> for details.
  198. =item B<-stream>, B<-indef>
  199. The B<-stream> and B<-indef> options are equivalent and enable streaming I/O
  200. for encoding operations. This permits single pass processing of data without
  201. the need to hold the entire contents in memory, potentially supporting very
  202. large files. Streaming is automatically set for S/MIME signing with detached
  203. data if the output format is B<SMIME> it is currently off by default for all
  204. other operations.
  205. =item B<-noindef>
  206. Disable streaming I/O where it would produce and indefinite length constructed
  207. encoding. This option currently has no effect. In future streaming will be
  208. enabled by default on all relevant operations and this option will disable it.
  209. =item B<-binary>
  210. Normally the input message is converted to "canonical" format which is
  211. effectively using CR and LF as end of line: as required by the S/MIME
  212. specification. When this option is present no translation occurs. This
  213. is useful when handling binary data which may not be in MIME format.
  214. =item B<-crlfeol>
  215. Normally the output file uses a single B<LF> as end of line. When this
  216. option is present B<CRLF> is used instead.
  217. =item B<-asciicrlf>
  218. When signing use ASCII CRLF format canonicalisation. This strips trailing
  219. whitespace from all lines, deletes trailing blank lines at EOF and sets
  220. the encapsulated content type. This option is normally used with detached
  221. content and an output signature format of DER. This option is not normally
  222. needed when verifying as it is enabled automatically if the encapsulated
  223. content format is detected.
  224. =back
  225. =head2 Keys and password options
  226. =over 4
  227. =item B<-pwri_password> I<password>
  228. Specify password for recipient.
  229. =item B<-secretkey> I<key>
  230. Specify symmetric key to use. The key must be supplied in hex format and be
  231. consistent with the algorithm used. Supported by the B<-EncryptedData_encrypt>
  232. B<-EncryptedData_decrypt>, B<-encrypt> and B<-decrypt> options. When used
  233. with B<-encrypt> or B<-decrypt> the supplied key is used to wrap or unwrap the
  234. content encryption key using an AES key in the B<KEKRecipientInfo> type.
  235. =item B<-secretkeyid> I<id>
  236. The key identifier for the supplied symmetric key for B<KEKRecipientInfo> type.
  237. This option B<must> be present if the B<-secretkey> option is used with
  238. B<-encrypt>. With B<-decrypt> operations the I<id> is used to locate the
  239. relevant key if it is not supplied then an attempt is used to decrypt any
  240. B<KEKRecipientInfo> structures.
  241. =item B<-inkey> I<filename>|I<uri>
  242. The private key to use when signing or decrypting. This must match the
  243. corresponding certificate. If this option is not specified then the
  244. private key must be included in the certificate file specified with
  245. the B<-recip> or B<-signer> file. When signing this option can be used
  246. multiple times to specify successive keys.
  247. =item B<-passin> I<arg>
  248. The private key password source. For more information about the format of B<arg>
  249. see L<openssl-passphrase-options(1)>.
  250. =item B<-keyopt> I<name>:I<parameter>
  251. For signing and encryption this option can be used multiple times to
  252. set customised parameters for the preceding key or certificate. It can
  253. currently be used to set RSA-PSS for signing, RSA-OAEP for encryption
  254. or to modify default parameters for ECDH.
  255. =item B<-keyform> B<DER>|B<PEM>|B<P12>|B<ENGINE>
  256. The format of the private key file; unspecified by default.
  257. See L<openssl-format-options(1)> for details.
  258. {- $OpenSSL::safe::opt_engine_item -}
  259. {- $OpenSSL::safe::opt_provider_item -}
  260. {- $OpenSSL::safe::opt_r_item -}
  261. =back
  262. =head2 Encryption and decryption options
  263. =over 4
  264. =item B<-originator> I<file>
  265. A certificate of the originator of the encrypted message. Necessary for
  266. decryption when Key Agreement is in use for a shared key.
  267. =item B<-recip> I<file>
  268. When decrypting a message this specifies the certificate of the recipient.
  269. The certificate must match one of the recipients of the message.
  270. When encrypting a message this option may be used multiple times to specify
  271. each recipient. This form B<must> be used if customised parameters are
  272. required (for example to specify RSA-OAEP).
  273. Only certificates carrying RSA, Diffie-Hellman or EC keys are supported by this
  274. option.
  275. =item I<recipient-cert> ...
  276. This is an alternative to using the B<-recip> option when encrypting a message.
  277. One or more certificate filenames may be given.
  278. =item B<-I<cipher>>
  279. The encryption algorithm to use. For example triple DES (168 bits) - B<-des3>
  280. or 256 bit AES - B<-aes256>. Any standard algorithm name (as used by the
  281. EVP_get_cipherbyname() function) can also be used preceded by a dash, for
  282. example B<-aes-128-cbc>. See L<openssl-enc(1)> for a list of ciphers
  283. supported by your version of OpenSSL.
  284. Currently the AES variants with GCM mode are the only supported AEAD
  285. algorithms.
  286. If not specified triple DES is used. Only used with B<-encrypt> and
  287. B<-EncryptedData_create> commands.
  288. =item B<-wrap> I<cipher>
  289. Cipher algorithm to use for key wrap when encrypting the message using Key
  290. Agreement for key transport. The algorithm specified should be suitable for key
  291. wrap.
  292. =item B<-aes128-wrap>, B<-aes192-wrap>, B<-aes256-wrap>, B<-des3-wrap>
  293. Use AES128, AES192, AES256, or 3DES-EDE, respectively, to wrap key.
  294. Depending on the OpenSSL build options used, B<-des3-wrap> may not be supported.
  295. =item B<-debug_decrypt>
  296. This option sets the B<CMS_DEBUG_DECRYPT> flag. This option should be used
  297. with caution: see the notes section below.
  298. =back
  299. =head2 Signing options
  300. =over 4
  301. =item B<-md> I<digest>
  302. Digest algorithm to use when signing or resigning. If not present then the
  303. default digest algorithm for the signing key will be used (usually SHA1).
  304. =item B<-signer> I<file>
  305. A signing certificate. When signing or resigning a message, this option can be
  306. used multiple times if more than one signer is required.
  307. =item B<-certfile> I<file>
  308. Allows additional certificates to be specified. When signing these will
  309. be included with the message. When verifying these will be searched for
  310. the signers certificates.
  311. The input can be in PEM, DER, or PKCS#12 format.
  312. =item B<-cades>
  313. When used with B<-sign>,
  314. add an ESS signingCertificate or ESS signingCertificateV2 signed-attribute
  315. to the SignerInfo, in order to make the signature comply with the requirements
  316. for a CAdES Basic Electronic Signature (CAdES-BES).
  317. =item B<-nodetach>
  318. When signing a message use opaque signing: this form is more resistant
  319. to translation by mail relays but it cannot be read by mail agents that
  320. do not support S/MIME. Without this option cleartext signing with
  321. the MIME type multipart/signed is used.
  322. =item B<-nocerts>
  323. When signing a message the signer's certificate is normally included
  324. with this option it is excluded. This will reduce the size of the
  325. signed message but the verifier must have a copy of the signers certificate
  326. available locally (passed using the B<-certfile> option for example).
  327. =item B<-noattr>
  328. Normally when a message is signed a set of attributes are included which
  329. include the signing time and supported symmetric algorithms. With this
  330. option they are not included.
  331. =item B<-nosmimecap>
  332. Exclude the list of supported algorithms from signed attributes, other options
  333. such as signing time and content type are still included.
  334. =item B<-receipt_request_all>, B<-receipt_request_first>
  335. For B<-sign> option include a signed receipt request. Indicate requests should
  336. be provided by all recipient or first tier recipients (those mailed directly
  337. and not from a mailing list). Ignored it B<-receipt_request_from> is included.
  338. =item B<-receipt_request_from> I<emailaddress>
  339. For B<-sign> option include a signed receipt request. Add an explicit email
  340. address where receipts should be supplied.
  341. =item B<-receipt_request_to> I<emailaddress>
  342. Add an explicit email address where signed receipts should be sent to. This
  343. option B<must> but supplied if a signed receipt is requested.
  344. =back
  345. =head2 Verification options
  346. =over 4
  347. =item B<-signer> I<file>
  348. If a message has been verified successfully then the signers certificate(s)
  349. will be written to this file if the verification was successful.
  350. =item B<-content> I<filename>
  351. This specifies a file containing the detached content for operations taking
  352. S/MIME input, such as the B<-verify> command. This is only usable if the CMS
  353. structure is using the detached signature form where the content is
  354. not included. This option will override any content if the input format
  355. is S/MIME and it uses the multipart/signed MIME content type.
  356. =item B<-no_content_verify>
  357. Do not verify signed content signatures.
  358. =item B<-no_attr_verify>
  359. Do not verify signed attribute signatures.
  360. =item B<-nosigs>
  361. Don't verify message signature.
  362. =item B<-noverify>
  363. Do not verify the signers certificate of a signed message.
  364. =item B<-nointern>
  365. When verifying a message normally certificates (if any) included in
  366. the message are searched for the signing certificate. With this option
  367. only the certificates specified in the B<-certfile> option are used.
  368. The supplied certificates can still be used as untrusted CAs however.
  369. =item B<-cades>
  370. When used with B<-verify>, require and check signer certificate digest.
  371. See the NOTES section for more details.
  372. =item B<-verify_retcode>
  373. Exit nonzero on verification failure.
  374. {- $OpenSSL::safe::opt_trust_item -}
  375. =back
  376. =head2 Output options
  377. =over 4
  378. =item B<-keyid>
  379. Use subject key identifier to identify certificates instead of issuer name and
  380. serial number. The supplied certificate B<must> include a subject key
  381. identifier extension. Supported by B<-sign> and B<-encrypt> options.
  382. =item B<-econtent_type> I<type>
  383. Set the encapsulated content type to I<type> if not supplied the B<Data> type
  384. is used. The I<type> argument can be any valid OID name in either text or
  385. numerical format.
  386. =item B<-text>
  387. This option adds plain text (text/plain) MIME headers to the supplied
  388. message if encrypting or signing. If decrypting or verifying it strips
  389. off text headers: if the decrypted or verified message is not of MIME
  390. type text/plain then an error occurs.
  391. =item B<-certsout> I<file>
  392. Any certificates contained in the input message are written to I<file>.
  393. =item B<-to>, B<-from>, B<-subject>
  394. The relevant email headers. These are included outside the signed
  395. portion of a message so they may be included manually. If signing
  396. then many S/MIME mail clients check the signers certificate's email
  397. address matches that specified in the From: address.
  398. =back
  399. =head2 Printing options
  400. =over 4
  401. =item B<-noout>
  402. For the B<-cmsout> operation do not output the parsed CMS structure.
  403. This is useful if the syntax of the CMS structure is being checked.
  404. =item B<-print>
  405. For the B<-cmsout> operation print out all fields of the CMS structure.
  406. This implies B<-noout>.
  407. This is mainly useful for testing purposes.
  408. =item B<-nameopt> I<option>
  409. For the B<-cmsout> operation when B<-print> option is in use, specifies
  410. printing options for string fields. For most cases B<utf8> is reasonable value.
  411. See L<openssl-namedisplay-options(1)> for details.
  412. =item B<-receipt_request_print>
  413. For the B<-verify> operation print out the contents of any signed receipt
  414. requests.
  415. =back
  416. =head2 Validation options
  417. =over 4
  418. {- $OpenSSL::safe::opt_v_item -}
  419. Any validation errors cause the command to exit.
  420. =back
  421. =head1 NOTES
  422. The MIME message must be sent without any blank lines between the
  423. headers and the output. Some mail programs will automatically add
  424. a blank line. Piping the mail directly to sendmail is one way to
  425. achieve the correct format.
  426. The supplied message to be signed or encrypted must include the
  427. necessary MIME headers or many S/MIME clients won't display it
  428. properly (if at all). You can use the B<-text> option to automatically
  429. add plain text headers.
  430. A "signed and encrypted" message is one where a signed message is
  431. then encrypted. This can be produced by encrypting an already signed
  432. message: see the examples section.
  433. This version of the program only allows one signer per message but it
  434. will verify multiple signers on received messages. Some S/MIME clients
  435. choke if a message contains multiple signers. It is possible to sign
  436. messages "in parallel" by signing an already signed message.
  437. The options B<-encrypt> and B<-decrypt> reflect common usage in S/MIME
  438. clients. Strictly speaking these process CMS enveloped data: CMS
  439. encrypted data is used for other purposes.
  440. The B<-resign> option uses an existing message digest when adding a new
  441. signer. This means that attributes must be present in at least one existing
  442. signer using the same message digest or this operation will fail.
  443. The B<-stream> and B<-indef> options enable streaming I/O support.
  444. As a result the encoding is BER using indefinite length constructed encoding
  445. and no longer DER. Streaming is supported for the B<-encrypt> operation and the
  446. B<-sign> operation if the content is not detached.
  447. Streaming is always used for the B<-sign> operation with detached data but
  448. since the content is no longer part of the CMS structure the encoding
  449. remains DER.
  450. If the B<-decrypt> option is used without a recipient certificate then an
  451. attempt is made to locate the recipient by trying each potential recipient
  452. in turn using the supplied private key. To thwart the MMA attack
  453. (Bleichenbacher's attack on PKCS #1 v1.5 RSA padding) all recipients are
  454. tried whether they succeed or not and if no recipients match the message
  455. is "decrypted" using a random key which will typically output garbage.
  456. The B<-debug_decrypt> option can be used to disable the MMA attack protection
  457. and return an error if no recipient can be found: this option should be used
  458. with caution. For a fuller description see L<CMS_decrypt(3)>).
  459. =head1 CADES BASIC ELECTRONIC SIGNATURE (CADES-BES)
  460. A CAdES Basic Electronic Signature (CAdES-BES),
  461. as defined in the European Standard ETSI EN 319 122-1 V1.1.1, contains:
  462. =over 4
  463. =item *
  464. The signed user data as defined in CMS (RFC 3852);
  465. =item *
  466. Content-type of the EncapsulatedContentInfo value being signed;
  467. =item *
  468. Message-digest of the eContent OCTET STRING within encapContentInfo being signed;
  469. =item *
  470. An ESS signingCertificate or ESS signingCertificateV2 attribute,
  471. as defined in Enhanced Security Services (ESS), RFC 2634 and RFC 5035.
  472. An ESS signingCertificate attribute only allows for SHA-1 as digest algorithm.
  473. An ESS signingCertificateV2 attribute allows for any digest algorithm.
  474. =item *
  475. The digital signature value computed on the user data and, when present, on the signed attributes.
  476. NOTE that the B<-cades> option applies to the B<-sign> or B<-verify> operations.
  477. With this option, the B<-verify> operation also requires that the
  478. signingCertificate attribute is present and checks that the given identifiers
  479. match the verification trust chain built during the verification process.
  480. =back
  481. =head1 EXIT CODES
  482. =over 4
  483. =item Z<>0
  484. The operation was completely successfully.
  485. =item Z<>1
  486. An error occurred parsing the command options.
  487. =item Z<>2
  488. One of the input files could not be read.
  489. =item Z<>3
  490. An error occurred creating the CMS file or when reading the MIME
  491. message.
  492. =item Z<>4
  493. An error occurred decrypting or verifying the message.
  494. =item Z<>5
  495. The message was verified correctly but an error occurred writing out
  496. the signers certificates.
  497. =back
  498. =head1 COMPATIBILITY WITH PKCS#7 FORMAT
  499. L<openssl-smime(1)> can only process the older B<PKCS#7> format.
  500. B<openssl cms> supports Cryptographic Message Syntax format.
  501. Use of some features will result in messages which cannot be processed by
  502. applications which only support the older format. These are detailed below.
  503. The use of the B<-keyid> option with B<-sign> or B<-encrypt>.
  504. The B<-outform> I<PEM> option uses different headers.
  505. The B<-compress> option.
  506. The B<-secretkey> option when used with B<-encrypt>.
  507. The use of PSS with B<-sign>.
  508. The use of OAEP or non-RSA keys with B<-encrypt>.
  509. Additionally the B<-EncryptedData_create> and B<-data_create> type cannot
  510. be processed by the older L<openssl-smime(1)> command.
  511. =head1 EXAMPLES
  512. Create a cleartext signed message:
  513. openssl cms -sign -in message.txt -text -out mail.msg \
  514. -signer mycert.pem
  515. Create an opaque signed message
  516. openssl cms -sign -in message.txt -text -out mail.msg -nodetach \
  517. -signer mycert.pem
  518. Create a signed message, include some additional certificates and
  519. read the private key from another file:
  520. openssl cms -sign -in in.txt -text -out mail.msg \
  521. -signer mycert.pem -inkey mykey.pem -certfile mycerts.pem
  522. Create a signed message with two signers, use key identifier:
  523. openssl cms -sign -in message.txt -text -out mail.msg \
  524. -signer mycert.pem -signer othercert.pem -keyid
  525. Send a signed message under Unix directly to sendmail, including headers:
  526. openssl cms -sign -in in.txt -text -signer mycert.pem \
  527. -from steve@openssl.org -to someone@somewhere \
  528. -subject "Signed message" | sendmail someone@somewhere
  529. Verify a message and extract the signer's certificate if successful:
  530. openssl cms -verify -in mail.msg -signer user.pem -out signedtext.txt
  531. Send encrypted mail using triple DES:
  532. openssl cms -encrypt -in in.txt -from steve@openssl.org \
  533. -to someone@somewhere -subject "Encrypted message" \
  534. -des3 user.pem -out mail.msg
  535. Sign and encrypt mail:
  536. openssl cms -sign -in ml.txt -signer my.pem -text \
  537. | openssl cms -encrypt -out mail.msg \
  538. -from steve@openssl.org -to someone@somewhere \
  539. -subject "Signed and Encrypted message" -des3 user.pem
  540. Note: the encryption command does not include the B<-text> option because the
  541. message being encrypted already has MIME headers.
  542. Decrypt a message:
  543. openssl cms -decrypt -in mail.msg -recip mycert.pem -inkey key.pem
  544. The output from Netscape form signing is a PKCS#7 structure with the
  545. detached signature format. You can use this program to verify the
  546. signature by line wrapping the base64 encoded structure and surrounding
  547. it with:
  548. -----BEGIN PKCS7-----
  549. -----END PKCS7-----
  550. and using the command,
  551. openssl cms -verify -inform PEM -in signature.pem -content content.txt
  552. alternatively you can base64 decode the signature and use
  553. openssl cms -verify -inform DER -in signature.der -content content.txt
  554. Create an encrypted message using 128 bit Camellia:
  555. openssl cms -encrypt -in plain.txt -camellia128 -out mail.msg cert.pem
  556. Add a signer to an existing message:
  557. openssl cms -resign -in mail.msg -signer newsign.pem -out mail2.msg
  558. Sign a message using RSA-PSS:
  559. openssl cms -sign -in message.txt -text -out mail.msg \
  560. -signer mycert.pem -keyopt rsa_padding_mode:pss
  561. Create an encrypted message using RSA-OAEP:
  562. openssl cms -encrypt -in plain.txt -out mail.msg \
  563. -recip cert.pem -keyopt rsa_padding_mode:oaep
  564. Use SHA256 KDF with an ECDH certificate:
  565. openssl cms -encrypt -in plain.txt -out mail.msg \
  566. -recip ecdhcert.pem -keyopt ecdh_kdf_md:sha256
  567. Print CMS signed binary data in human-readable form:
  568. openssl cms -in signed.cms -binary -inform DER -cmsout -print
  569. =head1 BUGS
  570. The MIME parser isn't very clever: it seems to handle most messages that I've
  571. thrown at it but it may choke on others.
  572. The code currently will only write out the signer's certificate to a file: if
  573. the signer has a separate encryption certificate this must be manually
  574. extracted. There should be some heuristic that determines the correct
  575. encryption certificate.
  576. Ideally a database should be maintained of a certificates for each email
  577. address.
  578. The code doesn't currently take note of the permitted symmetric encryption
  579. algorithms as supplied in the SMIMECapabilities signed attribute. this means the
  580. user has to manually include the correct encryption algorithm. It should store
  581. the list of permitted ciphers in a database and only use those.
  582. No revocation checking is done on the signer's certificate.
  583. =head1 SEE ALSO
  584. L<ossl_store-file(7)>
  585. =head1 HISTORY
  586. The use of multiple B<-signer> options and the B<-resign> command were first
  587. added in OpenSSL 1.0.0.
  588. The B<-keyopt> option was added in OpenSSL 1.0.2.
  589. Support for RSA-OAEP and RSA-PSS was added in OpenSSL 1.0.2.
  590. The use of non-RSA keys with B<-encrypt> and B<-decrypt>
  591. was added in OpenSSL 1.0.2.
  592. The -no_alt_chains option was added in OpenSSL 1.0.2b.
  593. The B<-nameopt> option was added in OpenSSL 3.0.0.
  594. The B<-engine> option was deprecated in OpenSSL 3.0.
  595. The B<-digest> option was added in OpenSSL 3.2.
  596. =head1 COPYRIGHT
  597. Copyright 2008-2023 The OpenSSL Project Authors. All Rights Reserved.
  598. Licensed under the Apache License 2.0 (the "License"). You may not use
  599. this file except in compliance with the License. You can obtain a copy
  600. in the file LICENSE in the source distribution or at
  601. L<https://www.openssl.org/source/license.html>.
  602. =cut