xref: /openbsd-src/lib/libcrypto/man/CMS_verify.3 (revision 99fd087599a8791921855f21bd7e36130f39aadc)
1.\" $OpenBSD: CMS_verify.3,v 1.7 2019/11/02 15:39:46 schwarze Exp $
2.\" full merge up to: OpenSSL 35fd9953 May 28 14:49:38 2019 +0200
3.\"
4.\" This file was written by Dr. Stephen Henson <steve@openssl.org>.
5.\" Copyright (c) 2008 The OpenSSL Project.  All rights reserved.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\"
11.\" 1. Redistributions of source code must retain the above copyright
12.\"    notice, this list of conditions and the following disclaimer.
13.\"
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in
16.\"    the documentation and/or other materials provided with the
17.\"    distribution.
18.\"
19.\" 3. All advertising materials mentioning features or use of this
20.\"    software must display the following acknowledgment:
21.\"    "This product includes software developed by the OpenSSL Project
22.\"    for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
23.\"
24.\" 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
25.\"    endorse or promote products derived from this software without
26.\"    prior written permission. For written permission, please contact
27.\"    openssl-core@openssl.org.
28.\"
29.\" 5. Products derived from this software may not be called "OpenSSL"
30.\"    nor may "OpenSSL" appear in their names without prior written
31.\"    permission of the OpenSSL Project.
32.\"
33.\" 6. Redistributions of any form whatsoever must retain the following
34.\"    acknowledgment:
35.\"    "This product includes software developed by the OpenSSL Project
36.\"    for use in the OpenSSL Toolkit (http://www.openssl.org/)"
37.\"
38.\" THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
39.\" EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
40.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
41.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
42.\" ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
43.\" SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
45.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
46.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
47.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
49.\" OF THE POSSIBILITY OF SUCH DAMAGE.
50.\"
51.Dd $Mdocdate: November 2 2019 $
52.Dt CMS_VERIFY 3
53.Os
54.Sh NAME
55.Nm CMS_verify ,
56.Nm CMS_get0_signers
57.Nd verify a CMS SignedData structure
58.Sh SYNOPSIS
59.In openssl/cms.h
60.Ft int
61.Fo CMS_verify
62.Fa "CMS_ContentInfo *cms"
63.Fa "STACK_OF(X509) *certs"
64.Fa "X509_STORE *store"
65.Fa "BIO *indata"
66.Fa "BIO *out"
67.Fa "unsigned int flags"
68.Fc
69.Ft STACK_OF(X509) *
70.Fo CMS_get0_signers
71.Fa "CMS_ContentInfo *cms"
72.Fc
73.Sh DESCRIPTION
74.Fn CMS_verify
75verifies the CMS
76.Vt SignedData
77structure
78.Fa cms .
79.Fa certs
80is a set of certificates in which to search for the signing
81certificate(s).
82.Fa store
83is a trusted certificate store used for chain verification.
84.Fa indata
85is the detached content if the content is not present in
86.Fa cms .
87The content is written to
88.Fa out
89if it is not
90.Dv NULL .
91.Pp
92.Fn CMS_get0_signers
93retrieves the signing certificate(s) from
94.Fa cms .
95It must be called after a successful
96.Fn CMS_verify
97operation.
98.Pp
99Normally the verify process proceeds as follows.
100.Pp
101Initially some sanity checks are performed on
102.Fa cms .
103There must be at least one signature on the data.
104If the content is detached,
105.Fa indata
106cannot be
107.Dv NULL .
108.Pp
109An attempt is made to locate all the signing certificate(s), first
110looking in the
111.Fa certs
112parameter (if it is not
113.Dv NULL )
114and then looking in any certificates contained in the
115.Fa cms
116structure itself.
117If any signing certificate cannot be located, the operation fails.
118.Pp
119Each signing certificate is chain verified using the
120.Sy smimesign
121purpose and the supplied trusted certificate
122.Fa store .
123Any internal certificates in the message are used as untrusted CAs.
124If CRL checking is enabled in
125.Fa store ,
126any internal CRLs are used in addition to attempting to look them up in
127.Fa store .
128If any chain verify fails, an error code is returned.
129.Pp
130Finally the signed content is read (and written to
131.Fa out
132if it is not
133.Dv NULL )
134and the signature is checked.
135.Pp
136If all signatures verify correctly, then the function is successful.
137.Pp
138Any of the following
139.Fa flags
140(OR'ed together) can be passed to change the default verify behaviour:
141.Bl -tag -width Ds
142.It Dv CMS_NOINTERN
143Do not use the certificates in the message itself when
144locating the signing certificate(s).
145This means that all the signing certificates must be in the
146.Fa certs
147parameter.
148.It Dv CMS_NOCRL
149If CRL checking is enabled in
150.Fa store ,
151then any CRLs in the message itself are ignored.
152.It Dv CMS_TEXT
153MIME headers for type text/plain are deleted from the content.
154If the content is not of type text/plain, an error is returned.
155.It Dv CMS_NO_SIGNER_CERT_VERIFY
156Do not verify signing certificates.
157.It Dv CMS_NO_ATTR_VERIFY
158Do not check the signed attributes signature.
159.It Dv CMS_NO_CONTENT_VERIFY
160Do not check the content digest.
161.El
162.Pp
163One application of
164.Dv CMS_NOINTERN
165is to only accept messages signed by a small number of certificates.
166The acceptable certificates would be passed in the
167.Fa certs
168parameter.
169In this case, if the signer is not one of the certificates supplied in
170.Fa certs ,
171then the verify will fail because the signer cannot be found.
172.Pp
173In some cases the standard techniques for looking up and validating
174certificates are not appropriate: for example an application may wish to
175lookup certificates in a database or perform customised verification.
176This can be achieved by setting and verifying the signers certificates
177manually using the signed data utility functions.
178.Pp
179Care should be taken when modifying the default verify behaviour, for
180example setting
181.Dv CMS_NO_CONTENT_VERIFY
182will totally disable all content verification and any modified content
183will be considered valid.
184This combination is however useful if one merely wishes to write the
185content to
186.Fa out
187and its validity is not considered important.
188.Pp
189Chain verification should arguably be performed using the signing time
190rather than the current time.
191However since the signing time is supplied by the signer it cannot be
192trusted without additional evidence (such as a trusted timestamp).
193.Sh RETURN VALUES
194.Fn CMS_verify
195returns 1 for a successful verification or 0 if an error occurred.
196.Pp
197.Fn CMS_get0_signers
198returns all signers or
199.Dv NULL
200if an error occurred.
201.Pp
202The error can be obtained from
203.Xr ERR_get_error 3 .
204.Sh SEE ALSO
205.Xr CMS_ContentInfo_new 3 ,
206.Xr CMS_get0_SignerInfos 3 ,
207.Xr CMS_sign 3 ,
208.Xr CMS_verify_receipt 3
209.Sh STANDARDS
210RFC 5652: Cryptographic Message Syntax (CMS),
211section 5.1: SignedData Type
212.Sh HISTORY
213These functions first appeared in OpenSSL 0.9.8h
214and have been available since
215.Ox 6.7 .
216.Sh BUGS
217The trusted certificate store is not searched for the signing certificate.
218This is primarily due to the inadequacies of the current
219.Vt X509_STORE
220functionality.
221.Pp
222The lack of single pass processing means that the signed content must
223all be held in memory if it is not detached.
224