The CertVerifyCTLUsage function verifies that a subject is trusted for a specified usage by finding a signed and time valid CTL with the usage identifiers that contains the subject. A subject can be identified by either its certificate context or any identifier such as its SHA1 hash.
#include <wincrypt.h>
BOOL WINAPI CertVerifyCTLUsage(
DWORD dwEncodingType, // in
DWORD dwSubjectType, // in
void* pvSubject, // in
PCTL_USAGE pSubjectUsage, // in
DWORD dwFlags, // in
PCTL_VERIFY_USAGE_PARA pVerifyUsagePara, // in, optional
PCTL_VERIFY_USAGE_STATUS pVerifyUsageStatus // in/out
);
Currently defined encoding types are shown in the following table:
Encoding type | Value |
---|---|
CRYPT_ASN_ENCODING | 0x00000001 |
X509_ASN_ENCODING | 0x00000001 |
PKCS_7_ASN_ENCODING | 0x00010000 |
If the CERT_VERIFY_TRUSTED_SIGNERS_FLAG is set, then, only the signer stores specified by rghSignerStore in CTL_VERIFY_USAGE_PARA are searched to find the signer. Otherwise, the signer stores provide additional sources to find the signer's certificate. See the Remarks for further details.
If CERT_VERIFY_NO_TIME_CHECK_FLAG is set, then, the CTLs aren't checked for time validity. Otherwise, they are.
If CERT_VERIFY_ALLOW_MORE_USAGE_FLAG is set, then, the CTL may contain additional usage identifiers than specified by pSubjectUsage. Otherwise, the found CTL will contain the same usage identifiers and no additional ones.
If the subject is trusted for the specified usage, then, TRUE is returned. Otherwise, FALSE is returned with dwError set to one of the following:
CRYPT_E_NO_VERIFY_USAGE_DLL
CRYPT_E_NO_VERIFY_USAGE_CHECK
CRYPT_E_VERIFY_USAGE_OFFLINE
CRYPT_E_NOT_IN_CTL
CRYPT_E_NO_TRUSTED_SIGNER
Call GetLastError to see the reason for any failures. This function has the following error codes.
Error code | Description |
---|---|
CRYPT_E_NO_VERIFY_ USAGE_DLL |
No Dll or exported function was found to verify subject usage. |
CRYPT_E_NO_VERIFY_ USAGE_CHECK |
The called function wasn't able to do a usage check on the subject. |
CRYPT_E_VERIFY_ USAGE_OFFLINE |
Since the server was offline, the called function wasn't able to complete the usage check. |
CRYPT_E_NOT_IN_CTL | The subject wasn't found in a Certificate Trust List (CTL). |
CRYPT_E_NO_TRUSTED_ SIGNER |
No trusted signer was found to verify the signature of the message or trust list. |
CertVerifyCTLUsage will be implemented as a dispatcher to OID installable functions. First, it will try to find an OID function matching the first usage object identifier in the pSubjectUsage sequence. Next, it will dispatch to the default CertDllVerifyCTLUsage functions.
Microsoft has implemented an OID installable CertDllVerifyCTLUsage function residing in the cryptnet.dll with the following properties:
// EXAMPLE CODE FOR USING CertVerifyCTLUsage().
// Verifies that a subject is trusted.
// Assume that the application has pointers to
// CERT_CONTEXT (pvSubject), PCTL_USAGE (pSubjectUsage),
// PCTL_VERIFY_USAGE_PARA (pVerifyUsagePara), and
// PCTL_VERIFY_USAGE_STATUS (pVerifyUsageStatus).
// Set up the variables.
DWORD dwEncodingType = X509_ASN_ENCODING;
// Type of encoding
DWORD dwSubjectType = CTL_CERT_SUBJECT_TYPE;
// CERT_CONTEXT or CTL_ANY_SUBJECT_INFO
CERT_CONTEXT* pvSubject; // Initialized elsewhere
PCTL_USAGE pSubjectUsage;// Initialized elsewhere
DWORD dwFlags = 0; // The flag values
PCTL_VERIFY_USAGE_PARA pVerifyUsagePara;
// Initialized elsewhere
PCTL_VERIFY_USAGE_STATUS pVerifyUsageStatus;
// Initialized elsewhere
BOOL fResult; // Return True if subject is trusted
// FALSE otherwise
fResult= CertVerifyCTLUsage(
dwEncodingType, // in - CRYPT_ASN_ENCODING
dwSubjectType, // in
pvSubject, // in
pSubjectUsage, // in - Specify the store to be
// searched
dwFlags, // in - Set to 0
pVerifyUsagePara, // in - optional
pVerifyUsageStatus);// in/out
if (!fResult) { // FALSE
cout<< "Subject is not trusted"<< endl
<< "dwError = "<< pVerifyUsageStatus->dwError<< endl
<< "error code = "<< GetLastError ()<< endl;
}
else { // TRUE
cout<< "Subject is trusted"<< endl;
}
Windows NT: Requires version 4.0 SP3 or later. Available also in IE 3.02 and later.
Windows: Requires Windows 98 (or Windows 95 with IE 3.02 or later).
Windows CE: Unsupported.
Header: Declared in wincrypt.h.
Import Library: Use crypt32.lib.
CTL_VERIFY_USAGE_PARA,
CTL_VERIFY_USAGE_STATUS,
CertFindSubjectInCTL,
CertFindCTLInStore