The CertFindSubjectInCTL function attempts to find the specified subject in the CTL. A subject can be identified by either its certificate context or any unique identifier such as its SHA1 hash.
#include <wincrypt.h>
PCTL_ENTRY WINAPI CertFindSubjectInCTL(
DWORD dwEncodingType, // in
DWORD dwSubjectType, // in
void *pvSubject, // in
PCCTL_CONTEXT pCtlContext, // in
DWORD dwFlags // in
);
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 |
For CTL_ANY_SUBJECT_TYPE, pvSubject points to the CTL_ANY_SUBJECT_INFO structure which contains the SubjectAlgorithm to be matched in the CTL and the SubjectIdentifer to be matched in one of the CTL entries.
The dwEncodingType isn't used for either of the above values for dwSubjectType.
Returns the entry, if it is found. If it is not found, it returns NULL.
Call GetLastError to see the reason for any failures. This function has the following error codes.
Error code | Description |
---|---|
CRYPT_E_NOT_FOUND | Subject not found in CTL. |
E-INVALIDARG | The dwSubjectType wasn't either CTL_CERT_SUBJECT_TYPE or CTL_ANY_SUBJECT_TYPE. |
NTE_BAD_ALGID | The CTL's SubjectAlgorithm member didn't map to either SHA1 or MD5. |
The certificate's hash or the CTL_ANY_SUBJECT_INFO's SubjectIdentifier is used as the key in searching the subject entries. A binary memory comparison is done between the key and the entry's SubjectIdentifer.
// EXAMPLE CODE FOR USING CertFindSubjectInCTL. Finds
// the subject in the CTL. The subject can be identified
// by its certificate context or unique identifier.
// Assume a pointer to the CERT_ANY_SUBJECT_INFO and a
// pointer to the CTL_CONTEXT is already known.
// Set up the variables.
DWORD dwEncodingType = X509_ASN_ENCODING; // Type of encoding
DWORD dwSubjectType = CTL_ANY_SUBJECT_TYPE; // Subject type
CTL_ANY_SUBJECT_INFO *pvSubject; // Initialized elsewhere
PCCTL_CONTEXT pCtlContext; // Initialized elsewhere
DWORD dwFlags = 0; // Flag value
PCTL_ENTRY pResult; // Pointer to the returned
// subject
pResult = CertFindSubjectInCTL(
dwEncodingType, // in - dwEncoding Type isn't used for
// for this dwSubjectType
dwSubjectType, // in - CTL_ANY_SUBJECT_TYPE
pvSubject, // in - points to CTL_ANY_SUBJECT_INFO
pCtlContext, // in - points to CTL_CONTEXT to be
// searched
dwFlags); // in - dwFlags set to 0
if (!pResult) { // NULL- no entry found
cout<< "no entry found "<< endl
<< "error code = "<< GetLastError ()<< endl;
}
else {
cout<< "entry is "<< &pResult<< endl;
}
Windows NT: Requires version 4.0 SP3 or later. Available also in IE 3.02 and later.
Windows: Requires Windows 95 OSR2 or later.
Windows CE: Unsupported.
Header: Declared in wincrypt.h.
Import Library: Use crypt32.lib.
CTL_CONTEXT, CertFindCTLInStore