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