Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(386)

Unified Diff: net/cert/x509_certificate_unittest.cc

Issue 412263003: Add SHA-256 fingerprint functions to x509 certs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Small fix from trybot failures Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« net/cert/x509_certificate.cc ('K') | « net/cert/x509_certificate.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/cert/x509_certificate_unittest.cc
diff --git a/net/cert/x509_certificate_unittest.cc b/net/cert/x509_certificate_unittest.cc
index 454fe074af168153c2f15099f2b00a671e88ee14..82cfa34e45ea1df706b45b3cde7a7ffa7c24ee42 100644
--- a/net/cert/x509_certificate_unittest.cc
+++ b/net/cert/x509_certificate_unittest.cc
@@ -375,6 +375,80 @@ TEST(X509CertificateTest, CAFingerprints) {
cert_chain2_ca_fingerprint, 20) == 0);
EXPECT_TRUE(memcmp(cert_chain3->ca_fingerprint().data,
cert_chain3_ca_fingerprint, 20) == 0);
+
+ // Test the SHA-256 hash calculation functions explicitly since they are not
+ // used by X509Certificate internally.
+ static const uint8 cert_chain1_ca_fingerprint_256[32] = {
+ 0x51, 0x15, 0x30, 0x49, 0x97, 0x54, 0xf8, 0xb4, 0x17, 0x41,
+ 0x6b, 0x58, 0x78, 0xb0, 0x89, 0xd2, 0xc3, 0xae, 0x66, 0xc1,
+ 0x16, 0x80, 0xa0, 0x78, 0xe7, 0x53, 0x45, 0xa2, 0xfb, 0x80,
+ 0xe1, 0x07
+ };
+ static const uint8 cert_chain2_ca_fingerprint_256[32] = {
+ 0x00, 0xbd, 0x2b, 0x0e, 0xdd, 0x83, 0x40, 0xb1, 0x74, 0x6c,
+ 0xc3, 0x95, 0xc0, 0xe3, 0x55, 0xb2, 0x16, 0x58, 0x53, 0xfd,
+ 0xb9, 0x3c, 0x52, 0xda, 0xdd, 0xa8, 0x22, 0x8b, 0x07, 0x00,
+ 0x2d, 0xce
+ };
+ // The SHA-256 hash of nothing.
+ static const uint8 cert_chain3_ca_fingerprint_256[32] = {
+ 0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb,
+ 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4,
+ 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52,
+ 0xb8, 0x55
+ };
+ SHA256HashValue ca_fingerprint_256_chain_1 =
+ X509Certificate::CalculateCAFingerprint256(
+ cert_chain1->GetIntermediateCertificates());
+ SHA256HashValue ca_fingerprint_256_chain_2 =
+ X509Certificate::CalculateCAFingerprint256(
+ cert_chain2->GetIntermediateCertificates());
+ SHA256HashValue ca_fingerprint_256_chain_3 =
+ X509Certificate::CalculateCAFingerprint256(
+ cert_chain3->GetIntermediateCertificates());
+ EXPECT_TRUE(memcmp(ca_fingerprint_256_chain_1.data,
+ cert_chain1_ca_fingerprint_256, 32) == 0);
+ EXPECT_TRUE(memcmp(ca_fingerprint_256_chain_2.data,
+ cert_chain2_ca_fingerprint_256, 32) == 0);
+ EXPECT_TRUE(memcmp(ca_fingerprint_256_chain_3.data,
+ cert_chain3_ca_fingerprint_256, 32) == 0);
+
+ static const uint8 cert_chain1_full_chain_fingerprint_256[32] = {
wtc 2014/07/28 17:29:52 Nit: since you renamed the CalculateFullChainFinge
jww 2014/07/28 18:36:14 Done.
+ 0xac, 0xff, 0xcc, 0x63, 0x0d, 0xd0, 0xa7, 0x19, 0x78, 0xb5,
+ 0x8a, 0x47, 0x8b, 0x67, 0x97, 0xcb, 0x8d, 0xe1, 0x6a, 0x8a,
+ 0x57, 0x70, 0xda, 0x9a, 0x53, 0x72, 0xe2, 0xa0, 0x08, 0xab,
+ 0xcc, 0x8f
+ };
+ static const uint8 cert_chain2_full_chain_fingerprint_256[32] = {
+ 0x67, 0x3a, 0x11, 0x20, 0xd6, 0x94, 0x14, 0xe4, 0x16, 0x9f,
+ 0x58, 0xe2, 0x8b, 0xf7, 0x27, 0xed, 0xbb, 0xe8, 0xa7, 0xff,
+ 0x1c, 0x8c, 0x0f, 0x21, 0x38, 0x16, 0x7c, 0xad, 0x1f, 0x22,
+ 0x6f, 0x9b
+ };
+ static const uint8 cert_chain3_full_chain_fingerprint_256[32] = {
+ 0x16, 0x7a, 0xbd, 0xb4, 0x57, 0x04, 0x65, 0x3c, 0x3b, 0xef,
+ 0x6e, 0x6a, 0xa6, 0x02, 0x73, 0x30, 0x3e, 0x34, 0x1b, 0x43,
+ 0xc2, 0x7c, 0x98, 0x52, 0x9f, 0x34, 0x7f, 0x55, 0x97, 0xe9,
+ 0x1a, 0x10
+ };
+ SHA256HashValue ca_fingerprint_256_full_chain_1 =
+ X509Certificate::CalculateChainFingerprint256(
+ cert_chain1->os_cert_handle(),
+ cert_chain1->GetIntermediateCertificates());
+ SHA256HashValue ca_fingerprint_256_full_chain_2 =
+ X509Certificate::CalculateChainFingerprint256(
+ cert_chain2->os_cert_handle(),
+ cert_chain2->GetIntermediateCertificates());
+ SHA256HashValue ca_fingerprint_256_full_chain_3 =
+ X509Certificate::CalculateChainFingerprint256(
+ cert_chain3->os_cert_handle(),
+ cert_chain3->GetIntermediateCertificates());
+ EXPECT_TRUE(memcmp(ca_fingerprint_256_full_chain_1.data,
+ cert_chain1_full_chain_fingerprint_256, 32) == 0);
+ EXPECT_TRUE(memcmp(ca_fingerprint_256_full_chain_2.data,
+ cert_chain2_full_chain_fingerprint_256, 32) == 0);
+ EXPECT_TRUE(memcmp(ca_fingerprint_256_full_chain_3.data,
+ cert_chain3_full_chain_fingerprint_256, 32) == 0);
}
TEST(X509CertificateTest, ParseSubjectAltNames) {
« net/cert/x509_certificate.cc ('K') | « net/cert/x509_certificate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698