openssl-cms.pod.in 26 KB

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