Blame doc/man3/PKCS7_verify.pod

Packit c4476c
=pod
Packit c4476c
Packit c4476c
=head1 NAME
Packit c4476c
Packit c4476c
PKCS7_verify, PKCS7_get0_signers - verify a PKCS#7 signedData structure
Packit c4476c
Packit c4476c
=head1 SYNOPSIS
Packit c4476c
Packit c4476c
 #include <openssl/pkcs7.h>
Packit c4476c
Packit c4476c
 int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store,
Packit c4476c
                  BIO *indata, BIO *out, int flags);
Packit c4476c
Packit c4476c
 STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags);
Packit c4476c
Packit c4476c
=head1 DESCRIPTION
Packit c4476c
Packit c4476c
PKCS7_verify() verifies a PKCS#7 signedData structure. B<p7> is the PKCS7
Packit c4476c
structure to verify. B<certs> is a set of certificates in which to search for
Packit c4476c
the signer's certificate. B<store> is a trusted certificate store (used for
Packit c4476c
chain verification). B<indata> is the signed data if the content is not
Packit c4476c
present in B<p7> (that is it is detached). The content is written to B<out>
Packit c4476c
if it is not NULL.
Packit c4476c
Packit c4476c
B<flags> is an optional set of flags, which can be used to modify the verify
Packit c4476c
operation.
Packit c4476c
Packit c4476c
PKCS7_get0_signers() retrieves the signer's certificates from B<p7>, it does
Packit c4476c
B<not> check their validity or whether any signatures are valid. The B<certs>
Packit c4476c
and B<flags> parameters have the same meanings as in PKCS7_verify().
Packit c4476c
Packit c4476c
=head1 VERIFY PROCESS
Packit c4476c
Packit c4476c
Normally the verify process proceeds as follows.
Packit c4476c
Packit c4476c
Initially some sanity checks are performed on B<p7>. The type of B<p7> must
Packit c4476c
be signedData. There must be at least one signature on the data and if
Packit c4476c
the content is detached B<indata> cannot be B<NULL>.  If the content is
Packit c4476c
not detached and B<indata> is not B<NULL>, then the structure has both
Packit c4476c
embedded and external content. To treat this as an error, use the flag
Packit c4476c
B<PKCS7_NO_DUAL_CONTENT>.
Packit c4476c
The default behavior allows this, for compatibility with older
Packit c4476c
versions of OpenSSL.
Packit c4476c
Packit c4476c
An attempt is made to locate all the signer's certificates, first looking in
Packit c4476c
the B<certs> parameter (if it is not B<NULL>) and then looking in any certificates
Packit c4476c
contained in the B<p7> structure itself. If any signer's certificates cannot be
Packit c4476c
located the operation fails.
Packit c4476c
Packit c4476c
Each signer's certificate is chain verified using the B<smimesign> purpose and
Packit c4476c
the supplied trusted certificate store. Any internal certificates in the message
Packit c4476c
are used as untrusted CAs. If any chain verify fails an error code is returned.
Packit c4476c
Packit c4476c
Finally the signed content is read (and written to B<out> is it is not NULL) and
Packit c4476c
the signature's checked.
Packit c4476c
Packit c4476c
If all signature's verify correctly then the function is successful.
Packit c4476c
Packit c4476c
Any of the following flags (ored together) can be passed in the B<flags> parameter
Packit c4476c
to change the default verify behaviour. Only the flag B<PKCS7_NOINTERN> is
Packit c4476c
meaningful to PKCS7_get0_signers().
Packit c4476c
Packit c4476c
If B<PKCS7_NOINTERN> is set the certificates in the message itself are not
Packit c4476c
searched when locating the signer's certificate. This means that all the signers
Packit c4476c
certificates must be in the B<certs> parameter.
Packit c4476c
Packit c4476c
If the B<PKCS7_TEXT> flag is set MIME headers for type B<text/plain> are deleted
Packit c4476c
from the content. If the content is not of type B<text/plain> then an error is
Packit c4476c
returned.
Packit c4476c
Packit c4476c
If B<PKCS7_NOVERIFY> is set the signer's certificates are not chain verified.
Packit c4476c
Packit c4476c
If B<PKCS7_NOCHAIN> is set then the certificates contained in the message are
Packit c4476c
not used as untrusted CAs. This means that the whole verify chain (apart from
Packit c4476c
the signer's certificate) must be contained in the trusted store.
Packit c4476c
Packit c4476c
If B<PKCS7_NOSIGS> is set then the signatures on the data are not checked.
Packit c4476c
Packit c4476c
=head1 NOTES
Packit c4476c
Packit c4476c
One application of B<PKCS7_NOINTERN> is to only accept messages signed by
Packit c4476c
a small number of certificates. The acceptable certificates would be passed
Packit c4476c
in the B<certs> parameter. In this case if the signer is not one of the
Packit c4476c
certificates supplied in B<certs> then the verify will fail because the
Packit c4476c
signer cannot be found.
Packit c4476c
Packit c4476c
Care should be taken when modifying the default verify behaviour, for example
Packit c4476c
setting B<PKCS7_NOVERIFY|PKCS7_NOSIGS> will totally disable all verification
Packit c4476c
and any signed message will be considered valid. This combination is however
Packit c4476c
useful if one merely wishes to write the content to B<out> and its validity
Packit c4476c
is not considered important.
Packit c4476c
Packit c4476c
Chain verification should arguably be performed  using the signing time rather
Packit c4476c
than the current time. However since the signing time is supplied by the
Packit c4476c
signer it cannot be trusted without additional evidence (such as a trusted
Packit c4476c
timestamp).
Packit c4476c
Packit c4476c
=head1 RETURN VALUES
Packit c4476c
Packit c4476c
PKCS7_verify() returns one for a successful verification and zero
Packit c4476c
if an error occurs.
Packit c4476c
Packit c4476c
PKCS7_get0_signers() returns all signers or B<NULL> if an error occurred.
Packit c4476c
Packit c4476c
The error can be obtained from L<ERR_get_error(3)>
Packit c4476c
Packit c4476c
=head1 BUGS
Packit c4476c
Packit c4476c
The trusted certificate store is not searched for the signers certificate,
Packit c4476c
this is primarily due to the inadequacies of the current B<X509_STORE>
Packit c4476c
functionality.
Packit c4476c
Packit c4476c
The lack of single pass processing and need to hold all data in memory as
Packit c4476c
mentioned in PKCS7_sign() also applies to PKCS7_verify().
Packit c4476c
Packit c4476c
=head1 SEE ALSO
Packit c4476c
Packit c4476c
L<ERR_get_error(3)>, L<PKCS7_sign(3)>
Packit c4476c
Packit c4476c
=head1 COPYRIGHT
Packit c4476c
Packit c4476c
Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
Packit c4476c
Packit c4476c
Licensed under the OpenSSL license (the "License").  You may not use
Packit c4476c
this file except in compliance with the License.  You can obtain a copy
Packit c4476c
in the file LICENSE in the source distribution or at
Packit c4476c
L<https://www.openssl.org/source/license.html>.
Packit c4476c
Packit c4476c
=cut