xref: /freebsd/crypto/openssl/doc/man3/CMS_verify.pod (revision cfc39718e9cc18943a6f8428c560b02c6f590b16)
1e71b7053SJung-uk Kim=pod
2e71b7053SJung-uk Kim
3e71b7053SJung-uk Kim=head1 NAME
4e71b7053SJung-uk Kim
5e71b7053SJung-uk KimCMS_verify, CMS_get0_signers - verify a CMS SignedData structure
6e71b7053SJung-uk Kim
7e71b7053SJung-uk Kim=head1 SYNOPSIS
8e71b7053SJung-uk Kim
9e71b7053SJung-uk Kim #include <openssl/cms.h>
10e71b7053SJung-uk Kim
11e71b7053SJung-uk Kim int CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs, X509_STORE *store,
12e71b7053SJung-uk Kim                BIO *indata, BIO *out, unsigned int flags);
13e71b7053SJung-uk Kim
14e71b7053SJung-uk Kim STACK_OF(X509) *CMS_get0_signers(CMS_ContentInfo *cms);
15e71b7053SJung-uk Kim
16e71b7053SJung-uk Kim=head1 DESCRIPTION
17e71b7053SJung-uk Kim
18*cfc39718SJung-uk KimCMS_verify() is very similar to L<PKCS7_verify(3)>. It verifies a
19*cfc39718SJung-uk KimB<CMS SignedData> structure contained in a structure of type B<CMS_ContentInfo>.
20*cfc39718SJung-uk KimI<cms> points to the B<CMS_ContentInfo> structure to verify.
21*cfc39718SJung-uk KimThe optional I<certs> parameter refers to a set of certificates
22*cfc39718SJung-uk Kimin which to search for signing certificates.
23*cfc39718SJung-uk KimI<cms> may contain extra untrusted CA certificates that may be used for
24*cfc39718SJung-uk Kimchain building as well as CRLs that may be used for certificate validation.
25*cfc39718SJung-uk KimI<store> may be NULL or point to
26*cfc39718SJung-uk Kimthe trusted certificate store to use for chain verification.
27*cfc39718SJung-uk KimI<indata> refers to the signed data if the content is detached from I<cms>.
28*cfc39718SJung-uk KimOtherwise I<indata> should be NULL and the signed data must be in I<cms>.
29*cfc39718SJung-uk KimThe content is written to the BIO I<out> unless it is NULL.
30*cfc39718SJung-uk KimI<flags> is an optional set of flags, which can be used to modify the operation.
31e71b7053SJung-uk Kim
32*cfc39718SJung-uk KimCMS_get0_signers() retrieves the signing certificate(s) from I<cms>, it may only
33e71b7053SJung-uk Kimbe called after a successful CMS_verify() operation.
34e71b7053SJung-uk Kim
35e71b7053SJung-uk Kim=head1 VERIFY PROCESS
36e71b7053SJung-uk Kim
37e71b7053SJung-uk KimNormally the verify process proceeds as follows.
38e71b7053SJung-uk Kim
39*cfc39718SJung-uk KimInitially some sanity checks are performed on I<cms>. The type of I<cms> must
40e71b7053SJung-uk Kimbe SignedData. There must be at least one signature on the data and if
41*cfc39718SJung-uk Kimthe content is detached I<indata> cannot be NULL.
42e71b7053SJung-uk Kim
43e71b7053SJung-uk KimAn attempt is made to locate all the signing certificate(s), first looking in
44*cfc39718SJung-uk Kimthe I<certs> parameter (if it is not NULL) and then looking in any
45*cfc39718SJung-uk Kimcertificates contained in the I<cms> structure unless B<CMS_NOINTERN> is set.
46*cfc39718SJung-uk KimIf any signing certificate cannot be located the operation fails.
47e71b7053SJung-uk Kim
48*cfc39718SJung-uk KimEach signing certificate is chain verified using the I<smimesign> purpose and
49*cfc39718SJung-uk Kimusing the trusted certificate store I<store> if supplied.
50*cfc39718SJung-uk KimAny internal certificates in the message, which may have been added using
51*cfc39718SJung-uk KimL<CMS_add1_cert(3)>, are used as untrusted CAs.
52*cfc39718SJung-uk KimIf CRL checking is enabled in I<store> and B<CMS_NOCRL> is not set,
53*cfc39718SJung-uk Kimany internal CRLs, which may have been added using L<CMS_add1_crl(3)>,
54*cfc39718SJung-uk Kimare used in addition to attempting to look them up in I<store>.
55*cfc39718SJung-uk KimIf I<store> is not NULL and any chain verify fails an error code is returned.
56e71b7053SJung-uk Kim
57*cfc39718SJung-uk KimFinally the signed content is read (and written to I<out> unless it is NULL)
58*cfc39718SJung-uk Kimand the signature is checked.
59e71b7053SJung-uk Kim
60*cfc39718SJung-uk KimIf all signatures verify correctly then the function is successful.
61e71b7053SJung-uk Kim
62*cfc39718SJung-uk KimAny of the following flags (ored together) can be passed in the I<flags>
63e71b7053SJung-uk Kimparameter to change the default verify behaviour.
64e71b7053SJung-uk Kim
65e71b7053SJung-uk KimIf B<CMS_NOINTERN> is set the certificates in the message itself are not
66*cfc39718SJung-uk Kimsearched when locating the signing certificate(s).
67*cfc39718SJung-uk KimThis means that all the signing certificates must be in the I<certs> parameter.
68e71b7053SJung-uk Kim
69*cfc39718SJung-uk KimIf B<CMS_NOCRL> is set and CRL checking is enabled in I<store> then any
70e71b7053SJung-uk KimCRLs in the message itself are ignored.
71e71b7053SJung-uk Kim
72e71b7053SJung-uk KimIf the B<CMS_TEXT> flag is set MIME headers for type B<text/plain> are deleted
73e71b7053SJung-uk Kimfrom the content. If the content is not of type B<text/plain> then an error is
74e71b7053SJung-uk Kimreturned.
75e71b7053SJung-uk Kim
76e71b7053SJung-uk KimIf B<CMS_NO_SIGNER_CERT_VERIFY> is set the signing certificates are not
77*cfc39718SJung-uk Kimchain verified.
78e71b7053SJung-uk Kim
79e71b7053SJung-uk KimIf B<CMS_NO_ATTR_VERIFY> is set the signed attributes signature is not
80e71b7053SJung-uk Kimverified.
81e71b7053SJung-uk Kim
82e71b7053SJung-uk KimIf B<CMS_NO_CONTENT_VERIFY> is set then the content digest is not checked.
83e71b7053SJung-uk Kim
84e71b7053SJung-uk Kim=head1 NOTES
85e71b7053SJung-uk Kim
86e71b7053SJung-uk KimOne application of B<CMS_NOINTERN> is to only accept messages signed by
87e71b7053SJung-uk Kima small number of certificates. The acceptable certificates would be passed
88*cfc39718SJung-uk Kimin the I<certs> parameter. In this case if the signer certificate is not one
89*cfc39718SJung-uk Kimof the certificates supplied in I<certs> then the verify will fail because the
90e71b7053SJung-uk Kimsigner cannot be found.
91e71b7053SJung-uk Kim
92e71b7053SJung-uk KimIn some cases the standard techniques for looking up and validating
93e71b7053SJung-uk Kimcertificates are not appropriate: for example an application may wish to
94e71b7053SJung-uk Kimlookup certificates in a database or perform customised verification. This
95*cfc39718SJung-uk Kimcan be achieved by setting and verifying the signer certificates manually
96e71b7053SJung-uk Kimusing the signed data utility functions.
97e71b7053SJung-uk Kim
98e71b7053SJung-uk KimCare should be taken when modifying the default verify behaviour, for example
99e71b7053SJung-uk Kimsetting B<CMS_NO_CONTENT_VERIFY> will totally disable all content verification
100e71b7053SJung-uk Kimand any modified content will be considered valid. This combination is however
101*cfc39718SJung-uk Kimuseful if one merely wishes to write the content to I<out> and its validity
102e71b7053SJung-uk Kimis not considered important.
103e71b7053SJung-uk Kim
104e71b7053SJung-uk KimChain verification should arguably be performed using the signing time rather
10558f35182SJung-uk Kimthan the current time. However, since the signing time is supplied by the
106e71b7053SJung-uk Kimsigner it cannot be trusted without additional evidence (such as a trusted
107e71b7053SJung-uk Kimtimestamp).
108e71b7053SJung-uk Kim
109e71b7053SJung-uk Kim=head1 RETURN VALUES
110e71b7053SJung-uk Kim
111*cfc39718SJung-uk KimCMS_verify() returns 1 for a successful verification and 0 if an error occurred.
112e71b7053SJung-uk Kim
113e71b7053SJung-uk KimCMS_get0_signers() returns all signers or NULL if an error occurred.
114e71b7053SJung-uk Kim
115e71b7053SJung-uk KimThe error can be obtained from L<ERR_get_error(3)>
116e71b7053SJung-uk Kim
117e71b7053SJung-uk Kim=head1 BUGS
118e71b7053SJung-uk Kim
119*cfc39718SJung-uk KimThe trusted certificate store is not searched for the signing certificate.
120*cfc39718SJung-uk KimThis is primarily due to the inadequacies of the current B<X509_STORE>
121e71b7053SJung-uk Kimfunctionality.
122e71b7053SJung-uk Kim
123e71b7053SJung-uk KimThe lack of single pass processing means that the signed content must all
124e71b7053SJung-uk Kimbe held in memory if it is not detached.
125e71b7053SJung-uk Kim
126e71b7053SJung-uk Kim=head1 SEE ALSO
127e71b7053SJung-uk Kim
128*cfc39718SJung-uk KimL<PKCS7_verify(3)>, L<CMS_add1_cert(3)>, L<CMS_add1_crl(3)>,
129*cfc39718SJung-uk KimL<OSSL_ESS_check_signing_certs(3)>,
130e71b7053SJung-uk KimL<ERR_get_error(3)>, L<CMS_sign(3)>
131e71b7053SJung-uk Kim
132e71b7053SJung-uk Kim=head1 COPYRIGHT
133e71b7053SJung-uk Kim
134*cfc39718SJung-uk KimCopyright 2008-2022 The OpenSSL Project Authors. All Rights Reserved.
135e71b7053SJung-uk Kim
136e71b7053SJung-uk KimLicensed under the OpenSSL license (the "License").  You may not use
137e71b7053SJung-uk Kimthis file except in compliance with the License.  You can obtain a copy
138e71b7053SJung-uk Kimin the file LICENSE in the source distribution or at
139e71b7053SJung-uk KimL<https://www.openssl.org/source/license.html>.
140e71b7053SJung-uk Kim
141e71b7053SJung-uk Kim=cut
142