6b4beb4c277e1aa484d9227f03200c959115ecc7
[openssl.git] / doc / apps / cms.pod
1 =pod
2
3 =head1 NAME
4
5 cms - CMS utility
6
7 =head1 SYNOPSIS
8
9 B<openssl> B<cms>
10 [B<-encrypt>]
11 [B<-decrypt>]
12 [B<-sign>]
13 [B<-verify>]
14 [B<-cmsout>]
15 [B<-resign>]
16 [B<-data_create>]
17 [B<-data_out>]
18 [B<-digest_create>]
19 [B<-digest_verify>]
20 [B<-compress>]
21 [B<-uncompress>]
22 [B<-EncryptedData_encrypt>]
23 [B<-sign_receipt>]
24 [B<-verify_receipt receipt>]
25 [B<-in filename>]
26 [B<-inform SMIME|PEM|DER>]
27 [B<-rctform SMIME|PEM|DER>]
28 [B<-out filename>]
29 [B<-outform SMIME|PEM|DER>]
30 [B<-stream -indef -noindef>]
31 [B<-noindef>]
32 [B<-content filename>]
33 [B<-text>]
34 [B<-noout>]
35 [B<-print>]
36 [B<-CAfile file>]
37 [B<-CApath dir>]
38 [B<-attime timestamp>]
39 [B<-check_ss_sig>]
40 [B<-crl_check>]
41 [B<-crl_check_all>]
42 [B<-explicit_policy>]
43 [B<-extended_crl>]
44 [B<-ignore_critical>]
45 [B<-inhibit_any>]
46 [B<-inhibit_map>]
47 [B<-issuer_checks>]
48 [B<-partial_chain>]
49 [B<-policy arg>]
50 [B<-policy_check>]
51 [B<-policy_print>]
52 [B<-purpose purpose>]
53 [B<-suiteB_128>]
54 [B<-suiteB_128_only>]
55 [B<-suiteB_192>]
56 [B<-trusted_first>]
57 [B<-no_alt_chains>]
58 [B<-use_deltas>]
59 [B<-verify_depth num>]
60 [B<-verify_email email>]
61 [B<-verify_hostname hostname>]
62 [B<-verify_ip ip>]
63 [B<-verify_name name>]
64 [B<-x509_strict>]
65 [B<-md digest>]
66 [B<-[cipher]>]
67 [B<-nointern>]
68 [B<-no_signer_cert_verify>]
69 [B<-nocerts>]
70 [B<-noattr>]
71 [B<-nosmimecap>]
72 [B<-binary>]
73 [B<-asciicrlf>]
74 [B<-nodetach>]
75 [B<-certfile file>]
76 [B<-certsout file>]
77 [B<-signer file>]
78 [B<-recip file>]
79 [B<-keyid>]
80 [B<-receipt_request_all -receipt_request_first>]
81 [B<-receipt_request_from emailaddress>]
82 [B<-receipt_request_to emailaddress>]
83 [B<-receipt_request_print>]
84 [B<-secretkey key>]
85 [B<-secretkeyid id>]
86 [B<-econtent_type type>]
87 [B<-inkey file>]
88 [B<-keyopt name:parameter>]
89 [B<-passin arg>]
90 [B<-rand file(s)>]
91 [B<cert.pem...>]
92 [B<-to addr>]
93 [B<-from addr>]
94 [B<-subject subj>]
95 [cert.pem]...
96
97 =head1 DESCRIPTION
98
99 The B<cms> command handles S/MIME v3.1 mail. It can encrypt, decrypt, sign and
100 verify, compress and uncompress S/MIME messages.
101
102 =head1 COMMAND OPTIONS
103
104 There are fourteen operation options that set the type of operation to be
105 performed. The meaning of the other options varies according to the operation
106 type.
107
108 =over 4
109
110 =item B<-encrypt>
111
112 encrypt mail for the given recipient certificates. Input file is the message
113 to be encrypted. The output file is the encrypted mail in MIME format. The
114 actual CMS type is <B>EnvelopedData<B>.
115
116 =item B<-decrypt>
117
118 decrypt mail using the supplied certificate and private key. Expects an
119 encrypted mail message in MIME format for the input file. The decrypted mail
120 is written to the output file.
121
122 =item B<-debug_decrypt>
123
124 this option sets the B<CMS_DEBUG_DECRYPT> flag. This option should be used
125 with caution: see the notes section below.
126
127 =item B<-sign>
128
129 sign mail using the supplied certificate and private key. Input file is
130 the message to be signed. The signed message in MIME format is written
131 to the output file.
132
133 =item B<-verify>
134
135 verify signed mail. Expects a signed mail message on input and outputs
136 the signed data. Both clear text and opaque signing is supported.
137
138 =item B<-cmsout>
139
140 takes an input message and writes out a PEM encoded CMS structure.
141
142 =item B<-resign>
143
144 resign a message: take an existing message and one or more new signers.
145
146 =item B<-data_create>
147
148 Create a CMS B<Data> type.
149
150 =item B<-data_out>
151
152 B<Data> type and output the content.
153
154 =item B<-digest_create>
155
156 Create a CMS B<DigestedData> type.
157
158 =item B<-digest_verify>
159
160 Verify a CMS B<DigestedData> type and output the content.
161
162 =item B<-compress>
163
164 Create a CMS B<CompressedData> type. OpenSSL must be compiled with B<zlib>
165 support for this option to work, otherwise it will output an error.
166
167 =item B<-uncompress>
168
169 Uncompress a CMS B<CompressedData> type and output the content. OpenSSL must be
170 compiled with B<zlib> support for this option to work, otherwise it will
171 output an error.
172
173 =item B<-EncryptedData_encrypt>
174
175 Encrypt content using supplied symmetric key and algorithm using a CMS
176 B<EncrytedData> type and output the content.
177
178 =item B<-sign_receipt>
179
180 Generate and output a signed receipt for the supplied message. The input 
181 message B<must> contain a signed receipt request. Functionality is otherwise
182 similar to the B<-sign> operation.
183
184 =item B<-verify_receipt receipt>
185
186 Verify a signed receipt in filename B<receipt>. The input message B<must> 
187 contain the original receipt request. Functionality is otherwise similar
188 to the B<-verify> operation.
189
190 =item B<-in filename>
191
192 the input message to be encrypted or signed or the message to be decrypted
193 or verified.
194
195 =item B<-inform SMIME|PEM|DER>
196
197 this specifies the input format for the CMS structure. The default
198 is B<SMIME> which reads an S/MIME format message. B<PEM> and B<DER>
199 format change this to expect PEM and DER format CMS structures
200 instead. This currently only affects the input format of the CMS
201 structure, if no CMS structure is being input (for example with
202 B<-encrypt> or B<-sign>) this option has no effect.
203
204 =item B<-rctform SMIME|PEM|DER>
205
206 specify the format for a signed receipt for use with the B<-receipt_verify>
207 operation.
208
209 =item B<-out filename>
210
211 the message text that has been decrypted or verified or the output MIME
212 format message that has been signed or verified.
213
214 =item B<-outform SMIME|PEM|DER>
215
216 this specifies the output format for the CMS structure. The default
217 is B<SMIME> which writes an S/MIME format message. B<PEM> and B<DER>
218 format change this to write PEM and DER format CMS structures
219 instead. This currently only affects the output format of the CMS
220 structure, if no CMS structure is being output (for example with
221 B<-verify> or B<-decrypt>) this option has no effect.
222
223 =item B<-stream -indef -noindef>
224
225 the B<-stream> and B<-indef> options are equivalent and enable streaming I/O
226 for encoding operations. This permits single pass processing of data without
227 the need to hold the entire contents in memory, potentially supporting very
228 large files. Streaming is automatically set for S/MIME signing with detached
229 data if the output format is B<SMIME> it is currently off by default for all
230 other operations.
231
232 =item B<-noindef>
233
234 disable streaming I/O where it would produce and indefinite length constructed
235 encoding. This option currently has no effect. In future streaming will be
236 enabled by default on all relevant operations and this option will disable it.
237
238 =item B<-content filename>
239
240 This specifies a file containing the detached content, this is only
241 useful with the B<-verify> command. This is only usable if the CMS
242 structure is using the detached signature form where the content is
243 not included. This option will override any content if the input format
244 is S/MIME and it uses the multipart/signed MIME content type.
245
246 =item B<-text>
247
248 this option adds plain text (text/plain) MIME headers to the supplied
249 message if encrypting or signing. If decrypting or verifying it strips
250 off text headers: if the decrypted or verified message is not of MIME 
251 type text/plain then an error occurs.
252
253 =item B<-noout>
254
255 for the B<-cmsout> operation do not output the parsed CMS structure. This
256 is useful when combined with the B<-print> option or if the syntax of the CMS
257 structure is being checked.
258
259 =item B<-print>
260
261 for the B<-cmsout> operation print out all fields of the CMS structure. This
262 is mainly useful for testing purposes.
263
264 =item B<-CAfile file>
265
266 a file containing trusted CA certificates, only used with B<-verify>.
267
268 =item B<-CApath dir>
269
270 a directory containing trusted CA certificates, only used with
271 B<-verify>. This directory must be a standard certificate directory: that
272 is a hash of each subject name (using B<x509 -hash>) should be linked
273 to each certificate.
274
275 =item B<-md digest>
276
277 digest algorithm to use when signing or resigning. If not present then the
278 default digest algorithm for the signing key will be used (usually SHA1).
279
280 =item B<-[cipher]>
281
282 the encryption algorithm to use. For example triple DES (168 bits) - B<-des3>
283 or 256 bit AES - B<-aes256>. Any standard algorithm name (as used by the
284 EVP_get_cipherbyname() function) can also be used preceded by a dash, for 
285 example B<-aes_128_cbc>. See L<B<enc>|enc(1)> for a list of ciphers
286 supported by your version of OpenSSL.
287
288 If not specified triple DES is used. Only used with B<-encrypt> and 
289 B<-EncryptedData_create> commands.
290
291 =item B<-nointern>
292
293 when verifying a message normally certificates (if any) included in
294 the message are searched for the signing certificate. With this option
295 only the certificates specified in the B<-certfile> option are used.
296 The supplied certificates can still be used as untrusted CAs however.
297
298 =item B<-no_signer_cert_verify>
299
300 do not verify the signers certificate of a signed message.
301
302 =item B<-nocerts>
303
304 when signing a message the signer's certificate is normally included
305 with this option it is excluded. This will reduce the size of the
306 signed message but the verifier must have a copy of the signers certificate
307 available locally (passed using the B<-certfile> option for example).
308
309 =item B<-noattr>
310
311 normally when a message is signed a set of attributes are included which
312 include the signing time and supported symmetric algorithms. With this
313 option they are not included.
314
315 =item B<-nosmimecap>
316
317 exclude the list of supported algorithms from signed attributes, other options
318 such as signing time and content type are still included.
319
320 =item B<-binary>
321
322 normally the input message is converted to "canonical" format which is
323 effectively using CR and LF as end of line: as required by the S/MIME
324 specification. When this option is present no translation occurs. This
325 is useful when handling binary data which may not be in MIME format.
326
327 =item B<-asciicrlf>
328
329 when signing use ASCII CRLF format canonicalisation. This strips trailing
330 whitespace from all lines, deletes trailing blank lines at EOF and sets
331 the encapsulated content type. This option is normally used with detached
332 content and an output signature format of DER. This option is not normally
333 needed when verifying as it is enabled automatically if the encapsulated
334 content format is detected.
335
336 =item B<-nodetach>
337
338 when signing a message use opaque signing: this form is more resistant
339 to translation by mail relays but it cannot be read by mail agents that
340 do not support S/MIME.  Without this option cleartext signing with
341 the MIME type multipart/signed is used.
342
343 =item B<-certfile file>
344
345 allows additional certificates to be specified. When signing these will
346 be included with the message. When verifying these will be searched for
347 the signers certificates. The certificates should be in PEM format.
348
349 =item B<-certsout file>
350
351 any certificates contained in the message are written to B<file>.
352
353 =item B<-signer file>
354
355 a signing certificate when signing or resigning a message, this option can be
356 used multiple times if more than one signer is required. If a message is being
357 verified then the signers certificates will be written to this file if the
358 verification was successful.
359
360 =item B<-recip file>
361
362 when decrypting a message this specifies the recipients certificate. The
363 certificate must match one of the recipients of the message or an error
364 occurs.
365
366 When encrypting a message this option may be used multiple times to specify
367 each recipient. This form B<must> be used if customised parameters are
368 required (for example to specify RSA-OAEP).
369
370 =item B<-keyid>
371
372 use subject key identifier to identify certificates instead of issuer name and
373 serial number. The supplied certificate B<must> include a subject key
374 identifier extension. Supported by B<-sign> and B<-encrypt> options.
375
376 =item B<-receipt_request_all -receipt_request_first>
377
378 for B<-sign> option include a signed receipt request. Indicate requests should
379 be provided by all recipient or first tier recipients (those mailed directly
380 and not from a mailing list). Ignored it B<-receipt_request_from> is included.
381
382 =item B<-receipt_request_from emailaddress>
383
384 for B<-sign> option include a signed receipt request. Add an explicit email
385 address where receipts should be supplied.
386
387 =item B<-receipt_request_to emailaddress>
388
389 Add an explicit email address where signed receipts should be sent to. This 
390 option B<must> but supplied if a signed receipt it requested.
391
392 =item B<-receipt_request_print>
393
394 For the B<-verify> operation print out the contents of any signed receipt
395 requests.
396
397 =item B<-secretkey key>
398
399 specify symmetric key to use. The key must be supplied in hex format and be
400 consistent with the algorithm used. Supported by the B<-EncryptedData_encrypt>
401 B<-EncryptedData_decrypt>, B<-encrypt> and B<-decrypt> options. When used
402 with B<-encrypt> or B<-decrypt> the supplied key is used to wrap or unwrap the
403 content encryption key using an AES key in the B<KEKRecipientInfo> type.
404
405 =item B<-secretkeyid id>
406
407 the key identifier for the supplied symmetric key for B<KEKRecipientInfo> type.
408 This option B<must> be present if the B<-secretkey> option is used with
409 B<-encrypt>. With B<-decrypt> operations the B<id> is used to locate the
410 relevant key if it is not supplied then an attempt is used to decrypt any
411 B<KEKRecipientInfo> structures.
412
413 =item B<-econtent_type type>
414
415 set the encapsulated content type to B<type> if not supplied the B<Data> type
416 is used. The B<type> argument can be any valid OID name in either text or
417 numerical format. 
418
419 =item B<-inkey file>
420
421 the private key to use when signing or decrypting. This must match the
422 corresponding certificate. If this option is not specified then the
423 private key must be included in the certificate file specified with
424 the B<-recip> or B<-signer> file. When signing this option can be used
425 multiple times to specify successive keys.
426
427 =item B<-keyopt name:opt>
428
429 for signing and encryption this option can be used multiple times to
430 set customised parameters for the preceding key or certificate. It can
431 currently be used to set RSA-PSS for signing, RSA-OAEP for encryption
432 or to modify default parameters for ECDH.
433
434 =item B<-passin arg>
435
436 the private key password source. For more information about the format of B<arg>
437 see the B<PASS PHRASE ARGUMENTS> section in L<openssl(1)>.
438
439 =item B<-rand file(s)>
440
441 a file or files containing random data used to seed the random number
442 generator, or an EGD socket (see L<RAND_egd(3)>).
443 Multiple files can be specified separated by a OS-dependent character.
444 The separator is B<;> for MS-Windows, B<,> for OpenVMS, and B<:> for
445 all others.
446
447 =item B<cert.pem...>
448
449 one or more certificates of message recipients: used when encrypting
450 a message. 
451
452 =item B<-to, -from, -subject>
453
454 the relevant mail headers. These are included outside the signed
455 portion of a message so they may be included manually. If signing
456 then many S/MIME mail clients check the signers certificate's email
457 address matches that specified in the From: address.
458
459 =item B<-attime>, B<-check_ss_sig>, B<-crl_check>, B<-crl_check_all>,
460 B<explicit_policy>, B<-extended_crl>, B<-ignore_critical>, B<-inhibit_any>,
461 B<-inhibit_map>, B<-issuer_checks>, B<-partial_chain>, B<-policy>,
462 B<-policy_check>, B<-policy_print>, B<-purpose>, B<-suiteB_128>,
463 B<-suiteB_128_only>, B<-suiteB_192>, B<-trusted_first>, B<-no_alt_chains>,
464 B<-use_deltas>, B<-verify_depth>, B<-verify_email>, B<-verify_hostname>,
465 B<-verify_ip>, B<-verify_name>, B<-x509_strict>
466
467 Set various certificate chain validation options. See the
468 L<verify(1)> manual page for details.
469
470 =back
471
472 =head1 NOTES
473
474 The MIME message must be sent without any blank lines between the
475 headers and the output. Some mail programs will automatically add
476 a blank line. Piping the mail directly to sendmail is one way to
477 achieve the correct format.
478
479 The supplied message to be signed or encrypted must include the
480 necessary MIME headers or many S/MIME clients wont display it
481 properly (if at all). You can use the B<-text> option to automatically
482 add plain text headers.
483
484 A "signed and encrypted" message is one where a signed message is
485 then encrypted. This can be produced by encrypting an already signed
486 message: see the examples section.
487
488 This version of the program only allows one signer per message but it
489 will verify multiple signers on received messages. Some S/MIME clients
490 choke if a message contains multiple signers. It is possible to sign
491 messages "in parallel" by signing an already signed message.
492
493 The options B<-encrypt> and B<-decrypt> reflect common usage in S/MIME
494 clients. Strictly speaking these process CMS enveloped data: CMS
495 encrypted data is used for other purposes.
496
497 The B<-resign> option uses an existing message digest when adding a new
498 signer. This means that attributes must be present in at least one existing
499 signer using the same message digest or this operation will fail.
500
501 The B<-stream> and B<-indef> options enable experimental streaming I/O support.
502 As a result the encoding is BER using indefinite length constructed encoding
503 and no longer DER. Streaming is supported for the B<-encrypt> operation and the
504 B<-sign> operation if the content is not detached.
505
506 Streaming is always used for the B<-sign> operation with detached data but
507 since the content is no longer part of the CMS structure the encoding
508 remains DER.
509
510 If the B<-decrypt> option is used without a recipient certificate then an
511 attempt is made to locate the recipient by trying each potential recipient
512 in turn using the supplied private key. To thwart the MMA attack
513 (Bleichenbacher's attack on PKCS #1 v1.5 RSA padding) all recipients are
514 tried whether they succeed or not and if no recipients match the message
515 is "decrypted" using a random key which will typically output garbage. 
516 The B<-debug_decrypt> option can be used to disable the MMA attack protection
517 and return an error if no recipient can be found: this option should be used
518 with caution. For a fuller description see L<CMS_decrypt(3)>).
519
520 =head1 EXIT CODES
521
522 =over 4
523
524 =item Z<>0
525
526 the operation was completely successfully.
527
528 =item Z<>1
529
530 an error occurred parsing the command options.
531
532 =item Z<>2
533
534 one of the input files could not be read.
535
536 =item Z<>3
537
538 an error occurred creating the CMS file or when reading the MIME
539 message.
540
541 =item Z<>4
542
543 an error occurred decrypting or verifying the message.
544
545 =item Z<>5
546
547 the message was verified correctly but an error occurred writing out
548 the signers certificates.
549
550 =back
551
552 =head1 COMPATIBILITY WITH PKCS#7 format.
553
554 The B<smime> utility can only process the older B<PKCS#7> format. The B<cms>
555 utility supports Cryptographic Message Syntax format. Use of some features
556 will result in messages which cannot be processed by applications which only
557 support the older format. These are detailed below.
558
559 The use of the B<-keyid> option with B<-sign> or B<-encrypt>.
560
561 The B<-outform PEM> option uses different headers.
562
563 The B<-compress> option.
564
565 The B<-secretkey> option when used with B<-encrypt>.
566
567 The use of PSS with B<-sign>.
568
569 The use of OAEP or non-RSA keys with B<-encrypt>.
570
571 Additionally the B<-EncryptedData_create> and B<-data_create> type cannot
572 be processed by the older B<smime> command.
573
574 =head1 EXAMPLES
575
576 Create a cleartext signed message:
577
578  openssl cms -sign -in message.txt -text -out mail.msg \
579         -signer mycert.pem
580
581 Create an opaque signed message
582
583  openssl cms -sign -in message.txt -text -out mail.msg -nodetach \
584         -signer mycert.pem
585
586 Create a signed message, include some additional certificates and
587 read the private key from another file:
588
589  openssl cms -sign -in in.txt -text -out mail.msg \
590         -signer mycert.pem -inkey mykey.pem -certfile mycerts.pem
591
592 Create a signed message with two signers, use key identifier:
593
594  openssl cms -sign -in message.txt -text -out mail.msg \
595         -signer mycert.pem -signer othercert.pem -keyid
596
597 Send a signed message under Unix directly to sendmail, including headers:
598
599  openssl cms -sign -in in.txt -text -signer mycert.pem \
600         -from steve@openssl.org -to someone@somewhere \
601         -subject "Signed message" | sendmail someone@somewhere
602
603 Verify a message and extract the signer's certificate if successful:
604
605  openssl cms -verify -in mail.msg -signer user.pem -out signedtext.txt
606
607 Send encrypted mail using triple DES:
608
609  openssl cms -encrypt -in in.txt -from steve@openssl.org \
610         -to someone@somewhere -subject "Encrypted message" \
611         -des3 user.pem -out mail.msg
612
613 Sign and encrypt mail:
614
615  openssl cms -sign -in ml.txt -signer my.pem -text \
616         | openssl cms -encrypt -out mail.msg \
617         -from steve@openssl.org -to someone@somewhere \
618         -subject "Signed and Encrypted message" -des3 user.pem
619
620 Note: the encryption command does not include the B<-text> option because the
621 message being encrypted already has MIME headers.
622
623 Decrypt mail:
624
625  openssl cms -decrypt -in mail.msg -recip mycert.pem -inkey key.pem
626
627 The output from Netscape form signing is a PKCS#7 structure with the
628 detached signature format. You can use this program to verify the
629 signature by line wrapping the base64 encoded structure and surrounding
630 it with:
631
632  -----BEGIN PKCS7-----
633  -----END PKCS7-----
634
635 and using the command, 
636
637  openssl cms -verify -inform PEM -in signature.pem -content content.txt
638
639 alternatively you can base64 decode the signature and use
640
641  openssl cms -verify -inform DER -in signature.der -content content.txt
642
643 Create an encrypted message using 128 bit Camellia:
644
645  openssl cms -encrypt -in plain.txt -camellia128 -out mail.msg cert.pem
646
647 Add a signer to an existing message:
648
649  openssl cms -resign -in mail.msg -signer newsign.pem -out mail2.msg
650
651 Sign mail using RSA-PSS:
652
653  openssl cms -sign -in message.txt -text -out mail.msg \
654         -signer mycert.pem -keyopt rsa_padding_mode:pss
655
656 Create encrypted mail using RSA-OAEP:
657
658  openssl cms -encrypt -in plain.txt -out mail.msg \
659         -recip cert.pem -keyopt rsa_padding_mode:oaep
660
661 Use SHA256 KDF with an ECDH certificate:
662
663  openssl cms -encrypt -in plain.txt -out mail.msg \
664         -recip ecdhcert.pem -keyopt ecdh_kdf_md:sha256
665
666 =head1 BUGS
667
668 The MIME parser isn't very clever: it seems to handle most messages that I've
669 thrown at it but it may choke on others.
670
671 The code currently will only write out the signer's certificate to a file: if
672 the signer has a separate encryption certificate this must be manually
673 extracted. There should be some heuristic that determines the correct
674 encryption certificate.
675
676 Ideally a database should be maintained of a certificates for each email
677 address.
678
679 The code doesn't currently take note of the permitted symmetric encryption
680 algorithms as supplied in the SMIMECapabilities signed attribute. this means the
681 user has to manually include the correct encryption algorithm. It should store
682 the list of permitted ciphers in a database and only use those.
683
684 No revocation checking is done on the signer's certificate.
685
686 =head1 HISTORY
687
688 The use of multiple B<-signer> options and the B<-resign> command were first
689 added in OpenSSL 1.0.0
690
691 The B<keyopt> option was first added in OpenSSL 1.1.0
692
693 The use of B<-recip> to specify the recipient when encrypting mail was first
694 added to OpenSSL 1.1.0
695
696 Support for RSA-OAEP and RSA-PSS was first added to OpenSSL 1.1.0. 
697
698 The use of non-RSA keys with B<-encrypt> and B<-decrypt> was first added
699 to OpenSSL 1.1.0.
700
701 The -no_alt_chains options was first added to OpenSSL 1.1.0.
702
703 =cut