xref: /netbsd-src/crypto/external/bsd/openssl/dist/doc/man3/PKCS7_verify.pod (revision b0d1725196a7921d003d2c66a14f186abda4176b)
113d40330Schristos=pod
213d40330Schristos
313d40330Schristos=head1 NAME
413d40330Schristos
513d40330SchristosPKCS7_verify, PKCS7_get0_signers - verify a PKCS#7 signedData structure
613d40330Schristos
713d40330Schristos=head1 SYNOPSIS
813d40330Schristos
913d40330Schristos #include <openssl/pkcs7.h>
1013d40330Schristos
1113d40330Schristos int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
1213d40330Schristos                  BIO *indata, BIO *out, int flags);
1313d40330Schristos
1413d40330Schristos STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags);
1513d40330Schristos
1613d40330Schristos=head1 DESCRIPTION
1713d40330Schristos
186f6db51eSchristosPKCS7_verify() is very similar to L<CMS_verify(3)>.
196f6db51eSchristosIt verifies a PKCS#7 signedData structure given in I<p7>.
206f6db51eSchristosThe optional I<certs> parameter refers to a set of certificates
216f6db51eSchristosin which to search for signer's certificates.
226f6db51eSchristosI<p7> may contain extra untrusted CA certificates that may be used for
236f6db51eSchristoschain building as well as CRLs that may be used for certificate validation.
246f6db51eSchristosI<store> may be NULL or point to
256f6db51eSchristosthe trusted certificate store to use for chain verification.
266f6db51eSchristosI<indata> refers to the signed data if the content is detached from I<p7>.
276f6db51eSchristosOtherwise I<indata> should be NULL, and then the signed data must be in I<p7>.
286f6db51eSchristosThe content is written to the BIO I<out> unless it is NULL.
296f6db51eSchristosI<flags> is an optional set of flags, which can be used to modify the operation.
3013d40330Schristos
316f6db51eSchristosPKCS7_get0_signers() retrieves the signer's certificates from I<p7>, it does
326f6db51eSchristosB<not> check their validity or whether any signatures are valid. The I<certs>
336f6db51eSchristosand I<flags> parameters have the same meanings as in PKCS7_verify().
3413d40330Schristos
3513d40330Schristos=head1 VERIFY PROCESS
3613d40330Schristos
3713d40330SchristosNormally the verify process proceeds as follows.
3813d40330Schristos
396f6db51eSchristosInitially some sanity checks are performed on I<p7>. The type of I<p7> must
406f6db51eSchristosbe SignedData. There must be at least one signature on the data and if
416f6db51eSchristosthe content is detached I<indata> cannot be NULL.  If the content is
426f6db51eSchristosnot detached and I<indata> is not NULL then the structure has both
4313d40330Schristosembedded and external content. To treat this as an error, use the flag
4413d40330SchristosB<PKCS7_NO_DUAL_CONTENT>.
4513d40330SchristosThe default behavior allows this, for compatibility with older
4613d40330Schristosversions of OpenSSL.
4713d40330Schristos
4813d40330SchristosAn attempt is made to locate all the signer's certificates, first looking in
496f6db51eSchristosthe I<certs> parameter (if it is not NULL). Then they are looked up in any
506f6db51eSchristoscertificates contained in the I<p7> structure unless B<PKCS7_NOINTERN> is set.
516f6db51eSchristosIf any signer's certificates cannot be located the operation fails.
5213d40330Schristos
5313d40330SchristosEach signer's certificate is chain verified using the B<smimesign> purpose and
546f6db51eSchristosusing the trusted certificate store I<store> if supplied.
556f6db51eSchristosAny internal certificates in the message, which may have been added using
566f6db51eSchristosL<PKCS7_add_certificate(3)>, are used as untrusted CAs unless B<PKCS7_NOCHAIN>
576f6db51eSchristosis set.
586f6db51eSchristosIf CRL checking is enabled in I<store> and B<PKCS7_NOCRL> is not set,
596f6db51eSchristosany internal CRLs, which may have been added using L<PKCS7_add_crl(3)>,
606f6db51eSchristosare used in addition to attempting to look them up in I<store>.
616f6db51eSchristosIf I<store> is not NULL and any chain verify fails an error code is returned.
6213d40330Schristos
636f6db51eSchristosFinally the signed content is read (and written to I<out> unless it is NULL)
646f6db51eSchristosand the signature is checked.
6513d40330Schristos
666f6db51eSchristosIf all signatures verify correctly then the function is successful.
6713d40330Schristos
686f6db51eSchristosAny of the following flags (ored together) can be passed in the I<flags>
696f6db51eSchristosparameter to change the default verify behaviour.
706f6db51eSchristosOnly the flag B<PKCS7_NOINTERN> is meaningful to PKCS7_get0_signers().
7113d40330Schristos
7213d40330SchristosIf B<PKCS7_NOINTERN> is set the certificates in the message itself are not
736f6db51eSchristossearched when locating the signer's certificates.
746f6db51eSchristosThis means that all the signer's certificates must be in the I<certs> parameter.
7513d40330Schristos
766f6db51eSchristosIf B<PKCS7_NOCRL> is set and CRL checking is enabled in I<store> then any
776f6db51eSchristosCRLs in the message itself are ignored.
786f6db51eSchristos
796f6db51eSchristosIf the B<PKCS7_TEXT> flag is set MIME headers for type C<text/plain> are deleted
806f6db51eSchristosfrom the content. If the content is not of type C<text/plain> then an error is
8113d40330Schristosreturned.
8213d40330Schristos
8313d40330SchristosIf B<PKCS7_NOVERIFY> is set the signer's certificates are not chain verified.
8413d40330Schristos
8513d40330SchristosIf B<PKCS7_NOCHAIN> is set then the certificates contained in the message are
8613d40330Schristosnot used as untrusted CAs. This means that the whole verify chain (apart from
876f6db51eSchristosthe signer's certificates) must be contained in the trusted store.
8813d40330Schristos
8913d40330SchristosIf B<PKCS7_NOSIGS> is set then the signatures on the data are not checked.
9013d40330Schristos
9113d40330Schristos=head1 NOTES
9213d40330Schristos
9313d40330SchristosOne application of B<PKCS7_NOINTERN> is to only accept messages signed by
9413d40330Schristosa small number of certificates. The acceptable certificates would be passed
956f6db51eSchristosin the I<certs> parameter. In this case if the signer's certificate is not one
966f6db51eSchristosof the certificates supplied in I<certs> then the verify will fail because the
9713d40330Schristossigner cannot be found.
9813d40330Schristos
9913d40330SchristosCare should be taken when modifying the default verify behaviour, for example
100*b0d17251Schristossetting C<PKCS7_NOVERIFY|PKCS7_NOSIGS> will totally disable all verification
10113d40330Schristosand any signed message will be considered valid. This combination is however
1026f6db51eSchristosuseful if one merely wishes to write the content to I<out> and its validity
10313d40330Schristosis not considered important.
10413d40330Schristos
10513d40330SchristosChain verification should arguably be performed using the signing time rather
106f30e0929Schristosthan the current time. However, since the signing time is supplied by the
10713d40330Schristossigner it cannot be trusted without additional evidence (such as a trusted
10813d40330Schristostimestamp).
10913d40330Schristos
11013d40330Schristos=head1 RETURN VALUES
11113d40330Schristos
1126f6db51eSchristosPKCS7_verify() returns 1 for a successful verification and 0 if an error occurs.
11313d40330Schristos
1146f6db51eSchristosPKCS7_get0_signers() returns all signers or NULL if an error occurred.
11513d40330Schristos
1166f6db51eSchristosThe error can be obtained from L<ERR_get_error(3)>.
11713d40330Schristos
11813d40330Schristos=head1 BUGS
11913d40330Schristos
1206f6db51eSchristosThe trusted certificate store is not searched for the signer's certificates.
1216f6db51eSchristosThis is primarily due to the inadequacies of the current B<X509_STORE>
12213d40330Schristosfunctionality.
12313d40330Schristos
1246f6db51eSchristosThe lack of single pass processing means that the signed content must all
1256f6db51eSchristosbe held in memory if it is not detached.
12613d40330Schristos
12713d40330Schristos=head1 SEE ALSO
12813d40330Schristos
1296f6db51eSchristosL<CMS_verify(3)>, L<PKCS7_add_certificate(3)>, L<PKCS7_add_crl(3)>,
13013d40330SchristosL<ERR_get_error(3)>, L<PKCS7_sign(3)>
13113d40330Schristos
13213d40330Schristos=head1 COPYRIGHT
13313d40330Schristos
1346f6db51eSchristosCopyright 2002-2022 The OpenSSL Project Authors. All Rights Reserved.
13513d40330Schristos
136*b0d17251SchristosLicensed under the Apache License 2.0 (the "License").  You may not use
13713d40330Schristosthis file except in compliance with the License.  You can obtain a copy
13813d40330Schristosin the file LICENSE in the source distribution or at
13913d40330SchristosL<https://www.openssl.org/source/license.html>.
14013d40330Schristos
14113d40330Schristos=cut
142