Skip to content

Commit

Permalink
crypt32/tests: Add more tests for CertComparePublicKeyInfo.
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Timoshkov <[email protected]>
Signed-off-by: Alexandre Julliard <[email protected]>
  • Loading branch information
Dmitry Timoshkov authored and julliard committed Oct 26, 2018
1 parent 81b0a38 commit d34dc5f
Showing 1 changed file with 60 additions and 3 deletions.
63 changes: 60 additions & 3 deletions dlls/crypt32/tests/cert.c
Original file line number Diff line number Diff line change
Expand Up @@ -3196,24 +3196,39 @@ static void testComparePublicKeyInfo(void)
static BYTE bits1[] = { 1, 0 };
static BYTE bits2[] = { 0 };
static BYTE bits3[] = { 1 };
static BYTE bits4[] = { 0x30,8, 2,1,0x81, 2,3,1,0,1 };
static BYTE bits5[] = { 0x30,9, 2,2,0,0x81, 2,3,1,0,1 };
static BYTE bits6[] = { 0x30,9, 2,2,0,0x82, 2,3,1,0,1 };
static BYTE bits4[] = { 0x30,8, 2,1,0x81, 2,3,1,0,1 }; /* ASN_SEQUENCE */
static BYTE bits5[] = { 0x30,9, 2,2,0,0x81, 2,3,1,0,1 }; /* ASN_SEQUENCE */
static BYTE bits6[] = { 0x30,9, 2,2,0,0x82, 2,3,1,0,1 }; /* ASN_SEQUENCE */
static BYTE bits7[] = { 0x04,8, 2,1,0x81, 2,3,1,0,1 }; /* ASN_OCTETSTRING */
static BYTE bits8[] = { 0x04,9, 2,2,0,0x81, 2,3,1,0,1 }; /* ASN_OCTETSTRING */
static BYTE bits9[] = { 0x04,9, 2,2,0,0x82, 2,3,1,0,1 }; /* ASN_OCTETSTRING */

/* crashes
ret = CertComparePublicKeyInfo(0, NULL, NULL);
*/
/* Empty public keys compare */
ret = CertComparePublicKeyInfo(0, &info1, &info2);
ok(ret, "CertComparePublicKeyInfo failed: %08x\n", GetLastError());
ret = CertComparePublicKeyInfo(X509_ASN_ENCODING, &info1, &info2);
todo_wine
ok(ret, "CertComparePublicKeyInfo failed: %08x\n", GetLastError());

/* Different OIDs appear to compare */
info1.Algorithm.pszObjId = oid_rsa_rsa;
info2.Algorithm.pszObjId = oid_rsa_sha1rsa;
ret = CertComparePublicKeyInfo(0, &info1, &info2);
ok(ret, "CertComparePublicKeyInfo failed: %08x\n", GetLastError());
ret = CertComparePublicKeyInfo(X509_ASN_ENCODING, &info1, &info2);
todo_wine
ok(ret, "CertComparePublicKeyInfo failed: %08x\n", GetLastError());

info2.Algorithm.pszObjId = oid_x957_dsa;
ret = CertComparePublicKeyInfo(0, &info1, &info2);
ok(ret, "CertComparePublicKeyInfo failed: %08x\n", GetLastError());
ret = CertComparePublicKeyInfo(X509_ASN_ENCODING, &info1, &info2);
todo_wine
ok(ret, "CertComparePublicKeyInfo failed: %08x\n", GetLastError());

info1.PublicKey.cbData = sizeof(bits1);
info1.PublicKey.pbData = bits1;
info1.PublicKey.cUnusedBits = 0;
Expand All @@ -3222,6 +3237,10 @@ static void testComparePublicKeyInfo(void)
info2.PublicKey.cUnusedBits = 0;
ret = CertComparePublicKeyInfo(0, &info1, &info2);
ok(ret, "CertComparePublicKeyInfo failed: %08x\n", GetLastError());
ret = CertComparePublicKeyInfo(X509_ASN_ENCODING, &info1, &info2);
todo_wine
ok(ret, "CertComparePublicKeyInfo failed: %08x\n", GetLastError());

info2.Algorithm.pszObjId = oid_rsa_rsa;
info1.PublicKey.cbData = sizeof(bits4);
info1.PublicKey.pbData = bits4;
Expand All @@ -3233,6 +3252,7 @@ static void testComparePublicKeyInfo(void)
ok(!ret, "CertComparePublicKeyInfo: as raw binary: keys should be unequal\n");
ret = CertComparePublicKeyInfo(X509_ASN_ENCODING, &info1, &info2);
ok(ret, "CertComparePublicKeyInfo: as ASN.1 encoded: keys should be equal\n");

info1.PublicKey.cUnusedBits = 1;
info2.PublicKey.cUnusedBits = 5;
ret = CertComparePublicKeyInfo(X509_ASN_ENCODING, &info1, &info2);
Expand All @@ -3252,11 +3272,38 @@ static void testComparePublicKeyInfo(void)
ret = CertComparePublicKeyInfo(0, &info1, &info2);
/* Simple (non-comparing) case */
ok(!ret, "Expected keys not to compare\n");
ret = CertComparePublicKeyInfo(X509_ASN_ENCODING, &info1, &info2);
ok(!ret, "Expected keys not to compare\n");

info2.PublicKey.cbData = sizeof(bits1);
info2.PublicKey.pbData = bits1;
info2.PublicKey.cUnusedBits = 0;
ret = CertComparePublicKeyInfo(0, &info1, &info2);
ok(!ret, "Expected keys not to compare\n");
ret = CertComparePublicKeyInfo(X509_ASN_ENCODING, &info1, &info2);
ok(!ret, "Expected keys not to compare\n");

info1.PublicKey.cbData = sizeof(bits7);
info1.PublicKey.pbData = bits7;
info1.PublicKey.cUnusedBits = 0;
info2.PublicKey.cbData = sizeof(bits8);
info2.PublicKey.pbData = bits8;
info2.PublicKey.cUnusedBits = 0;
ret = CertComparePublicKeyInfo(0, &info1, &info2);
ok(!ret, "CertComparePublicKeyInfo: as raw binary: keys should be unequal\n");
ret = CertComparePublicKeyInfo(X509_ASN_ENCODING, &info1, &info2);
ok(!ret, "CertComparePublicKeyInfo: as ASN.1 encoded: keys should be unequal\n");

ret = CertComparePublicKeyInfo(0, &info1, &info1);
ok(ret, "CertComparePublicKeyInfo: as raw binary: keys should be equal\n");
ret = CertComparePublicKeyInfo(X509_ASN_ENCODING, &info1, &info1);
todo_wine
ok(ret, "CertComparePublicKeyInfo: as ASN.1 encoded: keys should be equal\n");
info1.PublicKey.cbData--; /* kill one byte, make ASN.1 encoded data invalid */
ret = CertComparePublicKeyInfo(X509_ASN_ENCODING, &info1, &info1);
todo_wine
ok(ret, "CertComparePublicKeyInfo: as ASN.1 encoded: keys should be equal\n");

/* ASN.1 encoded non-comparing case */
info1.PublicKey.cbData = sizeof(bits5);
info1.PublicKey.pbData = bits5;
Expand All @@ -3266,6 +3313,16 @@ static void testComparePublicKeyInfo(void)
info2.PublicKey.cUnusedBits = 0;
ret = CertComparePublicKeyInfo(X509_ASN_ENCODING, &info1, &info2);
ok(!ret, "CertComparePublicKeyInfo: different keys should be unequal\n");

/* ASN.1 encoded non-comparing case */
info1.PublicKey.cbData = sizeof(bits8);
info1.PublicKey.pbData = bits8;
info1.PublicKey.cUnusedBits = 0;
info2.PublicKey.cbData = sizeof(bits9);
info2.PublicKey.pbData = bits9;
info2.PublicKey.cUnusedBits = 0;
ret = CertComparePublicKeyInfo(X509_ASN_ENCODING, &info1, &info2);
ok(!ret, "CertComparePublicKeyInfo: different keys should be unequal\n");
}

static void testHashPublicKeyInfo(void)
Expand Down

0 comments on commit d34dc5f

Please sign in to comment.