crypt32: Introduce an algorithm id encoding function that encodes missing parameters as NULL
and use it to match native encoding (and simplify PKCS signer tests).
This commit is contained in:
parent
880507d906
commit
678fb8ac14
|
@ -394,10 +394,38 @@ static BOOL WINAPI CRYPT_AsnEncodeValidity(DWORD dwCertEncodingType,
|
|||
return ret;
|
||||
}
|
||||
|
||||
static BOOL WINAPI CRYPT_AsnEncodeAlgorithmId(
|
||||
/* Like CRYPT_AsnEncodeAlgorithmId, but encodes parameters as an asn.1 NULL
|
||||
* if they are empty.
|
||||
*/
|
||||
static BOOL WINAPI CRYPT_AsnEncodeAlgorithmIdWithNullParams(
|
||||
DWORD dwCertEncodingType, LPCSTR lpszStructType, const void *pvStructInfo,
|
||||
DWORD dwFlags, PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded,
|
||||
DWORD *pcbEncoded)
|
||||
{
|
||||
const CRYPT_ALGORITHM_IDENTIFIER *algo =
|
||||
(const CRYPT_ALGORITHM_IDENTIFIER *)pvStructInfo;
|
||||
static const BYTE asn1Null[] = { ASN_NULL, 0 };
|
||||
static const CRYPT_DATA_BLOB nullBlob = { sizeof(asn1Null),
|
||||
(LPBYTE)asn1Null };
|
||||
BOOL ret;
|
||||
struct AsnEncodeSequenceItem items[2] = {
|
||||
{ algo->pszObjId, CRYPT_AsnEncodeOid, 0 },
|
||||
{ NULL, CRYPT_CopyEncodedBlob, 0 },
|
||||
};
|
||||
|
||||
if (algo->Parameters.cbData)
|
||||
items[1].pvStructInfo = &algo->Parameters;
|
||||
else
|
||||
items[1].pvStructInfo = &nullBlob;
|
||||
ret = CRYPT_AsnEncodeSequence(dwCertEncodingType, items,
|
||||
sizeof(items) / sizeof(items[0]), dwFlags, pEncodePara, pbEncoded,
|
||||
pcbEncoded);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static BOOL WINAPI CRYPT_AsnEncodeAlgorithmId(DWORD dwCertEncodingType,
|
||||
LPCSTR lpszStructType, const void *pvStructInfo, DWORD dwFlags,
|
||||
PCRYPT_ENCODE_PARA pEncodePara, BYTE *pbEncoded, DWORD *pcbEncoded)
|
||||
{
|
||||
const CRYPT_ALGORITHM_IDENTIFIER *algo =
|
||||
(const CRYPT_ALGORITHM_IDENTIFIER *)pvStructInfo;
|
||||
|
@ -1455,7 +1483,6 @@ static BOOL WINAPI CRYPT_AsnEncodePKCSContentInfo(DWORD dwCertEncodingType,
|
|||
ret = CRYPT_AsnEncodeSequence(dwCertEncodingType, items,
|
||||
cItem, dwFlags, pEncodePara, pbEncoded, pcbEncoded);
|
||||
}
|
||||
|
||||
}
|
||||
__EXCEPT_PAGE_FAULT
|
||||
{
|
||||
|
@ -3098,8 +3125,10 @@ static BOOL WINAPI CRYPT_AsnEncodePKCSSignerInfo(DWORD dwCertEncodingType,
|
|||
struct AsnEncodeSequenceItem items[7] = {
|
||||
{ &info->dwVersion, CRYPT_AsnEncodeInt, 0 },
|
||||
{ &info->Issuer, CRYPT_AsnEncodeIssuerSerialNumber, 0 },
|
||||
{ &info->HashAlgorithm, CRYPT_AsnEncodeAlgorithmId, 0 },
|
||||
{ &info->HashEncryptionAlgorithm, CRYPT_AsnEncodeAlgorithmId, 0 },
|
||||
{ &info->HashAlgorithm, CRYPT_AsnEncodeAlgorithmIdWithNullParams,
|
||||
0 },
|
||||
{ &info->HashEncryptionAlgorithm,
|
||||
CRYPT_AsnEncodeAlgorithmIdWithNullParams, 0 },
|
||||
};
|
||||
DWORD cItem = 4;
|
||||
|
||||
|
|
|
@ -4870,57 +4870,31 @@ static void test_decodePKCSAttributes(DWORD dwEncoding)
|
|||
static BYTE encodedCommonNameNoNull[] = { 0x30,0x14,0x31,0x12,0x30,0x10,
|
||||
0x06,0x03,0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,
|
||||
0x67 };
|
||||
/* As with the algorithm ID tests, accept the algorithm ID parameters either as
|
||||
* NULL or as nonexistent.
|
||||
*/
|
||||
static const BYTE minimalPKCSSigner[] = {
|
||||
0x30,0x2b,0x02,0x01,0x00,0x30,0x18,0x30,0x14,0x31,0x12,0x30,0x10,0x06,0x03,
|
||||
0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x02,
|
||||
0x00,0x30,0x04,0x06,0x00,0x05,0x00,0x30,0x04,0x06,0x00,0x05,0x00,0x04,0x00 };
|
||||
static const BYTE minimalPKCSSignerNoNull[] = {
|
||||
0x30,0x27,0x02,0x01,0x00,0x30,0x18,0x30,0x14,0x31,0x12,0x30,0x10,0x06,0x03,
|
||||
0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x02,
|
||||
0x00,0x30,0x02,0x06,0x00,0x30,0x02,0x06,0x00,0x04,0x00 };
|
||||
static const BYTE PKCSSignerWithSerial[] = {
|
||||
0x30,0x2c,0x02,0x01,0x00,0x30,0x19,0x30,0x14,0x31,0x12,0x30,0x10,0x06,0x03,
|
||||
0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x02,
|
||||
0x01,0x01,0x30,0x04,0x06,0x00,0x05,0x00,0x30,0x04,0x06,0x00,0x05,0x00,0x04,
|
||||
0x00 };
|
||||
static const BYTE PKCSSignerWithSerialNoNull[] = {
|
||||
0x30,0x28,0x02,0x01,0x00,0x30,0x19,0x30,0x14,0x31,0x12,0x30,0x10,0x06,0x03,
|
||||
0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x02,
|
||||
0x01,0x01,0x30,0x02,0x06,0x00,0x30,0x02,0x06,0x00,0x04,0x00 };
|
||||
static const BYTE PKCSSignerWithHashAlgo[] = {
|
||||
0x30,0x2e,0x02,0x01,0x00,0x30,0x19,0x30,0x14,0x31,0x12,0x30,0x10,0x06,0x03,
|
||||
0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x02,
|
||||
0x01,0x01,0x30,0x06,0x06,0x02,0x2a,0x03,0x05,0x00,0x30,0x04,0x06,0x00,0x05,
|
||||
0x00,0x04,0x00 };
|
||||
static const BYTE PKCSSignerWithHashAlgoNoNull[] = {
|
||||
0x30,0x2a,0x02,0x01,0x00,0x30,0x19,0x30,0x14,0x31,0x12,0x30,0x10,0x06,0x03,
|
||||
0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x02,
|
||||
0x01,0x01,0x30,0x04,0x06,0x02,0x2a,0x03,0x30,0x02,0x06,0x00,0x04,0x00 };
|
||||
static const BYTE PKCSSignerWithHashAndEncryptionAlgo[] = {
|
||||
0x30,0x30,0x02,0x01,0x00,0x30,0x19,0x30,0x14,0x31,0x12,0x30,0x10,0x06,0x03,
|
||||
0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x02,
|
||||
0x01,0x01,0x30,0x06,0x06,0x02,0x2a,0x03,0x05,0x00,0x30,0x06,0x06,0x02,0x2d,
|
||||
0x06,0x05,0x00,0x04,0x00 };
|
||||
static const BYTE PKCSSignerWithHashAndEncryptionAlgoNoNull[] = {
|
||||
0x30,0x2c,0x02,0x01,0x00,0x30,0x19,0x30,0x14,0x31,0x12,0x30,0x10,0x06,0x03,
|
||||
0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x02,
|
||||
0x01,0x01,0x30,0x04,0x06,0x02,0x2a,0x03,0x30,0x04,0x06,0x02,0x2d,0x06,0x04,
|
||||
0x00 };
|
||||
static const BYTE PKCSSignerWithHash[] = {
|
||||
0x30,0x40,0x02,0x01,0x00,0x30,0x19,0x30,0x14,0x31,0x12,0x30,0x10,0x06,0x03,
|
||||
0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x02,
|
||||
0x01,0x01,0x30,0x06,0x06,0x02,0x2a,0x03,0x05,0x00,0x30,0x06,0x06,0x02,0x2d,
|
||||
0x06,0x05,0x00,0x04,0x10,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,
|
||||
0x0a,0x0b,0x0c,0x0d,0x0e,0x0f };
|
||||
static const BYTE PKCSSignerWithHashNoNull[] = {
|
||||
0x30,0x3c,0x02,0x01,0x00,0x30,0x19,0x30,0x14,0x31,0x12,0x30,0x10,0x06,0x03,
|
||||
0x55,0x04,0x03,0x13,0x09,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,0x67,0x02,
|
||||
0x01,0x01,0x30,0x04,0x06,0x02,0x2a,0x03,0x30,0x04,0x06,0x02,0x2d,
|
||||
0x06,0x04,0x10,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,
|
||||
0x0a,0x0b,0x0c,0x0d,0x0e,0x0f };
|
||||
|
||||
static void test_encodePKCSSignerInfo(DWORD dwEncoding)
|
||||
{
|
||||
|
@ -4952,14 +4926,9 @@ static void test_encodePKCSSignerInfo(DWORD dwEncoding)
|
|||
ok(ret, "CryptEncodeObjectEx failed: %x\n", GetLastError());
|
||||
if (buf)
|
||||
{
|
||||
ok(size == sizeof(minimalPKCSSigner) ||
|
||||
size == sizeof(minimalPKCSSignerNoNull), "Unexpected size %d\n",
|
||||
size);
|
||||
ok(size == sizeof(minimalPKCSSigner), "Unexpected size %d\n", size);
|
||||
if (size == sizeof(minimalPKCSSigner))
|
||||
ok(!memcmp(buf, minimalPKCSSigner, size), "Unexpected value\n");
|
||||
else if (size == sizeof(minimalPKCSSignerNoNull))
|
||||
ok(!memcmp(buf, minimalPKCSSignerNoNull, size),
|
||||
"Unexpected value\n");
|
||||
else
|
||||
ok(0, "Unexpected value\n");
|
||||
LocalFree(buf);
|
||||
|
@ -4978,15 +4947,11 @@ static void test_encodePKCSSignerInfo(DWORD dwEncoding)
|
|||
ok(ret, "CryptEncodeObjectEx failed: %x\n", GetLastError());
|
||||
if (buf)
|
||||
{
|
||||
ok(size == sizeof(PKCSSignerWithSerial) ||
|
||||
size == sizeof(PKCSSignerWithSerialNoNull), "Unexpected size %d\n",
|
||||
ok(size == sizeof(PKCSSignerWithSerial), "Unexpected size %d\n",
|
||||
size);
|
||||
if (size == sizeof(PKCSSignerWithSerial))
|
||||
ok(!memcmp(buf, PKCSSignerWithSerial, size),
|
||||
"Unexpected value\n");
|
||||
else if (size == sizeof(PKCSSignerWithSerialNoNull))
|
||||
ok(!memcmp(buf, PKCSSignerWithSerialNoNull, size),
|
||||
"Unexpected value\n");
|
||||
else
|
||||
ok(0, "Unexpected value\n");
|
||||
LocalFree(buf);
|
||||
|
@ -5004,15 +4969,11 @@ static void test_encodePKCSSignerInfo(DWORD dwEncoding)
|
|||
ok(ret, "CryptEncodeObjectEx failed: %x\n", GetLastError());
|
||||
if (buf)
|
||||
{
|
||||
ok(size == sizeof(PKCSSignerWithHashAlgo) ||
|
||||
size == sizeof(PKCSSignerWithHashAlgoNoNull),
|
||||
"Unexpected size %d\n", size);
|
||||
ok(size == sizeof(PKCSSignerWithHashAlgo), "Unexpected size %d\n",
|
||||
size);
|
||||
if (size == sizeof(PKCSSignerWithHashAlgo))
|
||||
ok(!memcmp(buf, PKCSSignerWithHashAlgo, size),
|
||||
"Unexpected value\n");
|
||||
else if (size == sizeof(PKCSSignerWithHashAlgoNoNull))
|
||||
ok(!memcmp(buf, PKCSSignerWithHashAlgoNoNull, size),
|
||||
"Unexpected value\n");
|
||||
else
|
||||
ok(0, "Unexpected value\n");
|
||||
LocalFree(buf);
|
||||
|
@ -5030,15 +4991,11 @@ static void test_encodePKCSSignerInfo(DWORD dwEncoding)
|
|||
ok(ret, "CryptEncodeObjectEx failed: %x\n", GetLastError());
|
||||
if (buf)
|
||||
{
|
||||
ok(size == sizeof(PKCSSignerWithHashAndEncryptionAlgo) ||
|
||||
size == sizeof(PKCSSignerWithHashAndEncryptionAlgoNoNull),
|
||||
ok(size == sizeof(PKCSSignerWithHashAndEncryptionAlgo),
|
||||
"Unexpected size %d\n", size);
|
||||
if (size == sizeof(PKCSSignerWithHashAndEncryptionAlgo))
|
||||
ok(!memcmp(buf, PKCSSignerWithHashAndEncryptionAlgo, size),
|
||||
"Unexpected value\n");
|
||||
else if (size == sizeof(PKCSSignerWithHashAndEncryptionAlgoNoNull))
|
||||
ok(!memcmp(buf, PKCSSignerWithHashAndEncryptionAlgoNoNull,
|
||||
size), "Unexpected value\n");
|
||||
else
|
||||
ok(0, "Unexpected value\n");
|
||||
LocalFree(buf);
|
||||
|
@ -5057,15 +5014,11 @@ static void test_encodePKCSSignerInfo(DWORD dwEncoding)
|
|||
ok(ret, "CryptEncodeObjectEx failed: %x\n", GetLastError());
|
||||
if (buf)
|
||||
{
|
||||
ok(size == sizeof(PKCSSignerWithHash) ||
|
||||
size == sizeof(PKCSSignerWithHashNoNull), "Unexpected size %d\n",
|
||||
ok(size == sizeof(PKCSSignerWithHash), "Unexpected size %d\n",
|
||||
size);
|
||||
if (size == sizeof(PKCSSignerWithHash))
|
||||
ok(!memcmp(buf, PKCSSignerWithHash, size),
|
||||
"Unexpected value\n");
|
||||
else if (size == sizeof(PKCSSignerWithHashNoNull))
|
||||
ok(!memcmp(buf, PKCSSignerWithHashNoNull, size),
|
||||
"Unexpected value\n");
|
||||
else
|
||||
ok(0, "Unexpected value\n");
|
||||
LocalFree(buf);
|
||||
|
|
Loading…
Reference in New Issue