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

Unified Diff: components/cast_certificate/cast_crl_unittest.cc

Issue 2303673004: Hook up Chrome Cast sender to Cast CRL. (Closed)
Patch Set: VerifyDeviceCertUsingCustomTrustStore and ParseAndVerifyCRLUsingCustomTrustStore Created 4 years, 3 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
index 1062e8756e7e303753a4525d644c758a9dcb19b8..dc8b2d5912703ad4401186ec0100ecc7528a055b 100644
--- a/components/cast_certificate/cast_crl_unittest.cc
+++ b/components/cast_certificate/cast_crl_unittest.cc
@@ -13,30 +13,6 @@
namespace cast_certificate {
namespace {
-// Creates a trust store using the test roots encoded in the PEM file at |path|.
-std::unique_ptr<net::TrustStoreInMemory> CreateTrustStoreFromFile(
- const std::string& path) {
- std::unique_ptr<net::TrustStoreInMemory> trust_store(
- new net::TrustStoreInMemory());
- const auto trusted_test_roots =
- cast_certificate::testing::ReadCertificateChainFromFile(path);
- for (const auto& trusted_root : trusted_test_roots) {
- scoped_refptr<net::ParsedCertificate> cert(
- net::ParsedCertificate::CreateFromCertificateCopy(trusted_root, {}));
- EXPECT_TRUE(cert);
- scoped_refptr<net::TrustAnchor> anchor =
- net::TrustAnchor::CreateFromCertificateWithConstraints(std::move(cert));
- trust_store->AddTrustAnchor(std::move(anchor));
- }
- return trust_store;
-}
-
-// Converts uint64_t unix timestamp in seconds to base::Time.
-base::Time ConvertUnixTimestampSeconds(uint64_t time) {
- return base::Time::UnixEpoch() +
- base::TimeDelta::FromMilliseconds(time * 1000);
-}
-
// Indicates the expected result of test step's verification.
enum TestStepResult {
RESULT_SUCCESS,
@@ -52,10 +28,10 @@ bool TestVerifyCertificate(TestStepResult expected_result,
std::unique_ptr<CertVerificationContext> context;
CastDeviceCertPolicy policy;
int result;
- if (cast_trust_store != nullptr) {
- result = VerifyDeviceCertForTest(certificate_chain, time, &context, &policy,
- nullptr, CRLPolicy::CRL_OPTIONAL,
- cast_trust_store);
+ if (cast_trust_store) {
+ result = VerifyDeviceCertUsingCustomTrustStore(
+ certificate_chain, time, &context, &policy, nullptr,
+ CRLPolicy::CRL_OPTIONAL, cast_trust_store);
} else {
result = VerifyDeviceCert(certificate_chain, time, &context, &policy,
nullptr, CRLPolicy::CRL_OPTIONAL);
@@ -76,11 +52,13 @@ bool TestVerifyCRL(TestStepResult expected_result,
const base::Time& time,
net::TrustStore* crl_trust_store) {
std::unique_ptr<CastCRL> crl;
- if (crl_trust_store != nullptr) {
- crl = ParseAndVerifyCRLForTest(crl_bundle, time, crl_trust_store);
+ if (crl_trust_store) {
+ crl = ParseAndVerifyCRLUsingCustomTrustStore(crl_bundle, time,
+ crl_trust_store);
} else {
crl = ParseAndVerifyCRL(crl_bundle, time);
}
+
if (expected_result != RESULT_SUCCESS) {
EXPECT_EQ(crl, nullptr);
return crl == nullptr;
@@ -104,8 +82,9 @@ bool TestVerifyRevocation(TestStepResult expected_result,
net::TrustStore* crl_trust_store) {
std::unique_ptr<CastCRL> crl;
if (!crl_bundle.empty()) {
- if (crl_trust_store != nullptr) {
- crl = ParseAndVerifyCRLForTest(crl_bundle, crl_time, crl_trust_store);
+ if (crl_trust_store) {
+ crl = ParseAndVerifyCRLUsingCustomTrustStore(crl_bundle, crl_time,
+ crl_trust_store);
} else {
crl = ParseAndVerifyCRL(crl_bundle, crl_time);
}
@@ -118,10 +97,10 @@ bool TestVerifyRevocation(TestStepResult expected_result,
if (!crl_required)
crl_policy = CRLPolicy::CRL_OPTIONAL;
int result;
- if (cast_trust_store != nullptr) {
- result =
- VerifyDeviceCertForTest(certificate_chain, cert_time, &context, &policy,
- crl.get(), crl_policy, cast_trust_store);
+ if (cast_trust_store) {
+ result = VerifyDeviceCertUsingCustomTrustStore(
+ certificate_chain, cert_time, &context, &policy, crl.get(), crl_policy,
+ cast_trust_store);
} else {
result = VerifyDeviceCert(certificate_chain, cert_time, &context, &policy,
crl.get(), crl_policy);
@@ -139,10 +118,10 @@ bool RunTest(const DeviceCertTest& test_case) {
std::unique_ptr<net::TrustStoreInMemory> crl_trust_store;
std::unique_ptr<net::TrustStoreInMemory> cast_trust_store;
if (test_case.use_test_trust_anchors()) {
- crl_trust_store =
- CreateTrustStoreFromFile("certificates/cast_crl_test_root_ca.pem");
+ crl_trust_store = testing::CreateTrustStoreFromFile(
+ "certificates/cast_crl_test_root_ca.pem");
cast_trust_store =
- CreateTrustStoreFromFile("certificates/cast_test_root_ca.pem");
+ testing::CreateTrustStoreFromFile("certificates/cast_test_root_ca.pem");
EXPECT_TRUE(crl_trust_store.get());
EXPECT_TRUE(cast_trust_store.get());
@@ -153,12 +132,12 @@ bool RunTest(const DeviceCertTest& test_case) {
certificate_chain.push_back(cert);
}
- base::Time cert_verification_time =
- ConvertUnixTimestampSeconds(test_case.cert_verification_time_seconds());
+ base::Time cert_verification_time = testing::ConvertUnixTimestampSeconds(
+ test_case.cert_verification_time_seconds());
uint64_t crl_verify_time = test_case.crl_verification_time_seconds();
base::Time crl_verification_time =
- ConvertUnixTimestampSeconds(crl_verify_time);
+ testing::ConvertUnixTimestampSeconds(crl_verify_time);
if (crl_verify_time == 0)
crl_verification_time = cert_verification_time;

Powered by Google App Engine
This is Rietveld 408576698