crypt32: Fix conversion of multiple fields in CertStrToName.
This commit is contained in:
parent
b20365ee29
commit
4a28977f38
|
@ -840,13 +840,14 @@ static BOOL CRYPT_GetNextKeyW(LPCWSTR str, struct X500TokenW *token,
|
||||||
|
|
||||||
/* Assumes separators are characters in the 0-255 range */
|
/* Assumes separators are characters in the 0-255 range */
|
||||||
static BOOL CRYPT_GetNextValueW(LPCWSTR str, DWORD dwFlags, LPCWSTR separators,
|
static BOOL CRYPT_GetNextValueW(LPCWSTR str, DWORD dwFlags, LPCWSTR separators,
|
||||||
struct X500TokenW *token, LPCWSTR *ppszError)
|
WCHAR *separator_used, struct X500TokenW *token, LPCWSTR *ppszError)
|
||||||
{
|
{
|
||||||
BOOL ret = TRUE;
|
BOOL ret = TRUE;
|
||||||
|
|
||||||
TRACE("(%s, %s, %p, %p)\n", debugstr_w(str), debugstr_w(separators), token,
|
TRACE("(%s, %s, %p, %p)\n", debugstr_w(str), debugstr_w(separators), token,
|
||||||
ppszError);
|
ppszError);
|
||||||
|
|
||||||
|
*separator_used = 0;
|
||||||
while (*str && isspaceW(*str))
|
while (*str && isspaceW(*str))
|
||||||
str++;
|
str++;
|
||||||
if (*str)
|
if (*str)
|
||||||
|
@ -886,6 +887,7 @@ static BOOL CRYPT_GetNextValueW(LPCWSTR str, DWORD dwFlags, LPCWSTR separators,
|
||||||
while (*str && (*str >= 0xff || !map[*str]))
|
while (*str && (*str >= 0xff || !map[*str]))
|
||||||
str++;
|
str++;
|
||||||
token->end = str;
|
token->end = str;
|
||||||
|
if (map[*str]) *separator_used = *str;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1077,6 +1079,7 @@ BOOL WINAPI CertStrToNameW(DWORD dwCertEncodingType, LPCWSTR pszX500,
|
||||||
static const WCHAR allSepsWithoutPlus[] = { ',',';','\r','\n',0 };
|
static const WCHAR allSepsWithoutPlus[] = { ',',';','\r','\n',0 };
|
||||||
static const WCHAR allSeps[] = { '+',',',';','\r','\n',0 };
|
static const WCHAR allSeps[] = { '+',',',';','\r','\n',0 };
|
||||||
LPCWSTR sep;
|
LPCWSTR sep;
|
||||||
|
WCHAR sep_used;
|
||||||
|
|
||||||
str++;
|
str++;
|
||||||
if (dwStrType & CERT_NAME_STR_COMMA_FLAG)
|
if (dwStrType & CERT_NAME_STR_COMMA_FLAG)
|
||||||
|
@ -1089,11 +1092,14 @@ BOOL WINAPI CertStrToNameW(DWORD dwCertEncodingType, LPCWSTR pszX500,
|
||||||
sep = allSepsWithoutPlus;
|
sep = allSepsWithoutPlus;
|
||||||
else
|
else
|
||||||
sep = allSeps;
|
sep = allSeps;
|
||||||
ret = CRYPT_GetNextValueW(str, dwStrType, sep, &token,
|
ret = CRYPT_GetNextValueW(str, dwStrType, sep, &sep_used, &token,
|
||||||
ppszError);
|
ppszError);
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
str = token.end;
|
str = token.end;
|
||||||
|
/* if token.end points to the separator, skip it */
|
||||||
|
if (str && sep_used && *str == sep_used) str++;
|
||||||
|
|
||||||
ret = CRYPT_ValueToRDN(dwCertEncodingType, &info,
|
ret = CRYPT_ValueToRDN(dwCertEncodingType, &info,
|
||||||
keyOID, &token, dwStrType, ppszError);
|
keyOID, &token, dwStrType, ppszError);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1711,23 +1711,14 @@ static void testGetIssuerCert(void)
|
||||||
|
|
||||||
/* Self-sign a certificate, add to the store and test getting the issuer */
|
/* Self-sign a certificate, add to the store and test getting the issuer */
|
||||||
size = 0;
|
size = 0;
|
||||||
todo_wine
|
|
||||||
ok(CertStrToNameW(X509_ASN_ENCODING, certname, CERT_X500_NAME_STR, NULL, NULL, &size, NULL),
|
ok(CertStrToNameW(X509_ASN_ENCODING, certname, CERT_X500_NAME_STR, NULL, NULL, &size, NULL),
|
||||||
"CertStrToName should have worked\n");
|
"CertStrToName should have worked\n");
|
||||||
certencoded = HeapAlloc(GetProcessHeap(), 0, size);
|
certencoded = HeapAlloc(GetProcessHeap(), 0, size);
|
||||||
todo_wine
|
|
||||||
ok(CertStrToNameW(X509_ASN_ENCODING, certname, CERT_X500_NAME_STR, NULL, certencoded, &size, NULL),
|
ok(CertStrToNameW(X509_ASN_ENCODING, certname, CERT_X500_NAME_STR, NULL, certencoded, &size, NULL),
|
||||||
"CertStrToName should have worked\n");
|
"CertStrToName should have worked\n");
|
||||||
certsubject.pbData = certencoded;
|
certsubject.pbData = certencoded;
|
||||||
certsubject.cbData = size;
|
certsubject.cbData = size;
|
||||||
cert3 = CertCreateSelfSignCertificate(0, &certsubject, 0, NULL, NULL, NULL, NULL, NULL);
|
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");
|
ok(cert3 != NULL, "CertCreateSelfSignCertificate should have worked\n");
|
||||||
ret = CertAddCertificateContextToStore(store, cert3, CERT_STORE_ADD_REPLACE_EXISTING, 0);
|
ret = CertAddCertificateContextToStore(store, cert3, CERT_STORE_ADD_REPLACE_EXISTING, 0);
|
||||||
ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
|
ok(ret, "CertAddEncodedCertificateToStore failed: %08x\n", GetLastError());
|
||||||
|
@ -1737,10 +1728,11 @@ todo_wine
|
||||||
SetLastError(0xdeadbeef);
|
SetLastError(0xdeadbeef);
|
||||||
flags = 0;
|
flags = 0;
|
||||||
parent = CertGetIssuerCertificateFromStore(store, cert3, NULL, &flags);
|
parent = CertGetIssuerCertificateFromStore(store, cert3, NULL, &flags);
|
||||||
|
todo_wine
|
||||||
ok(!parent, "Expected NULL\n");
|
ok(!parent, "Expected NULL\n");
|
||||||
|
todo_wine
|
||||||
ok(GetLastError() == CRYPT_E_SELF_SIGNED,
|
ok(GetLastError() == CRYPT_E_SELF_SIGNED,
|
||||||
"Expected CRYPT_E_SELF_SIGNED, got %08X\n", GetLastError());
|
"Expected CRYPT_E_SELF_SIGNED, got %08X\n", GetLastError());
|
||||||
skiptest:
|
|
||||||
CertFreeCertificateContext(child);
|
CertFreeCertificateContext(child);
|
||||||
CertFreeCertificateContext(cert1);
|
CertFreeCertificateContext(cert1);
|
||||||
CertFreeCertificateContext(cert2);
|
CertFreeCertificateContext(cert2);
|
||||||
|
|
|
@ -450,6 +450,15 @@ static BYTE encodedSemiCN[] = {
|
||||||
static BYTE encodedNewlineCN[] = {
|
static BYTE encodedNewlineCN[] = {
|
||||||
0x30,0x11,0x31,0x0f,0x30,0x0d,0x06,0x03,0x55,0x04,0x03,0x1e,0x06,0x00,0x61,
|
0x30,0x11,0x31,0x0f,0x30,0x0d,0x06,0x03,0x55,0x04,0x03,0x1e,0x06,0x00,0x61,
|
||||||
0x00,0x0a,0x00,0x62 };
|
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)
|
static void test_CertNameToStrA(void)
|
||||||
{
|
{
|
||||||
|
@ -756,6 +765,8 @@ static const struct StrToNameA namesA[] = {
|
||||||
{ "CN=\">\"", sizeof(encodedGreaterThanCN), encodedGreaterThanCN },
|
{ "CN=\">\"", sizeof(encodedGreaterThanCN), encodedGreaterThanCN },
|
||||||
{ "CN=\"#\"", sizeof(encodedHashCN), encodedHashCN },
|
{ "CN=\"#\"", sizeof(encodedHashCN), encodedHashCN },
|
||||||
{ "CN=\";\"", sizeof(encodedSemiCN), encodedSemiCN },
|
{ "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)
|
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 simpleCN2_W[] = { 'C','N','=','"','1','"',0 };
|
||||||
static const WCHAR simpleCN3_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 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,
|
static const BYTE encodedJapaneseCN[] = { 0x30,0x0f,0x31,0x0d,0x30,0x0b,0x06,
|
||||||
0x03,0x55,0x04,0x03,0x1e,0x04,0x22,0x6f,0x57,0x5b };
|
0x03,0x55,0x04,0x03,0x1e,0x04,0x22,0x6f,0x57,0x5b };
|
||||||
|
|
||||||
|
@ -867,6 +882,8 @@ static const struct StrToNameW namesW[] = {
|
||||||
{ greaterThanCN_W, sizeof(encodedGreaterThanCN), encodedGreaterThanCN },
|
{ greaterThanCN_W, sizeof(encodedGreaterThanCN), encodedGreaterThanCN },
|
||||||
{ hashCN_W, sizeof(encodedHashCN), encodedHashCN },
|
{ hashCN_W, sizeof(encodedHashCN), encodedHashCN },
|
||||||
{ semiCN_W, sizeof(encodedSemiCN), encodedSemiCN },
|
{ semiCN_W, sizeof(encodedSemiCN), encodedSemiCN },
|
||||||
|
{ dummyCN_W, sizeof(encodedDummyCN), encodedDummyCN },
|
||||||
|
{ encodedFields_W, sizeof(encodedFields), encodedFields },
|
||||||
};
|
};
|
||||||
|
|
||||||
static void test_CertStrToNameW(void)
|
static void test_CertStrToNameW(void)
|
||||||
|
@ -922,7 +939,7 @@ static void test_CertStrToNameW(void)
|
||||||
size);
|
size);
|
||||||
if (ret)
|
if (ret)
|
||||||
ok(!memcmp(buf, namesW[i].encoded, size),
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue