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,
|
BOOL CRYPT_EncodeEnsureSpace(DWORD dwFlags, PCRYPT_ENCODE_PARA pEncodePara,
|
||||||
BYTE *pbEncoded, DWORD *pcbEncoded, DWORD bytesNeeded);
|
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" */
|
/* The following aren't defined in wincrypt.h, as they're "reserved" */
|
||||||
#define CERT_CERT_PROP_ID 32
|
#define CERT_CERT_PROP_ID 32
|
||||||
#define CERT_CRL_PROP_ID 33
|
#define CERT_CRL_PROP_ID 33
|
||||||
|
|
|
@ -2308,6 +2308,27 @@ static BOOL WINAPI CRYPT_AsnDecodePKCSContent(DWORD dwCertEncodingType,
|
||||||
return ret;
|
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,
|
static BOOL WINAPI CRYPT_AsnDecodePKCSContentInfo(DWORD dwCertEncodingType,
|
||||||
LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, DWORD dwFlags,
|
LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, DWORD dwFlags,
|
||||||
PCRYPT_DECODE_PARA pDecodePara, void *pvStructInfo, DWORD *pcbStructInfo)
|
PCRYPT_DECODE_PARA pDecodePara, void *pvStructInfo, DWORD *pcbStructInfo)
|
||||||
|
@ -2319,19 +2340,28 @@ static BOOL WINAPI CRYPT_AsnDecodePKCSContentInfo(DWORD dwCertEncodingType,
|
||||||
|
|
||||||
__TRY
|
__TRY
|
||||||
{
|
{
|
||||||
struct AsnDecodeSequenceItem items[] = {
|
ret = CRYPT_AsnDecodePKCSContentInfoInternal(dwCertEncodingType,
|
||||||
{ ASN_OBJECTIDENTIFIER, offsetof(CRYPT_CONTENT_INFO, pszObjId),
|
lpszStructType, pbEncoded, cbEncoded,
|
||||||
CRYPT_AsnDecodeOidInternal, sizeof(LPSTR), FALSE, TRUE,
|
dwFlags & ~CRYPT_DECODE_ALLOC_FLAG, NULL, NULL, pcbStructInfo);
|
||||||
offsetof(CRYPT_CONTENT_INFO, pszObjId), 0 },
|
if (ret && pvStructInfo)
|
||||||
{ ASN_CONTEXT | ASN_CONSTRUCTOR | 0,
|
{
|
||||||
offsetof(CRYPT_CONTENT_INFO, Content), CRYPT_AsnDecodePKCSContent,
|
ret = CRYPT_DecodeEnsureSpace(dwFlags, pDecodePara, pvStructInfo,
|
||||||
sizeof(CRYPT_DER_BLOB), TRUE, TRUE,
|
pcbStructInfo, *pcbStructInfo);
|
||||||
offsetof(CRYPT_CONTENT_INFO, Content.pbData), 0 },
|
if (ret)
|
||||||
};
|
{
|
||||||
|
CRYPT_CONTENT_INFO *info;
|
||||||
|
|
||||||
ret = CRYPT_AsnDecodeSequence(dwCertEncodingType, items,
|
if (dwFlags & CRYPT_DECODE_ALLOC_FLAG)
|
||||||
sizeof(items) / sizeof(items[0]), pbEncoded, cbEncoded, dwFlags,
|
pvStructInfo = *(BYTE **)pvStructInfo;
|
||||||
pDecodePara, pvStructInfo, pcbStructInfo, NULL);
|
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
|
__EXCEPT_PAGE_FAULT
|
||||||
{
|
{
|
||||||
|
@ -2341,6 +2371,33 @@ static BOOL WINAPI CRYPT_AsnDecodePKCSContentInfo(DWORD dwCertEncodingType,
|
||||||
return ret;
|
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,
|
static BOOL WINAPI CRYPT_AsnDecodeAltName(DWORD dwCertEncodingType,
|
||||||
LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, DWORD dwFlags,
|
LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, DWORD dwFlags,
|
||||||
PCRYPT_DECODE_PARA pDecodePara, void *pvStructInfo, DWORD *pcbStructInfo)
|
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;
|
msg->type = CMSG_DATA;
|
||||||
break;
|
break;
|
||||||
case CMSG_HASHED:
|
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_ENVELOPED:
|
||||||
case CMSG_SIGNED:
|
case CMSG_SIGNED:
|
||||||
FIXME("unimplemented for type %s\n", MSG_TYPE_STR(type));
|
FIXME("unimplemented for type %s\n", MSG_TYPE_STR(type));
|
||||||
|
|
|
@ -1138,7 +1138,6 @@ static void test_decode_msg_update(void)
|
||||||
NULL);
|
NULL);
|
||||||
SetLastError(0xdeadbeef);
|
SetLastError(0xdeadbeef);
|
||||||
ret = CryptMsgUpdate(msg, hashEmptyContent, sizeof(hashEmptyContent), TRUE);
|
ret = CryptMsgUpdate(msg, hashEmptyContent, sizeof(hashEmptyContent), TRUE);
|
||||||
todo_wine
|
|
||||||
ok(!ret && GetLastError() == CRYPT_E_ASN1_BADTAG,
|
ok(!ret && GetLastError() == CRYPT_E_ASN1_BADTAG,
|
||||||
"Expected CRYPT_E_ASN1_BADTAG, got %x\n", GetLastError());
|
"Expected CRYPT_E_ASN1_BADTAG, got %x\n", GetLastError());
|
||||||
CryptMsgClose(msg);
|
CryptMsgClose(msg);
|
||||||
|
@ -1173,7 +1172,6 @@ static void test_decode_msg_update(void)
|
||||||
NULL);
|
NULL);
|
||||||
SetLastError(0xdeadbeef);
|
SetLastError(0xdeadbeef);
|
||||||
ret = CryptMsgUpdate(msg, hashContent, sizeof(hashContent), TRUE);
|
ret = CryptMsgUpdate(msg, hashContent, sizeof(hashContent), TRUE);
|
||||||
todo_wine
|
|
||||||
ok(!ret && GetLastError() == CRYPT_E_ASN1_BADTAG,
|
ok(!ret && GetLastError() == CRYPT_E_ASN1_BADTAG,
|
||||||
"Expected CRYPT_E_ASN1_BADTAG, got %x\n", GetLastError());
|
"Expected CRYPT_E_ASN1_BADTAG, got %x\n", GetLastError());
|
||||||
CryptMsgClose(msg);
|
CryptMsgClose(msg);
|
||||||
|
|
Loading…
Reference in New Issue