crypt32: fix CertAddCertificateContextToStore when called with CERT_STORE_ADD_USE_EXISTING

Mounir IDRASSI mounir.idrassi at idrix.fr
Sun May 20 19:25:48 CDT 2007


Hi,
This patch corrects CertAddCertificateContextToStore when
dwAddDisposition is set to CERT_STORE_ADD_USE_EXISTING: it was not
setting ppStoreContext properly and when the certificate already exists
it didn't add a new one.
A test is added to verify this behavior.

Mounir IDRASSI
IDRIX - Cryptography and IT Security Experts
http://www.idrix.fr

-------------- next part --------------
>From d4f88c4438f2279a2061d3ac8e12836663032dba Mon Sep 17 00:00:00 2001
From: Mounir IDRASSI <mounir.idrassi at idrix.fr>
Date: Mon, 21 May 2007 02:08:24 +0200
Subject: crypt32: fix CertAddCertificateContextToStore when called with CERT_STORE_ADD_USE_EXISTING

---
 dlls/crypt32/store.c      |    5 +++++
 dlls/crypt32/tests/cert.c |   10 ++++++++++
 2 files changed, 15 insertions(+), 0 deletions(-)

diff --git a/dlls/crypt32/store.c b/dlls/crypt32/store.c
index a38d06c..77dfbaa 100644
--- a/dlls/crypt32/store.c
+++ b/dlls/crypt32/store.c
@@ -2160,7 +2160,12 @@ BOOL WINAPI CertAddCertificateContextToStore(HCERTSTORE hCertStore,
         break;
     case CERT_STORE_ADD_USE_EXISTING:
         if (existing)
+        {
             CertContext_CopyProperties(existing, pCertContext);
+            *ppStoreContext = CertDuplicateCertificateContext(existing);
+        }
+        else
+            toAdd = CertDuplicateCertificateContext(pCertContext);            
         break;
     default:
         FIXME("Unimplemented add disposition %d\n", dwAddDisposition);
diff --git a/dlls/crypt32/tests/cert.c b/dlls/crypt32/tests/cert.c
index c9f7a0a..74e955e 100644
--- a/dlls/crypt32/tests/cert.c
+++ b/dlls/crypt32/tests/cert.c
@@ -134,6 +134,7 @@ static void testAddCert(void)
     HCERTSTORE store;
     HCERTSTORE collection;
     PCCERT_CONTEXT context;
+    PCCERT_CONTEXT copyContext;
     BOOL ret;
 
     store = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
@@ -274,6 +275,15 @@ static void testAddCert(void)
              CERT_STORE_ADD_REPLACE_EXISTING, NULL);
             ok(ret, "CertAddCertificateContextToStore failed: %08x\n",
              GetLastError());
+            /* use the existing certificate and ask for a copy of the context*/
+            copyContext = NULL;
+            ret = CertAddCertificateContextToStore(collection, context,
+             CERT_STORE_ADD_USE_EXISTING, &copyContext);
+            ok(ret, "CertAddCertificateContextToStore failed: %08x\n",
+             GetLastError());
+            ok(copyContext != NULL, "Expected on output a non NULL copyContext\n");
+            if (copyContext)
+                CertFreeCertificateContext(copyContext);            
             /* but adding a new certificate isn't allowed. */
             ret = CertAddCertificateContextToStore(collection, context,
              CERT_STORE_ADD_ALWAYS, NULL);
-- 
1.4.4.2



More information about the wine-patches mailing list