openssl-cms.pod.in 25 KB

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