openssl-cms.pod.in 22.9 KB
Newer Older
1
=pod
2
{- OpenSSL::safe::output_do_not_edit_headers(); -}
3

4 5
=head1 NAME

6
openssl-cms - CMS utility
7 8 9 10

=head1 SYNOPSIS

B<openssl> B<cms>
11
[B<-help>]
12 13 14 15 16
[B<-encrypt>]
[B<-decrypt>]
[B<-sign>]
[B<-verify>]
[B<-cmsout>]
D
Dr. Stephen Henson 已提交
17
[B<-resign>]
18
[B<-cades>]
D
Dr. Stephen Henson 已提交
19 20 21 22 23 24 25 26
[B<-data_create>]
[B<-data_out>]
[B<-digest_create>]
[B<-digest_verify>]
[B<-compress>]
[B<-uncompress>]
[B<-EncryptedData_encrypt>]
[B<-sign_receipt>]
27 28 29
[B<-verify_receipt> I<receipt>]
[B<-in> I<filename>]
[B<-out> I<filename>]
30
[B<-inform> B<DER>|B<PEM>|B<SMIME>]
31
[B<-outform> B<DER>|B<PEM>|B<SMIME>]
32 33
[B<-rctform> B<DER>|B<PEM>|B<SMIME>]
[B<-keyform> B<DER>|B<PEM>|B<ENGINE>]
34 35
[B<-stream>]
[B<-indef>]
D
Dr. Stephen Henson 已提交
36
[B<-noindef>]
37 38
[B<-noindef>]
[B<-content> I<filename>]
D
Dr. Stephen Henson 已提交
39 40 41
[B<-text>]
[B<-noout>]
[B<-print>]
42
[B<-md> I<digest>]
R
Richard Levitte 已提交
43
[B<-I<cipher>>]
D
Dr. Stephen Henson 已提交
44
[B<-nointern>]
R
Rich Salz 已提交
45
[B<-noverify>]
D
Dr. Stephen Henson 已提交
46 47 48 49
[B<-nocerts>]
[B<-noattr>]
[B<-nosmimecap>]
[B<-binary>]
D
Dr. Stephen Henson 已提交
50
[B<-crlfeol>]
51
[B<-asciicrlf>]
D
Dr. Stephen Henson 已提交
52
[B<-nodetach>]
53 54 55
[B<-certsout> I<file>]
[B<-signer> I<file>]
[B<-recip> I<file>]
D
Dr. Stephen Henson 已提交
56
[B<-keyid>]
57 58
[B<-receipt_request_all>]
[B<-receipt_request_first>]
59 60
[B<-receipt_request_from> I<emailaddress>]
[B<-receipt_request_to> I<emailaddress>]
D
Dr. Stephen Henson 已提交
61
[B<-receipt_request_print>]
62 63 64 65 66 67 68 69 70
[B<-secretkey> I<key>]
[B<-secretkeyid> I<id>]
[B<-econtent_type> I<type>]
[B<-inkey> I<file>]
[B<-keyopt> I<name>:I<parameter>]
[B<-passin> I<arg>]
[B<-to> I<addr>]
[B<-from> I<addr>]
[B<-subject> I<subj>]
71
{- $OpenSSL::safe::opt_v_synopsis -}
72 73
{- $OpenSSL::safe::opt_trust_synopsis -}
{- $OpenSSL::safe::opt_r_synopsis -}
74
[I<cert.pem> ...]
75

76
=for openssl ifdef des-wrap engine
R
Rich Salz 已提交
77

78 79
=head1 DESCRIPTION

80 81
This command handles S/MIME v3.1 mail. It can encrypt, decrypt,
sign and verify, compress and uncompress S/MIME messages.
82

R
Rich Salz 已提交
83
=head1 OPTIONS
84

D
Dr. Stephen Henson 已提交
85 86
There are fourteen operation options that set the type of operation to be
performed. The meaning of the other options varies according to the operation
87 88 89 90
type.

=over 4

91 92 93 94
=item B<-help>

Print out a usage message.

95 96
=item B<-encrypt>

P
Pauli 已提交
97
Encrypt mail for the given recipient certificates. Input file is the message
98 99 100
to be encrypted. The output file is the encrypted mail in MIME format. The
actual CMS type is <B>EnvelopedData<B>.

101 102 103
Note that no revocation check is done for the recipient cert, so if that
key has been compromised, others may be able to decrypt the text.

104 105
=item B<-decrypt>

P
Pauli 已提交
106
Decrypt mail using the supplied certificate and private key. Expects an
107 108 109
encrypted mail message in MIME format for the input file. The decrypted mail
is written to the output file.

110 111
=item B<-debug_decrypt>

P
Pauli 已提交
112
This option sets the B<CMS_DEBUG_DECRYPT> flag. This option should be used
113 114
with caution: see the notes section below.

115 116
=item B<-sign>

P
Pauli 已提交
117
Sign mail using the supplied certificate and private key. Input file is
118 119 120 121 122
the message to be signed. The signed message in MIME format is written
to the output file.

=item B<-verify>

P
Pauli 已提交
123
Verify signed mail. Expects a signed mail message on input and outputs
124 125 126 127
the signed data. Both clear text and opaque signing is supported.

=item B<-cmsout>

P
Pauli 已提交
128
Takes an input message and writes out a PEM encoded CMS structure.
129 130 131

=item B<-resign>

P
Pauli 已提交
132
Resign a message: take an existing message and one or more new signers.
133

134 135 136 137 138 139
=item B<-cades>

Add an ESS signing-certificate or ESS signing-certificate-v2 signed-attribute to the SignerInfo, in order to make
the signature comply with the requirements for a CAdES Basic Electronic Signature (CAdES-BES). See the NOTES
section for more details.

140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
=item B<-data_create>

Create a CMS B<Data> type.

=item B<-data_out>

B<Data> type and output the content.

=item B<-digest_create>

Create a CMS B<DigestedData> type.

=item B<-digest_verify>

Verify a CMS B<DigestedData> type and output the content.

=item B<-compress>

Create a CMS B<CompressedData> type. OpenSSL must be compiled with B<zlib>
support for this option to work, otherwise it will output an error.

=item B<-uncompress>

Uncompress a CMS B<CompressedData> type and output the content. OpenSSL must be
compiled with B<zlib> support for this option to work, otherwise it will
output an error.

=item B<-EncryptedData_encrypt>

D
typo  
Dr. Stephen Henson 已提交
169
Encrypt content using supplied symmetric key and algorithm using a CMS
J
Josh Soref 已提交
170
B<EncryptedData> type and output the content.
171

D
Dr. Stephen Henson 已提交
172 173
=item B<-sign_receipt>

R
Rich Salz 已提交
174
Generate and output a signed receipt for the supplied message. The input
D
Dr. Stephen Henson 已提交
175 176 177
message B<must> contain a signed receipt request. Functionality is otherwise
similar to the B<-sign> operation.

178
=item B<-verify_receipt> I<receipt>
D
Dr. Stephen Henson 已提交
179

R
Rich Salz 已提交
180
Verify a signed receipt in filename B<receipt>. The input message B<must>
D
Dr. Stephen Henson 已提交
181 182 183
contain the original receipt request. Functionality is otherwise similar
to the B<-verify> operation.

184
=item B<-in> I<filename>
185

P
Pauli 已提交
186
The input message to be encrypted or signed or the message to be decrypted
D
Dr. Stephen Henson 已提交
187
or verified.
188

189 190 191 192 193
=item B<-out> I<filename>

The message text that has been decrypted or verified or the output MIME
format message that has been signed or verified.

194
=item B<-inform> B<DER>|B<PEM>|B<SMIME>
195

196 197 198
The input format of the CMS structure (if one is being read);
the default is B<SMIME>.
See L<openssl(1)/Format Options> for details.
199

200
=item B<-outform> B<DER>|B<PEM>|B<SMIME>
D
Dr. Stephen Henson 已提交
201

202 203 204
The output format of the CMS structure (if one is being written);
the default is B<SMIME>.
See L<openssl(1)/Format Options> for details.
D
Dr. Stephen Henson 已提交
205

206
=item B<-keyform> B<DER>|B<PEM>|B<ENGINE>
207

208 209
The format of the private key file; the default is B<PEM>.
See L<openssl(1)/Format Options> for details.
210

211
=item B<-rctform> B<DER>|B<PEM>|B<SMIME>
212

213 214 215
The signed receipt format for use with the B<-receipt_verify>; the default
is B<SMIME>.
See L<openssl(1)/Format Options> for details.
216

217
=item B<-stream>, B<-indef>, B<-noindef>
218

P
Pauli 已提交
219
The B<-stream> and B<-indef> options are equivalent and enable streaming I/O
220 221 222 223 224 225 226 227
for encoding operations. This permits single pass processing of data without
the need to hold the entire contents in memory, potentially supporting very
large files. Streaming is automatically set for S/MIME signing with detached
data if the output format is B<SMIME> it is currently off by default for all
other operations.

=item B<-noindef>

P
Pauli 已提交
228
Disable streaming I/O where it would produce and indefinite length constructed
229 230 231
encoding. This option currently has no effect. In future streaming will be
enabled by default on all relevant operations and this option will disable it.

232
=item B<-content> I<filename>
233 234 235 236 237 238 239 240 241

This specifies a file containing the detached content, this is only
useful with the B<-verify> command. This is only usable if the CMS
structure is using the detached signature form where the content is
not included. This option will override any content if the input format
is S/MIME and it uses the multipart/signed MIME content type.

=item B<-text>

P
Pauli 已提交
242
This option adds plain text (text/plain) MIME headers to the supplied
243
message if encrypting or signing. If decrypting or verifying it strips
R
Rich Salz 已提交
244
off text headers: if the decrypted or verified message is not of MIME
245 246
type text/plain then an error occurs.

D
Dr. Stephen Henson 已提交
247 248
=item B<-noout>

P
Pauli 已提交
249
For the B<-cmsout> operation do not output the parsed CMS structure. This
D
Dr. Stephen Henson 已提交
250 251 252 253 254
is useful when combined with the B<-print> option or if the syntax of the CMS
structure is being checked.

=item B<-print>

P
Pauli 已提交
255
For the B<-cmsout> operation print out all fields of the CMS structure. This
D
Dr. Stephen Henson 已提交
256 257
is mainly useful for testing purposes.

258
=item B<-md> I<digest>
259

P
Pauli 已提交
260
Digest algorithm to use when signing or resigning. If not present then the
261 262
default digest algorithm for the signing key will be used (usually SHA1).

R
Richard Levitte 已提交
263
=item B<-I<cipher>>
264

P
Pauli 已提交
265
The encryption algorithm to use. For example triple DES (168 bits) - B<-des3>
D
Dr. Stephen Henson 已提交
266
or 256 bit AES - B<-aes256>. Any standard algorithm name (as used by the
R
Rich Salz 已提交
267
EVP_get_cipherbyname() function) can also be used preceded by a dash, for
268
example B<-aes-128-cbc>. See L<openssl-enc(1)> for a list of ciphers
D
Dr. Stephen Henson 已提交
269
supported by your version of OpenSSL.
270

R
Rich Salz 已提交
271
If not specified triple DES is used. Only used with B<-encrypt> and
272 273 274 275
B<-EncryptedData_create> commands.

=item B<-nointern>

P
Pauli 已提交
276
When verifying a message normally certificates (if any) included in
277 278 279 280
the message are searched for the signing certificate. With this option
only the certificates specified in the B<-certfile> option are used.
The supplied certificates can still be used as untrusted CAs however.

R
Rich Salz 已提交
281
=item B<-noverify>
282

P
Pauli 已提交
283
Do not verify the signers certificate of a signed message.
284 285 286

=item B<-nocerts>

P
Pauli 已提交
287
When signing a message the signer's certificate is normally included
288 289 290 291 292 293
with this option it is excluded. This will reduce the size of the
signed message but the verifier must have a copy of the signers certificate
available locally (passed using the B<-certfile> option for example).

=item B<-noattr>

P
Pauli 已提交
294
Normally when a message is signed a set of attributes are included which
295 296 297 298 299
include the signing time and supported symmetric algorithms. With this
option they are not included.

=item B<-nosmimecap>

P
Pauli 已提交
300
Exclude the list of supported algorithms from signed attributes, other options
301 302 303 304
such as signing time and content type are still included.

=item B<-binary>

P
Pauli 已提交
305
Normally the input message is converted to "canonical" format which is
306 307 308 309
effectively using CR and LF as end of line: as required by the S/MIME
specification. When this option is present no translation occurs. This
is useful when handling binary data which may not be in MIME format.

D
Dr. Stephen Henson 已提交
310 311
=item B<-crlfeol>

P
Pauli 已提交
312
Normally the output file uses a single B<LF> as end of line. When this
D
Dr. Stephen Henson 已提交
313 314
option is present B<CRLF> is used instead.

315 316
=item B<-asciicrlf>

P
Pauli 已提交
317
When signing use ASCII CRLF format canonicalisation. This strips trailing
318 319 320 321 322 323
whitespace from all lines, deletes trailing blank lines at EOF and sets
the encapsulated content type. This option is normally used with detached
content and an output signature format of DER. This option is not normally
needed when verifying as it is enabled automatically if the encapsulated
content format is detected.

324 325
=item B<-nodetach>

P
Pauli 已提交
326
When signing a message use opaque signing: this form is more resistant
327 328 329 330
to translation by mail relays but it cannot be read by mail agents that
do not support S/MIME.  Without this option cleartext signing with
the MIME type multipart/signed is used.

331
=item B<-certfile> I<file>
332

P
Pauli 已提交
333
Allows additional certificates to be specified. When signing these will
334 335 336
be included with the message. When verifying these will be searched for
the signers certificates. The certificates should be in PEM format.

337
=item B<-certsout> I<file>
338

339
Any certificates contained in the message are written to I<file>.
340

341
=item B<-signer> I<file>
342

P
Pauli 已提交
343
A signing certificate when signing or resigning a message, this option can be
344 345 346 347
used multiple times if more than one signer is required. If a message is being
verified then the signers certificates will be written to this file if the
verification was successful.

348
=item B<-recip> I<file>
349

P
Pauli 已提交
350
When decrypting a message this specifies the recipients certificate. The
D
Dr. Stephen Henson 已提交
351 352 353 354 355 356
certificate must match one of the recipients of the message or an error
occurs.

When encrypting a message this option may be used multiple times to specify
each recipient. This form B<must> be used if customised parameters are
required (for example to specify RSA-OAEP).
357

358 359 360
Only certificates carrying RSA, Diffie-Hellman or EC keys are supported by this
option.

361 362
=item B<-keyid>

P
Pauli 已提交
363
Use subject key identifier to identify certificates instead of issuer name and
364 365 366
serial number. The supplied certificate B<must> include a subject key
identifier extension. Supported by B<-sign> and B<-encrypt> options.

367
=item B<-receipt_request_all>, B<-receipt_request_first>
D
Dr. Stephen Henson 已提交
368

P
Pauli 已提交
369
For B<-sign> option include a signed receipt request. Indicate requests should
A
Alok Menghrajani 已提交
370
be provided by all recipient or first tier recipients (those mailed directly
D
Dr. Stephen Henson 已提交
371 372
and not from a mailing list). Ignored it B<-receipt_request_from> is included.

373
=item B<-receipt_request_from> I<emailaddress>
D
Dr. Stephen Henson 已提交
374

P
Pauli 已提交
375
For B<-sign> option include a signed receipt request. Add an explicit email
D
Dr. Stephen Henson 已提交
376 377
address where receipts should be supplied.

378
=item B<-receipt_request_to> I<emailaddress>
D
Dr. Stephen Henson 已提交
379

R
Rich Salz 已提交
380
Add an explicit email address where signed receipts should be sent to. This
D
Dr. Stephen Henson 已提交
381 382 383 384 385 386 387
option B<must> but supplied if a signed receipt it requested.

=item B<-receipt_request_print>

For the B<-verify> operation print out the contents of any signed receipt
requests.

388
=item B<-secretkey> I<key>
389

P
Pauli 已提交
390
Specify symmetric key to use. The key must be supplied in hex format and be
391
consistent with the algorithm used. Supported by the B<-EncryptedData_encrypt>
A
Alok Menghrajani 已提交
392
B<-EncryptedData_decrypt>, B<-encrypt> and B<-decrypt> options. When used
393 394 395
with B<-encrypt> or B<-decrypt> the supplied key is used to wrap or unwrap the
content encryption key using an AES key in the B<KEKRecipientInfo> type.

396
=item B<-secretkeyid> I<id>
397

P
Pauli 已提交
398
The key identifier for the supplied symmetric key for B<KEKRecipientInfo> type.
399
This option B<must> be present if the B<-secretkey> option is used with
400
B<-encrypt>. With B<-decrypt> operations the I<id> is used to locate the
401 402 403
relevant key if it is not supplied then an attempt is used to decrypt any
B<KEKRecipientInfo> structures.

404
=item B<-econtent_type> I<type>
405

406 407
Set the encapsulated content type to I<type> if not supplied the B<Data> type
is used. The I<type> argument can be any valid OID name in either text or
R
Rich Salz 已提交
408
numerical format.
409

410
=item B<-inkey> I<file>
411

P
Pauli 已提交
412
The private key to use when signing or decrypting. This must match the
413 414 415 416 417
corresponding certificate. If this option is not specified then the
private key must be included in the certificate file specified with
the B<-recip> or B<-signer> file. When signing this option can be used
multiple times to specify successive keys.

418
=item B<-keyopt> I<name>:I<parameter>
D
Dr. Stephen Henson 已提交
419

P
Pauli 已提交
420
For signing and encryption this option can be used multiple times to
D
Dr. Stephen Henson 已提交
421
set customised parameters for the preceding key or certificate. It can
D
Dr. Stephen Henson 已提交
422 423
currently be used to set RSA-PSS for signing, RSA-OAEP for encryption
or to modify default parameters for ECDH.
D
Dr. Stephen Henson 已提交
424

425
=item B<-passin> I<arg>
426

P
Pauli 已提交
427
The private key password source. For more information about the format of B<arg>
428
see L<openssl(1)/Pass Phrase Options>.
429

430
=item B<-to>, B<-from>, B<-subject>
431

P
Pauli 已提交
432
The relevant mail headers. These are included outside the signed
433 434 435 436
portion of a message so they may be included manually. If signing
then many S/MIME mail clients check the signers certificate's email
address matches that specified in the From: address.

437
{- $OpenSSL::safe::opt_v_item -}
D
Dr. Stephen Henson 已提交
438

439
Any verification errors cause the command to exit.
D
Dr. Stephen Henson 已提交
440

441 442 443 444 445 446 447 448 449
{- $OpenSSL::safe::opt_trust_item -}

{- $OpenSSL::safe::opt_r_item -}

=item I<cert.pem> ...

One or more certificates of message recipients: used when encrypting
a message.

450 451 452 453 454 455 456 457 458 459
=back

=head1 NOTES

The MIME message must be sent without any blank lines between the
headers and the output. Some mail programs will automatically add
a blank line. Piping the mail directly to sendmail is one way to
achieve the correct format.

The supplied message to be signed or encrypted must include the
460
necessary MIME headers or many S/MIME clients won't display it
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480
properly (if at all). You can use the B<-text> option to automatically
add plain text headers.

A "signed and encrypted" message is one where a signed message is
then encrypted. This can be produced by encrypting an already signed
message: see the examples section.

This version of the program only allows one signer per message but it
will verify multiple signers on received messages. Some S/MIME clients
choke if a message contains multiple signers. It is possible to sign
messages "in parallel" by signing an already signed message.

The options B<-encrypt> and B<-decrypt> reflect common usage in S/MIME
clients. Strictly speaking these process CMS enveloped data: CMS
encrypted data is used for other purposes.

The B<-resign> option uses an existing message digest when adding a new
signer. This means that attributes must be present in at least one existing
signer using the same message digest or this operation will fail.

481
The B<-stream> and B<-indef> options enable streaming I/O support.
482 483 484 485 486 487 488 489
As a result the encoding is BER using indefinite length constructed encoding
and no longer DER. Streaming is supported for the B<-encrypt> operation and the
B<-sign> operation if the content is not detached.

Streaming is always used for the B<-sign> operation with detached data but
since the content is no longer part of the CMS structure the encoding
remains DER.

490 491 492 493 494
If the B<-decrypt> option is used without a recipient certificate then an
attempt is made to locate the recipient by trying each potential recipient
in turn using the supplied private key. To thwart the MMA attack
(Bleichenbacher's attack on PKCS #1 v1.5 RSA padding) all recipients are
tried whether they succeed or not and if no recipients match the message
R
Rich Salz 已提交
495
is "decrypted" using a random key which will typically output garbage.
496 497
The B<-debug_decrypt> option can be used to disable the MMA attack protection
and return an error if no recipient can be found: this option should be used
R
Rich Salz 已提交
498
with caution. For a fuller description see L<CMS_decrypt(3)>).
499

R
Rich Salz 已提交
500
=head1 CADES BASIC ELECTRONIC SIGNATURE (CADES-BES)
501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533

A CAdES Basic Electronic Signature (CAdES-BES), as defined in the European Standard ETSI EN 319 122-1 V1.1.1, contains:

=over 4

=item *

The signed user data as defined in CMS (RFC 3852);

=item *

Content-type of the EncapsulatedContentInfo value being signed;

=item *

Message-digest of the eContent OCTET STRING within encapContentInfo being signed;

=item *

An ESS signing-certificate or ESS signing-certificate-v2 attribute, as defined in Enhanced Security Services (ESS), RFC 2634 and RFC 5035.
An ESS signing-certificate attribute only allows for the use of SHA-1 as a digest algorithm.
An ESS signing-certificate-v2 attribute allows for the use of any digest algorithm.

=item *

The digital signature value computed on the user data and, when present, on the signed attributes.

Note that currently the B<-cades> option applies only to the B<-sign> operation and is ignored during
the B<-verify> operation, i.e. the signing certification is not checked during the verification process.
This feature might be added in a future version.

=back

534 535 536 537
=head1 EXIT CODES

=over 4

L
Lubomir Rintel 已提交
538
=item Z<>0
539

P
Pauli 已提交
540
The operation was completely successfully.
541

L
Lubomir Rintel 已提交
542
=item Z<>1
543

P
Pauli 已提交
544
An error occurred parsing the command options.
545

L
Lubomir Rintel 已提交
546
=item Z<>2
547

P
Pauli 已提交
548
One of the input files could not be read.
549

L
Lubomir Rintel 已提交
550
=item Z<>3
551

P
Pauli 已提交
552
An error occurred creating the CMS file or when reading the MIME
553 554
message.

L
Lubomir Rintel 已提交
555
=item Z<>4
556

P
Pauli 已提交
557
An error occurred decrypting or verifying the message.
558

L
Lubomir Rintel 已提交
559
=item Z<>5
560

P
Pauli 已提交
561
The message was verified correctly but an error occurred writing out
562 563 564 565
the signers certificates.

=back

R
Rich Salz 已提交
566
=head1 COMPATIBILITY WITH PKCS#7 FORMAT
567

568 569 570 571
L<openssl-smime(1)> can only process the older B<PKCS#7> format.
B<openssl cms> supports Cryptographic Message Syntax format.
Use of some features will result in messages which cannot be processed by
applications which only support the older format. These are detailed below.
572 573 574

The use of the B<-keyid> option with B<-sign> or B<-encrypt>.

575
The B<-outform> I<PEM> option uses different headers.
576 577 578 579 580

The B<-compress> option.

The B<-secretkey> option when used with B<-encrypt>.

D
Dr. Stephen Henson 已提交
581 582 583 584
The use of PSS with B<-sign>.

The use of OAEP or non-RSA keys with B<-encrypt>.

585
Additionally the B<-EncryptedData_create> and B<-data_create> type cannot
586
be processed by the older L<openssl-smime(1)> command.
587 588 589 590 591 592

=head1 EXAMPLES

Create a cleartext signed message:

 openssl cms -sign -in message.txt -text -out mail.msg \
R
Rich Salz 已提交
593
        -signer mycert.pem
594 595 596 597

Create an opaque signed message

 openssl cms -sign -in message.txt -text -out mail.msg -nodetach \
R
Rich Salz 已提交
598
        -signer mycert.pem
599 600 601 602 603

Create a signed message, include some additional certificates and
read the private key from another file:

 openssl cms -sign -in in.txt -text -out mail.msg \
R
Rich Salz 已提交
604
        -signer mycert.pem -inkey mykey.pem -certfile mycerts.pem
605 606 607 608

Create a signed message with two signers, use key identifier:

 openssl cms -sign -in message.txt -text -out mail.msg \
R
Rich Salz 已提交
609
        -signer mycert.pem -signer othercert.pem -keyid
610 611 612 613

Send a signed message under Unix directly to sendmail, including headers:

 openssl cms -sign -in in.txt -text -signer mycert.pem \
R
Rich Salz 已提交
614 615
        -from steve@openssl.org -to someone@somewhere \
        -subject "Signed message" | sendmail someone@somewhere
616 617 618 619 620 621 622 623

Verify a message and extract the signer's certificate if successful:

 openssl cms -verify -in mail.msg -signer user.pem -out signedtext.txt

Send encrypted mail using triple DES:

 openssl cms -encrypt -in in.txt -from steve@openssl.org \
R
Rich Salz 已提交
624 625
        -to someone@somewhere -subject "Encrypted message" \
        -des3 user.pem -out mail.msg
626 627 628 629

Sign and encrypt mail:

 openssl cms -sign -in ml.txt -signer my.pem -text \
R
Rich Salz 已提交
630 631 632
        | openssl cms -encrypt -out mail.msg \
        -from steve@openssl.org -to someone@somewhere \
        -subject "Signed and Encrypted message" -des3 user.pem
633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648

Note: the encryption command does not include the B<-text> option because the
message being encrypted already has MIME headers.

Decrypt mail:

 openssl cms -decrypt -in mail.msg -recip mycert.pem -inkey key.pem

The output from Netscape form signing is a PKCS#7 structure with the
detached signature format. You can use this program to verify the
signature by line wrapping the base64 encoded structure and surrounding
it with:

 -----BEGIN PKCS7-----
 -----END PKCS7-----

R
Rich Salz 已提交
649
and using the command,
650 651 652 653 654 655 656 657 658 659 660 661 662 663 664

 openssl cms -verify -inform PEM -in signature.pem -content content.txt

alternatively you can base64 decode the signature and use

 openssl cms -verify -inform DER -in signature.der -content content.txt

Create an encrypted message using 128 bit Camellia:

 openssl cms -encrypt -in plain.txt -camellia128 -out mail.msg cert.pem

Add a signer to an existing message:

 openssl cms -resign -in mail.msg -signer newsign.pem -out mail2.msg

D
Dr. Stephen Henson 已提交
665 666 667
Sign mail using RSA-PSS:

 openssl cms -sign -in message.txt -text -out mail.msg \
R
Rich Salz 已提交
668
        -signer mycert.pem -keyopt rsa_padding_mode:pss
D
Dr. Stephen Henson 已提交
669 670 671

Create encrypted mail using RSA-OAEP:

D
Dr. Stephen Henson 已提交
672
 openssl cms -encrypt -in plain.txt -out mail.msg \
R
Rich Salz 已提交
673
        -recip cert.pem -keyopt rsa_padding_mode:oaep
D
Dr. Stephen Henson 已提交
674

D
Dr. Stephen Henson 已提交
675 676 677
Use SHA256 KDF with an ECDH certificate:

 openssl cms -encrypt -in plain.txt -out mail.msg \
R
Rich Salz 已提交
678
        -recip ecdhcert.pem -keyopt ecdh_kdf_md:sha256
D
Dr. Stephen Henson 已提交
679

680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699
=head1 BUGS

The MIME parser isn't very clever: it seems to handle most messages that I've
thrown at it but it may choke on others.

The code currently will only write out the signer's certificate to a file: if
the signer has a separate encryption certificate this must be manually
extracted. There should be some heuristic that determines the correct
encryption certificate.

Ideally a database should be maintained of a certificates for each email
address.

The code doesn't currently take note of the permitted symmetric encryption
algorithms as supplied in the SMIMECapabilities signed attribute. this means the
user has to manually include the correct encryption algorithm. It should store
the list of permitted ciphers in a database and only use those.

No revocation checking is done on the signer's certificate.

700 701 702 703
=head1 SEE ALSO

L<ossl_store-file(7)>

704 705 706
=head1 HISTORY

The use of multiple B<-signer> options and the B<-resign> command were first
707
added in OpenSSL 1.0.0.
D
Dr. Stephen Henson 已提交
708

709
The B<-keyopt> option was added in OpenSSL 1.0.2.
D
Dr. Stephen Henson 已提交
710

711
Support for RSA-OAEP and RSA-PSS was added in OpenSSL 1.0.2.
712

713 714
The use of non-RSA keys with B<-encrypt> and B<-decrypt>
was added in OpenSSL 1.0.2.
D
Dr. Stephen Henson 已提交
715

716
The -no_alt_chains option was added in OpenSSL 1.0.2b.
717

R
Rich Salz 已提交
718 719
=head1 COPYRIGHT

720
Copyright 2008-2019 The OpenSSL Project Authors. All Rights Reserved.
R
Rich Salz 已提交
721

722
Licensed under the Apache License 2.0 (the "License").  You may not use
R
Rich Salz 已提交
723 724 725 726 727
this file except in compliance with the License.  You can obtain a copy
in the file LICENSE in the source distribution or at
L<https://www.openssl.org/source/license.html>.

=cut