Commit 4f2fae1d authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

wintrust: Test and implement pfnAddCert2Chain.

parent 8c34271a
......@@ -838,7 +838,7 @@ BOOL WINAPI WintrustLoadFunctionPointers( GUID* pgActionID,
pPfns->pfnFree = WINTRUST_Free;
pPfns->pfnAddStore2Chain = WINTRUST_AddStore;
pPfns->pfnAddSgnr2Chain = WINTRUST_AddSgnr;
pPfns->pfnAddCert2Chain = NULL;
pPfns->pfnAddCert2Chain = WINTRUST_AddCert;
pPfns->pfnAddPrivData2Chain = NULL;
pPfns->psUIpfns = NULL;
pPfns->pfnInitialize = (PFN_PROVIDER_INIT_CALL)WINTRUST_ReadProviderFromReg(GuidString, Initialization);
......
......@@ -130,6 +130,8 @@ static void test_utils(SAFE_PROVIDER_FUNCTIONS *funcs)
ok(data.pasSigners != NULL, "Expected pasSigners to be allocated\n");
if (data.pasSigners)
{
PCCERT_CONTEXT cert;
ok(!memcmp(&data.pasSigners[0], &sgnr, sizeof(sgnr)),
"Unexpected data in signer\n");
/* Adds into the location specified by the index */
......@@ -156,6 +158,32 @@ static void test_utils(SAFE_PROVIDER_FUNCTIONS *funcs)
ret = funcs->pfnAddSgnr2Chain(&data, FALSE, 0, &sgnr);
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
/* Crash
ret = funcs->pfnAddCert2Chain(NULL, 0, FALSE, 0, NULL);
ret = funcs->pfnAddCert2Chain(&data, 0, FALSE, 0, NULL);
*/
cert = CertCreateCertificateContext(X509_ASN_ENCODING, v1CertWithPubKey,
sizeof(v1CertWithPubKey));
if (cert)
{
/* Notes on behavior that are hard to test:
* 1. If pasSigners is invalid, pfnAddCert2Chain crashes
* 2. An invalid signer index isn't checked.
*/
ret = funcs->pfnAddCert2Chain(&data, 0, FALSE, 0, cert);
ok(ret, "pfnAddCert2Chain failed: %08x\n", GetLastError());
ok(data.pasSigners[0].csCertChain == 1, "Expected 1 cert, got %d\n",
data.pasSigners[0].csCertChain);
ok(data.pasSigners[0].pasCertChain != NULL,
"Expected pasCertChain to be allocated\n");
if (data.pasSigners[0].pasCertChain)
ok(data.pasSigners[0].pasCertChain[0].pCert == cert,
"Unexpected cert\n");
CertFreeCertificateContext(cert);
}
else
skip("CertCreateCertificateContext failed: %08x\n", GetLastError());
}
}
......
......@@ -303,3 +303,40 @@ BOOL WINAPI WINTRUST_AddSgnr(CRYPT_PROVIDER_DATA *data,
SetLastError(ERROR_OUTOFMEMORY);
return ret;
}
BOOL WINAPI WINTRUST_AddCert(CRYPT_PROVIDER_DATA *data, DWORD idxSigner,
BOOL fCounterSigner, DWORD idxCounterSigner, PCCERT_CONTEXT pCert2Add)
{
BOOL ret = FALSE;
if (fCounterSigner)
{
FIXME("unimplemented for counter signers\n");
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
if (data->pasSigners[idxSigner].csCertChain)
data->pasSigners[idxSigner].pasCertChain =
WINTRUST_ReAlloc(data->pasSigners[idxSigner].pasCertChain,
(data->pasSigners[idxSigner].csCertChain + 1) *
sizeof(CRYPT_PROVIDER_CERT));
else
{
data->pasSigners[idxSigner].pasCertChain =
WINTRUST_Alloc(sizeof(CRYPT_PROVIDER_CERT));
data->pasSigners[idxSigner].csCertChain = 0;
}
if (data->pasSigners[idxSigner].pasCertChain)
{
CRYPT_PROVIDER_CERT *cert = &data->pasSigners[idxSigner].pasCertChain[
data->pasSigners[idxSigner].csCertChain];
cert->cbStruct = sizeof(CRYPT_PROVIDER_CERT);
cert->pCert = CertDuplicateCertificateContext(pCert2Add);
data->pasSigners[idxSigner].csCertChain++;
ret = TRUE;
}
else
SetLastError(ERROR_OUTOFMEMORY);
return ret;
}
......@@ -24,5 +24,7 @@ void WINAPI WINTRUST_Free(void *p);
BOOL WINAPI WINTRUST_AddStore(CRYPT_PROVIDER_DATA *data, HCERTSTORE store);
BOOL WINAPI WINTRUST_AddSgnr(CRYPT_PROVIDER_DATA *data,
BOOL fCounterSigner, DWORD idxSigner, CRYPT_PROVIDER_SGNR *sgnr);
BOOL WINAPI WINTRUST_AddCert(CRYPT_PROVIDER_DATA *data, DWORD idxSigner,
BOOL fCounterSigner, DWORD idxCounterSigner, PCCERT_CONTEXT pCert2Add);
#endif /* ndef __WINTRUST_PRIV_H__ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment