[Wine-patches] [eterhack 2/3] crypt32: Add support for CryptDllConvertPublicKeyInfo (eterbug #5665).

Alexander Morozov amorozov на etersoft.ru
Чт Июн 24 17:47:45 MSD 2010


----------- следующая часть -----------
From a8139ea3bcf1b9b978224d9619e98652483f115f Mon Sep 17 00:00:00 2001
From: Alexander Morozov <amorozov на etersoft.ru>
Date: Wed, 23 Jun 2010 14:39:01 +0400
Subject: [eterhack 2/3] crypt32: Add support for CryptDllConvertPublicKeyInfo (eterbug #5665).

---
 dlls/crypt32/encode.c |   37 ++++++++++++++++++++++++++++++++-----
 include/wincrypt.h    |    1 +
 2 files changed, 33 insertions(+), 5 deletions(-)

diff --git a/dlls/crypt32/encode.c b/dlls/crypt32/encode.c
index c58b0e6..4c961c3 100644
--- a/dlls/crypt32/encode.c
+++ b/dlls/crypt32/encode.c
@@ -4798,13 +4798,18 @@ typedef BOOL (WINAPI *ImportPublicKeyInfoExFunc)(HCRYPTPROV hCryptProv,
  DWORD dwCertEncodingType, PCERT_PUBLIC_KEY_INFO pInfo, ALG_ID aiKeyAlg,
  DWORD dwFlags, void *pvAuxInfo, HCRYPTKEY *phKey);
 
+typedef BOOL (WINAPI *ConvertPublicKeyInfoFunc)(DWORD dwCertEncodingType,
+ PCERT_PUBLIC_KEY_INFO pInfo, ALG_ID aiKeyAlg, DWORD dwFlags,
+ BYTE **ppbData, DWORD *dwDataLen);
+
 BOOL WINAPI CryptImportPublicKeyInfoEx(HCRYPTPROV hCryptProv,
  DWORD dwCertEncodingType, PCERT_PUBLIC_KEY_INFO pInfo, ALG_ID aiKeyAlg,
  DWORD dwFlags, void *pvAuxInfo, HCRYPTKEY *phKey)
 {
-    static HCRYPTOIDFUNCSET set = NULL;
-    BOOL ret;
+    static HCRYPTOIDFUNCSET set = NULL, convSet = NULL;
+    BOOL ret = FALSE;
     ImportPublicKeyInfoExFunc importFunc = NULL;
+    ConvertPublicKeyInfoFunc convertFunc = NULL;
     HCRYPTOIDFUNCADDR hFunc = NULL;
 
     TRACE_(crypt)("(%08lx, %08x, %p, %08x, %08x, %p, %p)\n", hCryptProv,
@@ -4815,9 +4820,31 @@ BOOL WINAPI CryptImportPublicKeyInfoEx(HCRYPTPROV hCryptProv,
     CryptGetOIDFunctionAddress(set, dwCertEncodingType,
      pInfo->Algorithm.pszObjId, 0, (void **)&importFunc, &hFunc);
     if (!importFunc)
-        importFunc = CRYPT_ImportRsaPublicKeyInfoEx;
-    ret = importFunc(hCryptProv, dwCertEncodingType, pInfo, aiKeyAlg, dwFlags,
-     pvAuxInfo, phKey);
+    {
+        if (!convSet)
+            convSet = CryptInitOIDFunctionSet(
+             CRYPT_OID_CONVERT_PUBLIC_KEY_INFO_FUNC, 0);
+        CryptGetOIDFunctionAddress(convSet, dwCertEncodingType,
+         pInfo->Algorithm.pszObjId, 0, (void **)&convertFunc, &hFunc);
+        if (!convertFunc)
+            importFunc = CRYPT_ImportRsaPublicKeyInfoEx;
+    }
+    if (importFunc)
+        ret = importFunc(hCryptProv, dwCertEncodingType, pInfo, aiKeyAlg,
+         dwFlags, pvAuxInfo, phKey);
+    if (convertFunc)
+    {
+        LPBYTE pubKey = NULL;
+        DWORD pubKeySize = 0;
+
+        ret = convertFunc(dwCertEncodingType, pInfo, aiKeyAlg, dwFlags, &pubKey,
+         &pubKeySize);
+        if (ret)
+        {
+            ret = CryptImportKey(hCryptProv, pubKey, pubKeySize, 0, 0, phKey);
+            CryptMemFree(pubKey);
+        }
+    }
     if (hFunc)
         CryptFreeOIDFunctionAddress(hFunc, 0);
     return ret;
diff --git a/include/wincrypt.h b/include/wincrypt.h
index d3f56b9..54fe898 100644
--- a/include/wincrypt.h
+++ b/include/wincrypt.h
@@ -2271,6 +2271,7 @@ static const WCHAR CERT_TRUST_PUB_AUTHENTICODE_FLAGS_VALUE_NAME[] =
 #define CRYPT_OID_IMPORT_PRIVATE_KEY_INFO_FUNC "CryptDllImportPrivateKeyInfoEx"
 #define CRYPT_OID_VERIFY_CERTIFICATE_CHAIN_POLICY_FUNC \
  "CertDllVerifyCertificateChainPolicy"
+#define CRYPT_OID_CONVERT_PUBLIC_KEY_INFO_FUNC "CryptDllConvertPublicKeyInfo"
 #define URL_OID_GET_OBJECT_URL_FUNC    "UrlDllGetObjectUrl"
 #define TIME_VALID_OID_GET_OBJECT_FUNC "TimeValidDllGetObject"
 
-- 
1.6.5.8



Подробная информация о списке рассылки Wine-patches