crypt32: Test encoding a cert with a public key.

This commit is contained in:
Juan Lang 2007-08-02 12:22:17 -07:00 committed by Alexandre Julliard
parent 5885eb3cc3
commit 0c5772dc0a
1 changed files with 73 additions and 0 deletions

View File

@ -2713,6 +2713,29 @@ static const BYTE bigCert[] = { 0x30, 0x7a, 0x02, 0x01, 0x01, 0x30, 0x02, 0x06,
0x4c, 0x61, 0x6e, 0x67, 0x00, 0x30, 0x07, 0x30, 0x02, 0x06, 0x00, 0x03, 0x01,
0x00, 0xa3, 0x16, 0x30, 0x14, 0x30, 0x12, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x01,
0x01, 0xff, 0x04, 0x08, 0x30, 0x06, 0x01, 0x01, 0xff, 0x02, 0x01, 0x01 };
static const BYTE v1CertWithPubKey[] = {
0x30,0x81,0x95,0x02,0x01,0x01,0x30,0x02,0x06,0x00,0x30,0x15,0x31,0x13,0x30,
0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,
0x6e,0x67,0x00,0x30,0x22,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,
0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,
0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x15,0x31,0x13,0x30,0x11,
0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,
0x67,0x00,0x30,0x22,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,
0x01,0x01,0x05,0x00,0x03,0x11,0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,
0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0xa3,0x16,0x30,0x14,0x30,0x12,0x06,
0x03,0x55,0x1d,0x13,0x01,0x01,0xff,0x04,0x08,0x30,0x06,0x01,0x01,0xff,0x02,
0x01,0x01 };
static const BYTE v1CertWithPubKeyNoNull[] = {
0x30,0x81,0x93,0x02,0x01,0x01,0x30,0x02,0x06,0x00,0x30,0x15,0x31,0x13,0x30,
0x11,0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,
0x6e,0x67,0x00,0x30,0x22,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,0x30,0x31,
0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x18,0x0f,0x31,0x36,0x30,0x31,0x30,0x31,
0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x15,0x31,0x13,0x30,0x11,
0x06,0x03,0x55,0x04,0x03,0x13,0x0a,0x4a,0x75,0x61,0x6e,0x20,0x4c,0x61,0x6e,
0x67,0x00,0x30,0x20,0x30,0x0b,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,
0x01,0x01,0x03,0x11,0x00,0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,
0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0xa3,0x16,0x30,0x14,0x30,0x12,0x06,0x03,0x55,
0x1d,0x13,0x01,0x01,0xff,0x04,0x08,0x30,0x06,0x01,0x01,0xff,0x02,0x01,0x01 };
static const BYTE serialNum[] = { 0x01 };
@ -2722,6 +2745,7 @@ static void test_encodeCertToBeSigned(DWORD dwEncoding)
BYTE *buf = NULL;
DWORD size = 0;
CERT_INFO info = { 0 };
static char oid_rsa_rsa[] = szOID_RSA_RSA;
/* Test with NULL pvStructInfo */
ret = CryptEncodeObjectEx(dwEncoding, X509_CERT_TO_BE_SIGNED, NULL,
@ -2800,6 +2824,23 @@ static void test_encodeCertToBeSigned(DWORD dwEncoding)
ok(!memcmp(buf, bigCert, size), "Got unexpected value\n");
LocalFree(buf);
}
/* Add a public key */
info.SubjectPublicKeyInfo.Algorithm.pszObjId = oid_rsa_rsa;
info.SubjectPublicKeyInfo.PublicKey.cbData = sizeof(aKey);
info.SubjectPublicKeyInfo.PublicKey.pbData = (LPBYTE)aKey;
ret = CryptEncodeObjectEx(dwEncoding, X509_CERT_TO_BE_SIGNED, &info,
CRYPT_ENCODE_ALLOC_FLAG, NULL, (BYTE *)&buf, &size);
if (buf)
{
ok(size == sizeof(v1CertWithPubKey) ||
size == sizeof(v1CertWithPubKeyNoNull), "Wrong size %d\n", size);
if (size == sizeof(v1CertWithPubKey))
ok(!memcmp(buf, v1CertWithPubKey, size), "Got unexpected value\n");
else if (size == sizeof(v1CertWithPubKeyNoNull))
ok(!memcmp(buf, v1CertWithPubKeyNoNull, size),
"Got unexpected value\n");
LocalFree(buf);
}
/* for now, I let more interesting tests be done for each subcomponent,
* rather than retesting them all here.
*/
@ -2857,6 +2898,38 @@ static void test_decodeCertToBeSigned(DWORD dwEncoding)
info->Subject.cbData), "Unexpected subject\n");
LocalFree(buf);
}
/* Check again with pub key specified */
ret = CryptDecodeObjectEx(dwEncoding, X509_CERT_TO_BE_SIGNED,
v1CertWithPubKey, sizeof(v1CertWithPubKey), CRYPT_DECODE_ALLOC_FLAG, NULL,
(BYTE *)&buf, &size);
ok(ret, "CryptDecodeObjectEx failed: %08x\n", GetLastError());
if (buf)
{
CERT_INFO *info = (CERT_INFO *)buf;
ok(size >= sizeof(CERT_INFO), "Wrong size %d\n", size);
ok(info->SerialNumber.cbData == 1,
"Expected serial number size 1, got %d\n", info->SerialNumber.cbData);
ok(*info->SerialNumber.pbData == *serialNum,
"Expected serial number %d, got %d\n", *serialNum,
*info->SerialNumber.pbData);
ok(info->Issuer.cbData == sizeof(encodedCommonName),
"Wrong size %d\n", info->Issuer.cbData);
ok(!memcmp(info->Issuer.pbData, encodedCommonName, info->Issuer.cbData),
"Unexpected issuer\n");
ok(info->Subject.cbData == sizeof(encodedCommonName),
"Wrong size %d\n", info->Subject.cbData);
ok(!memcmp(info->Subject.pbData, encodedCommonName,
info->Subject.cbData), "Unexpected subject\n");
ok(!strcmp(info->SubjectPublicKeyInfo.Algorithm.pszObjId,
szOID_RSA_RSA), "Expected szOID_RSA_RSA, got %s\n",
info->SubjectPublicKeyInfo.Algorithm.pszObjId);
ok(info->SubjectPublicKeyInfo.PublicKey.cbData == sizeof(aKey),
"Wrong size %d\n", info->SubjectPublicKeyInfo.PublicKey.cbData);
ok(!memcmp(info->SubjectPublicKeyInfo.PublicKey.pbData, aKey,
sizeof(aKey)), "Unexpected public key\n");
LocalFree(buf);
}
}
static const BYTE hash[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, 0xc, 0xd,