
#use wml::openssl-macros area=docs page=PKCS7_verify

<title>Documents, PKCS7_verify(3)</title>

<h1>PKCS7_verify(3)</h1>

#use wml::imp::generic

{:
## What's this? [[s|(<STRONG>[^<].+?)</A>(</STRONG><DD>)|$1$2|sg]]
[[s|<P>\s+<P>|<P>|sg]]
[[s|<P>\s+</|</|sg]]
[[s|<DD>\s*<DT>|<DD>&nbsp;<DT>|sg]]
[[s|<DD>\s*</DL>|<DD>&nbsp;</DL>|sg]]
[[s|\[|&#91;|sg]]
[[s|\]|&#93;|sg]]

<!-- INDEX BEGIN -->

<UL>

	<LI><A HREF="#NAME">NAME</A>
	<LI><A HREF="#SYNOPSIS">SYNOPSIS</A>
	<LI><A HREF="#DESCRIPTION">DESCRIPTION</A>
	<LI><A HREF="#VERIFY_PROCESS">VERIFY PROCESS</A>
	<LI><A HREF="#NOTES">NOTES</A>
	<LI><A HREF="#RETURN_VALUES">RETURN VALUES</A>
	<LI><A HREF="#BUGS">BUGS</A>
	<LI><A HREF="#SEE_ALSO">SEE ALSO</A>
	<LI><A HREF="#HISTORY">HISTORY</A>
</UL>
<!-- INDEX END -->

<HR>
<P>
<HR>
<H1><A NAME="NAME">NAME</A></H1>
<P>
PKCS7_verify, PKCS7_get0_signers - verify a PKCS#7 signedData structure

</P>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<PRE> #include &lt;openssl/pkcs7.h&gt;
</PRE>
<PRE> int PKCS7_verify(PKCS7 *p7, STACK_OF(X509) *certs, X509_STORE *store, BIO *indata, BIO *out, int flags);
</PRE>
<PRE> STACK_OF(X509) *PKCS7_get0_signers(PKCS7 *p7, STACK_OF(X509) *certs, int flags);
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
<CODE>PKCS7_verify()</CODE> verifies a PKCS#7 signedData structure. <STRONG>p7</STRONG> is the PKCS7 structure to verify. <STRONG>certs</STRONG> is a set of certificates in which to search for the signer's certificate. <STRONG>store</STRONG> is a trusted certficate store (used for chain verification). <STRONG>indata</STRONG> is the signed data if the content is not present in <STRONG>p7</STRONG> (that is it is detached). The content is written to <STRONG>out</STRONG>
if it is not NULL.

</P>
<P>
<STRONG>flags</STRONG> is an optional set of flags, which can be used to modify the verify
operation.

</P>
<P>
<CODE>PKCS7_get0_signers()</CODE> retrieves the signer's certificates from <STRONG>p7</STRONG>, it does
<STRONG>not</STRONG> check their validity or whether any signatures are valid. The <STRONG>certs</STRONG>
and <STRONG>flags</STRONG> parameters have the same meanings as in <CODE>PKCS7_verify().</CODE>

</P>
<P>
<HR>
<H1><A NAME="VERIFY_PROCESS">VERIFY PROCESS</A></H1>
<P>
Normally the verify process proceeds as follows.

</P>
<P>
Initially some sanity checks are performed on <STRONG>p7</STRONG>. The type of <STRONG>p7</STRONG> must be signedData. There must be at least one signature on the data and if
the content is detached <STRONG>indata</STRONG> cannot be <STRONG>NULL</STRONG>.

</P>
<P>
An attempt is made to locate all the signer's certificates, first looking
in the <STRONG>certs</STRONG> parameter (if it is not <STRONG>NULL</STRONG>) and then looking in any certificates contained in the <STRONG>p7</STRONG> structure itself. If any signer's certificates cannot be located the
operation fails.

</P>
<P>
Each signer's certificate is chain verified using the <STRONG>smimesign</STRONG> purpose and the supplied trusted certificate store. Any internal
certificates in the message are used as untrusted CAs. If any chain verify
fails an error code is returned.

</P>
<P>
Finally the signed content is read (and written to <STRONG>out</STRONG> is it is not NULL) and the signature's checked.

</P>
<P>
If all signature's verify correctly then the function is successful.

</P>
<P>
Any of the following flags (ored together) can be passed in the <STRONG>flags</STRONG> parameter to change the default verify behaviour. Only the flag <STRONG>PKCS7_NOINTERN</STRONG> is meaningful to <CODE>PKCS7_get0_signers().</CODE>

</P>
<P>
If <STRONG>PKCS7_NOINTERN</STRONG> is set the certificates in the message itself are not searched when
locating the signer's certificate. This means that all the signers
certificates must be in the <STRONG>certs</STRONG> parameter.

</P>
<P>
If the <STRONG>PKCS7_TEXT</STRONG> flag is set MIME headers for type <STRONG>text/plain</STRONG> are deleted from the content. If the content is not of type <STRONG>text/plain</STRONG> then an error is returned.

</P>
<P>
If <STRONG>PKCS7_NOVERIFY</STRONG> is set the signer's certificates are not chain verified.

</P>
<P>
If <STRONG>PKCS7_NOCHAIN</STRONG> is set then the certificates contained in the message are not used as
untrusted CAs. This means that the whole verify chain (apart from the
signer's certificate) must be contained in the trusted store.

</P>
<P>
If <STRONG>PKCS7_NOSIGS</STRONG> is set then the signatures on the data are not checked.

</P>
<P>
<HR>
<H1><A NAME="NOTES">NOTES</A></H1>
<P>
One application of <STRONG>PKCS7_NOINTERN</STRONG> is to only accept messages signed by a small number of certificates. The
acceptable certificates would be passed in the <STRONG>certs</STRONG> parameter. In this case if the signer is not one of the certificates
supplied in <STRONG>certs</STRONG> then the verify will fail because the signer cannot be found.

</P>
<P>
Care should be taken when modifying the default verify behaviour, for
example setting <STRONG>PKCS7_NOVERIFY|PKCS7_NOSIGS</STRONG> will totally disable all verification and any signed message will be
considered valid. This combination is however useful if one merely wishes
to write the content to <STRONG>out</STRONG> and its validity is not considered important.

</P>
<P>
Chain verification should arguably be performed using the signing time
rather than the current time. However since the signing time is supplied by
the signer it cannot be trusted without additional evidence (such as a
trusted timestamp).

</P>
<P>
<HR>
<H1><A NAME="RETURN_VALUES">RETURN VALUES</A></H1>
<P>
<CODE>PKCS7_verify()</CODE> returns 1 for a successful verification and
zero or a negative value if an error occurs.

</P>
<P>
<CODE>PKCS7_get0_signers()</CODE> returns all signers or <STRONG>NULL</STRONG> if an error occurred.

</P>
<P>
The error can be obtained from <A HREF="../crypto/ERR_get_error.html#">ERR_get_error(3)</A>



</P>
<P>
<HR>
<H1><A NAME="BUGS">BUGS</A></H1>
<P>
The trusted certificate store is not searched for the signers certificate,
this is primarily due to the inadequacies of the current <STRONG>X509_STORE</STRONG>
functionality.

</P>
<P>
The lack of single pass processing and need to hold all data in memory as
mentioned in <CODE>PKCS7_sign()</CODE> also applies to
<CODE>PKCS7_verify().</CODE>

</P>
<P>
<HR>
<H1><A NAME="SEE_ALSO">SEE ALSO</A></H1>
<P>
<A HREF="../crypto/ERR_get_error.html#">ERR_get_error(3)</A>, <A HREF="../crypto/PKCS7_sign.html#">PKCS7_sign(3)</A>



</P>
<P>
<HR>
<H1><A NAME="HISTORY">HISTORY</A></H1>
<P>
<CODE>PKCS7_verify()</CODE> was added to OpenSSL 0.9.5

</P>
:}

