1e71b7053SJung-uk Kim=pod 2e71b7053SJung-uk Kim 3e71b7053SJung-uk Kim=head1 NAME 4e71b7053SJung-uk Kim 5e71b7053SJung-uk KimPKCS7_verify, PKCS7_get0_signers - verify a PKCS#7 signedData structure 6e71b7053SJung-uk Kim 7e71b7053SJung-uk Kim=head1 SYNOPSIS 8e71b7053SJung-uk Kim 9e71b7053SJung-uk Kim #include <openssl/pkcs7.h> 10e71b7053SJung-uk Kim 11e71b7053SJung-uk Kim int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, 12e71b7053SJung-uk Kim BIO *indata, BIO *out, int flags); 13e71b7053SJung-uk Kim 14e71b7053SJung-uk Kim STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags); 15e71b7053SJung-uk Kim 16e71b7053SJung-uk Kim=head1 DESCRIPTION 17e71b7053SJung-uk Kim 18cfc39718SJung-uk KimPKCS7_verify() is very similar to L<CMS_verify(3)>. 19cfc39718SJung-uk KimIt verifies a PKCS#7 signedData structure given in I<p7>. 20cfc39718SJung-uk KimThe optional I<certs> parameter refers to a set of certificates 21cfc39718SJung-uk Kimin which to search for signer's certificates. 22cfc39718SJung-uk KimI<p7> may contain extra untrusted CA certificates that may be used for 23cfc39718SJung-uk Kimchain building as well as CRLs that may be used for certificate validation. 24cfc39718SJung-uk KimI<store> may be NULL or point to 25cfc39718SJung-uk Kimthe trusted certificate store to use for chain verification. 26cfc39718SJung-uk KimI<indata> refers to the signed data if the content is detached from I<p7>. 27cfc39718SJung-uk KimOtherwise I<indata> should be NULL, and then the signed data must be in I<p7>. 28cfc39718SJung-uk KimThe content is written to the BIO I<out> unless it is NULL. 29cfc39718SJung-uk KimI<flags> is an optional set of flags, which can be used to modify the operation. 30e71b7053SJung-uk Kim 31cfc39718SJung-uk KimPKCS7_get0_signers() retrieves the signer's certificates from I<p7>, it does 32cfc39718SJung-uk KimB<not> check their validity or whether any signatures are valid. The I<certs> 33cfc39718SJung-uk Kimand I<flags> parameters have the same meanings as in PKCS7_verify(). 34e71b7053SJung-uk Kim 35e71b7053SJung-uk Kim=head1 VERIFY PROCESS 36e71b7053SJung-uk Kim 37e71b7053SJung-uk KimNormally the verify process proceeds as follows. 38e71b7053SJung-uk Kim 39cfc39718SJung-uk KimInitially some sanity checks are performed on I<p7>. The type of I<p7> must 40cfc39718SJung-uk Kimbe SignedData. There must be at least one signature on the data and if 41cfc39718SJung-uk Kimthe content is detached I<indata> cannot be NULL. If the content is 42cfc39718SJung-uk Kimnot detached and I<indata> is not NULL then the structure has both 43e71b7053SJung-uk Kimembedded and external content. To treat this as an error, use the flag 44e71b7053SJung-uk KimB<PKCS7_NO_DUAL_CONTENT>. 45e71b7053SJung-uk KimThe default behavior allows this, for compatibility with older 46e71b7053SJung-uk Kimversions of OpenSSL. 47e71b7053SJung-uk Kim 48e71b7053SJung-uk KimAn attempt is made to locate all the signer's certificates, first looking in 49cfc39718SJung-uk Kimthe I<certs> parameter (if it is not NULL). Then they are looked up in any 50cfc39718SJung-uk Kimcertificates contained in the I<p7> structure unless B<PKCS7_NOINTERN> is set. 51cfc39718SJung-uk KimIf any signer's certificates cannot be located the operation fails. 52e71b7053SJung-uk Kim 53e71b7053SJung-uk KimEach signer's certificate is chain verified using the B<smimesign> purpose and 54cfc39718SJung-uk Kimusing the trusted certificate store I<store> if supplied. 55cfc39718SJung-uk KimAny internal certificates in the message, which may have been added using 56cfc39718SJung-uk KimL<PKCS7_add_certificate(3)>, are used as untrusted CAs unless B<PKCS7_NOCHAIN> 57cfc39718SJung-uk Kimis set. 58cfc39718SJung-uk KimIf CRL checking is enabled in I<store> and B<PKCS7_NOCRL> is not set, 59cfc39718SJung-uk Kimany internal CRLs, which may have been added using L<PKCS7_add_crl(3)>, 60cfc39718SJung-uk Kimare used in addition to attempting to look them up in I<store>. 61cfc39718SJung-uk KimIf I<store> is not NULL and any chain verify fails an error code is returned. 62e71b7053SJung-uk Kim 63cfc39718SJung-uk KimFinally the signed content is read (and written to I<out> unless it is NULL) 64cfc39718SJung-uk Kimand the signature is checked. 65e71b7053SJung-uk Kim 66cfc39718SJung-uk KimIf all signatures verify correctly then the function is successful. 67e71b7053SJung-uk Kim 68cfc39718SJung-uk KimAny of the following flags (ored together) can be passed in the I<flags> 69cfc39718SJung-uk Kimparameter to change the default verify behaviour. 70cfc39718SJung-uk KimOnly the flag B<PKCS7_NOINTERN> is meaningful to PKCS7_get0_signers(). 71e71b7053SJung-uk Kim 72e71b7053SJung-uk KimIf B<PKCS7_NOINTERN> is set the certificates in the message itself are not 73cfc39718SJung-uk Kimsearched when locating the signer's certificates. 74cfc39718SJung-uk KimThis means that all the signer's certificates must be in the I<certs> parameter. 75e71b7053SJung-uk Kim 76cfc39718SJung-uk KimIf B<PKCS7_NOCRL> is set and CRL checking is enabled in I<store> then any 77cfc39718SJung-uk KimCRLs in the message itself are ignored. 78cfc39718SJung-uk Kim 79cfc39718SJung-uk KimIf the B<PKCS7_TEXT> flag is set MIME headers for type C<text/plain> are deleted 80cfc39718SJung-uk Kimfrom the content. If the content is not of type C<text/plain> then an error is 81e71b7053SJung-uk Kimreturned. 82e71b7053SJung-uk Kim 83e71b7053SJung-uk KimIf B<PKCS7_NOVERIFY> is set the signer's certificates are not chain verified. 84e71b7053SJung-uk Kim 85e71b7053SJung-uk KimIf B<PKCS7_NOCHAIN> is set then the certificates contained in the message are 86e71b7053SJung-uk Kimnot used as untrusted CAs. This means that the whole verify chain (apart from 87cfc39718SJung-uk Kimthe signer's certificates) must be contained in the trusted store. 88e71b7053SJung-uk Kim 89e71b7053SJung-uk KimIf B<PKCS7_NOSIGS> is set then the signatures on the data are not checked. 90e71b7053SJung-uk Kim 91e71b7053SJung-uk Kim=head1 NOTES 92e71b7053SJung-uk Kim 93e71b7053SJung-uk KimOne application of B<PKCS7_NOINTERN> is to only accept messages signed by 94e71b7053SJung-uk Kima small number of certificates. The acceptable certificates would be passed 95cfc39718SJung-uk Kimin the I<certs> parameter. In this case if the signer's certificate is not one 96cfc39718SJung-uk Kimof the certificates supplied in I<certs> then the verify will fail because the 97e71b7053SJung-uk Kimsigner cannot be found. 98e71b7053SJung-uk Kim 99e71b7053SJung-uk KimCare should be taken when modifying the default verify behaviour, for example 100*b077aed3SPierre Proncherysetting C<PKCS7_NOVERIFY|PKCS7_NOSIGS> will totally disable all verification 101e71b7053SJung-uk Kimand any signed message will be considered valid. This combination is however 102cfc39718SJung-uk Kimuseful if one merely wishes to write the content to I<out> and its validity 103e71b7053SJung-uk Kimis not considered important. 104e71b7053SJung-uk Kim 105e71b7053SJung-uk KimChain verification should arguably be performed using the signing time rather 10658f35182SJung-uk Kimthan the current time. However, since the signing time is supplied by the 107e71b7053SJung-uk Kimsigner it cannot be trusted without additional evidence (such as a trusted 108e71b7053SJung-uk Kimtimestamp). 109e71b7053SJung-uk Kim 110e71b7053SJung-uk Kim=head1 RETURN VALUES 111e71b7053SJung-uk Kim 112cfc39718SJung-uk KimPKCS7_verify() returns 1 for a successful verification and 0 if an error occurs. 113e71b7053SJung-uk Kim 114cfc39718SJung-uk KimPKCS7_get0_signers() returns all signers or NULL if an error occurred. 115e71b7053SJung-uk Kim 116cfc39718SJung-uk KimThe error can be obtained from L<ERR_get_error(3)>. 117e71b7053SJung-uk Kim 118e71b7053SJung-uk Kim=head1 BUGS 119e71b7053SJung-uk Kim 120cfc39718SJung-uk KimThe trusted certificate store is not searched for the signer's certificates. 121cfc39718SJung-uk KimThis is primarily due to the inadequacies of the current B<X509_STORE> 122e71b7053SJung-uk Kimfunctionality. 123e71b7053SJung-uk Kim 124cfc39718SJung-uk KimThe lack of single pass processing means that the signed content must all 125cfc39718SJung-uk Kimbe held in memory if it is not detached. 126e71b7053SJung-uk Kim 127e71b7053SJung-uk Kim=head1 SEE ALSO 128e71b7053SJung-uk Kim 129cfc39718SJung-uk KimL<CMS_verify(3)>, L<PKCS7_add_certificate(3)>, L<PKCS7_add_crl(3)>, 130e71b7053SJung-uk KimL<ERR_get_error(3)>, L<PKCS7_sign(3)> 131e71b7053SJung-uk Kim 132e71b7053SJung-uk Kim=head1 COPYRIGHT 133e71b7053SJung-uk Kim 134cfc39718SJung-uk KimCopyright 2002-2022 The OpenSSL Project Authors. All Rights Reserved. 135e71b7053SJung-uk Kim 136*b077aed3SPierre ProncheryLicensed under the Apache License 2.0 (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