Juan Lang : crypt32: Implement CryptFindCertificateInStore for unicode strings.

Alexandre Julliard julliard at winehq.org
Tue Oct 20 10:33:35 CDT 2009


Module: wine
Branch: master
Commit: 1e424138feead8b70d4d406af92acb079f2304c0
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=1e424138feead8b70d4d406af92acb079f2304c0

Author: Juan Lang <juan.lang at gmail.com>
Date:   Fri Oct 16 16:32:46 2009 -0700

crypt32: Implement CryptFindCertificateInStore for unicode strings.

---

 dlls/crypt32/cert.c       |   66 +++++++++++++++++++++++++++++++++++++++++++++
 dlls/crypt32/tests/cert.c |    3 --
 2 files changed, 66 insertions(+), 3 deletions(-)

diff --git a/dlls/crypt32/cert.c b/dlls/crypt32/cert.c
index b92aee9..5b3b6e3 100644
--- a/dlls/crypt32/cert.c
+++ b/dlls/crypt32/cert.c
@@ -1422,6 +1422,69 @@ static PCCERT_CONTEXT find_cert_by_issuer(HCERTSTORE store, DWORD dwType,
     return found;
 }
 
+static BOOL compare_cert_by_name_str(PCCERT_CONTEXT pCertContext,
+ DWORD dwType, DWORD dwFlags, const void *pvPara)
+{
+    PCERT_NAME_BLOB name;
+    DWORD len;
+    BOOL ret = FALSE;
+
+    if (dwType & CERT_INFO_SUBJECT_FLAG)
+        name = &pCertContext->pCertInfo->Subject;
+    else
+        name = &pCertContext->pCertInfo->Issuer;
+    len = CertNameToStrW(pCertContext->dwCertEncodingType, name,
+     CERT_SIMPLE_NAME_STR, NULL, 0);
+    if (len)
+    {
+        LPWSTR str = CryptMemAlloc(len * sizeof(WCHAR));
+
+        if (str)
+        {
+            LPWSTR ptr;
+
+            CertNameToStrW(pCertContext->dwCertEncodingType, name,
+             CERT_SIMPLE_NAME_STR, str, len);
+            for (ptr = str; *ptr; ptr++)
+                *ptr = tolowerW(*ptr);
+            if (strstrW(str, pvPara))
+                ret = TRUE;
+            CryptMemFree(str);
+        }
+    }
+    return ret;
+}
+
+static PCCERT_CONTEXT find_cert_by_name_str(HCERTSTORE store, DWORD dwType,
+ DWORD dwFlags, const void *pvPara, PCCERT_CONTEXT prev)
+{
+    PCCERT_CONTEXT found = NULL;
+
+    TRACE("%s\n", debugstr_w(pvPara));
+
+    if (pvPara)
+    {
+        DWORD len = strlenW(pvPara);
+        LPWSTR str = CryptMemAlloc((len + 1) * sizeof(WCHAR));
+
+        if (str)
+        {
+            LPCWSTR src;
+            LPWSTR dst;
+
+            for (src = pvPara, dst = str; *src; src++, dst++)
+                *dst = tolowerW(*src);
+            *dst = 0;
+           found = cert_compare_certs_in_store(store, prev,
+            compare_cert_by_name_str, dwType, dwFlags, str);
+           CryptMemFree(str);
+        }
+    }
+    else
+        found = find_cert_any(store, dwType, dwFlags, NULL, prev);
+    return found;
+}
+
 PCCERT_CONTEXT WINAPI CertFindCertificateInStore(HCERTSTORE hCertStore,
  DWORD dwCertEncodingType, DWORD dwFlags, DWORD dwType, const void *pvPara,
  PCCERT_CONTEXT pPrevCertContext)
@@ -1450,6 +1513,9 @@ PCCERT_CONTEXT WINAPI CertFindCertificateInStore(HCERTSTORE hCertStore,
     case CERT_COMPARE_PUBLIC_KEY:
         compare = compare_cert_by_public_key;
         break;
+    case CERT_COMPARE_NAME_STR_W:
+        find = find_cert_by_name_str;
+        break;
     case CERT_COMPARE_SUBJECT_CERT:
         compare = compare_cert_by_subject_cert;
         break;
diff --git a/dlls/crypt32/tests/cert.c b/dlls/crypt32/tests/cert.c
index 8a00509..685a564 100644
--- a/dlls/crypt32/tests/cert.c
+++ b/dlls/crypt32/tests/cert.c
@@ -1148,7 +1148,6 @@ static void testFindCert(void)
         if (context)
             count++;
     } while (context);
-    todo_wine
     ok(count == 3, "expected 3 contexts\n");
     count = 0;
     context = NULL;
@@ -1158,7 +1157,6 @@ static void testFindCert(void)
         if (context)
             count++;
     } while (context);
-    todo_wine
     ok(count == 2, "expected 2 contexts\n");
     count = 0;
     context = NULL;
@@ -1168,7 +1166,6 @@ static void testFindCert(void)
         if (context)
             count++;
     } while (context);
-    todo_wine
     ok(count == 3, "expected 3 contexts\n");
     SetLastError(0xdeadbeef);
     context = CertFindCertificateInStore(store, X509_ASN_ENCODING, 0,




More information about the wine-cvs mailing list