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

Unified Diff: components/cast_certificate/cast_crl_unittest.cc

Issue 2050983002: Cast device revocation checking. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: For review Created 4 years, 6 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
Index: components/cast_certificate/cast_crl_unittest.cc
diff --git a/components/cast_certificate/cast_crl_unittest.cc b/components/cast_certificate/cast_crl_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..69700fb2ce359629c1639b9fc5e4d18fabf71550
--- /dev/null
+++ b/components/cast_certificate/cast_crl_unittest.cc
@@ -0,0 +1,293 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/cast_certificate/cast_crl.h"
+
+#include "base/time/time.h"
+#include "components/cast_certificate/cast_cert_validator_test_helpers.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace cast_certificate {
+namespace {
+
+const unsigned char kCastCRLTestRootCaDer[] = {
+ 0x30, 0x82, 0x03, 0xee, 0x30, 0x82, 0x02, 0xd6, 0xa0, 0x03, 0x02, 0x01,
+ 0x02, 0x02, 0x02, 0x00, 0x91, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48,
+ 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x0b, 0x05, 0x00, 0x30, 0x81, 0x88, 0x31,
+ 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13, 0x02, 0x55, 0x53,
+ 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08, 0x0c, 0x0a, 0x43,
+ 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e, 0x69, 0x61, 0x31, 0x16, 0x30,
+ 0x14, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x0d, 0x4d, 0x6f, 0x75, 0x6e,
+ 0x74, 0x61, 0x69, 0x6e, 0x20, 0x56, 0x69, 0x65, 0x77, 0x31, 0x13, 0x30,
+ 0x11, 0x06, 0x03, 0x55, 0x04, 0x0a, 0x0c, 0x0a, 0x47, 0x6f, 0x6f, 0x67,
+ 0x6c, 0x65, 0x20, 0x49, 0x6e, 0x63, 0x31, 0x0d, 0x30, 0x0b, 0x06, 0x03,
+ 0x55, 0x04, 0x0b, 0x0c, 0x04, 0x43, 0x61, 0x73, 0x74, 0x31, 0x28, 0x30,
+ 0x26, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0c, 0x1f, 0x43, 0x61, 0x73, 0x74,
+ 0x20, 0x43, 0x52, 0x4c, 0x20, 0x54, 0x65, 0x73, 0x74, 0x20, 0x55, 0x6e,
+ 0x74, 0x72, 0x75, 0x73, 0x74, 0x65, 0x64, 0x20, 0x52, 0x6f, 0x6f, 0x74,
+ 0x20, 0x43, 0x41, 0x30, 0x1e, 0x17, 0x0d, 0x31, 0x36, 0x30, 0x35, 0x32,
+ 0x35, 0x32, 0x31, 0x30, 0x30, 0x30, 0x36, 0x5a, 0x17, 0x0d, 0x33, 0x36,
+ 0x30, 0x35, 0x32, 0x30, 0x32, 0x31, 0x30, 0x30, 0x30, 0x36, 0x5a, 0x30,
+ 0x81, 0x88, 0x31, 0x0b, 0x30, 0x09, 0x06, 0x03, 0x55, 0x04, 0x06, 0x13,
+ 0x02, 0x55, 0x53, 0x31, 0x13, 0x30, 0x11, 0x06, 0x03, 0x55, 0x04, 0x08,
+ 0x0c, 0x0a, 0x43, 0x61, 0x6c, 0x69, 0x66, 0x6f, 0x72, 0x6e, 0x69, 0x61,
+ 0x31, 0x16, 0x30, 0x14, 0x06, 0x03, 0x55, 0x04, 0x07, 0x0c, 0x0d, 0x4d,
+ 0x6f, 0x75, 0x6e, 0x74, 0x61, 0x69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cc, 0x55, 0x93, 0x46, 0x42, 0x17, 0x5a, 0x46,
+ 0xee, 0x57, 0x17, 0x26, 0x83, 0x4c, 0x1b, 0x02, 0x03, 0x01, 0x00, 0x01,
+ 0xa3, 0x60, 0x30, 0x5e, 0x30, 0x0f, 0x06, 0x03, 0x55, 0x1d, 0x13, 0x04,
+ 0x08, 0x30, 0x06, 0x01, 0x01, 0xff, 0x02, 0x01, 0x01, 0x30, 0x1d, 0x06,
+ 0x03, 0x55, 0x1d, 0x0e, 0x04, 0x16, 0x04, 0x14, 0x56, 0x47, 0xa3, 0x12,
+ 0xa6, 0xdb, 0xb7, 0xf3, 0xf1, 0xe4, 0x68, 0x62, 0xcb, 0x01, 0x45, 0xfd,
+ 0x2b, 0x02, 0x73, 0x68, 0x30, 0x1f, 0x06, 0x03, 0x55, 0x1d, 0x23, 0x04,
+ 0x18, 0x30, 0x16, 0x80, 0x14, 0x56, 0x47, 0xa3, 0x12, 0xa6, 0xdb, 0xb7,
+ 0xf3, 0xf1, 0xe4, 0x68, 0x62, 0xcb, 0x01, 0x45, 0xfd, 0x2b, 0x02, 0x73,
+ 0x68, 0x30, 0x0b, 0x06, 0x03, 0x55, 0x1d, 0x0f, 0x04, 0x04, 0x03, 0x02,
+ 0x02, 0x04, 0x30, 0x0d, 0x06, 0x09, 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x0d,
+ 0x01, 0x01, 0x0b, 0x05, 0x00, 0x03, 0x82, 0x01, 0x01, 0x00, 0x22, 0xce,
+ 0x56, 0x31, 0xcd, 0xe0, 0xac, 0xb4, 0xaf, 0x70, 0x8a, 0x0a, 0x60, 0x4d,
+ 0xa8, 0x16, 0x81, 0x11, 0xcf, 0xb6, 0xcf, 0x89, 0x87, 0x86, 0xec, 0x8e,
+ 0x72, 0xb3, 0xbc, 0x01, 0xb4, 0x29, 0xb1, 0x88, 0x48, 0x65, 0xcd, 0x7c,
+ 0x8f, 0xa0, 0x6f, 0x05, 0xb8, 0x60, 0x28, 0x60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a7, 0x41, 0xe0, 0xe3, 0x3e, 0x23, 0xdb, 0x63,
+ 0xa8, 0xfc, 0xfb, 0x76, 0x37, 0x59, 0xf8, 0xb2, 0x31, 0xe5, 0x6d, 0xcf,
+ 0xfa, 0x17, 0x84, 0xd9, 0x16, 0x2f, 0x97, 0x90, 0x8c, 0x83, 0xf2, 0x6f,
+ 0x82, 0xed};
+
+// Indicates the expected result of CRL verification
+enum TestResultCRL {
+ RESULT_CRL_INVALID,
+ RESULT_CRL_VALID,
+};
+
+// Indicates the expected result of test verification
+enum TestResultCert {
+ RESULT_CERT_INVALID,
+ RESULT_CERT_VALID,
+};
+
+std::unique_ptr<CastCRL> RunTestVerifyCRL(TestResultCRL expected_result,
+ const std::string& crl_file_name,
+ bool set_trust_anchor) {
+ std::string crl_raw =
+ cast_certificate::testing::ReadCRLFromFile(crl_file_name);
+
+ ClearCRLTrustAnchorForTest();
+ if (set_trust_anchor)
+ EXPECT_TRUE(AddCRLTrustAnchorForTest(kCastCRLTestRootCaDer,
+ sizeof(kCastCRLTestRootCaDer)));
+
+ std::unique_ptr<CastCRL> crl = ParseCRL(crl_raw);
+ if (expected_result == RESULT_CRL_INVALID) {
+ EXPECT_EQ(crl.get(), nullptr);
+ return nullptr;
+ }
+ EXPECT_NE(crl.get(), nullptr);
+ return crl;
+}
+
+void RunTest(TestResultCert expected_result,
+ const std::string& certs_file_name,
+ const std::string& crl_file_name,
+ const base::Time::Exploded& time) {
+ auto certs =
+ cast_certificate::testing::ReadCertificateChainFromFile(certs_file_name);
+
+ std::unique_ptr<CastCRL> crl =
+ RunTestVerifyCRL(RESULT_CRL_VALID, crl_file_name, true);
+ ASSERT_NE(crl.get(), nullptr);
+
+ bool result = crl->VerifyDeviceCertRevocation(certs, time);
+ if (expected_result == RESULT_CERT_INVALID) {
+ ASSERT_FALSE(result);
+ return;
+ }
+ EXPECT_TRUE(result);
+}
+
+base::Time::Exploded TestTimeValid() {
+ return cast_certificate::testing::CreateDate(2016, 6, 10);
+}
+
+base::Time::Exploded TestTimeFuture() {
+ return cast_certificate::testing::CreateDate(2200, 1, 1);
+}
+
+base::Time::Exploded TestTimePast() {
+ return cast_certificate::testing::CreateDate(1900, 1, 1);
+}
+
+// Tests the verification and parsing of an empty CRL signed by an unexpired
+// trusted CRL authoriy.
+TEST(ParseCRLTest, CRLEmpty) {
+ RunTestVerifyCRL(RESULT_CRL_VALID, "crl/empty.crl", true);
+}
+
+// Tests the verification and parsing of a CRL signed by an unexpired trusted
+// CRL authoriy.
+TEST(ParseCRLTest, CRLValid) {
+ RunTestVerifyCRL(RESULT_CRL_VALID, "crl/nonempty_norevoke.crl", true);
+}
+
+// Tests the verification and parsing of a CRL whose signer is not trusted.
+TEST(ParseCRLTest, CRLUntrusted) {
+ RunTestVerifyCRL(RESULT_CRL_INVALID, "crl/nonempty_norevoke.crl", false);
+}
+
+// Tests the verification and parsing of a CRL whose signer certificate is
+// expired.
+TEST(ParseCRLTest, CRLSignerExpired) {
+ RunTestVerifyCRL(RESULT_CRL_INVALID, "crl/signer_expired.crl", true);
+}
+
+// Tests the verification and parsing of a CRL whose certificate does not verify
+// the signature
+TEST(ParseCRLTest, CRLWrongSignature) {
+ RunTestVerifyCRL(RESULT_CRL_INVALID, "crl/badsignature.crl", true);
+}
+
+// Tests the verification of an unrevoked certificate (empty CRL)
+TEST(ParseCRLTest, ValidEmpty) {
+ RunTest(RESULT_CERT_VALID, "certificates/chromecast_gen1.pem",
+ "crl/empty.crl", TestTimeValid());
+}
+
+// Tests the verification of an unrevoked certificate
+TEST(ParseCRLTest, ValidCert) {
+ RunTest(RESULT_CERT_VALID, "certificates/chromecast_gen1.pem",
+ "crl/nonempty_norevoke.crl", TestTimeValid());
+}
+
+// Tests the verification of unrevoked certificates (serial number edge cases)
+TEST(ParseCRLTest, ValidCertSerialEdges) {
+ RunTest(RESULT_CERT_VALID, "certificates/fugu.pem", "crl/revoked_serial.crl",
+ TestTimeValid());
+}
+
+// Tests the verification of an unrevoked certificate (serial revoked for
+// different issuer)
+TEST(ParseCRLTest, ValidCertSerialRevokeWrongIssuer) {
+ RunTest(RESULT_CERT_VALID, "certificates/chromecast_gen1.pem",
+ "crl/revoked_serial.crl", TestTimeValid());
+}
+
+// Tests the verification of a certificate revoked by serial number
+TEST(ParseCRLTest, RevokedCertSerial) {
+ RunTest(RESULT_CERT_INVALID, "certificates/chromecast_gen2.pem",
+ "crl/revoked_serial.crl", TestTimeValid());
+}
+
+// Tests the verification of a certificate without a chain
+TEST(ParseCRLTest, RevokedUnchained) {
+ RunTest(RESULT_CERT_INVALID, "certificates/unchained.pem",
+ "crl/nonempty_norevoke.crl", TestTimeValid());
+}
+
+// Tests the verification of a certificate revoked by the public key hash
+TEST(ParseCRLTest, RevokedCertHash) {
+ RunTest(RESULT_CERT_INVALID, "certificates/chromecast_gen1.pem",
+ "crl/revoked_cert_hash.crl", TestTimeValid());
+}
+// Tests the verification of a certificate whose ICA is revoked by the public
+// key hash.
+TEST(ParseCRLTest, RevokedICAHash) {
+ RunTest(RESULT_CERT_INVALID, "certificates/chromecast_gen2.pem",
+ "crl/revoked_ica_hash.crl", TestTimeValid());
+}
+
+// Tests the verification of a certificate whose trust anchor is revoked by the
+// public key hash.
+TEST(ParseCRLTest, RevokedRootHash) {
+ RunTest(RESULT_CERT_INVALID, "certificates/chromecast_gen2.pem",
+ "crl/revoked_root_hash.crl", TestTimeValid());
+}
+
+// Tests the verification of a certificate whose ICA is revoked by the serial
+// number.
+TEST(ParseCRLTest, RevokedICASerial) {
+ RunTest(RESULT_CERT_INVALID, "certificates/fugu.pem",
+ "crl/revoked_ica_serial1.crl", TestTimeValid());
+}
+
+// Tests the verification of a certificate whose ICA is revoked by the serial
+// number (edge cases).
+TEST(ParseCRLTest, RevokedICASerialEdges) {
+ RunTest(RESULT_CERT_INVALID, "certificates/fugu.pem",
+ "crl/revoked_ica_serial2.crl", TestTimeValid());
+ RunTest(RESULT_CERT_INVALID, "certificates/chromecast_gen2.pem",
+ "crl/revoked_ica_serial2.crl", TestTimeValid());
+}
+
+// Tests the verification of a certificate whose trust anchor is revoked by the
+// serial number
+TEST(ParseCRLTest, RevokedRootSerial) {
+ RunTest(RESULT_CERT_INVALID, "certificates/cast_root_ca.pem",
+ "crl/revoked_ica_serial1.crl", TestTimeValid());
+}
+
+// Tests the verification of a valid certificate with an expired CRL
+TEST(ParseCRLTest, ExpiredCRLValidCert) {
+ RunTest(RESULT_CERT_INVALID, "certificates/chromecast_gen1.pem",
+ "crl/nonempty_norevoke.crl", TestTimeFuture());
+}
+
+// Tests the verification of a revoked certificate with an expired CRL
+TEST(ParseCRLTest, ExpiredCRLInvalidCert) {
+ RunTest(RESULT_CERT_INVALID, "certificates/chromecast_gen1.pem",
+ "crl/revoked_cert_hash.crl", TestTimeFuture());
+}
+
+// Tests the verification of a valid certificate with a CRL whose creation time
+// is in the future.
+TEST(ParseCRLTest, PostdatedCRLValidCert) {
+ RunTest(RESULT_CERT_INVALID, "certificates/chromecast_gen1.pem",
+ "crl/nonempty_norevoke.crl", TestTimePast());
+}
+
+} // namespace
+
+} // namespace cast_certificate

Powered by Google App Engine
This is Rietveld 408576698