rsaenh: fix bug in RSAENH_CPAcquireContext

Mounir IDRASSI mounir.idrassi at idrix.fr
Mon May 7 16:37:30 CDT 2007


Hi,
This patch corrects a bug in RSAENH_CPAcquireContext and adds a test
that demonstrate it:
    - when specifying CRYPT_DELETEKEYSET, the function always deletes
the container for the local user, while it should check the
CRYPT_MACHINE_KEYSET flag to see if it should be deleted on the local
machine or for the local user.

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

-------------- next part --------------
>From 9d5f1a72b3708d13a5f018746aecfafec5cf04fb Mon Sep 17 00:00:00 2001
From: Mounir IDRASSI <mounir.idrassi at idrix.fr>
Date: Mon, 7 May 2007 23:27:44 +0200
Subject: rsaenh: fix bug in RSAENH_CPAcquireContext

---
 dlls/rsaenh/rsaenh.c       |    7 ++++++-
 dlls/rsaenh/tests/rsaenh.c |   20 ++++++++++++++++++++
 2 files changed, 26 insertions(+), 1 deletions(-)

diff --git a/dlls/rsaenh/rsaenh.c b/dlls/rsaenh/rsaenh.c
index 66fa9f5..f875a12 100644
--- a/dlls/rsaenh/rsaenh.c
+++ b/dlls/rsaenh/rsaenh.c
@@ -1476,7 +1476,12 @@ BOOL WINAPI RSAENH_CPAcquireContext(HCRYPTPROV *phProv, LPSTR pszContainer,
                 SetLastError(NTE_BAD_KEYSET_PARAM);
                 return FALSE;
             } else {
-                if (!RegDeleteKeyA(HKEY_CURRENT_USER, szRegKey)) {
+                HKEY hRootKey;
+                if (dwFlags & CRYPT_MACHINE_KEYSET)
+                    hRootKey = HKEY_LOCAL_MACHINE;
+                else
+                    hRootKey = HKEY_CURRENT_USER;		    
+                if (!RegDeleteKeyA(hRootKey, szRegKey)) {
                     SetLastError(ERROR_SUCCESS);
                     return TRUE;
                 } else {
diff --git a/dlls/rsaenh/tests/rsaenh.c b/dlls/rsaenh/tests/rsaenh.c
index 57cf706..2d1b677 100644
--- a/dlls/rsaenh/tests/rsaenh.c
+++ b/dlls/rsaenh/tests/rsaenh.c
@@ -1622,6 +1622,26 @@ static void test_null_provider(void)
 
     CryptAcquireContext(&prov, szContainer, NULL, PROV_RSA_FULL,
      CRYPT_DELETEKEYSET);
+     
+    /* test the machine key set */
+    CryptAcquireContext(&prov, szContainer, NULL, PROV_RSA_FULL,
+     CRYPT_DELETEKEYSET|CRYPT_MACHINE_KEYSET);   
+    result = CryptAcquireContext(&prov, szContainer, NULL, PROV_RSA_FULL,
+     CRYPT_NEWKEYSET|CRYPT_MACHINE_KEYSET);
+    ok(result, "CryptAcquireContext with CRYPT_MACHINE_KEYSET failed: %08x\n", GetLastError());
+    CryptReleaseContext(prov, 0);
+    result = CryptAcquireContext(&prov, szContainer, NULL, PROV_RSA_FULL,
+     CRYPT_MACHINE_KEYSET);
+    ok(result, "CryptAcquireContext with CRYPT_MACHINE_KEYSET failed: %08x\n", GetLastError());
+    CryptReleaseContext(prov,0);
+    result = CryptAcquireContext(&prov, szContainer, NULL, PROV_RSA_FULL,
+       CRYPT_DELETEKEYSET|CRYPT_MACHINE_KEYSET); 
+    ok(result, "CryptAcquireContext with CRYPT_DELETEKEYSET|CRYPT_MACHINE_KEYSET failed: %08x\n", 
+		GetLastError());
+    result = CryptAcquireContext(&prov, szContainer, NULL, PROV_RSA_FULL,
+     CRYPT_MACHINE_KEYSET);
+    ok(!result && GetLastError() == NTE_BAD_KEYSET ,
+	"Expected NTE_BAD_KEYSET, got %08x\n", GetLastError());     
 
 }
 
-- 
1.4.4.2



More information about the wine-patches mailing list