Commit ff0760dc authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

crypt32: Implement CTL decoding.

parent a9636136
...@@ -112,6 +112,9 @@ static BOOL CRYPT_AsnDecodeIntegerInternal(const BYTE *pbEncoded, ...@@ -112,6 +112,9 @@ static BOOL CRYPT_AsnDecodeIntegerInternal(const BYTE *pbEncoded,
static BOOL CRYPT_AsnDecodeUnsignedIntegerInternal(const BYTE *pbEncoded, static BOOL CRYPT_AsnDecodeUnsignedIntegerInternal(const BYTE *pbEncoded,
DWORD cbEncoded, DWORD dwFlags, void *pvStructInfo, DWORD *pcbStructInfo, DWORD cbEncoded, DWORD dwFlags, void *pvStructInfo, DWORD *pcbStructInfo,
DWORD *pcbDecoded); DWORD *pcbDecoded);
static BOOL CRYPT_AsnDecodePKCSAttributesInternal(const BYTE *pbEncoded,
DWORD cbEncoded, DWORD dwFlags, void *pvStructInfo, DWORD *pcbStructInfo,
DWORD *pcbDecoded);
/* Gets the number of length bytes from the given (leading) length byte */ /* Gets the number of length bytes from the given (leading) length byte */
#define GET_LEN_BYTES(b) ((b) <= 0x80 ? 1 : 1 + ((b) & 0x7f)) #define GET_LEN_BYTES(b) ((b) <= 0x80 ? 1 : 1 + ((b) & 0x7f))
...@@ -2033,6 +2036,116 @@ static BOOL CRYPT_DecodeDERArray(const BYTE *pbEncoded, DWORD cbEncoded, ...@@ -2033,6 +2036,116 @@ static BOOL CRYPT_DecodeDERArray(const BYTE *pbEncoded, DWORD cbEncoded,
return ret; return ret;
} }
static BOOL CRYPT_AsnDecodeCTLUsage(const BYTE *pbEncoded, DWORD cbEncoded,
DWORD dwFlags, void *pvStructInfo, DWORD *pcbStructInfo, DWORD *pcbDecoded)
{
BOOL ret;
struct AsnArrayDescriptor arrayDesc = { ASN_SEQUENCEOF,
CRYPT_AsnDecodeOidInternal, sizeof(LPSTR), TRUE, 0 };
CTL_USAGE *usage = (CTL_USAGE *)pvStructInfo;
ret = CRYPT_AsnDecodeArray(&arrayDesc, pbEncoded, cbEncoded, dwFlags,
NULL, pvStructInfo, pcbStructInfo, pcbDecoded,
usage ? usage->rgpszUsageIdentifier : NULL);
return ret;
}
static BOOL CRYPT_AsnDecodeCTLEntry(const BYTE *pbEncoded, DWORD cbEncoded,
DWORD dwFlags, void *pvStructInfo, DWORD *pcbStructInfo, DWORD *pcbDecoded)
{
struct AsnDecodeSequenceItem items[] = {
{ ASN_OCTETSTRING, offsetof(CTL_ENTRY, SubjectIdentifier),
CRYPT_AsnDecodeOctetsInternal, sizeof(CRYPT_DATA_BLOB), FALSE, TRUE,
offsetof(CTL_ENTRY, SubjectIdentifier.pbData), 0 },
{ ASN_CONSTRUCTOR | ASN_SETOF, offsetof(CTL_ENTRY, cAttribute),
CRYPT_AsnDecodePKCSAttributesInternal, sizeof(CRYPT_ATTRIBUTES), FALSE,
TRUE, offsetof(CTL_ENTRY, rgAttribute), 0 },
};
BOOL ret = TRUE;
CTL_ENTRY *entry = (CTL_ENTRY *)pvStructInfo;
TRACE("%p, %d, %08x, %p, %d\n", pbEncoded, cbEncoded, dwFlags, entry,
*pcbStructInfo);
ret = CRYPT_AsnDecodeSequence(items, sizeof(items) / sizeof(items[0]),
pbEncoded, cbEncoded, dwFlags, NULL, entry, pcbStructInfo,
pcbDecoded, entry ? entry->SubjectIdentifier.pbData : NULL);
return ret;
}
static BOOL CRYPT_AsnDecodeCTLEntries(const BYTE *pbEncoded, DWORD cbEncoded,
DWORD dwFlags, void *pvStructInfo, DWORD *pcbStructInfo, DWORD *pcbDecoded)
{
BOOL ret;
struct AsnArrayDescriptor arrayDesc = { ASN_SEQUENCEOF,
CRYPT_AsnDecodeCTLEntry, sizeof(CTL_ENTRY), TRUE,
offsetof(CTL_ENTRY, SubjectIdentifier.pbData) };
struct GenericArray *entries = (struct GenericArray *)pvStructInfo;
TRACE("%p, %d, %08x, %p, %d, %p\n", pbEncoded, cbEncoded, dwFlags,
pvStructInfo, *pcbStructInfo, pcbDecoded);
ret = CRYPT_AsnDecodeArray(&arrayDesc, pbEncoded, cbEncoded, dwFlags,
NULL, pvStructInfo, pcbStructInfo, pcbDecoded,
entries ? entries->rgItems : NULL);
return ret;
}
static BOOL WINAPI CRYPT_AsnDecodeCTL(DWORD dwCertEncodingType,
LPCSTR lpszStructType, const BYTE *pbEncoded, DWORD cbEncoded, DWORD dwFlags,
PCRYPT_DECODE_PARA pDecodePara, void *pvStructInfo, DWORD *pcbStructInfo)
{
BOOL ret = FALSE;
TRACE("%p, %d, %08x, %p, %p, %d\n", pbEncoded, cbEncoded, dwFlags,
pDecodePara, pvStructInfo, *pcbStructInfo);
__TRY
{
struct AsnDecodeSequenceItem items[] = {
{ ASN_INTEGER, offsetof(CTL_INFO, dwVersion),
CRYPT_AsnDecodeIntInternal, sizeof(DWORD), TRUE, FALSE, 0, 0 },
{ ASN_SEQUENCEOF, offsetof(CTL_INFO, SubjectUsage),
CRYPT_AsnDecodeCTLUsage, sizeof(CTL_USAGE), FALSE, TRUE,
offsetof(CTL_INFO, SubjectUsage.rgpszUsageIdentifier), 0 },
{ ASN_OCTETSTRING, offsetof(CTL_INFO, ListIdentifier),
CRYPT_AsnDecodeOctetsInternal, sizeof(CRYPT_DATA_BLOB), TRUE,
TRUE, offsetof(CTL_INFO, ListIdentifier.pbData), 0 },
{ ASN_INTEGER, offsetof(CTL_INFO, SequenceNumber),
CRYPT_AsnDecodeIntegerInternal, sizeof(CRYPT_INTEGER_BLOB),
TRUE, TRUE, offsetof(CTL_INFO, SequenceNumber.pbData), 0 },
{ 0, offsetof(CTL_INFO, ThisUpdate),
CRYPT_AsnDecodeChoiceOfTimeInternal, sizeof(FILETIME), FALSE, FALSE,
0 },
{ 0, offsetof(CTL_INFO, NextUpdate),
CRYPT_AsnDecodeChoiceOfTimeInternal, sizeof(FILETIME), TRUE, FALSE,
0 },
{ ASN_SEQUENCEOF, offsetof(CTL_INFO, SubjectAlgorithm),
CRYPT_AsnDecodeAlgorithmId, sizeof(CRYPT_ALGORITHM_IDENTIFIER),
FALSE, TRUE, offsetof(CTL_INFO, SubjectAlgorithm.pszObjId), 0 },
{ ASN_SEQUENCEOF, offsetof(CTL_INFO, cCTLEntry),
CRYPT_AsnDecodeCTLEntries, sizeof(struct GenericArray),
TRUE, TRUE, offsetof(CTL_INFO, rgCTLEntry), 0 },
{ ASN_CONTEXT | ASN_CONSTRUCTOR | 0, offsetof(CTL_INFO, cExtension),
CRYPT_AsnDecodeCertExtensions, sizeof(CERT_EXTENSIONS), TRUE, TRUE,
offsetof(CTL_INFO, rgExtension), 0 },
};
TRACE("%p, %d, %08x, %p, %p, %d\n", pbEncoded, cbEncoded, dwFlags,
pDecodePara, pvStructInfo, *pcbStructInfo);
ret = CRYPT_AsnDecodeSequence(items, sizeof(items) / sizeof(items[0]),
pbEncoded, cbEncoded, dwFlags, pDecodePara, pvStructInfo,
pcbStructInfo, NULL, NULL);
}
__EXCEPT_PAGE_FAULT
{
SetLastError(STATUS_ACCESS_VIOLATION);
}
__ENDTRY
return ret;
}
static BOOL CRYPT_AsnDecodeSMIMECapability(const BYTE *pbEncoded, static BOOL CRYPT_AsnDecodeSMIMECapability(const BYTE *pbEncoded,
DWORD cbEncoded, DWORD dwFlags, void *pvStructInfo, DWORD *pcbStructInfo, DWORD cbEncoded, DWORD dwFlags, void *pvStructInfo, DWORD *pcbStructInfo,
DWORD *pcbDecoded) DWORD *pcbDecoded)
...@@ -4750,6 +4863,9 @@ static CryptDecodeObjectExFunc CRYPT_GetBuiltinDecoder(DWORD dwCertEncodingType, ...@@ -4750,6 +4863,9 @@ static CryptDecodeObjectExFunc CRYPT_GetBuiltinDecoder(DWORD dwCertEncodingType,
case LOWORD(X509_ENHANCED_KEY_USAGE): case LOWORD(X509_ENHANCED_KEY_USAGE):
decodeFunc = CRYPT_AsnDecodeEnhancedKeyUsage; decodeFunc = CRYPT_AsnDecodeEnhancedKeyUsage;
break; break;
case LOWORD(PKCS_CTL):
decodeFunc = CRYPT_AsnDecodeCTL;
break;
case LOWORD(PKCS_SMIME_CAPABILITIES): case LOWORD(PKCS_SMIME_CAPABILITIES):
decodeFunc = CRYPT_AsnDecodeSMIMECapabilities; decodeFunc = CRYPT_AsnDecodeSMIMECapabilities;
break; break;
...@@ -4810,6 +4926,8 @@ static CryptDecodeObjectExFunc CRYPT_GetBuiltinDecoder(DWORD dwCertEncodingType, ...@@ -4810,6 +4926,8 @@ static CryptDecodeObjectExFunc CRYPT_GetBuiltinDecoder(DWORD dwCertEncodingType,
decodeFunc = CRYPT_AsnDecodeNameConstraints; decodeFunc = CRYPT_AsnDecodeNameConstraints;
else if (!strcmp(lpszStructType, szOID_AUTHORITY_INFO_ACCESS)) else if (!strcmp(lpszStructType, szOID_AUTHORITY_INFO_ACCESS))
decodeFunc = CRYPT_AsnDecodeAuthorityInfoAccess; decodeFunc = CRYPT_AsnDecodeAuthorityInfoAccess;
else if (!strcmp(lpszStructType, szOID_CTL))
decodeFunc = CRYPT_AsnDecodeCTL;
return decodeFunc; return decodeFunc;
} }
......
...@@ -5303,7 +5303,6 @@ static void test_decodeCTL(DWORD dwEncoding) ...@@ -5303,7 +5303,6 @@ static void test_decodeCTL(DWORD dwEncoding)
memset(&info, 0, sizeof(info)); memset(&info, 0, sizeof(info));
ret = CryptDecodeObjectEx(dwEncoding, PKCS_CTL, emptyCTL, sizeof(emptyCTL), ret = CryptDecodeObjectEx(dwEncoding, PKCS_CTL, emptyCTL, sizeof(emptyCTL),
CRYPT_DECODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size); CRYPT_DECODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
todo_wine
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError()); ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
if (buf) if (buf)
{ {
...@@ -5315,7 +5314,6 @@ static void test_decodeCTL(DWORD dwEncoding) ...@@ -5315,7 +5314,6 @@ static void test_decodeCTL(DWORD dwEncoding)
ret = CryptDecodeObjectEx(dwEncoding, PKCS_CTL, emptyCTLWithVersion1, ret = CryptDecodeObjectEx(dwEncoding, PKCS_CTL, emptyCTLWithVersion1,
sizeof(emptyCTLWithVersion1), CRYPT_DECODE_ALLOC_FLAG, NULL, (BYTE *)&buf, sizeof(emptyCTLWithVersion1), CRYPT_DECODE_ALLOC_FLAG, NULL, (BYTE *)&buf,
&size); &size);
todo_wine
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError()); ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
if (buf) if (buf)
{ {
...@@ -5329,7 +5327,6 @@ static void test_decodeCTL(DWORD dwEncoding) ...@@ -5329,7 +5327,6 @@ static void test_decodeCTL(DWORD dwEncoding)
ret = CryptDecodeObjectEx(dwEncoding, PKCS_CTL, ctlWithUsageIdentifier, ret = CryptDecodeObjectEx(dwEncoding, PKCS_CTL, ctlWithUsageIdentifier,
sizeof(ctlWithUsageIdentifier), CRYPT_DECODE_ALLOC_FLAG, NULL, sizeof(ctlWithUsageIdentifier), CRYPT_DECODE_ALLOC_FLAG, NULL,
(BYTE *)&buf, &size); (BYTE *)&buf, &size);
todo_wine
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError()); ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
if (buf) if (buf)
{ {
...@@ -5343,7 +5340,6 @@ static void test_decodeCTL(DWORD dwEncoding) ...@@ -5343,7 +5340,6 @@ static void test_decodeCTL(DWORD dwEncoding)
ret = CryptDecodeObjectEx(dwEncoding, PKCS_CTL, ctlWithListIdentifier, ret = CryptDecodeObjectEx(dwEncoding, PKCS_CTL, ctlWithListIdentifier,
sizeof(ctlWithListIdentifier), CRYPT_DECODE_ALLOC_FLAG, NULL, sizeof(ctlWithListIdentifier), CRYPT_DECODE_ALLOC_FLAG, NULL,
(BYTE *)&buf, &size); (BYTE *)&buf, &size);
todo_wine
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError()); ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
if (buf) if (buf)
{ {
...@@ -5357,7 +5353,6 @@ static void test_decodeCTL(DWORD dwEncoding) ...@@ -5357,7 +5353,6 @@ static void test_decodeCTL(DWORD dwEncoding)
ret = CryptDecodeObjectEx(dwEncoding, PKCS_CTL, ctlWithSequenceNumber, ret = CryptDecodeObjectEx(dwEncoding, PKCS_CTL, ctlWithSequenceNumber,
sizeof(ctlWithSequenceNumber), CRYPT_DECODE_ALLOC_FLAG, NULL, sizeof(ctlWithSequenceNumber), CRYPT_DECODE_ALLOC_FLAG, NULL,
(BYTE *)&buf, &size); (BYTE *)&buf, &size);
todo_wine
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError()); ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
if (buf) if (buf)
{ {
...@@ -5370,7 +5365,6 @@ static void test_decodeCTL(DWORD dwEncoding) ...@@ -5370,7 +5365,6 @@ static void test_decodeCTL(DWORD dwEncoding)
ret = CryptDecodeObjectEx(dwEncoding, PKCS_CTL, ctlWithThisUpdate, ret = CryptDecodeObjectEx(dwEncoding, PKCS_CTL, ctlWithThisUpdate,
sizeof(ctlWithThisUpdate), CRYPT_DECODE_ALLOC_FLAG, NULL, sizeof(ctlWithThisUpdate), CRYPT_DECODE_ALLOC_FLAG, NULL,
(BYTE *)&buf, &size); (BYTE *)&buf, &size);
todo_wine
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError()); ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
if (buf) if (buf)
{ {
...@@ -5382,7 +5376,6 @@ static void test_decodeCTL(DWORD dwEncoding) ...@@ -5382,7 +5376,6 @@ static void test_decodeCTL(DWORD dwEncoding)
ret = CryptDecodeObjectEx(dwEncoding, PKCS_CTL, ctlWithThisAndNextUpdate, ret = CryptDecodeObjectEx(dwEncoding, PKCS_CTL, ctlWithThisAndNextUpdate,
sizeof(ctlWithThisAndNextUpdate), CRYPT_DECODE_ALLOC_FLAG, NULL, sizeof(ctlWithThisAndNextUpdate), CRYPT_DECODE_ALLOC_FLAG, NULL,
(BYTE *)&buf, &size); (BYTE *)&buf, &size);
todo_wine
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError()); ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
if (buf) if (buf)
{ {
...@@ -5398,7 +5391,6 @@ static void test_decodeCTL(DWORD dwEncoding) ...@@ -5398,7 +5391,6 @@ static void test_decodeCTL(DWORD dwEncoding)
ret = CryptDecodeObjectEx(dwEncoding, PKCS_CTL, ctlWithAlgId, ret = CryptDecodeObjectEx(dwEncoding, PKCS_CTL, ctlWithAlgId,
sizeof(ctlWithAlgId), CRYPT_DECODE_ALLOC_FLAG, NULL, sizeof(ctlWithAlgId), CRYPT_DECODE_ALLOC_FLAG, NULL,
(BYTE *)&buf, &size); (BYTE *)&buf, &size);
todo_wine
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError()); ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
if (buf) if (buf)
{ {
...@@ -5410,9 +5402,9 @@ static void test_decodeCTL(DWORD dwEncoding) ...@@ -5410,9 +5402,9 @@ static void test_decodeCTL(DWORD dwEncoding)
ret = CryptDecodeObjectEx(dwEncoding, PKCS_CTL, ctlWithBogusEntry, ret = CryptDecodeObjectEx(dwEncoding, PKCS_CTL, ctlWithBogusEntry,
sizeof(ctlWithBogusEntry), CRYPT_DECODE_ALLOC_FLAG, NULL, sizeof(ctlWithBogusEntry), CRYPT_DECODE_ALLOC_FLAG, NULL,
(BYTE *)&buf, &size); (BYTE *)&buf, &size);
todo_wine ok(!ret && (GetLastError() == CRYPT_E_ASN1_EOD || CRYPT_E_ASN1_CORRUPT),
ok(!ret && GetLastError() == CRYPT_E_ASN1_EOD, "expected CRYPT_E_ASN1_EOD or CRYPT_E_ASN1_CORRUPT, got %08x\n",
"expected CRYPT_E_ASN1_EOD, got %08x\n", GetLastError()); GetLastError());
info.SubjectAlgorithm.Parameters.cbData = 0; info.SubjectAlgorithm.Parameters.cbData = 0;
info.ThisUpdate.dwLowDateTime = info.ThisUpdate.dwHighDateTime = 0; info.ThisUpdate.dwLowDateTime = info.ThisUpdate.dwHighDateTime = 0;
info.NextUpdate.dwLowDateTime = info.NextUpdate.dwHighDateTime = 0; info.NextUpdate.dwLowDateTime = info.NextUpdate.dwHighDateTime = 0;
...@@ -5433,7 +5425,6 @@ static void test_decodeCTL(DWORD dwEncoding) ...@@ -5433,7 +5425,6 @@ static void test_decodeCTL(DWORD dwEncoding)
ret = CryptDecodeObjectEx(dwEncoding, PKCS_CTL, ctlWithOneEntry, ret = CryptDecodeObjectEx(dwEncoding, PKCS_CTL, ctlWithOneEntry,
sizeof(ctlWithOneEntry), CRYPT_DECODE_ALLOC_FLAG, NULL, sizeof(ctlWithOneEntry), CRYPT_DECODE_ALLOC_FLAG, NULL,
(BYTE *)&buf, &size); (BYTE *)&buf, &size);
todo_wine
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError()); ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
if (buf) if (buf)
{ {
...@@ -5454,7 +5445,6 @@ static void test_decodeCTL(DWORD dwEncoding) ...@@ -5454,7 +5445,6 @@ static void test_decodeCTL(DWORD dwEncoding)
ret = CryptDecodeObjectEx(dwEncoding, PKCS_CTL, ctlWithTwoEntries, ret = CryptDecodeObjectEx(dwEncoding, PKCS_CTL, ctlWithTwoEntries,
sizeof(ctlWithTwoEntries), CRYPT_DECODE_ALLOC_FLAG, NULL, sizeof(ctlWithTwoEntries), CRYPT_DECODE_ALLOC_FLAG, NULL,
(BYTE *)&buf, &size); (BYTE *)&buf, &size);
todo_wine
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError()); ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
if (buf) if (buf)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment