openssl-cms.pod.in 25 KB

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