]> git.ipfire.org Git - thirdparty/openssl.git/blame - doc/man1/openssl-smime.pod.in
Make Windows build more robust
[thirdparty/openssl.git] / doc / man1 / openssl-smime.pod.in
CommitLineData
e3775a33
DSH
1=pod
2
9fcb9702
RS
3=begin comment
4{- join("\n", @autowarntext) -}
5
6=end comment
7
e3775a33
DSH
8=head1 NAME
9
b6b66573 10openssl-smime - S/MIME utility
e3775a33
DSH
11
12=head1 SYNOPSIS
13
14B<openssl> B<smime>
169394d4 15[B<-help>]
e3775a33
DSH
16[B<-encrypt>]
17[B<-decrypt>]
18[B<-sign>]
d884c5ba 19[B<-resign>]
e3775a33
DSH
20[B<-verify>]
21[B<-pk7out>]
2197494d
DSH
22[B<-binary>]
23[B<-crlfeol>]
8dc57d76 24[B<-I<cipher>>]
e8769719 25[B<-in> I<file>]
e8769719 26[B<-attime> I<timestamp>]
e42d84be
HK
27[B<-check_ss_sig>]
28[B<-crl_check>]
29[B<-crl_check_all>]
30[B<-explicit_policy>]
31[B<-extended_crl>]
32[B<-ignore_critical>]
33[B<-inhibit_any>]
34[B<-inhibit_map>]
e42d84be 35[B<-partial_chain>]
e8769719 36[B<-policy> I<arg>]
e42d84be
HK
37[B<-policy_check>]
38[B<-policy_print>]
e8769719 39[B<-purpose> I<purpose>]
e42d84be
HK
40[B<-suiteB_128>]
41[B<-suiteB_128_only>]
42[B<-suiteB_192>]
6d3d5793 43[B<-trusted_first>]
fa7b0111 44[B<-no_alt_chains>]
e42d84be 45[B<-use_deltas>]
e8769719
RS
46[B<-auth_level> I<num>]
47[B<-verify_depth> I<num>]
48[B<-verify_email> I<email>]
49[B<-verify_hostname> I<hostname>]
50[B<-verify_ip> I<ip>]
51[B<-verify_name> I<name>]
e42d84be 52[B<-x509_strict>]
e8769719
RS
53[B<-certfile> I<file>]
54[B<-signer> I<file>]
55[B<-recip> I< file>]
56[B<-inform> B<DER>|B<PEM>|B<SMIME>]
777182a0
RS
57[B<-outform> B<DER>|B<PEM>|B<SMIME>]
58[B<-keyform> B<DER>|B<PEM>|B<ENGINE>]
e8769719
RS
59[B<-passin> I<arg>]
60[B<-inkey> I<file_or_id>]
61[B<-out> I<file>]
e8769719
RS
62[B<-content> I<file>]
63[B<-to> I<addr>]
64[B<-from> I<ad>]
65[B<-subject> I<s>]
e3775a33 66[B<-text>]
76b46e77
DSH
67[B<-indef>]
68[B<-noindef>]
69[B<-stream>]
e8769719 70[B<-md> I<digest>]
9fcb9702
RS
71{- $OpenSSL::safe::opt_trust_synopsis -}
72{- $OpenSSL::safe::opt_r_synopsis -}
b1c0cc24 73I<cert.pem> ...
e3775a33 74
9f3c076b 75=for openssl ifdef engine
1738c0ce 76
e3775a33
DSH
77=head1 DESCRIPTION
78
35a810bb
RL
79This command handles S/MIME mail. It can encrypt, decrypt, sign
80and verify S/MIME messages.
e3775a33 81
3dfda1a6 82=head1 OPTIONS
e3775a33 83
76b46e77 84There are six operation options that set the type of operation to be performed.
e3775a33
DSH
85The meaning of the other options varies according to the operation type.
86
87=over 4
88
169394d4
MR
89=item B<-help>
90
91Print out a usage message.
92
e3775a33
DSH
93=item B<-encrypt>
94
c4de074e 95Encrypt mail for the given recipient certificates. Input file is the message
e3775a33
DSH
96to be encrypted. The output file is the encrypted mail in MIME format.
97
2a9afa40
RS
98Note that no revocation check is done for the recipient cert, so if that
99key has been compromised, others may be able to decrypt the text.
100
e3775a33
DSH
101=item B<-decrypt>
102
c4de074e 103Decrypt mail using the supplied certificate and private key. Expects an
e3775a33
DSH
104encrypted mail message in MIME format for the input file. The decrypted mail
105is written to the output file.
106
107=item B<-sign>
108
c4de074e 109Sign mail using the supplied certificate and private key. Input file is
e3775a33
DSH
110the message to be signed. The signed message in MIME format is written
111to the output file.
112
113=item B<-verify>
114
c4de074e 115Verify signed mail. Expects a signed mail message on input and outputs
e3775a33
DSH
116the signed data. Both clear text and opaque signing is supported.
117
118=item B<-pk7out>
119
c4de074e 120Takes an input message and writes out a PEM encoded PKCS#7 structure.
e3775a33 121
d884c5ba
DSH
122=item B<-resign>
123
c4de074e 124Resign a message: take an existing message and one or more new signers.
d884c5ba 125
e8769719 126=item B<-in> I<filename>
e3775a33 127
c4de074e 128The input message to be encrypted or signed or the MIME message to
e3775a33
DSH
129be decrypted or verified.
130
e8769719 131=item B<-out> I<filename>
e3775a33 132
c4de074e 133The message text that has been decrypted or verified or the output MIME
e3775a33
DSH
134format message that has been signed or verified.
135
777182a0
RS
136=item B<-inform> B<DER>|B<PEM>|B<SMIME>
137
138The input format of the PKCS#7 (S/MIME) structure (if one is being read);
139the default is B<SMIME>.
140See L<openssl(1)/Format Options> for details.
141
e8769719 142=item B<-outform> B<DER>|B<PEM>|B<SMIME>
fd13f0ee 143
777182a0
RS
144The output format of the PKCS#7 (S/MIME) structure (if one is being written);
145the default is B<SMIME>.
146See L<openssl(1)/Format Options> for details.
147
148=item B<-keyform> B<DER>|B<PEM>
149
150The key format; the default is B<PEM>.
151See L<openssl(1)/Format Options> for details.
fd13f0ee 152
e8769719 153=item B<-stream>, B<-indef>, B<-noindef>
76b46e77 154
c4de074e 155The B<-stream> and B<-indef> options are equivalent and enable streaming I/O
76b46e77
DSH
156for encoding operations. This permits single pass processing of data without
157the need to hold the entire contents in memory, potentially supporting very
158large files. Streaming is automatically set for S/MIME signing with detached
159data if the output format is B<SMIME> it is currently off by default for all
160other operations.
161
162=item B<-noindef>
163
c4de074e 164Disable streaming I/O where it would produce and indefinite length constructed
76b46e77
DSH
165encoding. This option currently has no effect. In future streaming will be
166enabled by default on all relevant operations and this option will disable it.
167
e8769719 168=item B<-content> I<filename>
fd13f0ee
DSH
169
170This specifies a file containing the detached content, this is only
171useful with the B<-verify> command. This is only usable if the PKCS#7
172structure is using the detached signature form where the content is
173not included. This option will override any content if the input format
174is S/MIME and it uses the multipart/signed MIME content type.
175
e3775a33
DSH
176=item B<-text>
177
c4de074e 178This option adds plain text (text/plain) MIME headers to the supplied
e3775a33 179message if encrypting or signing. If decrypting or verifying it strips
1bc74519 180off text headers: if the decrypted or verified message is not of MIME
e3775a33
DSH
181type text/plain then an error occurs.
182
e8769719 183=item B<-md> I<digest>
d884c5ba 184
c4de074e 185Digest algorithm to use when signing or resigning. If not present then the
d884c5ba
DSH
186default digest algorithm for the signing key will be used (usually SHA1).
187
8dc57d76 188=item B<-I<cipher>>
e3775a33 189
c4de074e 190The encryption algorithm to use. For example DES (56 bits) - B<-des>,
e5fa864f 191triple DES (168 bits) - B<-des3>,
1bc74519 192EVP_get_cipherbyname() function) can also be used preceded by a dash, for
35a810bb 193example B<-aes-128-cbc>. See L<openssl-enc(1)> for list of ciphers
e5fa864f 194supported by your version of OpenSSL.
d884c5ba 195
6f719f06 196If not specified triple DES is used. Only used with B<-encrypt>.
e3775a33
DSH
197
198=item B<-nointern>
199
c4de074e 200When verifying a message normally certificates (if any) included in
e3775a33
DSH
201the message are searched for the signing certificate. With this option
202only the certificates specified in the B<-certfile> option are used.
203The supplied certificates can still be used as untrusted CAs however.
204
205=item B<-noverify>
206
c4de074e 207Do not verify the signers certificate of a signed message.
e3775a33
DSH
208
209=item B<-nochain>
210
c4de074e 211Do not do chain verification of signers certificates: that is don't
e3775a33
DSH
212use the certificates in the signed message as untrusted CAs.
213
214=item B<-nosigs>
215
c4de074e 216Don't try to verify the signatures on the message.
e3775a33
DSH
217
218=item B<-nocerts>
219
c4de074e 220When signing a message the signer's certificate is normally included
e3775a33
DSH
221with this option it is excluded. This will reduce the size of the
222signed message but the verifier must have a copy of the signers certificate
223available locally (passed using the B<-certfile> option for example).
224
225=item B<-noattr>
226
c4de074e 227Normally when a message is signed a set of attributes are included which
e3775a33
DSH
228include the signing time and supported symmetric algorithms. With this
229option they are not included.
230
231=item B<-binary>
232
c4de074e 233Normally the input message is converted to "canonical" format which is
3fc9635e
DSH
234effectively using CR and LF as end of line: as required by the S/MIME
235specification. When this option is present no translation occurs. This
236is useful when handling binary data which may not be in MIME format.
e3775a33 237
2197494d
DSH
238=item B<-crlfeol>
239
c4de074e 240Normally the output file uses a single B<LF> as end of line. When this
2197494d
DSH
241option is present B<CRLF> is used instead.
242
e3775a33
DSH
243=item B<-nodetach>
244
c4de074e 245When signing a message use opaque signing: this form is more resistant
e3775a33
DSH
246to translation by mail relays but it cannot be read by mail agents that
247do not support S/MIME. Without this option cleartext signing with
248the MIME type multipart/signed is used.
249
e8769719 250=item B<-certfile> I<file>
e3775a33 251
c4de074e 252Allows additional certificates to be specified. When signing these will
e3775a33
DSH
253be included with the message. When verifying these will be searched for
254the signers certificates. The certificates should be in PEM format.
255
e8769719 256=item B<-signer> I<file>
e3775a33 257
c4de074e 258A signing certificate when signing or resigning a message, this option can be
d884c5ba
DSH
259used multiple times if more than one signer is required. If a message is being
260verified then the signers certificates will be written to this file if the
261verification was successful.
e3775a33 262
e8769719 263=item B<-recip> I<file>
e3775a33 264
c4de074e 265The recipients certificate when decrypting a message. This certificate
e3775a33
DSH
266must match one of the recipients of the message or an error occurs.
267
e8769719 268=item B<-inkey> I<file_or_id>
e3775a33 269
c4de074e 270The private key to use when signing or decrypting. This must match the
e3775a33
DSH
271corresponding certificate. If this option is not specified then the
272private key must be included in the certificate file specified with
d884c5ba
DSH
273the B<-recip> or B<-signer> file. When signing this option can be used
274multiple times to specify successive keys.
48b53522
RS
275If no engine is used, the argument is taken as a file; if an engine is
276specified, the argument is given to the engine as a key identifier.
e3775a33 277
e8769719 278=item B<-passin> I<arg>
84b65340 279
2f0ea936 280The private key password source. For more information about the format of I<arg>
3a4e43de 281see L<openssl(1)/Pass Phrase Options>.
84b65340 282
8dc57d76 283=item B<-to>, B<-from>, B<-subject>
e3775a33 284
c4de074e 285The relevant mail headers. These are included outside the signed
e3775a33
DSH
286portion of a message so they may be included manually. If signing
287then many S/MIME mail clients check the signers certificate's email
288address matches that specified in the From: address.
289
e42d84be 290=item B<-attime>, B<-check_ss_sig>, B<-crl_check>, B<-crl_check_all>,
d33def66
VD
291B<-explicit_policy>, B<-extended_crl>, B<-ignore_critical>, B<-inhibit_any>,
292B<-inhibit_map>, B<-no_alt_chains>, B<-partial_chain>, B<-policy>,
e42d84be 293B<-policy_check>, B<-policy_print>, B<-purpose>, B<-suiteB_128>,
d33def66 294B<-suiteB_128_only>, B<-suiteB_192>, B<-trusted_first>, B<-use_deltas>,
fbb82a60
VD
295B<-auth_level>, B<-verify_depth>, B<-verify_email>, B<-verify_hostname>,
296B<-verify_ip>, B<-verify_name>, B<-x509_strict>
e5fa864f
DSH
297
298Set various options of certificate chain verification. See
8bc93d2f 299L<openssl-verify(1)> manual page for details.
e5fa864f 300
9fcb9702
RS
301{- $OpenSSL::safe::opt_trust_item -}
302
303{- $OpenSSL::safe::opt_r_item -}
304
b1c0cc24
RL
305=item I<cert.pem> ...
306
307One or more certificates of message recipients, used when encrypting
308a message.
309
e3775a33
DSH
310=back
311
312=head1 NOTES
313
314The MIME message must be sent without any blank lines between the
315headers and the output. Some mail programs will automatically add
316a blank line. Piping the mail directly to sendmail is one way to
317achieve the correct format.
318
3fc9635e 319The supplied message to be signed or encrypted must include the
60250017 320necessary MIME headers or many S/MIME clients won't display it
3fc9635e
DSH
321properly (if at all). You can use the B<-text> option to automatically
322add plain text headers.
323
e3775a33
DSH
324A "signed and encrypted" message is one where a signed message is
325then encrypted. This can be produced by encrypting an already signed
3fc9635e 326message: see the examples section.
e3775a33
DSH
327
328This version of the program only allows one signer per message but it
329will verify multiple signers on received messages. Some S/MIME clients
19d2bb57 330choke if a message contains multiple signers. It is possible to sign
e3775a33
DSH
331messages "in parallel" by signing an already signed message.
332
3fc9635e
DSH
333The options B<-encrypt> and B<-decrypt> reflect common usage in S/MIME
334clients. Strictly speaking these process PKCS#7 enveloped data: PKCS#7
335encrypted data is used for other purposes.
336
d884c5ba
DSH
337The B<-resign> option uses an existing message digest when adding a new
338signer. This means that attributes must be present in at least one existing
339signer using the same message digest or this operation will fail.
340
e4ef2e25 341The B<-stream> and B<-indef> options enable streaming I/O support.
76b46e77
DSH
342As a result the encoding is BER using indefinite length constructed encoding
343and no longer DER. Streaming is supported for the B<-encrypt> operation and the
344B<-sign> operation if the content is not detached.
345
346Streaming is always used for the B<-sign> operation with detached data but
347since the content is no longer part of the PKCS#7 structure the encoding
348remains DER.
349
e3775a33
DSH
350=head1 EXIT CODES
351
352=over 4
353
c8919dde 354=item Z<>0
e3775a33 355
c4de074e 356The operation was completely successfully.
e3775a33 357
c8919dde 358=item Z<>1
e3775a33 359
c4de074e 360An error occurred parsing the command options.
e3775a33 361
c8919dde 362=item Z<>2
e3775a33 363
c4de074e 364One of the input files could not be read.
e3775a33 365
c8919dde 366=item Z<>3
e3775a33 367
c4de074e 368An error occurred creating the PKCS#7 file or when reading the MIME
e3775a33
DSH
369message.
370
c8919dde 371=item Z<>4
e3775a33 372
c4de074e 373An error occurred decrypting or verifying the message.
e3775a33 374
c8919dde 375=item Z<>5
e3775a33 376
c4de074e 377The message was verified correctly but an error occurred writing out
e3775a33
DSH
378the signers certificates.
379
380=back
381
382=head1 EXAMPLES
383
3fc9635e
DSH
384Create a cleartext signed message:
385
1675f6eb 386 openssl smime -sign -in message.txt -text -out mail.msg \
1bc74519 387 -signer mycert.pem
3fc9635e 388
0d638dc1 389Create an opaque signed message:
3fc9635e 390
1675f6eb 391 openssl smime -sign -in message.txt -text -out mail.msg -nodetach \
1bc74519 392 -signer mycert.pem
3fc9635e
DSH
393
394Create a signed message, include some additional certificates and
395read the private key from another file:
396
1675f6eb 397 openssl smime -sign -in in.txt -text -out mail.msg \
1bc74519 398 -signer mycert.pem -inkey mykey.pem -certfile mycerts.pem
3fc9635e 399
d884c5ba
DSH
400Create a signed message with two signers:
401
402 openssl smime -sign -in message.txt -text -out mail.msg \
1bc74519 403 -signer mycert.pem -signer othercert.pem
d884c5ba 404
3fc9635e
DSH
405Send a signed message under Unix directly to sendmail, including headers:
406
1675f6eb 407 openssl smime -sign -in in.txt -text -signer mycert.pem \
1bc74519
RS
408 -from steve@openssl.org -to someone@somewhere \
409 -subject "Signed message" | sendmail someone@somewhere
3fc9635e
DSH
410
411Verify a message and extract the signer's certificate if successful:
412
413 openssl smime -verify -in mail.msg -signer user.pem -out signedtext.txt
414
415Send encrypted mail using triple DES:
416
1675f6eb 417 openssl smime -encrypt -in in.txt -from steve@openssl.org \
1bc74519
RS
418 -to someone@somewhere -subject "Encrypted message" \
419 -des3 user.pem -out mail.msg
3fc9635e
DSH
420
421Sign and encrypt mail:
422
1675f6eb 423 openssl smime -sign -in ml.txt -signer my.pem -text \
1bc74519
RS
424 | openssl smime -encrypt -out mail.msg \
425 -from steve@openssl.org -to someone@somewhere \
426 -subject "Signed and Encrypted message" -des3 user.pem
3fc9635e 427
d884c5ba
DSH
428Note: the encryption command does not include the B<-text> option because the
429message being encrypted already has MIME headers.
3fc9635e
DSH
430
431Decrypt mail:
432
433 openssl smime -decrypt -in mail.msg -recip mycert.pem -inkey key.pem
434
fd13f0ee
DSH
435The output from Netscape form signing is a PKCS#7 structure with the
436detached signature format. You can use this program to verify the
437signature by line wrapping the base64 encoded structure and surrounding
438it with:
439
a8c12555
DSH
440 -----BEGIN PKCS7-----
441 -----END PKCS7-----
fd13f0ee 442
1bc74519 443and using the command:
fd13f0ee
DSH
444
445 openssl smime -verify -inform PEM -in signature.pem -content content.txt
446
0d638dc1 447Alternatively you can base64 decode the signature and use:
fd13f0ee
DSH
448
449 openssl smime -verify -inform DER -in signature.der -content content.txt
450
f3dea9a5
BM
451Create an encrypted message using 128 bit Camellia:
452
453 openssl smime -encrypt -in plain.txt -camellia128 -out mail.msg cert.pem
454
d884c5ba
DSH
455Add a signer to an existing message:
456
457 openssl smime -resign -in mail.msg -signer newsign.pem -out mail2.msg
458
3fc9635e
DSH
459=head1 BUGS
460
d884c5ba
DSH
461The MIME parser isn't very clever: it seems to handle most messages that I've
462thrown at it but it may choke on others.
3fc9635e 463
d884c5ba
DSH
464The code currently will only write out the signer's certificate to a file: if
465the signer has a separate encryption certificate this must be manually
466extracted. There should be some heuristic that determines the correct
467encryption certificate.
3fc9635e 468
d884c5ba
DSH
469Ideally a database should be maintained of a certificates for each email
470address.
3fc9635e
DSH
471
472The code doesn't currently take note of the permitted symmetric encryption
7e0de9e8 473algorithms as supplied in the SMIMECapabilities signed attribute. This means the
3fc9635e
DSH
474user has to manually include the correct encryption algorithm. It should store
475the list of permitted ciphers in a database and only use those.
476
477No revocation checking is done on the signer's certificate.
478
479The current code can only handle S/MIME v2 messages, the more complex S/MIME v3
480structures may cause parsing errors.
e3775a33 481
fd3397fc
RL
482=head1 SEE ALSO
483
484L<ossl_store-file(7)>
485
d884c5ba
DSH
486=head1 HISTORY
487
488The use of multiple B<-signer> options and the B<-resign> command were first
fb552ac6 489added in OpenSSL 1.0.0
d884c5ba 490
fc5ecadd 491The -no_alt_chains option was added in OpenSSL 1.1.0.
d884c5ba 492
e2f92610
RS
493=head1 COPYRIGHT
494
b6b66573 495Copyright 2000-2019 The OpenSSL Project Authors. All Rights Reserved.
e2f92610 496
449040b4 497Licensed under the Apache License 2.0 (the "License"). You may not use
e2f92610
RS
498this file except in compliance with the License. You can obtain a copy
499in the file LICENSE in the source distribution or at
500L<https://www.openssl.org/source/license.html>.
501
502=cut