crypt32: Implement CryptHashToBeSigned.
This commit is contained in:
parent
b18919bef7
commit
d8da3e83ff
|
@ -1534,9 +1534,45 @@ BOOL WINAPI CryptHashToBeSigned(HCRYPTPROV_LEGACY hCryptProv,
|
||||||
DWORD dwCertEncodingType, const BYTE *pbEncoded, DWORD cbEncoded,
|
DWORD dwCertEncodingType, const BYTE *pbEncoded, DWORD cbEncoded,
|
||||||
BYTE *pbComputedHash, DWORD *pcbComputedHash)
|
BYTE *pbComputedHash, DWORD *pcbComputedHash)
|
||||||
{
|
{
|
||||||
FIXME("(%08lx, %08x, %p, %d, %p, %d): stub\n", hCryptProv, dwCertEncodingType,
|
BOOL ret;
|
||||||
|
CERT_SIGNED_CONTENT_INFO *info;
|
||||||
|
DWORD size;
|
||||||
|
|
||||||
|
TRACE("(%08lx, %08x, %p, %d, %p, %d)\n", hCryptProv, dwCertEncodingType,
|
||||||
pbEncoded, cbEncoded, pbComputedHash, *pcbComputedHash);
|
pbEncoded, cbEncoded, pbComputedHash, *pcbComputedHash);
|
||||||
return FALSE;
|
|
||||||
|
ret = CryptDecodeObjectEx(dwCertEncodingType, X509_CERT,
|
||||||
|
pbEncoded, cbEncoded, CRYPT_DECODE_ALLOC_FLAG, NULL, (void *)&info, &size);
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
PCCRYPT_OID_INFO oidInfo;
|
||||||
|
HCRYPTHASH hHash;
|
||||||
|
|
||||||
|
if (!hCryptProv)
|
||||||
|
hCryptProv = CRYPT_GetDefaultProvider();
|
||||||
|
oidInfo = CryptFindOIDInfo(CRYPT_OID_INFO_OID_KEY,
|
||||||
|
info->SignatureAlgorithm.pszObjId, 0);
|
||||||
|
if (!oidInfo)
|
||||||
|
{
|
||||||
|
SetLastError(NTE_BAD_ALGID);
|
||||||
|
ret = FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ret = CryptCreateHash(hCryptProv, oidInfo->u.Algid, 0, 0, &hHash);
|
||||||
|
if (ret)
|
||||||
|
{
|
||||||
|
ret = CryptHashData(hHash, info->ToBeSigned.pbData,
|
||||||
|
info->ToBeSigned.cbData, 0);
|
||||||
|
if (ret)
|
||||||
|
ret = CryptGetHashParam(hHash, HP_HASHVAL, pbComputedHash,
|
||||||
|
pcbComputedHash, 0);
|
||||||
|
CryptDestroyHash(hHash);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LocalFree(info);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL WINAPI CryptSignCertificate(HCRYPTPROV_OR_NCRYPT_KEY_HANDLE hCryptProv,
|
BOOL WINAPI CryptSignCertificate(HCRYPTPROV_OR_NCRYPT_KEY_HANDLE hCryptProv,
|
||||||
|
|
|
@ -2575,33 +2575,28 @@ static void testHashToBeSigned(void)
|
||||||
"expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
|
"expected ERROR_FILE_NOT_FOUND, got %d\n", GetLastError());
|
||||||
SetLastError(0xdeadbeef);
|
SetLastError(0xdeadbeef);
|
||||||
ret = CryptHashToBeSigned(0, X509_ASN_ENCODING, NULL, 0, NULL, &size);
|
ret = CryptHashToBeSigned(0, X509_ASN_ENCODING, NULL, 0, NULL, &size);
|
||||||
todo_wine
|
|
||||||
ok(!ret && GetLastError() == CRYPT_E_ASN1_EOD,
|
ok(!ret && GetLastError() == CRYPT_E_ASN1_EOD,
|
||||||
"expected CRYPT_E_ASN1_EOD, got %08x\n", GetLastError());
|
"expected CRYPT_E_ASN1_EOD, got %08x\n", GetLastError());
|
||||||
/* Can't sign anything: has to be asn.1 encoded, at least */
|
/* Can't sign anything: has to be asn.1 encoded, at least */
|
||||||
SetLastError(0xdeadbeef);
|
SetLastError(0xdeadbeef);
|
||||||
ret = CryptHashToBeSigned(0, X509_ASN_ENCODING, int1, sizeof(int1),
|
ret = CryptHashToBeSigned(0, X509_ASN_ENCODING, int1, sizeof(int1),
|
||||||
NULL, &size);
|
NULL, &size);
|
||||||
todo_wine
|
|
||||||
ok(!ret && GetLastError() == CRYPT_E_ASN1_BADTAG,
|
ok(!ret && GetLastError() == CRYPT_E_ASN1_BADTAG,
|
||||||
"expected CRYPT_E_ASN1_BADTAG, got %08x\n", GetLastError());
|
"expected CRYPT_E_ASN1_BADTAG, got %08x\n", GetLastError());
|
||||||
/* Can't be empty, either */
|
/* Can't be empty, either */
|
||||||
SetLastError(0xdeadbeef);
|
SetLastError(0xdeadbeef);
|
||||||
ret = CryptHashToBeSigned(0, X509_ASN_ENCODING, emptyCert,
|
ret = CryptHashToBeSigned(0, X509_ASN_ENCODING, emptyCert,
|
||||||
sizeof(emptyCert), NULL, &size);
|
sizeof(emptyCert), NULL, &size);
|
||||||
todo_wine
|
|
||||||
ok(!ret && GetLastError() == CRYPT_E_ASN1_CORRUPT,
|
ok(!ret && GetLastError() == CRYPT_E_ASN1_CORRUPT,
|
||||||
"expected CRYPT_E_ASN1_CORRUPT, got %08x\n", GetLastError());
|
"expected CRYPT_E_ASN1_CORRUPT, got %08x\n", GetLastError());
|
||||||
/* Signing a cert works */
|
/* Signing a cert works */
|
||||||
ret = CryptHashToBeSigned(0, X509_ASN_ENCODING, md5SignedEmptyCert,
|
ret = CryptHashToBeSigned(0, X509_ASN_ENCODING, md5SignedEmptyCert,
|
||||||
sizeof(md5SignedEmptyCert), NULL, &size);
|
sizeof(md5SignedEmptyCert), NULL, &size);
|
||||||
todo_wine {
|
|
||||||
ok(ret, "CryptHashToBeSigned failed: %08x\n", GetLastError());
|
ok(ret, "CryptHashToBeSigned failed: %08x\n", GetLastError());
|
||||||
ok(size == sizeof(md5SignedEmptyCertHash), "unexpected size %d\n", size);
|
ok(size == sizeof(md5SignedEmptyCertHash), "unexpected size %d\n", size);
|
||||||
ret = CryptHashToBeSigned(0, X509_ASN_ENCODING, md5SignedEmptyCert,
|
ret = CryptHashToBeSigned(0, X509_ASN_ENCODING, md5SignedEmptyCert,
|
||||||
sizeof(md5SignedEmptyCert), hash, &size);
|
sizeof(md5SignedEmptyCert), hash, &size);
|
||||||
ok(!memcmp(hash, md5SignedEmptyCertHash, size), "unexpected value\n");
|
ok(!memcmp(hash, md5SignedEmptyCertHash, size), "unexpected value\n");
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void testCompareCert(void)
|
static void testCompareCert(void)
|
||||||
|
|
Loading…
Reference in New Issue