xref: /netbsd-src/crypto/external/bsd/openssl.old/dist/doc/man3/PKCS7_verify.pod (revision 4724848cf0da353df257f730694b7882798e5daf)
1*4724848cSchristos=pod
2*4724848cSchristos
3*4724848cSchristos=head1 NAME
4*4724848cSchristos
5*4724848cSchristosPKCS7_verify, PKCS7_get0_signers - verify a PKCS#7 signedData structure
6*4724848cSchristos
7*4724848cSchristos=head1 SYNOPSIS
8*4724848cSchristos
9*4724848cSchristos #include <openssl/pkcs7.h>
10*4724848cSchristos
11*4724848cSchristos int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
12*4724848cSchristos                  BIO *indata, BIO *out, int flags);
13*4724848cSchristos
14*4724848cSchristos STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags);
15*4724848cSchristos
16*4724848cSchristos=head1 DESCRIPTION
17*4724848cSchristos
18*4724848cSchristosPKCS7_verify() is very similar to L<CMS_verify(3)>.
19*4724848cSchristosIt verifies a PKCS#7 signedData structure given in I<p7>.
20*4724848cSchristosThe optional I<certs> parameter refers to a set of certificates
21*4724848cSchristosin which to search for signer's certificates.
22*4724848cSchristosI<p7> may contain extra untrusted CA certificates that may be used for
23*4724848cSchristoschain building as well as CRLs that may be used for certificate validation.
24*4724848cSchristosI<store> may be NULL or point to
25*4724848cSchristosthe trusted certificate store to use for chain verification.
26*4724848cSchristosI<indata> refers to the signed data if the content is detached from I<p7>.
27*4724848cSchristosOtherwise I<indata> should be NULL, and then the signed data must be in I<p7>.
28*4724848cSchristosThe content is written to the BIO I<out> unless it is NULL.
29*4724848cSchristosI<flags> is an optional set of flags, which can be used to modify the operation.
30*4724848cSchristos
31*4724848cSchristosPKCS7_get0_signers() retrieves the signer's certificates from I<p7>, it does
32*4724848cSchristosB<not> check their validity or whether any signatures are valid. The I<certs>
33*4724848cSchristosand I<flags> parameters have the same meanings as in PKCS7_verify().
34*4724848cSchristos
35*4724848cSchristos=head1 VERIFY PROCESS
36*4724848cSchristos
37*4724848cSchristosNormally the verify process proceeds as follows.
38*4724848cSchristos
39*4724848cSchristosInitially some sanity checks are performed on I<p7>. The type of I<p7> must
40*4724848cSchristosbe SignedData. There must be at least one signature on the data and if
41*4724848cSchristosthe content is detached I<indata> cannot be NULL.  If the content is
42*4724848cSchristosnot detached and I<indata> is not NULL then the structure has both
43*4724848cSchristosembedded and external content. To treat this as an error, use the flag
44*4724848cSchristosB<PKCS7_NO_DUAL_CONTENT>.
45*4724848cSchristosThe default behavior allows this, for compatibility with older
46*4724848cSchristosversions of OpenSSL.
47*4724848cSchristos
48*4724848cSchristosAn attempt is made to locate all the signer's certificates, first looking in
49*4724848cSchristosthe I<certs> parameter (if it is not NULL). Then they are looked up in any
50*4724848cSchristoscertificates contained in the I<p7> structure unless B<PKCS7_NOINTERN> is set.
51*4724848cSchristosIf any signer's certificates cannot be located the operation fails.
52*4724848cSchristos
53*4724848cSchristosEach signer's certificate is chain verified using the B<smimesign> purpose and
54*4724848cSchristosusing the trusted certificate store I<store> if supplied.
55*4724848cSchristosAny internal certificates in the message, which may have been added using
56*4724848cSchristosL<PKCS7_add_certificate(3)>, are used as untrusted CAs unless B<PKCS7_NOCHAIN>
57*4724848cSchristosis set.
58*4724848cSchristosIf CRL checking is enabled in I<store> and B<PKCS7_NOCRL> is not set,
59*4724848cSchristosany internal CRLs, which may have been added using L<PKCS7_add_crl(3)>,
60*4724848cSchristosare used in addition to attempting to look them up in I<store>.
61*4724848cSchristosIf I<store> is not NULL and any chain verify fails an error code is returned.
62*4724848cSchristos
63*4724848cSchristosFinally the signed content is read (and written to I<out> unless it is NULL)
64*4724848cSchristosand the signature is checked.
65*4724848cSchristos
66*4724848cSchristosIf all signatures verify correctly then the function is successful.
67*4724848cSchristos
68*4724848cSchristosAny of the following flags (ored together) can be passed in the I<flags>
69*4724848cSchristosparameter to change the default verify behaviour.
70*4724848cSchristosOnly the flag B<PKCS7_NOINTERN> is meaningful to PKCS7_get0_signers().
71*4724848cSchristos
72*4724848cSchristosIf B<PKCS7_NOINTERN> is set the certificates in the message itself are not
73*4724848cSchristossearched when locating the signer's certificates.
74*4724848cSchristosThis means that all the signer's certificates must be in the I<certs> parameter.
75*4724848cSchristos
76*4724848cSchristosIf B<PKCS7_NOCRL> is set and CRL checking is enabled in I<store> then any
77*4724848cSchristosCRLs in the message itself are ignored.
78*4724848cSchristos
79*4724848cSchristosIf the B<PKCS7_TEXT> flag is set MIME headers for type C<text/plain> are deleted
80*4724848cSchristosfrom the content. If the content is not of type C<text/plain> then an error is
81*4724848cSchristosreturned.
82*4724848cSchristos
83*4724848cSchristosIf B<PKCS7_NOVERIFY> is set the signer's certificates are not chain verified.
84*4724848cSchristos
85*4724848cSchristosIf B<PKCS7_NOCHAIN> is set then the certificates contained in the message are
86*4724848cSchristosnot used as untrusted CAs. This means that the whole verify chain (apart from
87*4724848cSchristosthe signer's certificates) must be contained in the trusted store.
88*4724848cSchristos
89*4724848cSchristosIf B<PKCS7_NOSIGS> is set then the signatures on the data are not checked.
90*4724848cSchristos
91*4724848cSchristos=head1 NOTES
92*4724848cSchristos
93*4724848cSchristosOne application of B<PKCS7_NOINTERN> is to only accept messages signed by
94*4724848cSchristosa small number of certificates. The acceptable certificates would be passed
95*4724848cSchristosin the I<certs> parameter. In this case if the signer's certificate is not one
96*4724848cSchristosof the certificates supplied in I<certs> then the verify will fail because the
97*4724848cSchristossigner cannot be found.
98*4724848cSchristos
99*4724848cSchristosCare should be taken when modifying the default verify behaviour, for example
100*4724848cSchristossetting B<PKCS7_NOVERIFY|PKCS7_NOSIGS> will totally disable all verification
101*4724848cSchristosand any signed message will be considered valid. This combination is however
102*4724848cSchristosuseful if one merely wishes to write the content to I<out> and its validity
103*4724848cSchristosis not considered important.
104*4724848cSchristos
105*4724848cSchristosChain verification should arguably be performed using the signing time rather
106*4724848cSchristosthan the current time. However, since the signing time is supplied by the
107*4724848cSchristossigner it cannot be trusted without additional evidence (such as a trusted
108*4724848cSchristostimestamp).
109*4724848cSchristos
110*4724848cSchristos=head1 RETURN VALUES
111*4724848cSchristos
112*4724848cSchristosPKCS7_verify() returns 1 for a successful verification and 0 if an error occurs.
113*4724848cSchristos
114*4724848cSchristosPKCS7_get0_signers() returns all signers or NULL if an error occurred.
115*4724848cSchristos
116*4724848cSchristosThe error can be obtained from L<ERR_get_error(3)>.
117*4724848cSchristos
118*4724848cSchristos=head1 BUGS
119*4724848cSchristos
120*4724848cSchristosThe trusted certificate store is not searched for the signer's certificates.
121*4724848cSchristosThis is primarily due to the inadequacies of the current B<X509_STORE>
122*4724848cSchristosfunctionality.
123*4724848cSchristos
124*4724848cSchristosThe lack of single pass processing means that the signed content must all
125*4724848cSchristosbe held in memory if it is not detached.
126*4724848cSchristos
127*4724848cSchristos=head1 SEE ALSO
128*4724848cSchristos
129*4724848cSchristosL<CMS_verify(3)>, L<PKCS7_add_certificate(3)>, L<PKCS7_add_crl(3)>,
130*4724848cSchristosL<ERR_get_error(3)>, L<PKCS7_sign(3)>
131*4724848cSchristos
132*4724848cSchristos=head1 COPYRIGHT
133*4724848cSchristos
134*4724848cSchristosCopyright 2002-2022 The OpenSSL Project Authors. All Rights Reserved.
135*4724848cSchristos
136*4724848cSchristosLicensed under the OpenSSL license (the "License").  You may not use
137*4724848cSchristosthis file except in compliance with the License.  You can obtain a copy
138*4724848cSchristosin the file LICENSE in the source distribution or at
139*4724848cSchristosL<https://www.openssl.org/source/license.html>.
140*4724848cSchristos
141*4724848cSchristos=cut
142