crypt32: Vista doesn't actually add duplicate usage identifiers; fix tests and change Wine to match.
This commit is contained in:
parent
b579eac22f
commit
b04c4aa6ff
|
@ -1902,29 +1902,43 @@ BOOL WINAPI CertAddEnhancedKeyUsageIdentifier(PCCERT_CONTEXT pCertContext,
|
||||||
CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG, usage, &size);
|
CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG, usage, &size);
|
||||||
if (ret)
|
if (ret)
|
||||||
{
|
{
|
||||||
PCERT_ENHKEY_USAGE newUsage = CryptMemAlloc(size +
|
DWORD i;
|
||||||
sizeof(LPSTR) + strlen(pszUsageIdentifier) + 1);
|
BOOL exists = FALSE;
|
||||||
|
|
||||||
if (newUsage)
|
/* Make sure usage doesn't already exist */
|
||||||
|
for (i = 0; !exists && i < usage->cUsageIdentifier; i++)
|
||||||
{
|
{
|
||||||
LPSTR nextOID;
|
if (!strcmp(usage->rgpszUsageIdentifier[i],
|
||||||
DWORD i;
|
pszUsageIdentifier))
|
||||||
|
exists = TRUE;
|
||||||
|
}
|
||||||
|
if (!exists)
|
||||||
|
{
|
||||||
|
PCERT_ENHKEY_USAGE newUsage = CryptMemAlloc(size +
|
||||||
|
sizeof(LPSTR) + strlen(pszUsageIdentifier) + 1);
|
||||||
|
|
||||||
newUsage->rgpszUsageIdentifier =
|
if (newUsage)
|
||||||
(LPSTR *)((LPBYTE)newUsage + sizeof(CERT_ENHKEY_USAGE));
|
|
||||||
nextOID = (LPSTR)((LPBYTE)newUsage->rgpszUsageIdentifier +
|
|
||||||
(usage->cUsageIdentifier + 1) * sizeof(LPSTR));
|
|
||||||
for (i = 0; i < usage->cUsageIdentifier; i++)
|
|
||||||
{
|
{
|
||||||
|
LPSTR nextOID;
|
||||||
|
|
||||||
|
newUsage->rgpszUsageIdentifier = (LPSTR *)
|
||||||
|
((LPBYTE)newUsage + sizeof(CERT_ENHKEY_USAGE));
|
||||||
|
nextOID = (LPSTR)((LPBYTE)newUsage->rgpszUsageIdentifier
|
||||||
|
+ (usage->cUsageIdentifier + 1) * sizeof(LPSTR));
|
||||||
|
for (i = 0; i < usage->cUsageIdentifier; i++)
|
||||||
|
{
|
||||||
|
newUsage->rgpszUsageIdentifier[i] = nextOID;
|
||||||
|
strcpy(nextOID, usage->rgpszUsageIdentifier[i]);
|
||||||
|
nextOID += strlen(nextOID) + 1;
|
||||||
|
}
|
||||||
newUsage->rgpszUsageIdentifier[i] = nextOID;
|
newUsage->rgpszUsageIdentifier[i] = nextOID;
|
||||||
strcpy(nextOID, usage->rgpszUsageIdentifier[i]);
|
strcpy(nextOID, pszUsageIdentifier);
|
||||||
nextOID += strlen(nextOID) + 1;
|
newUsage->cUsageIdentifier = i + 1;
|
||||||
|
ret = CertSetEnhancedKeyUsage(pCertContext, newUsage);
|
||||||
|
CryptMemFree(newUsage);
|
||||||
}
|
}
|
||||||
newUsage->rgpszUsageIdentifier[i] = nextOID;
|
else
|
||||||
strcpy(nextOID, pszUsageIdentifier);
|
ret = FALSE;
|
||||||
newUsage->cUsageIdentifier = i + 1;
|
|
||||||
ret = CertSetEnhancedKeyUsage(pCertContext, newUsage);
|
|
||||||
CryptMemFree(newUsage);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
CryptMemFree(usage);
|
CryptMemFree(usage);
|
||||||
|
|
|
@ -2053,7 +2053,9 @@ static void testKeyUsage(void)
|
||||||
if (pUsage->cUsageIdentifier)
|
if (pUsage->cUsageIdentifier)
|
||||||
ok(!strcmp(pUsage->rgpszUsageIdentifier[0], oid),
|
ok(!strcmp(pUsage->rgpszUsageIdentifier[0], oid),
|
||||||
"Expected %s, got %s\n", oid, pUsage->rgpszUsageIdentifier[0]);
|
"Expected %s, got %s\n", oid, pUsage->rgpszUsageIdentifier[0]);
|
||||||
/* Yep, I can re-add the same usage identifier */
|
/* Re-adding the same usage identifier succeeds, though it only adds
|
||||||
|
* a duplicate usage identifier on versions prior to Vista
|
||||||
|
*/
|
||||||
ret = CertAddEnhancedKeyUsageIdentifier(context, oid);
|
ret = CertAddEnhancedKeyUsageIdentifier(context, oid);
|
||||||
ok(ret, "CertAddEnhancedKeyUsageIdentifier failed: %08x\n",
|
ok(ret, "CertAddEnhancedKeyUsageIdentifier failed: %08x\n",
|
||||||
GetLastError());
|
GetLastError());
|
||||||
|
@ -2061,8 +2063,8 @@ static void testKeyUsage(void)
|
||||||
ret = CertGetEnhancedKeyUsage(context, 0, pUsage, &size);
|
ret = CertGetEnhancedKeyUsage(context, 0, pUsage, &size);
|
||||||
ok(ret && GetLastError() == 0,
|
ok(ret && GetLastError() == 0,
|
||||||
"CertGetEnhancedKeyUsage failed: %08x\n", GetLastError());
|
"CertGetEnhancedKeyUsage failed: %08x\n", GetLastError());
|
||||||
ok(pUsage->cUsageIdentifier == 2, "Expected 2 identifiers, got %d\n",
|
ok(pUsage->cUsageIdentifier == 1 || pUsage->cUsageIdentifier == 2,
|
||||||
pUsage->cUsageIdentifier);
|
"Expected 1 or 2 identifiers, got %d\n", pUsage->cUsageIdentifier);
|
||||||
if (pUsage->cUsageIdentifier)
|
if (pUsage->cUsageIdentifier)
|
||||||
ok(!strcmp(pUsage->rgpszUsageIdentifier[0], oid),
|
ok(!strcmp(pUsage->rgpszUsageIdentifier[0], oid),
|
||||||
"Expected %s, got %s\n", oid, pUsage->rgpszUsageIdentifier[0]);
|
"Expected %s, got %s\n", oid, pUsage->rgpszUsageIdentifier[0]);
|
||||||
|
|
Loading…
Reference in New Issue