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