openssl-smime.pod.in 15 KB

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