Commit 0f6a6dcd authored by Juan Lang's avatar Juan Lang Committed by Alexandre Julliard

cryptnet/tests: Add more tests for revocation checking.

parent ec0a8600
...@@ -481,7 +481,7 @@ static const BYTE rootWithKeySignAndCRLSign[] = { ...@@ -481,7 +481,7 @@ static const BYTE rootWithKeySignAndCRLSign[] = {
0x2e,0x7c,0xf2,0x06,0x9d,0xb3,0x3b,0x7e,0x2f,0xda,0x25,0x66,0x7e,0xa7,0x1f, 0x2e,0x7c,0xf2,0x06,0x9d,0xb3,0x3b,0x7e,0x2f,0xda,0x25,0x66,0x7e,0xa7,0x1f,
0x45,0xd4,0xf5,0xe3,0xdf,0x2a,0xf1,0x18,0x28,0x20,0xb5,0xf8,0xf5,0x8d,0x7a, 0x45,0xd4,0xf5,0xe3,0xdf,0x2a,0xf1,0x18,0x28,0x20,0xb5,0xf8,0xf5,0x8d,0x7a,
0x2e,0x84,0xee }; 0x2e,0x84,0xee };
static const BYTE eeCert[] = { static const BYTE revokedCert[] = {
0x30,0x82,0x01,0xb9,0x30,0x82,0x01,0x22,0xa0,0x03,0x02,0x01,0x02,0x02,0x01, 0x30,0x82,0x01,0xb9,0x30,0x82,0x01,0x22,0xa0,0x03,0x02,0x01,0x02,0x02,0x01,
0x01,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05, 0x01,0x30,0x0d,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,
0x00,0x30,0x10,0x31,0x0e,0x30,0x0c,0x06,0x03,0x55,0x04,0x03,0x13,0x05,0x43, 0x00,0x30,0x10,0x31,0x0e,0x30,0x0c,0x06,0x03,0x55,0x04,0x03,0x13,0x05,0x43,
...@@ -512,7 +512,37 @@ static const BYTE eeCert[] = { ...@@ -512,7 +512,37 @@ static const BYTE eeCert[] = {
0xd6,0x5e,0x0a,0x74,0xf2,0x85,0xa6,0xd5,0x3c,0x28,0xc0,0x89,0x5d,0xda,0xf3, 0xd6,0x5e,0x0a,0x74,0xf2,0x85,0xa6,0xd5,0x3c,0x28,0xc0,0x89,0x5d,0xda,0xf3,
0xa6,0x01,0xc2,0xe9,0xa3,0xc1,0xb7,0x21,0x08,0xba,0x18,0x07,0x45,0xeb,0x77, 0xa6,0x01,0xc2,0xe9,0xa3,0xc1,0xb7,0x21,0x08,0xba,0x18,0x07,0x45,0xeb,0x77,
0x7d,0xcd,0xc6,0xe7,0x2a,0x7b,0x46,0xd2,0x3d,0xb5 }; 0x7d,0xcd,0xc6,0xe7,0x2a,0x7b,0x46,0xd2,0x3d,0xb5 };
static const BYTE rootSignedCRL[] = { static const BYTE unRevokedCert[] = {
0x30,0x82,0x01,0xa2,0x30,0x82,0x01,0x0d,0xa0,0x03,0x02,0x01,0x02,0x02,0x01,
0x02,0x30,0x0b,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x30,
0x10,0x31,0x0e,0x30,0x0c,0x06,0x03,0x55,0x04,0x03,0x13,0x05,0x43,0x65,0x72,
0x74,0x31,0x30,0x1e,0x17,0x0d,0x30,0x37,0x30,0x35,0x30,0x31,0x30,0x30,0x30,
0x30,0x30,0x30,0x5a,0x17,0x0d,0x30,0x37,0x31,0x30,0x30,0x31,0x30,0x30,0x30,
0x30,0x30,0x30,0x5a,0x30,0x24,0x31,0x22,0x30,0x0e,0x06,0x03,0x55,0x04,0x03,
0x13,0x07,0x66,0x6f,0x6f,0x2e,0x63,0x6f,0x6d,0x30,0x10,0x06,0x03,0x55,0x04,
0x03,0x13,0x09,0x2a,0x2e,0x66,0x6f,0x6f,0x2e,0x63,0x6f,0x6d,0x30,0x81,0x9d,
0x30,0x0b,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x01,0x03,0x81,
0x8d,0x00,0x30,0x81,0x89,0x02,0x81,0x81,0x00,0xb8,0x52,0xda,0xc5,0x4b,0x3f,
0xe5,0x33,0x0e,0x67,0x5f,0x48,0x21,0xdc,0x7e,0xef,0x37,0x33,0xba,0xff,0xb4,
0xc6,0xdc,0xb6,0x17,0x8e,0x20,0x55,0x07,0x12,0xd2,0x7b,0x3c,0xce,0x30,0xc5,
0xa7,0x48,0x9f,0x6e,0xfe,0xb8,0xbe,0xdb,0x9f,0x9b,0x17,0x60,0x16,0xde,0xc6,
0x8b,0x47,0xd1,0x57,0x71,0x3c,0x93,0xfc,0xbd,0xec,0x44,0x32,0x3b,0xb9,0xcf,
0x6b,0x05,0x72,0xa7,0x87,0x8e,0x7e,0xd4,0x9a,0x87,0x1c,0x2f,0xb7,0x82,0x40,
0xfc,0x6a,0x80,0x83,0x68,0x28,0xce,0x84,0xf4,0x0b,0x2e,0x44,0xcb,0x53,0xac,
0x85,0x85,0xb5,0x46,0x36,0x98,0x3c,0x10,0x02,0xaa,0x02,0xbc,0x8b,0xa2,0x23,
0xb2,0xd3,0x51,0x9a,0x22,0x4a,0xe3,0xaa,0x4e,0x7c,0xda,0x38,0xcf,0x49,0x98,
0x72,0xa3,0x02,0x03,0x01,0x00,0x01,0x30,0x0b,0x06,0x09,0x2a,0x86,0x48,0x86,
0xf7,0x0d,0x01,0x01,0x05,0x03,0x81,0x81,0x00,0x9f,0x11,0x8a,0x0a,0x6e,0xb0,
0x73,0xcc,0x48,0xf1,0x92,0xca,0xaf,0x9a,0x3d,0xb9,0xcf,0xbe,0x84,0xd0,0xa8,
0x34,0x25,0x27,0x9d,0x28,0x68,0xc5,0x35,0x2b,0x84,0xff,0xdb,0xd0,0x1f,0x0d,
0xd7,0xd6,0x8c,0x1b,0x33,0x52,0x7d,0x19,0xd0,0xc2,0xf3,0x63,0xd6,0x55,0x45,
0xf9,0x46,0xa0,0xb7,0xb3,0x94,0xbb,0x25,0x9b,0x29,0x76,0x7c,0x11,0xc7,0x7b,
0xcc,0xcb,0x99,0x3c,0xae,0xe7,0x16,0xb5,0xa7,0x6a,0x1f,0x75,0x4a,0x58,0x65,
0xb1,0x5b,0x91,0x29,0x20,0x81,0x51,0x64,0x05,0x24,0xa5,0x77,0xb7,0x8e,0xc8,
0x32,0x0f,0x0d,0x4f,0xf9,0x78,0x0f,0xc4,0xef,0xd6,0x25,0x5a,0xa4,0x9b,0x07,
0x17,0xea,0x56,0xe2,0x7b,0x61,0x1c,0x2d,0x40,0x38,0x9a,0x24,0x64,0x4b,0x6d,
0x08,0x96 };
static const BYTE rootSignedCRLWithBadAKI[] = {
0x30,0x82,0x01,0x1f,0x30,0x81,0x89,0x02,0x01,0x01,0x30,0x0d,0x06,0x09,0x2a, 0x30,0x82,0x01,0x1f,0x30,0x81,0x89,0x02,0x01,0x01,0x30,0x0d,0x06,0x09,0x2a,
0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,0x00,0x30,0x10,0x31,0x0e,0x30, 0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x05,0x00,0x30,0x10,0x31,0x0e,0x30,
0x0c,0x06,0x03,0x55,0x04,0x03,0x13,0x05,0x43,0x65,0x72,0x74,0x31,0x17,0x0d, 0x0c,0x06,0x03,0x55,0x04,0x03,0x13,0x05,0x43,0x65,0x72,0x74,0x31,0x17,0x0d,
...@@ -533,12 +563,31 @@ static const BYTE rootSignedCRL[] = { ...@@ -533,12 +563,31 @@ static const BYTE rootSignedCRL[] = {
0xa5,0xed,0xf9,0x77,0xb0,0x3c,0x81,0xcf,0xcc,0x49,0xb2,0x1a,0xc3,0xfd,0x34, 0xa5,0xed,0xf9,0x77,0xb0,0x3c,0x81,0xcf,0xcc,0x49,0xb2,0x1a,0xc3,0xfd,0x34,
0xd5,0xbc,0xb0,0xd5,0xa5,0x9c,0x1b,0x72,0xc3,0x0f,0xa3,0xe3,0x3c,0xf0,0xc3, 0xd5,0xbc,0xb0,0xd5,0xa5,0x9c,0x1b,0x72,0xc3,0x0f,0xa3,0xe3,0x3c,0xf0,0xc3,
0x91,0xe8,0x93,0x4f,0xd4,0x2f }; 0x91,0xe8,0x93,0x4f,0xd4,0x2f };
static const BYTE rootSignedCRL[] = {
0x30,0x81,0xe6,0x30,0x53,0x30,0x0b,0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,
0x01,0x01,0x05,0x30,0x10,0x31,0x0e,0x30,0x0c,0x06,0x03,0x55,0x04,0x03,0x13,
0x05,0x43,0x65,0x72,0x74,0x31,0x17,0x0d,0x30,0x37,0x30,0x35,0x30,0x31,0x30,
0x30,0x30,0x30,0x30,0x30,0x5a,0x17,0x0d,0x30,0x37,0x31,0x32,0x33,0x31,0x32,
0x33,0x35,0x39,0x35,0x39,0x5a,0x30,0x14,0x30,0x12,0x02,0x01,0x01,0x17,0x0d,
0x30,0x37,0x31,0x30,0x30,0x31,0x30,0x30,0x30,0x30,0x30,0x30,0x5a,0x30,0x0b,
0x06,0x09,0x2a,0x86,0x48,0x86,0xf7,0x0d,0x01,0x01,0x05,0x03,0x81,0x81,0x00,
0x94,0x84,0x0a,0xad,0x63,0xe3,0x05,0xc1,0xd8,0x94,0x44,0xeb,0x30,0x03,0xa1,
0xb4,0x7b,0x09,0x2f,0xf6,0xef,0x0f,0xe5,0x58,0x70,0x67,0xac,0x32,0x91,0xc0,
0x9d,0xf1,0x2b,0xf4,0xb3,0xcf,0xdd,0x1d,0x74,0x7b,0x6f,0x59,0x36,0x73,0xca,
0xcd,0x9c,0xb6,0xd9,0x35,0x39,0x45,0x8d,0xfd,0xf9,0x65,0xf3,0x42,0x2c,0x2c,
0xa6,0xfc,0xd2,0x23,0x6c,0x73,0x28,0x21,0x47,0x22,0x88,0x36,0x7d,0xd8,0xf0,
0xd0,0xca,0x11,0x20,0x50,0x6b,0x1e,0xb1,0x16,0x16,0xde,0xa6,0xc1,0x8d,0x18,
0xf1,0x42,0x22,0x1d,0x95,0x11,0xd7,0xa9,0x8f,0x90,0xe5,0x2f,0x71,0x52,0x47,
0xe0,0x45,0xb1,0x5a,0x2c,0x72,0x8a,0x25,0xca,0xd6,0x96,0xa2,0x7b,0x83,0x4c,
0xa3,0x24,0x7e,0xdd,0x45,0xa1,0x38,0xf8 };
static BOOL (WINAPI *pCertVerifyRevocation)(DWORD, DWORD, DWORD, void **, DWORD, static BOOL (WINAPI *pCertVerifyRevocation)(DWORD, DWORD, DWORD, void **, DWORD,
PCERT_REVOCATION_PARA, PCERT_REVOCATION_STATUS); PCERT_REVOCATION_PARA, PCERT_REVOCATION_STATUS);
/* Wednesday, Oct 1, 2007 */ /* Wednesday, Oct 1, 2007 */
static SYSTEMTIME oct2007 = { 2007, 10, 1, 1, 0, 0, 0, 0 }; static SYSTEMTIME oct2007 = { 2007, 10, 1, 1, 0, 0, 0, 0 };
/* Tuesday, May 1, 2007 */
static SYSTEMTIME may2007 = { 2007, 5, 2, 1, 0, 0, 0, 0 };
static void test_verifyRevocation(void) static void test_verifyRevocation(void)
{ {
...@@ -589,7 +638,7 @@ static void test_verifyRevocation(void) ...@@ -589,7 +638,7 @@ static void test_verifyRevocation(void)
certs[0] = CertCreateCertificateContext(X509_ASN_ENCODING, certs[0] = CertCreateCertificateContext(X509_ASN_ENCODING,
rootWithKeySignAndCRLSign, sizeof(rootWithKeySignAndCRLSign)); rootWithKeySignAndCRLSign, sizeof(rootWithKeySignAndCRLSign));
certs[1] = CertCreateCertificateContext(X509_ASN_ENCODING, certs[1] = CertCreateCertificateContext(X509_ASN_ENCODING,
eeCert, sizeof(eeCert)); revokedCert, sizeof(revokedCert));
/* The root cert itself can't be checked for revocation */ /* The root cert itself can't be checked for revocation */
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
ret = pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE, ret = pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE,
...@@ -621,7 +670,8 @@ static void test_verifyRevocation(void) ...@@ -621,7 +670,8 @@ static void test_verifyRevocation(void)
revPara.hCrlStore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0, revPara.hCrlStore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
CERT_STORE_CREATE_NEW_FLAG, NULL); CERT_STORE_CREATE_NEW_FLAG, NULL);
CertAddEncodedCRLToStore(revPara.hCrlStore, X509_ASN_ENCODING, CertAddEncodedCRLToStore(revPara.hCrlStore, X509_ASN_ENCODING,
rootSignedCRL, sizeof(rootSignedCRL), CERT_STORE_ADD_ALWAYS, NULL); rootSignedCRLWithBadAKI, sizeof(rootSignedCRLWithBadAKI),
CERT_STORE_ADD_ALWAYS, NULL);
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
ret = pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE, ret = pCertVerifyRevocation(0, CERT_CONTEXT_REVOCATION_TYPE,
2, (void **)certs, 0, &revPara, &status); 2, (void **)certs, 0, &revPara, &status);
...@@ -644,8 +694,9 @@ static void test_verifyRevocation(void) ...@@ -644,8 +694,9 @@ static void test_verifyRevocation(void)
SetLastError(0xdeadbeef); SetLastError(0xdeadbeef);
ret = CertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE, ret = CertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE,
1, (void **)&certs[1], 0, &revPara, &status); 1, (void **)&certs[1], 0, &revPara, &status);
/* Win2k thinks the cert is revoked, and it is, except the CRL is out of /* Win2k thinks the cert is revoked, and it is, except the CRL contains a
* date, hence the revocation status should be unknown. * bad authority key ID extension and can't be matched with the issuer
* cert, hence the revocation status should be unknown.
*/ */
ok(!ret && (GetLastError() == CRYPT_E_NO_REVOCATION_CHECK || ok(!ret && (GetLastError() == CRYPT_E_NO_REVOCATION_CHECK ||
broken(GetLastError() == CRYPT_E_REVOKED /* Win2k */)), broken(GetLastError() == CRYPT_E_REVOKED /* Win2k */)),
...@@ -668,6 +719,72 @@ static void test_verifyRevocation(void) ...@@ -668,6 +719,72 @@ static void test_verifyRevocation(void)
"expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", status.dwError); "expected CRYPT_E_NO_REVOCATION_CHECK, got %08x\n", status.dwError);
ok(status.dwIndex == 0, "expected index 0, got %d\n", status.dwIndex); ok(status.dwIndex == 0, "expected index 0, got %d\n", status.dwIndex);
CertCloseStore(revPara.hCrlStore, 0); CertCloseStore(revPara.hCrlStore, 0);
/* Test again with a valid CRL. This time, the cert should be revoked when
* the time is after the validity period of the CRL, or considered
* "revocation offline" when the the checked time precedes the validity
* period of the CRL.
*/
revPara.hCrlStore = CertOpenStore(CERT_STORE_PROV_MEMORY, 0, 0,
CERT_STORE_CREATE_NEW_FLAG, NULL);
ret = CertAddEncodedCRLToStore(revPara.hCrlStore, X509_ASN_ENCODING,
rootSignedCRL, sizeof(rootSignedCRL), CERT_STORE_ADD_ALWAYS, NULL);
ok(ret, "CertAddEncodedCRLToStore failed: %08x\n", GetLastError());
revPara.pftTimeToUse = NULL;
SetLastError(0xdeadbeef);
ret = CertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE,
1, (void **)&certs[1], 0, &revPara, &status);
todo_wine
ok(!ret && (GetLastError() == CRYPT_E_REVOKED ||
broken(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK /* NT4 */)),
"expected CRYPT_E_REVOKED, got %08x\n", GetLastError());
revPara.pftTimeToUse = &time;
SetLastError(0xdeadbeef);
ret = CertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE,
1, (void **)&certs[1], 0, &revPara, &status);
ok(!ret && (GetLastError() == CRYPT_E_REVOKED ||
broken(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK /* NT4 */)),
"expected CRYPT_E_REVOKED, got %08x\n", GetLastError());
SystemTimeToFileTime(&may2007, &time);
SetLastError(0xdeadbeef);
ret = CertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE,
1, (void **)&certs[1], 0, &revPara, &status);
todo_wine
ok(!ret && (GetLastError() == CRYPT_E_REVOCATION_OFFLINE ||
broken(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK /* NT4 */)),
"expected CRYPT_E_REVOCATION_OFFLINE, got %08x\n", GetLastError());
CertFreeCertificateContext(certs[1]);
/* Test again with a valid CRL and an un-revoked cert. No matter the
* time checked, it's reported as revocation offline.
*/
certs[1] = CertCreateCertificateContext(X509_ASN_ENCODING,
unRevokedCert, sizeof(unRevokedCert));
ok(certs[1] != NULL, "CertCreateCertificateContext failed: %08x\n",
GetLastError());
revPara.pftTimeToUse = NULL;
SetLastError(0xdeadbeef);
ret = CertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE,
1, (void **)&certs[1], 0, &revPara, &status);
todo_wine
ok(!ret && (GetLastError() == CRYPT_E_REVOCATION_OFFLINE ||
broken(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK /* NT4 */)),
"expected CRYPT_E_REVOCATION_OFFLINE, got %08x\n", GetLastError());
revPara.pftTimeToUse = &time;
SetLastError(0xdeadbeef);
ret = CertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE,
1, (void **)&certs[1], 0, &revPara, &status);
todo_wine
ok(!ret && (GetLastError() == CRYPT_E_REVOCATION_OFFLINE ||
broken(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK /* NT4 */)),
"expected CRYPT_E_REVOCATION_OFFLINE, got %08x\n", GetLastError());
SystemTimeToFileTime(&may2007, &time);
SetLastError(0xdeadbeef);
ret = CertVerifyRevocation(X509_ASN_ENCODING, CERT_CONTEXT_REVOCATION_TYPE,
1, (void **)&certs[1], 0, &revPara, &status);
todo_wine
ok(!ret && (GetLastError() == CRYPT_E_REVOCATION_OFFLINE ||
broken(GetLastError() == CRYPT_E_NO_REVOCATION_CHECK /* NT4 */)),
"expected CRYPT_E_REVOCATION_OFFLINE, got %08x\n", GetLastError());
CertCloseStore(revPara.hCrlStore, 0);
CertFreeCertificateContext(certs[1]); CertFreeCertificateContext(certs[1]);
CertFreeCertificateContext(certs[0]); CertFreeCertificateContext(certs[0]);
} }
......
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