From 0cc08cccb92cf974cd50074bed2f652ad7dcce23 Mon Sep 17 00:00:00 2001 From: Juan Lang Date: Thu, 2 Aug 2007 12:30:19 -0700 Subject: [PATCH] crypt32: Support finding certificates by cert id. --- dlls/crypt32/cert.c | 54 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/dlls/crypt32/cert.c b/dlls/crypt32/cert.c index f3d5809098e..c208873f7c7 100644 --- a/dlls/crypt32/cert.c +++ b/dlls/crypt32/cert.c @@ -911,8 +911,55 @@ static BOOL compare_cert_by_subject_cert(PCCERT_CONTEXT pCertContext, &pCertInfo->Issuer, &pCertContext->pCertInfo->Subject); } -static BOOL compare_cert_by_issuer(PCCERT_CONTEXT pCertContext, - DWORD dwType, DWORD dwFlags, const void *pvPara) +static BOOL compare_cert_by_cert_id(PCCERT_CONTEXT pCertContext, DWORD dwType, + DWORD dwFlags, const void *pvPara) +{ + CERT_ID *id = (CERT_ID *)pvPara; + BOOL ret; + + switch (id->dwIdChoice) + { + case CERT_ID_ISSUER_SERIAL_NUMBER: + ret = CertCompareCertificateName(pCertContext->dwCertEncodingType, + &pCertContext->pCertInfo->Issuer, &id->u.IssuerSerialNumber.Issuer); + if (ret) + ret = CertCompareIntegerBlob(&pCertContext->pCertInfo->SerialNumber, + &id->u.IssuerSerialNumber.SerialNumber); + break; + case CERT_ID_SHA1_HASH: + ret = compare_cert_by_sha1_hash(pCertContext, dwType, dwFlags, + &id->u.HashId); + break; + case CERT_ID_KEY_IDENTIFIER: + { + DWORD size = 0; + + ret = CertGetCertificateContextProperty(pCertContext, + CERT_KEY_IDENTIFIER_PROP_ID, NULL, &size); + if (ret && size == id->u.KeyId.cbData) + { + LPBYTE buf = CryptMemAlloc(size); + + if (buf) + { + CertGetCertificateContextProperty(pCertContext, + CERT_KEY_IDENTIFIER_PROP_ID, buf, &size); + ret = !memcmp(buf, id->u.KeyId.pbData, size); + CryptMemFree(buf); + } + } + else + ret = FALSE; + } + default: + ret = FALSE; + break; + } + return ret; +} + +static BOOL compare_cert_by_issuer(PCCERT_CONTEXT pCertContext, DWORD dwType, + DWORD dwFlags, const void *pvPara) { return compare_cert_by_subject_cert(pCertContext, dwType, dwFlags, ((PCCERT_CONTEXT)pvPara)->pCertInfo); @@ -945,6 +992,9 @@ PCCERT_CONTEXT WINAPI CertFindCertificateInStore(HCERTSTORE hCertStore, case CERT_COMPARE_SUBJECT_CERT: compare = compare_cert_by_subject_cert; break; + case CERT_COMPARE_CERT_ID: + compare = compare_cert_by_cert_id; + break; case CERT_COMPARE_ISSUER_OF: compare = compare_cert_by_issuer; break;