1*4724848cSchristos=pod 2*4724848cSchristos 3*4724848cSchristos=head1 NAME 4*4724848cSchristos 5*4724848cSchristosCMS_verify, CMS_get0_signers - verify a CMS SignedData structure 6*4724848cSchristos 7*4724848cSchristos=head1 SYNOPSIS 8*4724848cSchristos 9*4724848cSchristos #include <openssl/cms.h> 10*4724848cSchristos 11*4724848cSchristos int CMS_verify(CMS_ContentInfo *cms, STACK_OF(X509) *certs, X509_STORE *store, 12*4724848cSchristos BIO *indata, BIO *out, unsigned int flags); 13*4724848cSchristos 14*4724848cSchristos STACK_OF(X509) *CMS_get0_signers(CMS_ContentInfo *cms); 15*4724848cSchristos 16*4724848cSchristos=head1 DESCRIPTION 17*4724848cSchristos 18*4724848cSchristosCMS_verify() is very similar to L<PKCS7_verify(3)>. It verifies a 19*4724848cSchristosB<CMS SignedData> structure contained in a structure of type B<CMS_ContentInfo>. 20*4724848cSchristosI<cms> points to the B<CMS_ContentInfo> structure to verify. 21*4724848cSchristosThe optional I<certs> parameter refers to a set of certificates 22*4724848cSchristosin which to search for signing certificates. 23*4724848cSchristosI<cms> may contain extra untrusted CA certificates that may be used for 24*4724848cSchristoschain building as well as CRLs that may be used for certificate validation. 25*4724848cSchristosI<store> may be NULL or point to 26*4724848cSchristosthe trusted certificate store to use for chain verification. 27*4724848cSchristosI<indata> refers to the signed data if the content is detached from I<cms>. 28*4724848cSchristosOtherwise I<indata> should be NULL and the signed data must be in I<cms>. 29*4724848cSchristosThe content is written to the BIO I<out> unless it is NULL. 30*4724848cSchristosI<flags> is an optional set of flags, which can be used to modify the operation. 31*4724848cSchristos 32*4724848cSchristosCMS_get0_signers() retrieves the signing certificate(s) from I<cms>, it may only 33*4724848cSchristosbe called after a successful CMS_verify() operation. 34*4724848cSchristos 35*4724848cSchristos=head1 VERIFY PROCESS 36*4724848cSchristos 37*4724848cSchristosNormally the verify process proceeds as follows. 38*4724848cSchristos 39*4724848cSchristosInitially some sanity checks are performed on I<cms>. The type of I<cms> must 40*4724848cSchristosbe SignedData. There must be at least one signature on the data and if 41*4724848cSchristosthe content is detached I<indata> cannot be NULL. 42*4724848cSchristos 43*4724848cSchristosAn attempt is made to locate all the signing certificate(s), first looking in 44*4724848cSchristosthe I<certs> parameter (if it is not NULL) and then looking in any 45*4724848cSchristoscertificates contained in the I<cms> structure unless B<CMS_NOINTERN> is set. 46*4724848cSchristosIf any signing certificate cannot be located the operation fails. 47*4724848cSchristos 48*4724848cSchristosEach signing certificate is chain verified using the I<smimesign> purpose and 49*4724848cSchristosusing the trusted certificate store I<store> if supplied. 50*4724848cSchristosAny internal certificates in the message, which may have been added using 51*4724848cSchristosL<CMS_add1_cert(3)>, are used as untrusted CAs. 52*4724848cSchristosIf CRL checking is enabled in I<store> and B<CMS_NOCRL> is not set, 53*4724848cSchristosany internal CRLs, which may have been added using L<CMS_add1_crl(3)>, 54*4724848cSchristosare used in addition to attempting to look them up in I<store>. 55*4724848cSchristosIf I<store> is not NULL and any chain verify fails an error code is returned. 56*4724848cSchristos 57*4724848cSchristosFinally the signed content is read (and written to I<out> unless it is NULL) 58*4724848cSchristosand the signature is checked. 59*4724848cSchristos 60*4724848cSchristosIf all signatures verify correctly then the function is successful. 61*4724848cSchristos 62*4724848cSchristosAny of the following flags (ored together) can be passed in the I<flags> 63*4724848cSchristosparameter to change the default verify behaviour. 64*4724848cSchristos 65*4724848cSchristosIf B<CMS_NOINTERN> is set the certificates in the message itself are not 66*4724848cSchristossearched when locating the signing certificate(s). 67*4724848cSchristosThis means that all the signing certificates must be in the I<certs> parameter. 68*4724848cSchristos 69*4724848cSchristosIf B<CMS_NOCRL> is set and CRL checking is enabled in I<store> then any 70*4724848cSchristosCRLs in the message itself are ignored. 71*4724848cSchristos 72*4724848cSchristosIf the B<CMS_TEXT> flag is set MIME headers for type B<text/plain> are deleted 73*4724848cSchristosfrom the content. If the content is not of type B<text/plain> then an error is 74*4724848cSchristosreturned. 75*4724848cSchristos 76*4724848cSchristosIf B<CMS_NO_SIGNER_CERT_VERIFY> is set the signing certificates are not 77*4724848cSchristoschain verified. 78*4724848cSchristos 79*4724848cSchristosIf B<CMS_NO_ATTR_VERIFY> is set the signed attributes signature is not 80*4724848cSchristosverified. 81*4724848cSchristos 82*4724848cSchristosIf B<CMS_NO_CONTENT_VERIFY> is set then the content digest is not checked. 83*4724848cSchristos 84*4724848cSchristos=head1 NOTES 85*4724848cSchristos 86*4724848cSchristosOne application of B<CMS_NOINTERN> is to only accept messages signed by 87*4724848cSchristosa small number of certificates. The acceptable certificates would be passed 88*4724848cSchristosin the I<certs> parameter. In this case if the signer certificate is not one 89*4724848cSchristosof the certificates supplied in I<certs> then the verify will fail because the 90*4724848cSchristossigner cannot be found. 91*4724848cSchristos 92*4724848cSchristosIn some cases the standard techniques for looking up and validating 93*4724848cSchristoscertificates are not appropriate: for example an application may wish to 94*4724848cSchristoslookup certificates in a database or perform customised verification. This 95*4724848cSchristoscan be achieved by setting and verifying the signer certificates manually 96*4724848cSchristosusing the signed data utility functions. 97*4724848cSchristos 98*4724848cSchristosCare should be taken when modifying the default verify behaviour, for example 99*4724848cSchristossetting B<CMS_NO_CONTENT_VERIFY> will totally disable all content verification 100*4724848cSchristosand any modified content will be considered valid. This combination is however 101*4724848cSchristosuseful if one merely wishes to write the content to I<out> and its validity 102*4724848cSchristosis not considered important. 103*4724848cSchristos 104*4724848cSchristosChain verification should arguably be performed using the signing time rather 105*4724848cSchristosthan the current time. However, since the signing time is supplied by the 106*4724848cSchristossigner it cannot be trusted without additional evidence (such as a trusted 107*4724848cSchristostimestamp). 108*4724848cSchristos 109*4724848cSchristos=head1 RETURN VALUES 110*4724848cSchristos 111*4724848cSchristosCMS_verify() returns 1 for a successful verification and 0 if an error occurred. 112*4724848cSchristos 113*4724848cSchristosCMS_get0_signers() returns all signers or NULL if an error occurred. 114*4724848cSchristos 115*4724848cSchristosThe error can be obtained from L<ERR_get_error(3)> 116*4724848cSchristos 117*4724848cSchristos=head1 BUGS 118*4724848cSchristos 119*4724848cSchristosThe trusted certificate store is not searched for the signing certificate. 120*4724848cSchristosThis is primarily due to the inadequacies of the current B<X509_STORE> 121*4724848cSchristosfunctionality. 122*4724848cSchristos 123*4724848cSchristosThe lack of single pass processing means that the signed content must all 124*4724848cSchristosbe held in memory if it is not detached. 125*4724848cSchristos 126*4724848cSchristos=head1 SEE ALSO 127*4724848cSchristos 128*4724848cSchristosL<PKCS7_verify(3)>, L<CMS_add1_cert(3)>, L<CMS_add1_crl(3)>, 129*4724848cSchristosL<OSSL_ESS_check_signing_certs(3)>, 130*4724848cSchristosL<ERR_get_error(3)>, L<CMS_sign(3)> 131*4724848cSchristos 132*4724848cSchristos=head1 COPYRIGHT 133*4724848cSchristos 134*4724848cSchristosCopyright 2008-2022 The OpenSSL Project Authors. All Rights Reserved. 135*4724848cSchristos 136*4724848cSchristosLicensed under the OpenSSL license (the "License"). You may not use 137*4724848cSchristosthis file except in compliance with the License. You can obtain a copy 138*4724848cSchristosin the file LICENSE in the source distribution or at 139*4724848cSchristosL<https://www.openssl.org/source/license.html>. 140*4724848cSchristos 141*4724848cSchristos=cut 142