crypt32: Test and correct finding a subject certificate.

oldstable
Juan Lang 2007-08-07 13:15:00 -07:00 committed by Alexandre Julliard
parent d89528b016
commit bcbf5dcee3
2 changed files with 29 additions and 1 deletions

View File

@ -906,9 +906,15 @@ static BOOL compare_cert_by_subject_cert(PCCERT_CONTEXT pCertContext,
DWORD dwType, DWORD dwFlags, const void *pvPara)
{
CERT_INFO *pCertInfo = (CERT_INFO *)pvPara;
BOOL ret;
return CertCompareCertificateName(pCertContext->dwCertEncodingType,
ret = CertCompareCertificateName(pCertContext->dwCertEncodingType,
&pCertInfo->Issuer, &pCertContext->pCertInfo->Subject);
if (ret && pCertInfo->SerialNumber.cbData)
ret = CertCompareIntegerBlob(&pCertContext->pCertInfo->SerialNumber,
&pCertInfo->SerialNumber);
TRACE("returning %d\n", ret);
return ret;
}
static BOOL compare_cert_by_cert_id(PCCERT_CONTEXT pCertContext, DWORD dwType,

View File

@ -604,6 +604,7 @@ static void testFindCert(void)
BOOL ret;
CERT_INFO certInfo = { 0 };
CRYPT_HASH_BLOB blob;
BYTE otherSerialNumber[] = { 2 };
store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
CERT_STORE_CREATE_NEW_FLAG, NULL);
@ -685,6 +686,27 @@ static void testFindCert(void)
CERT_FIND_SUBJECT_CERT, &certInfo.Subject, context);
ok(context == NULL, "Expected one cert only\n");
}
/* The above search matched even though no serial number is set. A
* non-matching serial number will not match.
*/
certInfo.SerialNumber.pbData = otherSerialNumber;
certInfo.SerialNumber.cbData = sizeof(otherSerialNumber);
context = CertFindCertificateInStore(store, X509_ASN_ENCODING, 0,
CERT_FIND_SUBJECT_CERT, &certInfo, NULL);
ok(context == NULL, "Expected no match\n");
/* A matching serial number will match. */
certInfo.SerialNumber.pbData = serialNum;
certInfo.SerialNumber.cbData = sizeof(serialNum);
context = CertFindCertificateInStore(store, X509_ASN_ENCODING, 0,
CERT_FIND_SUBJECT_CERT, &certInfo, NULL);
ok(context != NULL, "CertFindCertificateInStore failed: %08x\n",
GetLastError());
if (context)
{
context = CertFindCertificateInStore(store, X509_ASN_ENCODING, 0,
CERT_FIND_SUBJECT_CERT, &certInfo.Subject, context);
ok(context == NULL, "Expected one cert only\n");
}
/* The nice thing about hashes, they're unique */
blob.pbData = bigCertHash;