CertGetIssuerCertificateFromStore function (wincrypt.h)
The CertGetIssuerCertificateFromStore function retrieves the certificate context from the certificate store for the first or next issuer of the specified subject certificate. The new Certificate Chain Verification Functions are recommended instead of the use of this function.
PCCERT_CONTEXT CertGetIssuerCertificateFromStore( [in] HCERTSTORE hCertStore, [in] PCCERT_CONTEXT pSubjectContext, [in, optional] PCCERT_CONTEXT pPrevIssuerContext, [in, out] DWORD *pdwFlags );
Handle of a certificate store.
A pointer to a CERT_CONTEXT structure that contains the subject information. This parameter can be obtained from any certificate store or can be created by the calling application using the CertCreateCertificateContext function.
[in, optional] pPrevIssuerContext
A pointer to a CERT_CONTEXT structure that contains the issuer information. An issuer can have multiple certificates, especially when a validity period is about to change. This parameter must be NULL on the call to get the first issuer certificate. To get the next certificate for the issuer, set pPrevIssuerContext to the CERT_CONTEXT structure returned by the previous call.
This function frees the CERT_CONTEXT referenced by non-NULL values of this parameter.
[in, out] pdwFlags
The following flags enable verification checks on the returned certificate. They can be combined using a bitwise-OR operation to enable multiple verifications.
If a verification check of an enabled type succeeds, its flag is set to zero. If it fails, its flag remains set upon return. For CERT_STORE_REVOCATION_FLAG, the verification succeeds if the function does not find a CRL related to the subject certificate.
If CERT_STORE_REVOCATION_FLAG is set and the issuer does not have a CRL in the store, CERT_STORE_NO_CRL_FLAG is set and CERT_STORE_REVOCATION_FLAG remains set.
If CERT_STORE_SIGNATURE_FLAG or CERT_STORE_REVOCATION_FLAG is set, CERT_STORE_NO_ISSUER_FLAG is set if the function does not find an issuer certificate in the store. For more details, see Remarks.
In the case of a verification check failure, a pointer to the issuer's CERT_CONTEXT is still returned and GetLastError is not updated.
If the function succeeds, the return value is a pointer to a read-only issuer CERT_CONTEXT.
If the function fails and the first or next issuer certificate is not found, the return value is NULL.
Only the last returned CERT_CONTEXT structure must be freed by calling CertFreeCertificateContext. When the returned CERT_CONTEXT from one call to the function is supplied as the pPrevIssuerContext parameter on a subsequent call, the context is freed as part of the action of the function.
For extended error information, call GetLastError. Some possible error codes follow.
||No issuer was found for the subject certificate.|
||The issuer certificate is the same as the subject certificate. It is a self-signed root certificate.|
||The handle in the hCertStore parameter is not the same as that of the certificate context pointed to by the pPrevIssuerContext parameter, or an unsupported flag was set in pdwFlags.|
The returned pointer is freed when passed as the pPrevIssuerContext parameter on a subsequent call to the function. Otherwise, the pointer must be explicitly freed by calling CertFreeCertificateContext. A pPrevIssuerContext that is not NULL is always freed by CertGetIssuerCertificateFromStore using a call to CertFreeCertificateContext, even if there is an error in the function.
CertDuplicateCertificateContext can be called to make a duplicate of the issuer certificate.
The hexadecimal values for dwFlags can be combined using a bitwise-OR operation to enable multiple verifications. For example, to enable both signature and time validity, the value 0x00000003 is passed in dwFlags on input. In this case, if CERT_STORE_SIGNATURE_FLAG verification succeeds but CERT_STORE_TIME_VALIDITY_FLAG verification fails, dwFlags returns as 0x00000002 on output.
|Minimum supported client||Windows XP [desktop apps | UWP apps]|
|Minimum supported server||Windows Server 2003 [desktop apps | UWP apps]|