cms.pod 19 KB

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