crypt32: Pass on aiKeyAlg on RSA key import

Michael Karcher wine at mkarcher.dialup.fu-berlin.de
Sun May 25 13:16:14 CDT 2008


Patch is needed because wine's crypt32 rejects keys larger than
1024 bits as CALG_RSA_KEYX in the "Base" provider, which is the
default. Without this patch, importing bigger CALG_RSA_SIGN keys
is inhibited.

Testcase passes in XP SP3 and patched wine.
---
 dlls/crypt32/encode.c       |    4 ++++
 dlls/crypt32/tests/encode.c |   30 ++++++++++++++++++++++++++++++
 2 files changed, 34 insertions(+), 0 deletions(-)

diff --git a/dlls/crypt32/encode.c b/dlls/crypt32/encode.c
index 80f30ae..ee42a3d 100644
--- a/dlls/crypt32/encode.c
+++ b/dlls/crypt32/encode.c
@@ -3918,8 +3918,12 @@ static BOOL WINAPI CRYPT_ImportRsaPublicKeyInfoEx(HCRYPTPROV hCryptProv,
              pInfo->PublicKey.pbData, pInfo->PublicKey.cbData, 0, pubKey,
              &pubKeySize);
             if (ret)
+            {
+                if(aiKeyAlg)
+                  ((BLOBHEADER*)pubKey)->aiKeyAlg = aiKeyAlg;
                 ret = CryptImportKey(hCryptProv, pubKey, pubKeySize, 0, 0,
                  phKey);
+            }
             CryptMemFree(pubKey);
         }
         else
diff --git a/dlls/crypt32/tests/encode.c b/dlls/crypt32/tests/encode.c
index 8e75689..9b399bd 100644
--- a/dlls/crypt32/tests/encode.c
+++ b/dlls/crypt32/tests/encode.c
@@ -5802,6 +5802,8 @@ static void testImportPublicKey(HCRYPTPROV csp, PCERT_PUBLIC_KEY_INFO info)
     BOOL ret;
     HCRYPTKEY key;
     PCCERT_CONTEXT context;
+    DWORD dwSize;
+    ALG_ID ai;
 
     /* These crash
     ret = CryptImportPublicKeyInfoEx(0, 0, NULL, 0, 0, NULL, NULL);
@@ -5820,9 +5822,37 @@ static void testImportPublicKey(HCRYPTPROV csp, PCERT_PUBLIC_KEY_INFO info)
      &key);
     ok(!ret && GetLastError() == ERROR_INVALID_PARAMETER,
      "Expected ERROR_INVALID_PARAMETER, got %08x\n", GetLastError());
+
+    /* Export key with standard algorithm (CALG_RSA_KEYX) */
     ret = CryptImportPublicKeyInfoEx(csp, X509_ASN_ENCODING, info, 0, 0, NULL,
      &key);
     ok(ret, "CryptImportPublicKeyInfoEx failed: %08x\n", GetLastError());
+
+    dwSize = sizeof(ai);
+    CryptGetKeyParam(key, KP_ALGID, (LPVOID)&ai, &dwSize, 0);
+    ok(ret, "CryptGetKeyParam failed: %08x\n", GetLastError());
+    if(ret)
+    {
+      ok(dwSize == sizeof(ai), "CryptGetKeyParam returned size %d\n",dwSize);
+      ok(ai == CALG_RSA_KEYX, "Default ALG_ID is %04x (expected CALG_RSA_KEYX)\n", ai);
+    }
+    
+    CryptDestroyKey(key);
+
+    /* Repeat with forced algorithm */
+    ret = CryptImportPublicKeyInfoEx(csp, X509_ASN_ENCODING, info, CALG_RSA_SIGN, 0, NULL,
+     &key);
+    ok(ret, "CryptImportPublicKeyInfoEx failed: %08x\n", GetLastError());
+
+    dwSize = sizeof(ai);
+    CryptGetKeyParam(key, KP_ALGID, (LPVOID)&ai, &dwSize, 0);
+    ok(ret, "CryptGetKeyParam failed: %08x\n", GetLastError());
+    if(ret)
+    {
+      ok(dwSize == sizeof(ai), "CryptGetKeyParam returned size %d\n",dwSize);
+      ok(ai == CALG_RSA_SIGN, "ALG_ID is %04x (expected CALG_RSA_SIGN)\n", ai);
+    }
+    
     CryptDestroyKey(key);
 
     /* Test importing a public key from a certificate context */
-- 
1.5.5.1




More information about the wine-patches mailing list