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

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

<h1>CMS_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>
<PRE> CMS_verify - verify a CMS SignedData structure
</PRE>
<P>
<HR>
<H1><A NAME="SYNOPSIS">SYNOPSIS</A></H1>
<PRE> #include &lt;openssl/cms.h&gt;
</PRE>
<PRE> int CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs, X509_STORE *store, BIO *indata, BIO *out, unsigned int flags);
</PRE>
<PRE> STACK_OF(X509) *CMS_get0_signers(CMS_ContentInfo *cms);
</PRE>
<P>
<HR>
<H1><A NAME="DESCRIPTION">DESCRIPTION</A></H1>
<P>
<CODE>CMS_verify()</CODE> verifies a CMS SignedData structure. <STRONG>cms</STRONG> is the CMS_ContentInfo structure to verify. <STRONG>certs</STRONG> is a set of certificates in which to search for the signing
<CODE>certificate(s).</CODE> <STRONG>store</STRONG> is a trusted certificate store used for chain verification. <STRONG>indata</STRONG> is the detached content if the content is not present in <STRONG>cms</STRONG>. 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>CMS_get0_signers()</CODE> retrieves the signing
<CODE>certificate(s)</CODE> from <STRONG>cms</STRONG>, it must be called after a successful <CODE>CMS_verify()</CODE> operation.

</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>cms</STRONG>. The type of <STRONG>cms</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 signing <CODE>certificate(s),</CODE>
first looking in the <STRONG>certs</STRONG> parameter (if it is not NULL) and then looking in any certificates
contained in the <STRONG>cms</STRONG> structure itself. If any signing certificate cannot be located the
operation fails.

</P>
<P>
Each signing 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 CRL checking is
enabled in <STRONG>store</STRONG> any internal CRLs are used in addition to attempting to look them up in <STRONG>store</STRONG>. 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.

</P>
<P>
If <STRONG>CMS_NOINTERN</STRONG> is set the certificates in the message itself are not searched when
locating the signing <CODE>certificate(s).</CODE> This means that all the
signing certificates must be in the <STRONG>certs</STRONG> parameter.

</P>
<P>
If <STRONG>CMS_NOCRL</STRONG> is set and CRL checking is enabled in <STRONG>store</STRONG> then any CRLs in the message itself are ignored.

</P>
<P>
If the <STRONG>CMS_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>CMS_NO_SIGNER_CERT_VERIFY</STRONG> is set the signing certificates are not verified.

</P>
<P>
If <STRONG>CMS_NO_ATTR_VERIFY</STRONG> is set the signed attributes signature is not verified.

</P>
<P>
If <STRONG>CMS_NO_CONTENT_VERIFY</STRONG> is set then the content digest is not checked.

</P>
<P>
<HR>
<H1><A NAME="NOTES">NOTES</A></H1>
<P>
One application of <STRONG>CMS_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>
In some cases the standard techniques for looking up and validating
certificates are not appropriate: for example an application may wish to
lookup certificates in a database or perform customised verification. This
can be achieved by setting and verifying the signers certificates manually
using the signed data utility functions.

</P>
<P>
Care should be taken when modifying the default verify behaviour, for
example setting <STRONG>CMS_NO_CONTENT_VERIFY</STRONG> will totally disable all content verification and any modified content 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>CMS_verify()</CODE> returns 1 for a successful verification and zero
if an error occurred.

</P>
<P>
<CODE>CMS_get0_signers()</CODE> returns all signers or NULL 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 signing certificate,
this is primarily due to the inadequacies of the current <STRONG>X509_STORE</STRONG>
functionality.

</P>
<P>
The lack of single pass processing means that the signed content must all
be held in memory if it is not detached.

</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/CMS_sign.html#">CMS_sign(3)</A>



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

</P>
:}


