wintrust(5/10): Test and implement pfnAddStore2Chain

Juan Lang juan.lang at gmail.com
Mon Aug 27 18:35:24 CDT 2007


--Juan
-------------- next part --------------
From e6ced3c914795b1385406a05d621aec1522ac42f Mon Sep 17 00:00:00 2001
From: Juan Lang <juanlang at juan.corp.google.com>
Date: Mon, 27 Aug 2007 16:22:52 -0700
Subject: [PATCH] Test and implement pfnAddStore2Chain
---
 dlls/wintrust/register.c      |    2 +
 dlls/wintrust/tests/softpub.c |   60 ++++++++++++++++++++++++++++++++---------
 dlls/wintrust/wintrust_main.c |   21 ++++++++++++++
 dlls/wintrust/wintrust_priv.h |    1 +
 4 files changed, 70 insertions(+), 14 deletions(-)

diff --git a/dlls/wintrust/register.c b/dlls/wintrust/register.c
index 1f0054b..0a02ed2 100644
--- a/dlls/wintrust/register.c
+++ b/dlls/wintrust/register.c
@@ -836,7 +836,7 @@ BOOL WINAPI WintrustLoadFunctionPointers
     /* 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 a6e2025..7b95199 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
     }
 }
 
-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 6b855a6..6ecfb1d 100644
--- a/dlls/wintrust/wintrust_main.c
+++ b/dlls/wintrust/wintrust_main.c
@@ -231,3 +231,24 @@ 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 dc6a873..40f2e5d 100644
--- a/dlls/wintrust/wintrust_priv.h
+++ b/dlls/wintrust/wintrust_priv.h
@@ -21,5 +21,6 @@ #define __WINTRUST_PRIV_H__
 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__ */
-- 
1.4.1


More information about the wine-patches mailing list