PCCTL_CONTEXT WINAPI CertFindCTLInStore(HCERTSTORE hCertStore, DWORD dwCertEncodingType, DWORD dwFindFlags, DWORD dwFindType, const void *pvFindPara, PCCTL_CONTEXT pPrevCtlContext) { PCCTL_CONTEXT ret; CtlCompareFunc compare; TRACE("(%p, %d, %d, %d, %p, %p)\n", hCertStore, dwCertEncodingType, dwFindFlags, dwFindType, pvFindPara, pPrevCtlContext); switch (dwFindType) { case CTL_FIND_ANY: compare = compare_ctl_any; break; case CTL_FIND_SHA1_HASH: compare = compare_ctl_by_sha1_hash; break; case CTL_FIND_MD5_HASH: compare = compare_ctl_by_md5_hash; break; case CTL_FIND_EXISTING: compare = compare_ctl_existing; break; default: FIXME("find type %08x unimplemented\n", dwFindType); compare = NULL; } if (compare) { BOOL matches = FALSE; ret = pPrevCtlContext; do { ret = CertEnumCTLsInStore(hCertStore, ret); if (ret) matches = compare(ret, dwFindType, dwFindFlags, pvFindPara); } while (ret != NULL && !matches); if (!ret) SetLastError(CRYPT_E_NOT_FOUND); } else { SetLastError(CRYPT_E_NOT_FOUND); ret = NULL; } return ret; }
static void testAddCTLToStore(void) { HCERTSTORE store; BOOL ret; DWORD numCTLs, expectedCTLs; PCCTL_CONTEXT ctl; store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0, CERT_STORE_CREATE_NEW_FLAG, NULL); /* Add two CTLs */ ret = CertAddEncodedCTLToStore(store, X509_ASN_ENCODING, signedCTLWithCTLInnerContent, sizeof(signedCTLWithCTLInnerContent), CERT_STORE_ADD_ALWAYS, NULL); ok(ret, "CertAddEncodedCTLToStore failed: %08x\n", GetLastError()); ret = CertAddEncodedCTLToStore(store, X509_ASN_ENCODING, signedCTLWithCTLInnerContentAndBadSig, sizeof(signedCTLWithCTLInnerContentAndBadSig), CERT_STORE_ADD_ALWAYS, NULL); ok(ret, "CertAddEncodedCTLToStore failed: %08x\n", GetLastError()); /* Check that two exist */ numCTLs = 0; ctl = NULL; do { ctl = CertEnumCTLsInStore(store, ctl); if (ctl) numCTLs++; } while (ctl); ok(numCTLs == 2, "expected 2 CTLs, got %d\n", numCTLs); CertCloseStore(store, 0); store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0, CERT_STORE_CREATE_NEW_FLAG, NULL); /* Add the two CTLs again. They're identical except for the signature.. */ ret = CertAddEncodedCTLToStore(store, X509_ASN_ENCODING, signedCTLWithCTLInnerContent, sizeof(signedCTLWithCTLInnerContent), CERT_STORE_ADD_NEW, NULL); ok(ret, "CertAddEncodedCTLToStore failed: %08x\n", GetLastError()); /* so adding the second CTL fails. */ SetLastError(0xdeadbeef); ret = CertAddEncodedCTLToStore(store, X509_ASN_ENCODING, signedCTLWithCTLInnerContentAndBadSig, sizeof(signedCTLWithCTLInnerContentAndBadSig), CERT_STORE_ADD_NEW, NULL); if (ret) { /* win9x */ ok(GetLastError() == CRYPT_E_NOT_FOUND || GetLastError() == OSS_DATA_ERROR /* some win98 */, "Expected CRYPT_E_NOT_FOUND, got %08x\n", GetLastError()); } else { ok(!ret && (GetLastError() == CRYPT_E_EXISTS || GetLastError() == OSS_DATA_ERROR), "expected CRYPT_E_EXISTS or OSS_DATA_ERROR, got %d %08x\n", ret, GetLastError()); } CertCloseStore(store, 0); store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0, CERT_STORE_CREATE_NEW_FLAG, NULL); /* Add two CTLs. These two have different usages, so they're considered * different. */ ret = CertAddEncodedCTLToStore(store, X509_ASN_ENCODING, signedCTLWithCTLInnerContent, sizeof(signedCTLWithCTLInnerContent), CERT_STORE_ADD_NEW, NULL); ok(ret, "CertAddEncodedCTLToStore failed: %08x\n", GetLastError()); expectedCTLs = 1; ret = CertAddEncodedCTLToStore(store, X509_ASN_ENCODING, signedCTLWithUsage, sizeof(signedCTLWithUsage), CERT_STORE_ADD_NEW, NULL); ok(ret || broken(GetLastError() == OSS_DATA_ERROR /* some win98 */), "CertAddEncodedCTLToStore failed: %08x\n", GetLastError()); if (ret) expectedCTLs++; /* Check that two exist */ numCTLs = 0; ctl = NULL; do { ctl = CertEnumCTLsInStore(store, ctl); if (ctl) numCTLs++; } while (ctl); ok(numCTLs == expectedCTLs, "expected %d CTLs, got %d\n", expectedCTLs, numCTLs); CertCloseStore(store, 0); store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0, CERT_STORE_CREATE_NEW_FLAG, NULL); /* Add two CTLs. Now they have the same (empty) usages and different list * IDs, so they're different. */ ret = CertAddEncodedCTLToStore(store, X509_ASN_ENCODING, signedCTLWithListID1, sizeof(signedCTLWithListID1), CERT_STORE_ADD_NEW, NULL); if (!ret) { skip("adding a CTL with an empty usage not supported\n"); return; } ok(ret, "CertAddEncodedCTLToStore failed: %08x\n", GetLastError()); ret = CertAddEncodedCTLToStore(store, X509_ASN_ENCODING, signedCTLWithListID2, sizeof(signedCTLWithListID2), CERT_STORE_ADD_NEW, NULL); ok(ret, "CertAddEncodedCTLToStore failed: %08x\n", GetLastError()); /* Check that two exist */ numCTLs = 0; ctl = NULL; do { ctl = CertEnumCTLsInStore(store, ctl); if (ctl) numCTLs++; } while (ctl); ok(numCTLs == 2, "expected 2 CTLs, got %d\n", numCTLs); CertCloseStore(store, 0); }