diff --git a/dlls/wintrust/register.c b/dlls/wintrust/register.c index 1f0054b4b6b..0a02ed209da 100644 --- a/dlls/wintrust/register.c +++ b/dlls/wintrust/register.c @@ -836,7 +836,7 @@ BOOL WINAPI WintrustLoadFunctionPointers( GUID* pgActionID, /* Get the function pointers from the registry, where applicable */ pPfns->pfnAlloc = WINTRUST_Alloc; pPfns->pfnFree = WINTRUST_Free; - pPfns->pfnAddStore2Chain = NULL; + pPfns->pfnAddStore2Chain = WINTRUST_AddStore; pPfns->pfnAddSgnr2Chain = NULL; pPfns->pfnAddCert2Chain = NULL; pPfns->pfnAddPrivData2Chain = NULL; diff --git a/dlls/wintrust/tests/softpub.c b/dlls/wintrust/tests/softpub.c index 5df430b6e51..1eb967a72e4 100644 --- a/dlls/wintrust/tests/softpub.c +++ b/dlls/wintrust/tests/softpub.c @@ -74,6 +74,52 @@ typedef struct _SAFE_PROVIDER_FUNCTIONS SAFE_PROVIDER_CLEANUP_CALL pfnCleanupPolicy; } SAFE_PROVIDER_FUNCTIONS; +static const BYTE v1CertWithPubKey[] = { +0x30,0x81,0x95,0x02,0x01,0x01,0x30,0x02,0x06,0x00,0x30,0x15,0x31,0x13,0x30, +0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61, +0x6e,0x67,0x00,0x30,0x22,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31, +0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31, +0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x15,0x31,0x13,0x30,0x11, +0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e, +0x67,0x00,0x30,0x22,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01, +0x01,0x01,0x05,0x00,0x03,0x11,0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, +0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0xa3,0x16,0x30,0x14,0x30,0x12,0x06, +0x03,0x55,0x1d,0x13,0x01,0x01,0xff,0x04,0x08,0x30,0x06,0x01,0x01,0xff,0x02, +0x01,0x01 }; + +static void test_utils(SAFE_PROVIDER_FUNCTIONS *funcs) +{ + CRYPT_PROVIDER_DATA data = { 0 }; + HCERTSTORE store; + BOOL ret; + + /* Crash + ret = funcs->pfnAddStore2Chain(NULL, NULL); + ret = funcs->pfnAddStore2Chain(&data, NULL); + */ + store = CertOpenStore(CERT_STORE_PROV_MEMORY, X509_ASN_ENCODING, 0, + CERT_STORE_CREATE_NEW_FLAG, NULL); + if (store) + { + ret = funcs->pfnAddStore2Chain(&data, store); + ok(ret, "pfnAddStore2Chain failed: %08x\n", GetLastError()); + ok(data.chStores == 1, "Expected 1 store, got %d\n", data.chStores); + ok(data.pahStores != NULL, "Expected pahStores to be allocated\n"); + if (data.pahStores) + { + ok(data.pahStores[0] == store, "Unexpected store\n"); + CertCloseStore(data.pahStores[0], 0); + funcs->pfnFree(data.pahStores); + data.pahStores = NULL; + data.chStores = 0; + CertCloseStore(store, 0); + store = NULL; + } + } + else + skip("CertOpenStore failed: %08x\n", GetLastError()); +} + static void testInitialize(SAFE_PROVIDER_FUNCTIONS *funcs, GUID *actionID) { HRESULT ret; @@ -115,19 +161,6 @@ static void testInitialize(SAFE_PROVIDER_FUNCTIONS *funcs, GUID *actionID) } } -static const BYTE v1CertWithPubKey[] = { -0x30,0x81,0x95,0x02,0x01,0x01,0x30,0x02,0x06,0x00,0x30,0x15,0x31,0x13,0x30, -0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61, -0x6e,0x67,0x00,0x30,0x22,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31, -0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31, -0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x15,0x31,0x13,0x30,0x11, -0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e, -0x67,0x00,0x30,0x22,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01, -0x01,0x01,0x05,0x00,0x03,0x11,0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07, -0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0xa3,0x16,0x30,0x14,0x30,0x12,0x06, -0x03,0x55,0x1d,0x13,0x01,0x01,0xff,0x04,0x08,0x30,0x06,0x01,0x01,0xff,0x02, -0x01,0x01 }; - static void testObjTrust(SAFE_PROVIDER_FUNCTIONS *funcs, GUID *actionID) { HRESULT ret; @@ -216,6 +249,7 @@ START_TEST(softpub) skip("WintrustLoadFunctionPointers failed\n"); else { + test_utils(&funcs); testInitialize(&funcs, &generic_verify_v2); testObjTrust(&funcs, &generic_verify_v2); } diff --git a/dlls/wintrust/wintrust_main.c b/dlls/wintrust/wintrust_main.c index 4b0c8ffdb6f..6ecfb1daa2d 100644 --- a/dlls/wintrust/wintrust_main.c +++ b/dlls/wintrust/wintrust_main.c @@ -230,3 +230,25 @@ void WINAPI WINTRUST_Free(void *p) { HeapFree(GetProcessHeap(), 0, p); } + +BOOL WINAPI WINTRUST_AddStore(CRYPT_PROVIDER_DATA *data, HCERTSTORE store) +{ + BOOL ret = FALSE; + + if (data->chStores) + data->pahStores = WINTRUST_ReAlloc(data->pahStores, + (data->chStores + 1) * sizeof(HCERTSTORE)); + else + { + data->pahStores = WINTRUST_Alloc(sizeof(HCERTSTORE)); + data->chStores = 0; + } + if (data->pahStores) + { + data->pahStores[data->chStores++] = CertDuplicateStore(store); + ret = TRUE; + } + else + SetLastError(ERROR_OUTOFMEMORY); + return ret; +} diff --git a/dlls/wintrust/wintrust_priv.h b/dlls/wintrust/wintrust_priv.h index dc6a8734048..40f2e5d9d1a 100644 --- a/dlls/wintrust/wintrust_priv.h +++ b/dlls/wintrust/wintrust_priv.h @@ -21,5 +21,6 @@ void * WINAPI WINTRUST_Alloc(DWORD cb); void * WINAPI WINTRUST_ReAlloc(void *ptr, DWORD cb); void WINAPI WINTRUST_Free(void *p); +BOOL WINAPI WINTRUST_AddStore(CRYPT_PROVIDER_DATA *data, HCERTSTORE store); #endif /* ndef __WINTRUST_PRIV_H__ */