wintrust: Test and implement pfnAddSgnr2Chain.

This commit is contained in:
Juan Lang 2007-08-28 16:07:30 -07:00 committed by Alexandre Julliard
parent 150ddd6bd4
commit 8c34271aaa
4 changed files with 93 additions and 1 deletions

View File

@ -837,7 +837,7 @@ BOOL WINAPI WintrustLoadFunctionPointers( GUID* pgActionID,
pPfns->pfnAlloc = WINTRUST_Alloc; pPfns->pfnAlloc = WINTRUST_Alloc;
pPfns->pfnFree = WINTRUST_Free; pPfns->pfnFree = WINTRUST_Free;
pPfns->pfnAddStore2Chain = WINTRUST_AddStore; pPfns->pfnAddStore2Chain = WINTRUST_AddStore;
pPfns->pfnAddSgnr2Chain = NULL; pPfns->pfnAddSgnr2Chain = WINTRUST_AddSgnr;
pPfns->pfnAddCert2Chain = NULL; pPfns->pfnAddCert2Chain = NULL;
pPfns->pfnAddPrivData2Chain = NULL; pPfns->pfnAddPrivData2Chain = NULL;
pPfns->psUIpfns = NULL; pPfns->psUIpfns = NULL;

View File

@ -91,6 +91,7 @@ static void test_utils(SAFE_PROVIDER_FUNCTIONS *funcs)
{ {
CRYPT_PROVIDER_DATA data = { 0 }; CRYPT_PROVIDER_DATA data = { 0 };
HCERTSTORE store; HCERTSTORE store;
CRYPT_PROVIDER_SGNR sgnr = { 0 };
BOOL ret; BOOL ret;
/* Crash /* Crash
@ -118,6 +119,44 @@ static void test_utils(SAFE_PROVIDER_FUNCTIONS *funcs)
} }
else else
skip("CertOpenStore failed: %08x\n", GetLastError()); skip("CertOpenStore failed: %08x\n", GetLastError());
/* Crash
ret = funcs->pfnAddSgnr2Chain(NULL, FALSE, 0, NULL);
ret = funcs->pfnAddSgnr2Chain(&data, FALSE, 0, NULL);
*/
ret = funcs->pfnAddSgnr2Chain(&data, FALSE, 0, &sgnr);
ok(ret, "pfnAddSgnr2Chain failed: %08x\n", GetLastError());
ok(data.csSigners == 1, "Expected 1 signer, got %d\n", data.csSigners);
ok(data.pasSigners != NULL, "Expected pasSigners to be allocated\n");
if (data.pasSigners)
{
ok(!memcmp(&data.pasSigners[0], &sgnr, sizeof(sgnr)),
"Unexpected data in signer\n");
/* Adds into the location specified by the index */
sgnr.cbStruct = sizeof(CRYPT_PROVIDER_SGNR);
sgnr.sftVerifyAsOf.dwLowDateTime = 0xdeadbeef;
ret = funcs->pfnAddSgnr2Chain(&data, FALSE, 1, &sgnr);
ok(ret, "pfnAddSgnr2Chain failed: %08x\n", GetLastError());
ok(data.csSigners == 2, "Expected 2 signers, got %d\n", data.csSigners);
ok(!memcmp(&data.pasSigners[1], &sgnr, sizeof(sgnr)),
"Unexpected data in signer\n");
/* This also adds, but the data aren't copied */
sgnr.cbStruct = sizeof(DWORD);
ret = funcs->pfnAddSgnr2Chain(&data, FALSE, 0, &sgnr);
ok(ret, "pfnAddSgnr2Chain failed: %08x\n", GetLastError());
ok(data.csSigners == 3, "Expected 3 signers, got %d\n", data.csSigners);
ok(data.pasSigners[0].cbStruct == 0, "Unexpected data size %d\n",
data.pasSigners[0].cbStruct);
ok(data.pasSigners[0].sftVerifyAsOf.dwLowDateTime == 0,
"Unexpected verify time %d\n",
data.pasSigners[0].sftVerifyAsOf.dwLowDateTime);
/* But too large a thing isn't added */
sgnr.cbStruct = sizeof(sgnr) + sizeof(DWORD);
SetLastError(0xdeadbeef);
ret = funcs->pfnAddSgnr2Chain(&data, FALSE, 0, &sgnr);
ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
"Expected ERROR_INVALID_PARAMETER, got %d\n", GetLastError());
}
} }
static void testInitialize(SAFE_PROVIDER_FUNCTIONS *funcs, GUID *actionID) static void testInitialize(SAFE_PROVIDER_FUNCTIONS *funcs, GUID *actionID)

View File

@ -252,3 +252,54 @@ BOOL WINAPI WINTRUST_AddStore(CRYPT_PROVIDER_DATA *data, HCERTSTORE store)
SetLastError(ERROR_OUTOFMEMORY); SetLastError(ERROR_OUTOFMEMORY);
return ret; return ret;
} }
BOOL WINAPI WINTRUST_AddSgnr(CRYPT_PROVIDER_DATA *data,
BOOL fCounterSigner, DWORD idxSigner, CRYPT_PROVIDER_SGNR *sgnr)
{
BOOL ret = FALSE;
if (sgnr->cbStruct > sizeof(CRYPT_PROVIDER_SGNR))
{
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
if (fCounterSigner)
{
FIXME("unimplemented for counter signers\n");
SetLastError(ERROR_INVALID_PARAMETER);
return FALSE;
}
if (data->csSigners)
data->pasSigners = WINTRUST_ReAlloc(data->pasSigners,
(data->csSigners + 1) * sizeof(CRYPT_PROVIDER_SGNR));
else
{
data->pasSigners = WINTRUST_Alloc(sizeof(CRYPT_PROVIDER_SGNR));
data->csSigners = 0;
}
if (data->pasSigners)
{
if (idxSigner < data->csSigners)
memmove(&data->pasSigners[idxSigner],
&data->pasSigners[idxSigner + 1],
(data->csSigners - idxSigner) * sizeof(CRYPT_PROVIDER_SGNR));
ret = TRUE;
if (sgnr->cbStruct == sizeof(CRYPT_PROVIDER_SGNR))
{
/* The PSDK says psSigner should be allocated using pfnAlloc, but
* it doesn't say anything about ownership. Since callers are
* internal, assume ownership is passed, and just store the
* pointer.
*/
memcpy(&data->pasSigners[idxSigner], sgnr,
sizeof(CRYPT_PROVIDER_SGNR));
}
else
memset(&data->pasSigners[idxSigner], 0,
sizeof(CRYPT_PROVIDER_SGNR));
data->csSigners++;
}
else
SetLastError(ERROR_OUTOFMEMORY);
return ret;
}

View File

@ -22,5 +22,7 @@ void * WINAPI WINTRUST_Alloc(DWORD cb);
void * WINAPI WINTRUST_ReAlloc(void *ptr, DWORD cb); void * WINAPI WINTRUST_ReAlloc(void *ptr, DWORD cb);
void WINAPI WINTRUST_Free(void *p); void WINAPI WINTRUST_Free(void *p);
BOOL WINAPI WINTRUST_AddStore(CRYPT_PROVIDER_DATA *data, HCERTSTORE store); 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);
#endif /* ndef __WINTRUST_PRIV_H__ */ #endif /* ndef __WINTRUST_PRIV_H__ */