crypt32: Fix conversion of multiple fields in CertStrToName

Bruno Jesus 00cpxxx at gmail.com
Tue Jul 22 01:43:35 CDT 2014


-------------- next part --------------
diff --git a/dlls/crypt32/str.c b/dlls/crypt32/str.c
index cf29c6f..568472c4 100644
--- a/dlls/crypt32/str.c
+++ b/dlls/crypt32/str.c
@@ -840,13 +840,14 @@ static BOOL CRYPT_GetNextKeyW(LPCWSTR str, struct X500TokenW *token,
 
 /* Assumes separators are characters in the 0-255 range */
 static BOOL CRYPT_GetNextValueW(LPCWSTR str, DWORD dwFlags, LPCWSTR separators,
- struct X500TokenW *token, LPCWSTR *ppszError)
+ LPWSTR separatorused, struct X500TokenW *token, LPCWSTR *ppszError)
 {
     BOOL ret = TRUE;
 
     TRACE("(%s, %s, %p, %p)\n", debugstr_w(str), debugstr_w(separators), token,
      ppszError);
 
+    *separatorused = 0;
     while (*str && isspaceW(*str))
         str++;
     if (*str)
@@ -886,6 +887,7 @@ static BOOL CRYPT_GetNextValueW(LPCWSTR str, DWORD dwFlags, LPCWSTR separators,
             while (*str && (*str >= 0xff || !map[*str]))
                 str++;
             token->end = str;
+            if (map[*str]) *separatorused = *str;
         }
     }
     else
@@ -1077,6 +1079,7 @@ BOOL WINAPI CertStrToNameW(DWORD dwCertEncodingType, LPCWSTR pszX500,
                     static const WCHAR allSepsWithoutPlus[] = { ',',';','\r','\n',0 };
                     static const WCHAR allSeps[] = { '+',',',';','\r','\n',0 };
                     LPCWSTR sep;
+                    WCHAR sepused;
 
                     str++;
                     if (dwStrType & CERT_NAME_STR_COMMA_FLAG)
@@ -1089,11 +1092,14 @@ BOOL WINAPI CertStrToNameW(DWORD dwCertEncodingType, LPCWSTR pszX500,
                         sep = allSepsWithoutPlus;
                     else
                         sep = allSeps;
-                    ret = CRYPT_GetNextValueW(str, dwStrType, sep, &token,
+                    ret = CRYPT_GetNextValueW(str, dwStrType, sep, &sepused, &token,
                      ppszError);
                     if (ret)
                     {
                         str = token.end;
+                        /* if token.end points to the separator, skip it */
+                        if (str && sepused && *str == sepused) str++;
+
                         ret = CRYPT_ValueToRDN(dwCertEncodingType, &info,
                          keyOID, &token, dwStrType, ppszError);
                     }
diff --git a/dlls/crypt32/tests/cert.c b/dlls/crypt32/tests/cert.c
index e16ca5d..a19ef1e 100644
--- a/dlls/crypt32/tests/cert.c
+++ b/dlls/crypt32/tests/cert.c
@@ -1711,23 +1711,14 @@ static void testGetIssuerCert(void)
 
     /* Self-sign a certificate, add to the store and test getting the issuer */
     size = 0;
-todo_wine
     ok(CertStrToNameW(X509_ASN_ENCODING, certname, CERT_X500_NAME_STR, NULL, NULL, &size, NULL),
        "CertStrToName should have worked\n");
     certencoded = HeapAlloc(GetProcessHeap(), 0, size);
-todo_wine
     ok(CertStrToNameW(X509_ASN_ENCODING, certname, CERT_X500_NAME_STR, NULL, certencoded, &size, NULL),
        "CertStrToName should have worked\n");
     certsubject.pbData = certencoded;
     certsubject.cbData = size;
     cert3 = CertCreateSelfSignCertificate(0, &certsubject, 0, NULL, NULL, NULL, NULL, NULL);
-    /* wine fails to create the certificate, this makes it crash later.
-     * Remove IF when wine is fixed, all windows versions must work */
-    if(cert3 == NULL)
-    {
-        todo_wine ok(0, "Must work on windows\n");
-        goto skiptest;
-    }
     ok(cert3 != NULL, "CertCreateSelfSignCertificate should have worked\n");
     ret = CertAddCertificateContextToStore(store, cert3, CERT_STORE_ADD_REPLACE_EXISTING, 0);
     ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
@@ -1737,10 +1728,11 @@ todo_wine
     SetLastError(0xdeadbeef);
     flags = 0;
     parent = CertGetIssuerCertificateFromStore(store, cert3, NULL, &flags);
+todo_wine
     ok(!parent, "Expected NULL\n");
+todo_wine
     ok(GetLastError() == CRYPT_E_SELF_SIGNED,
        "Expected CRYPT_E_SELF_SIGNED, got %08X\n", GetLastError());
-skiptest:
     CertFreeCertificateContext(child);
     CertFreeCertificateContext(cert1);
     CertFreeCertificateContext(cert2);
diff --git a/dlls/crypt32/tests/str.c b/dlls/crypt32/tests/str.c
index dd61888..cf7c2ef 100644
--- a/dlls/crypt32/tests/str.c
+++ b/dlls/crypt32/tests/str.c
@@ -450,6 +450,15 @@ static BYTE encodedSemiCN[] = {
 static BYTE encodedNewlineCN[] = {
 0x30,0x11,0x31,0x0f,0x30,0x0d,0x06,0x03,0x55,0x04,0x03,0x1e,0x06,0x00,0x61,
 0x00,0x0a,0x00,0x62 };
+static BYTE encodedDummyCN[] = {
+0x30,0x1F,0x31,0x0E,0x30,0x0C,0x06,0x03,0x55,0x04,0x03,0x13,0x05,0x64,0x75,
+0x6D,0x6D,0x79,0x31,0x0D,0x30,0x0B,0x06,0x03,0x55,0x04,0x0C,0x13,0x04,0x74,
+0x65,0x73,0x74 };
+static BYTE encodedFields[] = {
+0x30,0x2F,0x31,0x12,0x30,0x10,0x06,0x03,0x55,0x04,0x03,0x13,0x09,0x57,0x69,
+0x6E,0x65,0x20,0x54,0x65,0x73,0x74,0x31,0x0C,0x30,0x0A,0x06,0x03,0x55,0x04,
+0x0C,0x13,0x03,0x31,0x32,0x33,0x31,0x0B,0x30,0x09,0x06,0x03,0x55,0x04,0x06,
+0x13,0x02,0x42,0x52 };
 
 static void test_CertNameToStrA(void)
 {
@@ -756,6 +765,8 @@ static const struct StrToNameA namesA[] = {
  { "CN=\">\"", sizeof(encodedGreaterThanCN), encodedGreaterThanCN },
  { "CN=\"#\"", sizeof(encodedHashCN), encodedHashCN },
  { "CN=\";\"", sizeof(encodedSemiCN), encodedSemiCN },
+ { "CN=dummy,T=test", sizeof(encodedDummyCN), encodedDummyCN },
+ { " CN =   Wine Test,T = 123, C = BR", sizeof(encodedFields), encodedFields },
 };
 
 static void test_CertStrToNameA(void)
@@ -849,6 +860,10 @@ static const WCHAR badlyQuotedCN_W[] = { 'C','N','=','"','"','1','"','"',0 };
 static const WCHAR simpleCN2_W[] = { 'C','N','=','"','1','"',0 };
 static const WCHAR simpleCN3_W[] = { 'C','N',' ','=',' ','"','1','"',0 };
 static const WCHAR japaneseCN_W[] = { 'C','N','=',0x226f,0x575b,0 };
+static const WCHAR dummyCN_W[] = { 'C','N','=','d','u','m','m','y',',','T','=','t','e','s','t',0 };
+static const WCHAR encodedFields_W[] = { ' ','C','N',' ','=',' ',' ',' ','W','i','n','e',' ','T',
+                                         'e','s','t',',','T',' ','=',' ','1','2','3',',',' ','C',
+                                         ' ','=',' ','B','R',0 };
 static const BYTE encodedJapaneseCN[] = { 0x30,0x0f,0x31,0x0d,0x30,0x0b,0x06,
  0x03,0x55,0x04,0x03,0x1e,0x04,0x22,0x6f,0x57,0x5b };
 
@@ -867,6 +882,8 @@ static const struct StrToNameW namesW[] = {
  { greaterThanCN_W, sizeof(encodedGreaterThanCN), encodedGreaterThanCN },
  { hashCN_W, sizeof(encodedHashCN), encodedHashCN },
  { semiCN_W, sizeof(encodedSemiCN), encodedSemiCN },
+ { dummyCN_W, sizeof(encodedDummyCN), encodedDummyCN },
+ { encodedFields_W, sizeof(encodedFields), encodedFields },
 };
 
 static void test_CertStrToNameW(void)
@@ -922,7 +939,7 @@ static void test_CertStrToNameW(void)
          size);
         if (ret)
             ok(!memcmp(buf, namesW[i].encoded, size),
-             "Index %d: unexpected value\n", i);
+             "Index %d: unexpected value for string %s\n", i, wine_dbgstr_w(namesW[i].x500));
     }
 }
 


More information about the wine-patches mailing list