crypt32: Fix string quoting in CertRDNValueToStrA/W and CertNameToStrA/W.
Based on an idea of Christian Inci's.
This commit is contained in:
parent
307e247f21
commit
74cf35d2ab
|
@ -29,6 +29,133 @@
|
|||
|
||||
WINE_DEFAULT_DEBUG_CHANNEL(crypt);
|
||||
|
||||
DWORD WINAPI CertRDNValueToStrA(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue,
|
||||
LPSTR psz, DWORD csz)
|
||||
{
|
||||
DWORD ret = 0, len;
|
||||
|
||||
TRACE("(%d, %p, %p, %d)\n", dwValueType, pValue, psz, csz);
|
||||
|
||||
switch (dwValueType)
|
||||
{
|
||||
case CERT_RDN_ANY_TYPE:
|
||||
break;
|
||||
case CERT_RDN_NUMERIC_STRING:
|
||||
case CERT_RDN_PRINTABLE_STRING:
|
||||
case CERT_RDN_TELETEX_STRING:
|
||||
case CERT_RDN_VIDEOTEX_STRING:
|
||||
case CERT_RDN_IA5_STRING:
|
||||
case CERT_RDN_GRAPHIC_STRING:
|
||||
case CERT_RDN_VISIBLE_STRING:
|
||||
case CERT_RDN_GENERAL_STRING:
|
||||
len = pValue->cbData;
|
||||
if (!psz || !csz)
|
||||
ret = len;
|
||||
else
|
||||
{
|
||||
DWORD chars = min(len, csz - 1);
|
||||
|
||||
if (chars)
|
||||
{
|
||||
memcpy(psz, pValue->pbData, chars);
|
||||
ret += chars;
|
||||
csz -= chars;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case CERT_RDN_BMP_STRING:
|
||||
case CERT_RDN_UTF8_STRING:
|
||||
len = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)pValue->pbData,
|
||||
pValue->cbData / sizeof(WCHAR), NULL, 0, NULL, NULL);
|
||||
if (!psz || !csz)
|
||||
ret = len;
|
||||
else
|
||||
{
|
||||
DWORD chars = min(pValue->cbData / sizeof(WCHAR), csz - 1);
|
||||
|
||||
if (chars)
|
||||
{
|
||||
ret = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)pValue->pbData,
|
||||
chars, psz, csz - 1, NULL, NULL);
|
||||
csz -= ret;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
FIXME("string type %d unimplemented\n", dwValueType);
|
||||
}
|
||||
if (psz && csz)
|
||||
{
|
||||
*(psz + ret) = '\0';
|
||||
csz--;
|
||||
ret++;
|
||||
}
|
||||
else
|
||||
ret++;
|
||||
TRACE("returning %d (%s)\n", ret, debugstr_a(psz));
|
||||
return ret;
|
||||
}
|
||||
|
||||
DWORD WINAPI CertRDNValueToStrW(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue,
|
||||
LPWSTR psz, DWORD csz)
|
||||
{
|
||||
DWORD ret = 0, len, i, strLen;
|
||||
|
||||
TRACE("(%d, %p, %p, %d)\n", dwValueType, pValue, psz, csz);
|
||||
|
||||
switch (dwValueType)
|
||||
{
|
||||
case CERT_RDN_ANY_TYPE:
|
||||
break;
|
||||
case CERT_RDN_NUMERIC_STRING:
|
||||
case CERT_RDN_PRINTABLE_STRING:
|
||||
case CERT_RDN_TELETEX_STRING:
|
||||
case CERT_RDN_VIDEOTEX_STRING:
|
||||
case CERT_RDN_IA5_STRING:
|
||||
case CERT_RDN_GRAPHIC_STRING:
|
||||
case CERT_RDN_VISIBLE_STRING:
|
||||
case CERT_RDN_GENERAL_STRING:
|
||||
len = pValue->cbData;
|
||||
if (!psz || !csz)
|
||||
ret = len;
|
||||
else
|
||||
{
|
||||
WCHAR *ptr = psz;
|
||||
|
||||
for (i = 0; i < pValue->cbData && ptr - psz < csz; ptr++, i++)
|
||||
*ptr = pValue->pbData[i];
|
||||
ret = ptr - psz;
|
||||
}
|
||||
break;
|
||||
case CERT_RDN_BMP_STRING:
|
||||
case CERT_RDN_UTF8_STRING:
|
||||
strLen = len = pValue->cbData / sizeof(WCHAR);
|
||||
if (!psz || !csz)
|
||||
ret = len;
|
||||
else
|
||||
{
|
||||
WCHAR *ptr = psz;
|
||||
|
||||
for (i = 0; i < strLen && ptr - psz < csz; ptr++, i++)
|
||||
*ptr = ((LPCWSTR)pValue->pbData)[i];
|
||||
ret = ptr - psz;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
FIXME("string type %d unimplemented\n", dwValueType);
|
||||
}
|
||||
if (psz && csz)
|
||||
{
|
||||
*(psz + ret) = '\0';
|
||||
csz--;
|
||||
ret++;
|
||||
}
|
||||
else
|
||||
ret++;
|
||||
TRACE("returning %d (%s)\n", ret, debugstr_w(psz));
|
||||
return ret;
|
||||
}
|
||||
|
||||
static inline BOOL is_quotable_char(char c)
|
||||
{
|
||||
switch(c)
|
||||
|
@ -48,8 +175,8 @@ static inline BOOL is_quotable_char(char c)
|
|||
}
|
||||
}
|
||||
|
||||
DWORD WINAPI CertRDNValueToStrA(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue,
|
||||
LPSTR psz, DWORD csz)
|
||||
static DWORD quote_rdn_value_to_str_a(DWORD dwValueType,
|
||||
PCERT_RDN_VALUE_BLOB pValue, LPSTR psz, DWORD csz)
|
||||
{
|
||||
DWORD ret = 0, len, i;
|
||||
BOOL needsQuotes = FALSE;
|
||||
|
@ -157,8 +284,8 @@ DWORD WINAPI CertRDNValueToStrA(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue,
|
|||
return ret;
|
||||
}
|
||||
|
||||
DWORD WINAPI CertRDNValueToStrW(DWORD dwValueType, PCERT_RDN_VALUE_BLOB pValue,
|
||||
LPWSTR psz, DWORD csz)
|
||||
static DWORD quote_rdn_value_to_str_w(DWORD dwValueType,
|
||||
PCERT_RDN_VALUE_BLOB pValue, LPWSTR psz, DWORD csz)
|
||||
{
|
||||
DWORD ret = 0, len, i, strLen;
|
||||
BOOL needsQuotes = FALSE;
|
||||
|
@ -358,7 +485,7 @@ DWORD WINAPI CertNameToStrA(DWORD dwCertEncodingType, PCERT_NAME_BLOB pName,
|
|||
psz ? psz + ret : NULL, psz ? csz - ret - 1 : 0);
|
||||
ret += chars;
|
||||
}
|
||||
chars = CertRDNValueToStrA(
|
||||
chars = quote_rdn_value_to_str_a(
|
||||
rdn->rgRDNAttr[j].dwValueType,
|
||||
&rdn->rgRDNAttr[j].Value, psz ? psz + ret : NULL,
|
||||
psz ? csz - ret : 0);
|
||||
|
@ -537,7 +664,7 @@ DWORD cert_name_to_str_with_indent(DWORD dwCertEncodingType, DWORD indentLevel,
|
|||
psz ? psz + ret : NULL, psz ? csz - ret - 1 : 0);
|
||||
ret += chars;
|
||||
}
|
||||
chars = CertRDNValueToStrW(
|
||||
chars = quote_rdn_value_to_str_w(
|
||||
rdn->rgRDNAttr[j].dwValueType,
|
||||
&rdn->rgRDNAttr[j].Value, psz ? psz + ret : NULL,
|
||||
psz ? csz - ret : 0);
|
||||
|
|
|
@ -227,17 +227,17 @@ static void test_CertRDNValueToStrA(void)
|
|||
{ "1.2.840.113549.1.9.1", CERT_RDN_IA5_STRING,
|
||||
{ sizeof(bin7), bin7 }, "aric@codeweavers.com", FALSE },
|
||||
{ "0", CERT_RDN_PRINTABLE_STRING,
|
||||
{ sizeof(bin9), bin9 }, "abc\"def", TRUE },
|
||||
{ sizeof(bin9), bin9 }, "abc\"def", FALSE },
|
||||
{ "0", CERT_RDN_PRINTABLE_STRING,
|
||||
{ sizeof(bin10), bin10 }, "abc'def", FALSE },
|
||||
{ "0", CERT_RDN_PRINTABLE_STRING,
|
||||
{ sizeof(bin11), bin11 }, "abc, def", TRUE },
|
||||
{ sizeof(bin11), bin11 }, "abc, def", FALSE },
|
||||
{ "0", CERT_RDN_PRINTABLE_STRING,
|
||||
{ sizeof(bin12), bin12 }, " abc ", TRUE },
|
||||
{ sizeof(bin12), bin12 }, " abc ", FALSE },
|
||||
{ "0", CERT_RDN_PRINTABLE_STRING,
|
||||
{ sizeof(bin13), bin13 }, "\"def\"", TRUE },
|
||||
{ sizeof(bin13), bin13 }, "\"def\"", FALSE },
|
||||
{ "0", CERT_RDN_PRINTABLE_STRING,
|
||||
{ sizeof(bin14), bin14 }, "1;3", TRUE },
|
||||
{ sizeof(bin14), bin14 }, "1;3", FALSE },
|
||||
};
|
||||
DWORD i, ret;
|
||||
char buffer[2000];
|
||||
|
@ -328,17 +328,17 @@ static void test_CertRDNValueToStrW(void)
|
|||
{ "1.2.840.113549.1.9.1", CERT_RDN_IA5_STRING,
|
||||
{ sizeof(bin7), bin7 }, aricW, FALSE },
|
||||
{ "0", CERT_RDN_PRINTABLE_STRING,
|
||||
{ sizeof(bin9), bin9 }, embeddedDoubleQuoteW, TRUE },
|
||||
{ sizeof(bin9), bin9 }, embeddedDoubleQuoteW, FALSE },
|
||||
{ "0", CERT_RDN_PRINTABLE_STRING,
|
||||
{ sizeof(bin10), bin10 }, embeddedSingleQuoteW, FALSE },
|
||||
{ "0", CERT_RDN_PRINTABLE_STRING,
|
||||
{ sizeof(bin11), bin11 }, embeddedCommaW, TRUE },
|
||||
{ sizeof(bin11), bin11 }, embeddedCommaW, FALSE },
|
||||
{ "0", CERT_RDN_PRINTABLE_STRING,
|
||||
{ sizeof(bin12), bin12 }, trailingAndEndingSpaceW, TRUE },
|
||||
{ sizeof(bin12), bin12 }, trailingAndEndingSpaceW, FALSE },
|
||||
{ "0", CERT_RDN_PRINTABLE_STRING,
|
||||
{ sizeof(bin13), bin13 }, enclosingQuotesW, TRUE },
|
||||
{ sizeof(bin13), bin13 }, enclosingQuotesW, FALSE },
|
||||
{ "0", CERT_RDN_PRINTABLE_STRING,
|
||||
{ sizeof(bin14), bin14 }, embeddedSemiW, TRUE },
|
||||
{ sizeof(bin14), bin14 }, embeddedSemiW, FALSE },
|
||||
};
|
||||
DWORD i, ret;
|
||||
WCHAR buffer[2000];
|
||||
|
|
Loading…
Reference in New Issue