smime.pod 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. =pod
  2. =head1 NAME
  3. openssl-smime,
  4. smime - S/MIME utility
  5. =head1 SYNOPSIS
  6. B<openssl> B<smime>
  7. [B<-help>]
  8. [B<-encrypt>]
  9. [B<-decrypt>]
  10. [B<-sign>]
  11. [B<-resign>]
  12. [B<-verify>]
  13. [B<-pk7out>]
  14. [B<-binary>]
  15. [B<-crlfeol>]
  16. [B<-I<cipher>>]
  17. [B<-in file>]
  18. [B<-CAfile file>]
  19. [B<-CApath dir>]
  20. [B<-no-CAfile>]
  21. [B<-no-CApath>]
  22. [B<-attime timestamp>]
  23. [B<-check_ss_sig>]
  24. [B<-crl_check>]
  25. [B<-crl_check_all>]
  26. [B<-explicit_policy>]
  27. [B<-extended_crl>]
  28. [B<-ignore_critical>]
  29. [B<-inhibit_any>]
  30. [B<-inhibit_map>]
  31. [B<-partial_chain>]
  32. [B<-policy arg>]
  33. [B<-policy_check>]
  34. [B<-policy_print>]
  35. [B<-purpose purpose>]
  36. [B<-suiteB_128>]
  37. [B<-suiteB_128_only>]
  38. [B<-suiteB_192>]
  39. [B<-trusted_first>]
  40. [B<-no_alt_chains>]
  41. [B<-use_deltas>]
  42. [B<-auth_level num>]
  43. [B<-verify_depth num>]
  44. [B<-verify_email email>]
  45. [B<-verify_hostname hostname>]
  46. [B<-verify_ip ip>]
  47. [B<-verify_name name>]
  48. [B<-x509_strict>]
  49. [B<-certfile file>]
  50. [B<-signer file>]
  51. [B<-recip file>]
  52. [B<-inform SMIME|PEM|DER>]
  53. [B<-passin arg>]
  54. [B<-inkey file_or_id>]
  55. [B<-out file>]
  56. [B<-outform SMIME|PEM|DER>]
  57. [B<-content file>]
  58. [B<-to addr>]
  59. [B<-from ad>]
  60. [B<-subject s>]
  61. [B<-text>]
  62. [B<-indef>]
  63. [B<-noindef>]
  64. [B<-stream>]
  65. [B<-rand file...>]
  66. [B<-writerand file>]
  67. [B<-md digest>]
  68. [cert.pem]...
  69. =head1 DESCRIPTION
  70. The B<smime> command handles S/MIME mail. It can encrypt, decrypt, sign and
  71. verify S/MIME messages.
  72. =head1 OPTIONS
  73. There are six operation options that set the type of operation to be performed.
  74. The meaning of the other options varies according to the operation type.
  75. =over 4
  76. =item B<-help>
  77. Print out a usage message.
  78. =item B<-encrypt>
  79. Encrypt mail for the given recipient certificates. Input file is the message
  80. to be encrypted. The output file is the encrypted mail in MIME format.
  81. Note that no revocation check is done for the recipient cert, so if that
  82. key has been compromised, others may be able to decrypt the text.
  83. =item B<-decrypt>
  84. Decrypt mail using the supplied certificate and private key. Expects an
  85. encrypted mail message in MIME format for the input file. The decrypted mail
  86. is written to the output file.
  87. =item B<-sign>
  88. Sign mail using the supplied certificate and private key. Input file is
  89. the message to be signed. The signed message in MIME format is written
  90. to the output file.
  91. =item B<-verify>
  92. Verify signed mail. Expects a signed mail message on input and outputs
  93. the signed data. Both clear text and opaque signing is supported.
  94. =item B<-pk7out>
  95. Takes an input message and writes out a PEM encoded PKCS#7 structure.
  96. =item B<-resign>
  97. Resign a message: take an existing message and one or more new signers.
  98. =item B<-in filename>
  99. The input message to be encrypted or signed or the MIME message to
  100. be decrypted or verified.
  101. =item B<-inform SMIME|PEM|DER>
  102. This specifies the input format for the PKCS#7 structure. The default
  103. is B<SMIME> which reads an S/MIME format message. B<PEM> and B<DER>
  104. format change this to expect PEM and DER format PKCS#7 structures
  105. instead. This currently only affects the input format of the PKCS#7
  106. structure, if no PKCS#7 structure is being input (for example with
  107. B<-encrypt> or B<-sign>) this option has no effect.
  108. =item B<-out filename>
  109. The message text that has been decrypted or verified or the output MIME
  110. format message that has been signed or verified.
  111. =item B<-outform SMIME|PEM|DER>
  112. This specifies the output format for the PKCS#7 structure. The default
  113. is B<SMIME> which write an S/MIME format message. B<PEM> and B<DER>
  114. format change this to write PEM and DER format PKCS#7 structures
  115. instead. This currently only affects the output format of the PKCS#7
  116. structure, if no PKCS#7 structure is being output (for example with
  117. B<-verify> or B<-decrypt>) this option has no effect.
  118. =item B<-stream -indef -noindef>
  119. The B<-stream> and B<-indef> options are equivalent and enable streaming I/O
  120. for encoding operations. This permits single pass processing of data without
  121. the need to hold the entire contents in memory, potentially supporting very
  122. large files. Streaming is automatically set for S/MIME signing with detached
  123. data if the output format is B<SMIME> it is currently off by default for all
  124. other operations.
  125. =item B<-noindef>
  126. Disable streaming I/O where it would produce and indefinite length constructed
  127. encoding. This option currently has no effect. In future streaming will be
  128. enabled by default on all relevant operations and this option will disable it.
  129. =item B<-content filename>
  130. This specifies a file containing the detached content, this is only
  131. useful with the B<-verify> command. This is only usable if the PKCS#7
  132. structure is using the detached signature form where the content is
  133. not included. This option will override any content if the input format
  134. is S/MIME and it uses the multipart/signed MIME content type.
  135. =item B<-text>
  136. This option adds plain text (text/plain) MIME headers to the supplied
  137. message if encrypting or signing. If decrypting or verifying it strips
  138. off text headers: if the decrypted or verified message is not of MIME
  139. type text/plain then an error occurs.
  140. =item B<-CAfile file>
  141. A file containing trusted CA certificates, only used with B<-verify>.
  142. =item B<-CApath dir>
  143. A directory containing trusted CA certificates, only used with
  144. B<-verify>. This directory must be a standard certificate directory: that
  145. is a hash of each subject name (using B<x509 -hash>) should be linked
  146. to each certificate.
  147. =item B<-no-CAfile>
  148. Do not load the trusted CA certificates from the default file location.
  149. =item B<-no-CApath>
  150. Do not load the trusted CA certificates from the default directory location.
  151. =item B<-md digest>
  152. Digest algorithm to use when signing or resigning. If not present then the
  153. default digest algorithm for the signing key will be used (usually SHA1).
  154. =item B<-I<cipher>>
  155. The encryption algorithm to use. For example DES (56 bits) - B<-des>,
  156. triple DES (168 bits) - B<-des3>,
  157. EVP_get_cipherbyname() function) can also be used preceded by a dash, for
  158. example B<-aes-128-cbc>. See L<B<enc>|enc(1)> for list of ciphers
  159. supported by your version of OpenSSL.
  160. If not specified triple DES is used. Only used with B<-encrypt>.
  161. =item B<-nointern>
  162. When verifying a message normally certificates (if any) included in
  163. the message are searched for the signing certificate. With this option
  164. only the certificates specified in the B<-certfile> option are used.
  165. The supplied certificates can still be used as untrusted CAs however.
  166. =item B<-noverify>
  167. Do not verify the signers certificate of a signed message.
  168. =item B<-nochain>
  169. Do not do chain verification of signers certificates: that is don't
  170. use the certificates in the signed message as untrusted CAs.
  171. =item B<-nosigs>
  172. Don't try to verify the signatures on the message.
  173. =item B<-nocerts>
  174. When signing a message the signer's certificate is normally included
  175. with this option it is excluded. This will reduce the size of the
  176. signed message but the verifier must have a copy of the signers certificate
  177. available locally (passed using the B<-certfile> option for example).
  178. =item B<-noattr>
  179. Normally when a message is signed a set of attributes are included which
  180. include the signing time and supported symmetric algorithms. With this
  181. option they are not included.
  182. =item B<-binary>
  183. Normally the input message is converted to "canonical" format which is
  184. effectively using CR and LF as end of line: as required by the S/MIME
  185. specification. When this option is present no translation occurs. This
  186. is useful when handling binary data which may not be in MIME format.
  187. =item B<-crlfeol>
  188. Normally the output file uses a single B<LF> as end of line. When this
  189. option is present B<CRLF> is used instead.
  190. =item B<-nodetach>
  191. When signing a message use opaque signing: this form is more resistant
  192. to translation by mail relays but it cannot be read by mail agents that
  193. do not support S/MIME. Without this option cleartext signing with
  194. the MIME type multipart/signed is used.
  195. =item B<-certfile file>
  196. Allows additional certificates to be specified. When signing these will
  197. be included with the message. When verifying these will be searched for
  198. the signers certificates. The certificates should be in PEM format.
  199. =item B<-signer file>
  200. A signing certificate when signing or resigning a message, this option can be
  201. used multiple times if more than one signer is required. If a message is being
  202. verified then the signers certificates will be written to this file if the
  203. verification was successful.
  204. =item B<-recip file>
  205. The recipients certificate when decrypting a message. This certificate
  206. must match one of the recipients of the message or an error occurs.
  207. =item B<-inkey file_or_id>
  208. The private key to use when signing or decrypting. This must match the
  209. corresponding certificate. If this option is not specified then the
  210. private key must be included in the certificate file specified with
  211. the B<-recip> or B<-signer> file. When signing this option can be used
  212. multiple times to specify successive keys.
  213. If no engine is used, the argument is taken as a file; if an engine is
  214. specified, the argument is given to the engine as a key identifier.
  215. =item B<-passin arg>
  216. The private key password source. For more information about the format of B<arg>
  217. see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)>.
  218. =item B<-rand file...>
  219. A file or files containing random data used to seed the random number
  220. generator.
  221. Multiple files can be specified separated by an OS-dependent character.
  222. The separator is B<;> for MS-Windows, B<,> for OpenVMS, and B<:> for
  223. all others.
  224. =item [B<-writerand file>]
  225. Writes random data to the specified I<file> upon exit.
  226. This can be used with a subsequent B<-rand> flag.
  227. =item B<cert.pem...>
  228. One or more certificates of message recipients: used when encrypting
  229. a message.
  230. =item B<-to, -from, -subject>
  231. The relevant mail headers. These are included outside the signed
  232. portion of a message so they may be included manually. If signing
  233. then many S/MIME mail clients check the signers certificate's email
  234. address matches that specified in the From: address.
  235. =item B<-attime>, B<-check_ss_sig>, B<-crl_check>, B<-crl_check_all>,
  236. B<-explicit_policy>, B<-extended_crl>, B<-ignore_critical>, B<-inhibit_any>,
  237. B<-inhibit_map>, B<-no_alt_chains>, B<-partial_chain>, B<-policy>,
  238. B<-policy_check>, B<-policy_print>, B<-purpose>, B<-suiteB_128>,
  239. B<-suiteB_128_only>, B<-suiteB_192>, B<-trusted_first>, B<-use_deltas>,
  240. B<-auth_level>, B<-verify_depth>, B<-verify_email>, B<-verify_hostname>,
  241. B<-verify_ip>, B<-verify_name>, B<-x509_strict>
  242. Set various options of certificate chain verification. See
  243. L<verify(1)> manual page for details.
  244. =back
  245. =head1 NOTES
  246. The MIME message must be sent without any blank lines between the
  247. headers and the output. Some mail programs will automatically add
  248. a blank line. Piping the mail directly to sendmail is one way to
  249. achieve the correct format.
  250. The supplied message to be signed or encrypted must include the
  251. necessary MIME headers or many S/MIME clients won't display it
  252. properly (if at all). You can use the B<-text> option to automatically
  253. add plain text headers.
  254. A "signed and encrypted" message is one where a signed message is
  255. then encrypted. This can be produced by encrypting an already signed
  256. message: see the examples section.
  257. This version of the program only allows one signer per message but it
  258. will verify multiple signers on received messages. Some S/MIME clients
  259. choke if a message contains multiple signers. It is possible to sign
  260. messages "in parallel" by signing an already signed message.
  261. The options B<-encrypt> and B<-decrypt> reflect common usage in S/MIME
  262. clients. Strictly speaking these process PKCS#7 enveloped data: PKCS#7
  263. encrypted data is used for other purposes.
  264. The B<-resign> option uses an existing message digest when adding a new
  265. signer. This means that attributes must be present in at least one existing
  266. signer using the same message digest or this operation will fail.
  267. The B<-stream> and B<-indef> options enable streaming I/O support.
  268. As a result the encoding is BER using indefinite length constructed encoding
  269. and no longer DER. Streaming is supported for the B<-encrypt> operation and the
  270. B<-sign> operation if the content is not detached.
  271. Streaming is always used for the B<-sign> operation with detached data but
  272. since the content is no longer part of the PKCS#7 structure the encoding
  273. remains DER.
  274. =head1 EXIT CODES
  275. =over 4
  276. =item Z<>0
  277. The operation was completely successfully.
  278. =item Z<>1
  279. An error occurred parsing the command options.
  280. =item Z<>2
  281. One of the input files could not be read.
  282. =item Z<>3
  283. An error occurred creating the PKCS#7 file or when reading the MIME
  284. message.
  285. =item Z<>4
  286. An error occurred decrypting or verifying the message.
  287. =item Z<>5
  288. The message was verified correctly but an error occurred writing out
  289. the signers certificates.
  290. =back
  291. =head1 EXAMPLES
  292. Create a cleartext signed message:
  293. openssl smime -sign -in message.txt -text -out mail.msg \
  294. -signer mycert.pem
  295. Create an opaque signed message:
  296. openssl smime -sign -in message.txt -text -out mail.msg -nodetach \
  297. -signer mycert.pem
  298. Create a signed message, include some additional certificates and
  299. read the private key from another file:
  300. openssl smime -sign -in in.txt -text -out mail.msg \
  301. -signer mycert.pem -inkey mykey.pem -certfile mycerts.pem
  302. Create a signed message with two signers:
  303. openssl smime -sign -in message.txt -text -out mail.msg \
  304. -signer mycert.pem -signer othercert.pem
  305. Send a signed message under Unix directly to sendmail, including headers:
  306. openssl smime -sign -in in.txt -text -signer mycert.pem \
  307. -from steve@openssl.org -to someone@somewhere \
  308. -subject "Signed message" | sendmail someone@somewhere
  309. Verify a message and extract the signer's certificate if successful:
  310. openssl smime -verify -in mail.msg -signer user.pem -out signedtext.txt
  311. Send encrypted mail using triple DES:
  312. openssl smime -encrypt -in in.txt -from steve@openssl.org \
  313. -to someone@somewhere -subject "Encrypted message" \
  314. -des3 user.pem -out mail.msg
  315. Sign and encrypt mail:
  316. openssl smime -sign -in ml.txt -signer my.pem -text \
  317. | openssl smime -encrypt -out mail.msg \
  318. -from steve@openssl.org -to someone@somewhere \
  319. -subject "Signed and Encrypted message" -des3 user.pem
  320. Note: the encryption command does not include the B<-text> option because the
  321. message being encrypted already has MIME headers.
  322. Decrypt mail:
  323. openssl smime -decrypt -in mail.msg -recip mycert.pem -inkey key.pem
  324. The output from Netscape form signing is a PKCS#7 structure with the
  325. detached signature format. You can use this program to verify the
  326. signature by line wrapping the base64 encoded structure and surrounding
  327. it with:
  328. -----BEGIN PKCS7-----
  329. -----END PKCS7-----
  330. and using the command:
  331. openssl smime -verify -inform PEM -in signature.pem -content content.txt
  332. Alternatively you can base64 decode the signature and use:
  333. openssl smime -verify -inform DER -in signature.der -content content.txt
  334. Create an encrypted message using 128 bit Camellia:
  335. openssl smime -encrypt -in plain.txt -camellia128 -out mail.msg cert.pem
  336. Add a signer to an existing message:
  337. openssl smime -resign -in mail.msg -signer newsign.pem -out mail2.msg
  338. =head1 BUGS
  339. The MIME parser isn't very clever: it seems to handle most messages that I've
  340. thrown at it but it may choke on others.
  341. The code currently will only write out the signer's certificate to a file: if
  342. the signer has a separate encryption certificate this must be manually
  343. extracted. There should be some heuristic that determines the correct
  344. encryption certificate.
  345. Ideally a database should be maintained of a certificates for each email
  346. address.
  347. The code doesn't currently take note of the permitted symmetric encryption
  348. algorithms as supplied in the SMIMECapabilities signed attribute. This means the
  349. user has to manually include the correct encryption algorithm. It should store
  350. the list of permitted ciphers in a database and only use those.
  351. No revocation checking is done on the signer's certificate.
  352. The current code can only handle S/MIME v2 messages, the more complex S/MIME v3
  353. structures may cause parsing errors.
  354. =head1 HISTORY
  355. The use of multiple B<-signer> options and the B<-resign> command were first
  356. added in OpenSSL 1.0.0
  357. The -no_alt_chains option was added in OpenSSL 1.1.0.
  358. =head1 COPYRIGHT
  359. Copyright 2000-2017 The OpenSSL Project Authors. All Rights Reserved.
  360. Licensed under the Apache License 2.0 (the "License"). You may not use
  361. this file except in compliance with the License. You can obtain a copy
  362. in the file LICENSE in the source distribution or at
  363. L<https://www.openssl.org/source/license.html>.
  364. =cut