xref: /openbsd/lib/libcrypto/man/CMS_verify.3 (revision 4bdff4be)
1.\" $OpenBSD: CMS_verify.3,v 1.9 2023/06/05 17:17:23 job 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: June 5 2023 $
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 may only be called after a successful
96.Fn CMS_verify
97operation.
98The signers must be freed with
99.Fn sk_X509_free .
100.Pp
101Normally the verify process proceeds as follows.
102.Pp
103Initially some sanity checks are performed on
104.Fa cms .
105There must be at least one signature on the data.
106If the content is detached,
107.Fa indata
108cannot be
109.Dv NULL .
110.Pp
111An attempt is made to locate all the signing certificate(s), first
112looking in the
113.Fa certs
114parameter (if it is not
115.Dv NULL )
116and then looking in any certificates contained in the
117.Fa cms
118structure itself.
119If any signing certificate cannot be located, the operation fails.
120.Pp
121Each signing certificate is chain verified using the
122.Sy smimesign
123purpose and the supplied trusted certificate
124.Fa store .
125Any internal certificates in the message are used as untrusted CAs.
126If CRL checking is enabled in
127.Fa store ,
128any internal CRLs are used in addition to attempting to look them up in
129.Fa store .
130If any chain verify fails, an error code is returned.
131.Pp
132Finally the signed content is read (and written to
133.Fa out
134if it is not
135.Dv NULL )
136and the signature is checked.
137.Pp
138If all signatures verify correctly, then the function is successful.
139.Pp
140Any of the following
141.Fa flags
142(OR'ed together) can be passed to change the default verify behaviour:
143.Bl -tag -width Ds
144.It Dv CMS_NOINTERN
145Do not use the certificates in the message itself when
146locating the signing certificate(s).
147This means that all the signing certificates must be in the
148.Fa certs
149parameter.
150.It Dv CMS_NOCRL
151If CRL checking is enabled in
152.Fa store ,
153then any CRLs in the message itself are ignored.
154.It Dv CMS_TEXT
155MIME headers for type text/plain are deleted from the content.
156If the content is not of type text/plain, an error is returned.
157.It Dv CMS_NO_SIGNER_CERT_VERIFY
158Do not verify signing certificates.
159.It Dv CMS_NO_ATTR_VERIFY
160Do not check the signed attributes signature.
161.It Dv CMS_NO_CONTENT_VERIFY
162Do not check the content digest.
163.El
164.Pp
165One application of
166.Dv CMS_NOINTERN
167is to only accept messages signed by a small number of certificates.
168The acceptable certificates would be passed in the
169.Fa certs
170parameter.
171In this case, if the signer is not one of the certificates supplied in
172.Fa certs ,
173then the verify will fail because the signer cannot be found.
174.Pp
175In some cases the standard techniques for looking up and validating
176certificates are not appropriate: for example an application may wish to
177lookup certificates in a database or perform customised verification.
178This can be achieved by setting and verifying the signers certificates
179manually using the signed data utility functions.
180.Pp
181Care should be taken when modifying the default verify behaviour, for
182example setting
183.Dv CMS_NO_CONTENT_VERIFY
184will totally disable all content verification and any modified content
185will be considered valid.
186This combination is however useful if one merely wishes to write the
187content to
188.Fa out
189and its validity is not considered important.
190.Pp
191Chain verification should arguably be performed using the signing time
192rather than the current time.
193However since the signing time is supplied by the signer it cannot be
194trusted without additional evidence (such as a trusted timestamp).
195.Sh RETURN VALUES
196.Fn CMS_verify
197returns 1 for a successful verification or 0 if an error occurred.
198.Pp
199.Fn CMS_get0_signers
200returns all signers or
201.Dv NULL
202if an error occurred.
203The signers must be freed with
204.Fn sk_X509_free .
205.Pp
206The error can be obtained from
207.Xr ERR_get_error 3 .
208.Sh SEE ALSO
209.Xr CMS_ContentInfo_new 3 ,
210.Xr CMS_get0_SignerInfos 3 ,
211.Xr CMS_sign 3 ,
212.Xr CMS_verify_receipt 3
213.Sh STANDARDS
214RFC 5652: Cryptographic Message Syntax (CMS),
215section 5.1: SignedData Type
216.Sh HISTORY
217These functions first appeared in OpenSSL 0.9.8h
218and have been available since
219.Ox 6.7 .
220.Sh BUGS
221The trusted certificate store is not searched for the signing certificate.
222This is primarily due to the inadequacies of the current
223.Vt X509_STORE
224functionality.
225.Pp
226The lack of single pass processing means that the signed content must
227all be held in memory if it is not detached.
228