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