mirror of
https://github.com/reactos/wine.git
synced 2024-11-29 06:30:37 +00:00
crypt32: Implement decoding hash messages.
This commit is contained in:
parent
8cf82d8a0e
commit
35abf3adf3
@ -90,6 +90,10 @@ BOOL CRYPT_AsnEncodePKCSDigestedData(CRYPT_DIGESTED_DATA *digestedData,
|
||||
BOOL CRYPT_EncodeEnsureSpace(DWORD dwFlags, PCRYPT_ENCODE_PARA pEncodePara,
|
||||
BYTE *pbEncoded, DWORD *pcbEncoded, DWORD bytesNeeded);
|
||||
|
||||
BOOL CRYPT_AsnDecodePKCSDigestedData(const BYTE *pbEncoded, DWORD cbEncoded,
|
||||
DWORD dwFlags, PCRYPT_DECODE_PARA pDecodePara,
|
||||
CRYPT_DIGESTED_DATA *digestedData, DWORD *pcbDigestedData);
|
||||
|
||||
/* The following aren't defined in wincrypt.h, as they're "reserved" */
|
||||
#define CERT_CERT_PROP_ID 32
|
||||
#define CERT_CRL_PROP_ID 33
|
||||
|
@ -2308,6 +2308,27 @@ static BOOL WINAPI CRYPT_AsnDecodePKCSContent(DWORD dwCertEncodingType,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static BOOL WINAPI CRYPT_AsnDecodePKCSContentInfoInternal(
|
||||
DWORD dwCertEncodingType, LPCSTR lpszStructType, const BYTE *pbEncoded,
|
||||
DWORD cbEncoded, DWORD dwFlags, PCRYPT_DECODE_PARA pDecodePara,
|
||||
void *pvStructInfo, DWORD *pcbStructInfo)
|
||||
{
|
||||
CRYPT_CONTENT_INFO *info = (CRYPT_CONTENT_INFO *)pvStructInfo;
|
||||
struct AsnDecodeSequenceItem items[] = {
|
||||
{ ASN_OBJECTIDENTIFIER, offsetof(CRYPT_CONTENT_INFO, pszObjId),
|
||||
CRYPT_AsnDecodeOidInternal, sizeof(LPSTR), FALSE, TRUE,
|
||||
offsetof(CRYPT_CONTENT_INFO, pszObjId), 0 },
|
||||
{ ASN_CONTEXT | ASN_CONSTRUCTOR | 0,
|
||||
offsetof(CRYPT_CONTENT_INFO, Content), CRYPT_AsnDecodePKCSContent,
|
||||
sizeof(CRYPT_DER_BLOB), TRUE, TRUE,
|
||||
offsetof(CRYPT_CONTENT_INFO, Content.pbData), 0 },
|
||||
};
|
||||
|
||||
return CRYPT_AsnDecodeSequence(dwCertEncodingType, items,
|
||||
sizeof(items) / sizeof(items[0]), pbEncoded, cbEncoded, dwFlags,
|
||||
pDecodePara, pvStructInfo, pcbStructInfo, info ? info->pszObjId : NULL);
|
||||
}
|
||||
|
||||
static BOOL WINAPI CRYPT_AsnDecodePKCSContentInfo(DWORD dwCertEncodingType,
|
||||
LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, DWORD dwFlags,
|
||||
PCRYPT_DECODE_PARA pDecodePara, void *pvStructInfo, DWORD *pcbStructInfo)
|
||||
@ -2319,19 +2340,28 @@ static BOOL WINAPI CRYPT_AsnDecodePKCSContentInfo(DWORD dwCertEncodingType,
|
||||
|
||||
__TRY
|
||||
{
|
||||
struct AsnDecodeSequenceItem items[] = {
|
||||
{ ASN_OBJECTIDENTIFIER, offsetof(CRYPT_CONTENT_INFO, pszObjId),
|
||||
CRYPT_AsnDecodeOidInternal, sizeof(LPSTR), FALSE, TRUE,
|
||||
offsetof(CRYPT_CONTENT_INFO, pszObjId), 0 },
|
||||
{ ASN_CONTEXT | ASN_CONSTRUCTOR | 0,
|
||||
offsetof(CRYPT_CONTENT_INFO, Content), CRYPT_AsnDecodePKCSContent,
|
||||
sizeof(CRYPT_DER_BLOB), TRUE, TRUE,
|
||||
offsetof(CRYPT_CONTENT_INFO, Content.pbData), 0 },
|
||||
};
|
||||
ret = CRYPT_AsnDecodePKCSContentInfoInternal(dwCertEncodingType,
|
||||
lpszStructType, pbEncoded, cbEncoded,
|
||||
dwFlags & ~CRYPT_DECODE_ALLOC_FLAG, NULL, NULL, pcbStructInfo);
|
||||
if (ret && pvStructInfo)
|
||||
{
|
||||
ret = CRYPT_DecodeEnsureSpace(dwFlags, pDecodePara, pvStructInfo,
|
||||
pcbStructInfo, *pcbStructInfo);
|
||||
if (ret)
|
||||
{
|
||||
CRYPT_CONTENT_INFO *info;
|
||||
|
||||
ret = CRYPT_AsnDecodeSequence(dwCertEncodingType, items,
|
||||
sizeof(items) / sizeof(items[0]), pbEncoded, cbEncoded, dwFlags,
|
||||
pDecodePara, pvStructInfo, pcbStructInfo, NULL);
|
||||
if (dwFlags & CRYPT_DECODE_ALLOC_FLAG)
|
||||
pvStructInfo = *(BYTE **)pvStructInfo;
|
||||
info = (CRYPT_CONTENT_INFO *)pvStructInfo;
|
||||
info->pszObjId = (LPSTR)((BYTE *)info +
|
||||
sizeof(CRYPT_CONTENT_INFO));
|
||||
ret = CRYPT_AsnDecodePKCSContentInfoInternal(dwCertEncodingType,
|
||||
lpszStructType, pbEncoded, cbEncoded,
|
||||
dwFlags & ~CRYPT_DECODE_ALLOC_FLAG, NULL, pvStructInfo,
|
||||
pcbStructInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
__EXCEPT_PAGE_FAULT
|
||||
{
|
||||
@ -2341,6 +2371,33 @@ static BOOL WINAPI CRYPT_AsnDecodePKCSContentInfo(DWORD dwCertEncodingType,
|
||||
return ret;
|
||||
}
|
||||
|
||||
BOOL CRYPT_AsnDecodePKCSDigestedData(const BYTE *pbEncoded, DWORD cbEncoded,
|
||||
DWORD dwFlags, PCRYPT_DECODE_PARA pDecodePara,
|
||||
CRYPT_DIGESTED_DATA *digestedData, DWORD *pcbDigestedData)
|
||||
{
|
||||
BOOL ret;
|
||||
struct AsnDecodeSequenceItem items[] = {
|
||||
{ ASN_INTEGER, offsetof(CRYPT_DIGESTED_DATA, version), CRYPT_AsnDecodeInt,
|
||||
sizeof(DWORD), FALSE, FALSE, 0, 0 },
|
||||
{ ASN_SEQUENCEOF, offsetof(CRYPT_DIGESTED_DATA, DigestAlgorithm),
|
||||
CRYPT_AsnDecodeAlgorithmId, sizeof(CRYPT_ALGORITHM_IDENTIFIER),
|
||||
FALSE, TRUE, offsetof(CRYPT_DIGESTED_DATA, DigestAlgorithm.pszObjId),
|
||||
0 },
|
||||
{ ASN_SEQUENCEOF, offsetof(CRYPT_DIGESTED_DATA, ContentInfo),
|
||||
CRYPT_AsnDecodePKCSContentInfoInternal,
|
||||
sizeof(CRYPT_CONTENT_INFO), FALSE, TRUE, offsetof(CRYPT_DIGESTED_DATA,
|
||||
ContentInfo.pszObjId), 0 },
|
||||
{ ASN_OCTETSTRING, offsetof(CRYPT_DIGESTED_DATA, hash),
|
||||
CRYPT_AsnDecodeOctetsInternal, sizeof(CRYPT_HASH_BLOB), FALSE, TRUE,
|
||||
offsetof(CRYPT_DIGESTED_DATA, hash.pbData), 0 },
|
||||
};
|
||||
|
||||
ret = CRYPT_AsnDecodeSequence(X509_ASN_ENCODING, items,
|
||||
sizeof(items) / sizeof(items[0]), pbEncoded, cbEncoded, dwFlags,
|
||||
pDecodePara, digestedData, pcbDigestedData, NULL);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static BOOL WINAPI CRYPT_AsnDecodeAltName(DWORD dwCertEncodingType,
|
||||
LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, DWORD dwFlags,
|
||||
PCRYPT_DECODE_PARA pDecodePara, void *pvStructInfo, DWORD *pcbStructInfo)
|
||||
|
@ -652,6 +652,19 @@ static BOOL CDecodeMsg_DecodeContent(CDecodeMsg *msg, CRYPT_DER_BLOB *blob,
|
||||
msg->type = CMSG_DATA;
|
||||
break;
|
||||
case CMSG_HASHED:
|
||||
{
|
||||
CRYPT_DIGESTED_DATA *digestedData;
|
||||
|
||||
ret = CRYPT_AsnDecodePKCSDigestedData(blob->pbData, blob->cbData,
|
||||
CRYPT_DECODE_ALLOC_FLAG, NULL, (CRYPT_DIGESTED_DATA *)&digestedData,
|
||||
&size);
|
||||
if (ret)
|
||||
{
|
||||
FIXME("need to store data for CMSG_HASHED\n");
|
||||
LocalFree(digestedData);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CMSG_ENVELOPED:
|
||||
case CMSG_SIGNED:
|
||||
FIXME("unimplemented for type %s\n", MSG_TYPE_STR(type));
|
||||
|
@ -1138,7 +1138,6 @@ static void test_decode_msg_update(void)
|
||||
NULL);
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = CryptMsgUpdate(msg, hashEmptyContent, sizeof(hashEmptyContent), TRUE);
|
||||
todo_wine
|
||||
ok(!ret && GetLastError() == CRYPT_E_ASN1_BADTAG,
|
||||
"Expected CRYPT_E_ASN1_BADTAG, got %x\n", GetLastError());
|
||||
CryptMsgClose(msg);
|
||||
@ -1173,7 +1172,6 @@ static void test_decode_msg_update(void)
|
||||
NULL);
|
||||
SetLastError(0xdeadbeef);
|
||||
ret = CryptMsgUpdate(msg, hashContent, sizeof(hashContent), TRUE);
|
||||
todo_wine
|
||||
ok(!ret && GetLastError() == CRYPT_E_ASN1_BADTAG,
|
||||
"Expected CRYPT_E_ASN1_BADTAG, got %x\n", GetLastError());
|
||||
CryptMsgClose(msg);
|
||||
|
Loading…
Reference in New Issue
Block a user