cms.pod 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. =pod
  2. =head1 NAME
  3. cms - CMS utility
  4. =head1 SYNOPSIS
  5. B<openssl> B<cms>
  6. [B<-encrypt>]
  7. [B<-decrypt>]
  8. [B<-sign>]
  9. [B<-verify>]
  10. [B<-cmsout>]
  11. [B<-resign>]
  12. [B<-data_create>]
  13. [B<-data_out>]
  14. [B<-digest_create>]
  15. [B<-digest_verify>]
  16. [B<-compress>]
  17. [B<-uncompress>]
  18. [B<-EncryptedData_encrypt>]
  19. [B<-sign_receipt>]
  20. [B<-verify_receipt receipt>]
  21. [B<-in filename>]
  22. [B<-inform SMIME|PEM|DER>]
  23. [B<-rctform SMIME|PEM|DER>]
  24. [B<-out filename>]
  25. [B<-outform SMIME|PEM|DER>]
  26. [B<-stream -indef -noindef>]
  27. [B<-noindef>]
  28. [B<-content filename>]
  29. [B<-text>]
  30. [B<-noout>]
  31. [B<-print>]
  32. [B<-CAfile file>]
  33. [B<-CApath dir>]
  34. [B<-no_alt_chains>]
  35. [B<-md digest>]
  36. [B<-[cipher]>]
  37. [B<-nointern>]
  38. [B<-no_signer_cert_verify>]
  39. [B<-nocerts>]
  40. [B<-noattr>]
  41. [B<-nosmimecap>]
  42. [B<-binary>]
  43. [B<-nodetach>]
  44. [B<-certfile file>]
  45. [B<-certsout file>]
  46. [B<-signer file>]
  47. [B<-recip file>]
  48. [B<-keyid>]
  49. [B<-receipt_request_all -receipt_request_first>]
  50. [B<-receipt_request_from emailaddress>]
  51. [B<-receipt_request_to emailaddress>]
  52. [B<-receipt_request_print>]
  53. [B<-secretkey key>]
  54. [B<-secretkeyid id>]
  55. [B<-econtent_type type>]
  56. [B<-inkey file>]
  57. [B<-keyopt name:parameter>]
  58. [B<-passin arg>]
  59. [B<-rand file(s)>]
  60. [B<cert.pem...>]
  61. [B<-to addr>]
  62. [B<-from addr>]
  63. [B<-subject subj>]
  64. [cert.pem]...
  65. =head1 DESCRIPTION
  66. The B<cms> command handles S/MIME v3.1 mail. It can encrypt, decrypt, sign and
  67. verify, compress and uncompress S/MIME messages.
  68. =head1 COMMAND OPTIONS
  69. There are fourteen operation options that set the type of operation to be
  70. performed. The meaning of the other options varies according to the operation
  71. type.
  72. =over 4
  73. =item B<-encrypt>
  74. encrypt mail for the given recipient certificates. Input file is the message
  75. to be encrypted. The output file is the encrypted mail in MIME format. The
  76. actual CMS type is <B>EnvelopedData<B>.
  77. Note that no revocation check is done for the recipient cert, so if that
  78. key has been compromised, others may be able to decrypt the text.
  79. =item B<-decrypt>
  80. decrypt mail using the supplied certificate and private key. Expects an
  81. encrypted mail message in MIME format for the input file. The decrypted mail
  82. is written to the output file.
  83. =item B<-debug_decrypt>
  84. this option sets the B<CMS_DEBUG_DECRYPT> flag. This option should be used
  85. with caution: see the notes section below.
  86. =item B<-sign>
  87. sign mail using the supplied certificate and private key. Input file is
  88. the message to be signed. The signed message in MIME format is written
  89. to the output file.
  90. =item B<-verify>
  91. verify signed mail. Expects a signed mail message on input and outputs
  92. the signed data. Both clear text and opaque signing is supported.
  93. =item B<-cmsout>
  94. takes an input message and writes out a PEM encoded CMS structure.
  95. =item B<-resign>
  96. resign a message: take an existing message and one or more new signers.
  97. =item B<-data_create>
  98. Create a CMS B<Data> type.
  99. =item B<-data_out>
  100. B<Data> type and output the content.
  101. =item B<-digest_create>
  102. Create a CMS B<DigestedData> type.
  103. =item B<-digest_verify>
  104. Verify a CMS B<DigestedData> type and output the content.
  105. =item B<-compress>
  106. Create a CMS B<CompressedData> type. OpenSSL must be compiled with B<zlib>
  107. support for this option to work, otherwise it will output an error.
  108. =item B<-uncompress>
  109. Uncompress a CMS B<CompressedData> type and output the content. OpenSSL must be
  110. compiled with B<zlib> support for this option to work, otherwise it will
  111. output an error.
  112. =item B<-EncryptedData_encrypt>
  113. Encrypt content using supplied symmetric key and algorithm using a CMS
  114. B<EncrytedData> type and output the content.
  115. =item B<-sign_receipt>
  116. Generate and output a signed receipt for the supplied message. The input
  117. message B<must> contain a signed receipt request. Functionality is otherwise
  118. similar to the B<-sign> operation.
  119. =item B<-verify_receipt receipt>
  120. Verify a signed receipt in filename B<receipt>. The input message B<must>
  121. contain the original receipt request. Functionality is otherwise similar
  122. to the B<-verify> operation.
  123. =item B<-in filename>
  124. the input message to be encrypted or signed or the message to be decrypted
  125. or verified.
  126. =item B<-inform SMIME|PEM|DER>
  127. this specifies the input format for the CMS structure. The default
  128. is B<SMIME> which reads an S/MIME format message. B<PEM> and B<DER>
  129. format change this to expect PEM and DER format CMS structures
  130. instead. This currently only affects the input format of the CMS
  131. structure, if no CMS structure is being input (for example with
  132. B<-encrypt> or B<-sign>) this option has no effect.
  133. =item B<-rctform SMIME|PEM|DER>
  134. specify the format for a signed receipt for use with the B<-receipt_verify>
  135. operation.
  136. =item B<-out filename>
  137. the message text that has been decrypted or verified or the output MIME
  138. format message that has been signed or verified.
  139. =item B<-outform SMIME|PEM|DER>
  140. this specifies the output format for the CMS structure. The default
  141. is B<SMIME> which writes an S/MIME format message. B<PEM> and B<DER>
  142. format change this to write PEM and DER format CMS structures
  143. instead. This currently only affects the output format of the CMS
  144. structure, if no CMS structure is being output (for example with
  145. B<-verify> or B<-decrypt>) this option has no effect.
  146. =item B<-stream -indef -noindef>
  147. the B<-stream> and B<-indef> options are equivalent and enable streaming I/O
  148. for encoding operations. This permits single pass processing of data without
  149. the need to hold the entire contents in memory, potentially supporting very
  150. large files. Streaming is automatically set for S/MIME signing with detached
  151. data if the output format is B<SMIME> it is currently off by default for all
  152. other operations.
  153. =item B<-noindef>
  154. disable streaming I/O where it would produce and indefinite length constructed
  155. encoding. This option currently has no effect. In future streaming will be
  156. enabled by default on all relevant operations and this option will disable it.
  157. =item B<-content filename>
  158. This specifies a file containing the detached content, this is only
  159. useful with the B<-verify> command. This is only usable if the CMS
  160. structure is using the detached signature form where the content is
  161. not included. This option will override any content if the input format
  162. is S/MIME and it uses the multipart/signed MIME content type.
  163. =item B<-text>
  164. this option adds plain text (text/plain) MIME headers to the supplied
  165. message if encrypting or signing. If decrypting or verifying it strips
  166. off text headers: if the decrypted or verified message is not of MIME
  167. type text/plain then an error occurs.
  168. =item B<-noout>
  169. for the B<-cmsout> operation do not output the parsed CMS structure. This
  170. is useful when combined with the B<-print> option or if the syntax of the CMS
  171. structure is being checked.
  172. =item B<-print>
  173. for the B<-cmsout> operation print out all fields of the CMS structure. This
  174. is mainly useful for testing purposes.
  175. =item B<-CAfile file>
  176. a file containing trusted CA certificates, only used with B<-verify>.
  177. =item B<-CApath dir>
  178. a directory containing trusted CA certificates, only used with
  179. B<-verify>. This directory must be a standard certificate directory: that
  180. is a hash of each subject name (using B<x509 -hash>) should be linked
  181. to each certificate.
  182. =item B<-md digest>
  183. digest algorithm to use when signing or resigning. If not present then the
  184. default digest algorithm for the signing key will be used (usually SHA1).
  185. =item B<-[cipher]>
  186. the encryption algorithm to use. For example triple DES (168 bits) - B<-des3>
  187. or 256 bit AES - B<-aes256>. Any standard algorithm name (as used by the
  188. EVP_get_cipherbyname() function) can also be used preceded by a dash, for
  189. example B<-aes_128_cbc>. See L<B<enc>|enc(1)> for a list of ciphers
  190. supported by your version of OpenSSL.
  191. If not specified triple DES is used. Only used with B<-encrypt> and
  192. B<-EncryptedData_create> commands.
  193. =item B<-nointern>
  194. when verifying a message normally certificates (if any) included in
  195. the message are searched for the signing certificate. With this option
  196. only the certificates specified in the B<-certfile> option are used.
  197. The supplied certificates can still be used as untrusted CAs however.
  198. =item B<-no_signer_cert_verify>
  199. do not verify the signers certificate of a signed message.
  200. =item B<-nocerts>
  201. when signing a message the signer's certificate is normally included
  202. with this option it is excluded. This will reduce the size of the
  203. signed message but the verifier must have a copy of the signers certificate
  204. available locally (passed using the B<-certfile> option for example).
  205. =item B<-noattr>
  206. normally when a message is signed a set of attributes are included which
  207. include the signing time and supported symmetric algorithms. With this
  208. option they are not included.
  209. =item B<-nosmimecap>
  210. exclude the list of supported algorithms from signed attributes, other options
  211. such as signing time and content type are still included.
  212. =item B<-binary>
  213. normally the input message is converted to "canonical" format which is
  214. effectively using CR and LF as end of line: as required by the S/MIME
  215. specification. When this option is present no translation occurs. This
  216. is useful when handling binary data which may not be in MIME format.
  217. =item B<-nodetach>
  218. when signing a message use opaque signing: this form is more resistant
  219. to translation by mail relays but it cannot be read by mail agents that
  220. do not support S/MIME. Without this option cleartext signing with
  221. the MIME type multipart/signed is used.
  222. =item B<-certfile file>
  223. allows additional certificates to be specified. When signing these will
  224. be included with the message. When verifying these will be searched for
  225. the signers certificates. The certificates should be in PEM format.
  226. =item B<-certsout file>
  227. any certificates contained in the message are written to B<file>.
  228. =item B<-signer file>
  229. a signing certificate when signing or resigning a message, this option can be
  230. used multiple times if more than one signer is required. If a message is being
  231. verified then the signers certificates will be written to this file if the
  232. verification was successful.
  233. =item B<-recip file>
  234. when decrypting a message this specifies the recipients certificate. The
  235. certificate must match one of the recipients of the message or an error
  236. occurs.
  237. When encrypting a message this option may be used multiple times to specify
  238. each recipient. This form B<must> be used if customised parameters are
  239. required (for example to specify RSA-OAEP).
  240. =item B<-keyid>
  241. use subject key identifier to identify certificates instead of issuer name and
  242. serial number. The supplied certificate B<must> include a subject key
  243. identifier extension. Supported by B<-sign> and B<-encrypt> options.
  244. =item B<-receipt_request_all -receipt_request_first>
  245. for B<-sign> option include a signed receipt request. Indicate requests should
  246. be provided by all receipient or first tier recipients (those mailed directly
  247. and not from a mailing list). Ignored it B<-receipt_request_from> is included.
  248. =item B<-receipt_request_from emailaddress>
  249. for B<-sign> option include a signed receipt request. Add an explicit email
  250. address where receipts should be supplied.
  251. =item B<-receipt_request_to emailaddress>
  252. Add an explicit email address where signed receipts should be sent to. This
  253. option B<must> but supplied if a signed receipt it requested.
  254. =item B<-receipt_request_print>
  255. For the B<-verify> operation print out the contents of any signed receipt
  256. requests.
  257. =item B<-secretkey key>
  258. specify symmetric key to use. The key must be supplied in hex format and be
  259. consistent with the algorithm used. Supported by the B<-EncryptedData_encrypt>
  260. B<-EncrryptedData_decrypt>, B<-encrypt> and B<-decrypt> options. When used
  261. with B<-encrypt> or B<-decrypt> the supplied key is used to wrap or unwrap the
  262. content encryption key using an AES key in the B<KEKRecipientInfo> type.
  263. =item B<-secretkeyid id>
  264. the key identifier for the supplied symmetric key for B<KEKRecipientInfo> type.
  265. This option B<must> be present if the B<-secretkey> option is used with
  266. B<-encrypt>. With B<-decrypt> operations the B<id> is used to locate the
  267. relevant key if it is not supplied then an attempt is used to decrypt any
  268. B<KEKRecipientInfo> structures.
  269. =item B<-econtent_type type>
  270. set the encapsulated content type to B<type> if not supplied the B<Data> type
  271. is used. The B<type> argument can be any valid OID name in either text or
  272. numerical format.
  273. =item B<-inkey file>
  274. the private key to use when signing or decrypting. This must match the
  275. corresponding certificate. If this option is not specified then the
  276. private key must be included in the certificate file specified with
  277. the B<-recip> or B<-signer> file. When signing this option can be used
  278. multiple times to specify successive keys.
  279. =item B<-keyopt name:opt>
  280. for signing and encryption this option can be used multiple times to
  281. set customised parameters for the preceding key or certificate. It can
  282. currently be used to set RSA-PSS for signing, RSA-OAEP for encryption
  283. or to modify default parameters for ECDH.
  284. =item B<-passin arg>
  285. the private key password source. For more information about the format of B<arg>
  286. see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)|openssl(1)>.
  287. =item B<-rand file(s)>
  288. a file or files containing random data used to seed the random number
  289. generator, or an EGD socket (see L<RAND_egd(3)|RAND_egd(3)>).
  290. Multiple files can be specified separated by a OS-dependent character.
  291. The separator is B<;> for MS-Windows, B<,> for OpenVMS, and B<:> for
  292. all others.
  293. =item B<cert.pem...>
  294. one or more certificates of message recipients: used when encrypting
  295. a message.
  296. =item B<-to, -from, -subject>
  297. the relevant mail headers. These are included outside the signed
  298. portion of a message so they may be included manually. If signing
  299. then many S/MIME mail clients check the signers certificate's email
  300. address matches that specified in the From: address.
  301. =item B<-purpose, -ignore_critical, -issuer_checks, -crl_check, -crl_check_all, -policy_check, -extended_crl, -x509_strict, -policy -check_ss_sig -no_alt_chains>
  302. Set various certificate chain valiadition option. See the
  303. L<B<verify>|verify(1)> manual page for details.
  304. =back
  305. =head1 NOTES
  306. The MIME message must be sent without any blank lines between the
  307. headers and the output. Some mail programs will automatically add
  308. a blank line. Piping the mail directly to sendmail is one way to
  309. achieve the correct format.
  310. The supplied message to be signed or encrypted must include the
  311. necessary MIME headers or many S/MIME clients wont display it
  312. properly (if at all). You can use the B<-text> option to automatically
  313. add plain text headers.
  314. A "signed and encrypted" message is one where a signed message is
  315. then encrypted. This can be produced by encrypting an already signed
  316. message: see the examples section.
  317. This version of the program only allows one signer per message but it
  318. will verify multiple signers on received messages. Some S/MIME clients
  319. choke if a message contains multiple signers. It is possible to sign
  320. messages "in parallel" by signing an already signed message.
  321. The options B<-encrypt> and B<-decrypt> reflect common usage in S/MIME
  322. clients. Strictly speaking these process CMS enveloped data: CMS
  323. encrypted data is used for other purposes.
  324. The B<-resign> option uses an existing message digest when adding a new
  325. signer. This means that attributes must be present in at least one existing
  326. signer using the same message digest or this operation will fail.
  327. The B<-stream> and B<-indef> options enable experimental streaming I/O support.
  328. As a result the encoding is BER using indefinite length constructed encoding
  329. and no longer DER. Streaming is supported for the B<-encrypt> operation and the
  330. B<-sign> operation if the content is not detached.
  331. Streaming is always used for the B<-sign> operation with detached data but
  332. since the content is no longer part of the CMS structure the encoding
  333. remains DER.
  334. If the B<-decrypt> option is used without a recipient certificate then an
  335. attempt is made to locate the recipient by trying each potential recipient
  336. in turn using the supplied private key. To thwart the MMA attack
  337. (Bleichenbacher's attack on PKCS #1 v1.5 RSA padding) all recipients are
  338. tried whether they succeed or not and if no recipients match the message
  339. is "decrypted" using a random key which will typically output garbage.
  340. The B<-debug_decrypt> option can be used to disable the MMA attack protection
  341. and return an error if no recipient can be found: this option should be used
  342. with caution. For a fuller description see L<CMS_decrypt(3)|CMS_decrypt(3)>).
  343. =head1 EXIT CODES
  344. =over 4
  345. =item Z<>0
  346. the operation was completely successfully.
  347. =item Z<>1
  348. an error occurred parsing the command options.
  349. =item Z<>2
  350. one of the input files could not be read.
  351. =item Z<>3
  352. an error occurred creating the CMS file or when reading the MIME
  353. message.
  354. =item Z<>4
  355. an error occurred decrypting or verifying the message.
  356. =item Z<>5
  357. the message was verified correctly but an error occurred writing out
  358. the signers certificates.
  359. =back
  360. =head1 COMPATIBILITY WITH PKCS#7 format.
  361. The B<smime> utility can only process the older B<PKCS#7> format. The B<cms>
  362. utility supports Cryptographic Message Syntax format. Use of some features
  363. will result in messages which cannot be processed by applications which only
  364. support the older format. These are detailed below.
  365. The use of the B<-keyid> option with B<-sign> or B<-encrypt>.
  366. The B<-outform PEM> option uses different headers.
  367. The B<-compress> option.
  368. The B<-secretkey> option when used with B<-encrypt>.
  369. The use of PSS with B<-sign>.
  370. The use of OAEP or non-RSA keys with B<-encrypt>.
  371. Additionally the B<-EncryptedData_create> and B<-data_create> type cannot
  372. be processed by the older B<smime> command.
  373. =head1 EXAMPLES
  374. Create a cleartext signed message:
  375. openssl cms -sign -in message.txt -text -out mail.msg \
  376. -signer mycert.pem
  377. Create an opaque signed message
  378. openssl cms -sign -in message.txt -text -out mail.msg -nodetach \
  379. -signer mycert.pem
  380. Create a signed message, include some additional certificates and
  381. read the private key from another file:
  382. openssl cms -sign -in in.txt -text -out mail.msg \
  383. -signer mycert.pem -inkey mykey.pem -certfile mycerts.pem
  384. Create a signed message with two signers, use key identifier:
  385. openssl cms -sign -in message.txt -text -out mail.msg \
  386. -signer mycert.pem -signer othercert.pem -keyid
  387. Send a signed message under Unix directly to sendmail, including headers:
  388. openssl cms -sign -in in.txt -text -signer mycert.pem \
  389. -from steve@openssl.org -to someone@somewhere \
  390. -subject "Signed message" | sendmail someone@somewhere
  391. Verify a message and extract the signer's certificate if successful:
  392. openssl cms -verify -in mail.msg -signer user.pem -out signedtext.txt
  393. Send encrypted mail using triple DES:
  394. openssl cms -encrypt -in in.txt -from steve@openssl.org \
  395. -to someone@somewhere -subject "Encrypted message" \
  396. -des3 user.pem -out mail.msg
  397. Sign and encrypt mail:
  398. openssl cms -sign -in ml.txt -signer my.pem -text \
  399. | openssl cms -encrypt -out mail.msg \
  400. -from steve@openssl.org -to someone@somewhere \
  401. -subject "Signed and Encrypted message" -des3 user.pem
  402. Note: the encryption command does not include the B<-text> option because the
  403. message being encrypted already has MIME headers.
  404. Decrypt mail:
  405. openssl cms -decrypt -in mail.msg -recip mycert.pem -inkey key.pem
  406. The output from Netscape form signing is a PKCS#7 structure with the
  407. detached signature format. You can use this program to verify the
  408. signature by line wrapping the base64 encoded structure and surrounding
  409. it with:
  410. -----BEGIN PKCS7-----
  411. -----END PKCS7-----
  412. and using the command,
  413. openssl cms -verify -inform PEM -in signature.pem -content content.txt
  414. alternatively you can base64 decode the signature and use
  415. openssl cms -verify -inform DER -in signature.der -content content.txt
  416. Create an encrypted message using 128 bit Camellia:
  417. openssl cms -encrypt -in plain.txt -camellia128 -out mail.msg cert.pem
  418. Add a signer to an existing message:
  419. openssl cms -resign -in mail.msg -signer newsign.pem -out mail2.msg
  420. Sign mail using RSA-PSS:
  421. openssl cms -sign -in message.txt -text -out mail.msg \
  422. -signer mycert.pem -keyopt rsa_padding_mode:pss
  423. Create encrypted mail using RSA-OAEP:
  424. openssl cms -encrypt -in plain.txt -out mail.msg \
  425. -recip cert.pem -keyopt rsa_padding_mode:oaep
  426. Use SHA256 KDF with an ECDH certificate:
  427. openssl cms -encrypt -in plain.txt -out mail.msg \
  428. -recip ecdhcert.pem -keyopt ecdh_kdf_md:sha256
  429. =head1 BUGS
  430. The MIME parser isn't very clever: it seems to handle most messages that I've
  431. thrown at it but it may choke on others.
  432. The code currently will only write out the signer's certificate to a file: if
  433. the signer has a separate encryption certificate this must be manually
  434. extracted. There should be some heuristic that determines the correct
  435. encryption certificate.
  436. Ideally a database should be maintained of a certificates for each email
  437. address.
  438. The code doesn't currently take note of the permitted symmetric encryption
  439. algorithms as supplied in the SMIMECapabilities signed attribute. this means the
  440. user has to manually include the correct encryption algorithm. It should store
  441. the list of permitted ciphers in a database and only use those.
  442. No revocation checking is done on the signer's certificate.
  443. =head1 HISTORY
  444. The use of multiple B<-signer> options and the B<-resign> command were first
  445. added in OpenSSL 1.0.0
  446. The B<keyopt> option was first added in OpenSSL 1.1.0
  447. The use of B<-recip> to specify the recipient when encrypting mail was first
  448. added to OpenSSL 1.1.0
  449. Support for RSA-OAEP and RSA-PSS was first added to OpenSSL 1.1.0.
  450. The use of non-RSA keys with B<-encrypt> and B<-decrypt> was first added
  451. to OpenSSL 1.1.0.
  452. The -no_alt_chains options was first added to OpenSSL 1.0.2b.
  453. =cut