OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/cast_certificate/cast_crl.h" | 5 #include "components/cast_certificate/cast_crl.h" |
6 | 6 |
7 #include <unordered_map> | 7 #include <unordered_map> |
8 #include <unordered_set> | 8 #include <unordered_set> |
9 | 9 |
10 #include "base/base64.h" | 10 #include "base/base64.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 friend struct base::DefaultSingletonTraits<CastCRLTrustStore>; | 63 friend struct base::DefaultSingletonTraits<CastCRLTrustStore>; |
64 | 64 |
65 CastCRLTrustStore() { | 65 CastCRLTrustStore() { |
66 // Initialize the trust store with the root certificate. | 66 // Initialize the trust store with the root certificate. |
67 net::CertErrors errors; | 67 net::CertErrors errors; |
68 scoped_refptr<net::ParsedCertificate> cert = | 68 scoped_refptr<net::ParsedCertificate> cert = |
69 net::ParsedCertificate::CreateWithoutCopyingUnsafe( | 69 net::ParsedCertificate::CreateWithoutCopyingUnsafe( |
70 kCastCRLRootCaDer, sizeof(kCastCRLRootCaDer), {}, &errors); | 70 kCastCRLRootCaDer, sizeof(kCastCRLRootCaDer), {}, &errors); |
71 CHECK(cert) << errors.ToDebugString(); | 71 CHECK(cert) << errors.ToDebugString(); |
72 // Enforce pathlen constraints and policies defined on the root certificate. | 72 // Enforce pathlen constraints and policies defined on the root certificate. |
73 scoped_refptr<net::TrustAnchor> anchor = | 73 store_.AddTrustAnchorWithConstraints(std::move(cert)); |
74 net::TrustAnchor::CreateFromCertificateWithConstraints(std::move(cert)); | |
75 CHECK(anchor); | |
76 store_.AddTrustAnchor(std::move(anchor)); | |
77 } | 74 } |
78 | 75 |
79 net::TrustStoreInMemory store_; | 76 net::TrustStoreInMemory store_; |
80 DISALLOW_COPY_AND_ASSIGN(CastCRLTrustStore); | 77 DISALLOW_COPY_AND_ASSIGN(CastCRLTrustStore); |
81 }; | 78 }; |
82 | 79 |
83 // Converts a uint64_t unix timestamp to net::der::GeneralizedTime. | 80 // Converts a uint64_t unix timestamp to net::der::GeneralizedTime. |
84 bool ConvertTimeSeconds(uint64_t seconds, | 81 bool ConvertTimeSeconds(uint64_t seconds, |
85 net::der::GeneralizedTime* generalized_time) { | 82 net::der::GeneralizedTime* generalized_time) { |
86 base::Time unix_timestamp = | 83 base::Time unix_timestamp = |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 | 251 |
255 CastCRLImpl::~CastCRLImpl() {} | 252 CastCRLImpl::~CastCRLImpl() {} |
256 | 253 |
257 // Verifies the revocation status of the certificate chain, at the specified | 254 // Verifies the revocation status of the certificate chain, at the specified |
258 // time. | 255 // time. |
259 bool CastCRLImpl::CheckRevocation(const net::CertPath& trusted_chain, | 256 bool CastCRLImpl::CheckRevocation(const net::CertPath& trusted_chain, |
260 const base::Time& time) const { | 257 const base::Time& time) const { |
261 if (trusted_chain.IsEmpty()) | 258 if (trusted_chain.IsEmpty()) |
262 return false; | 259 return false; |
263 | 260 |
264 DCHECK(trusted_chain.trust_anchor); | 261 DCHECK(trusted_chain.last_cert_trust.IsTrustAnchor()); |
265 | 262 |
266 // Check the validity of the CRL at the specified time. | 263 // Check the validity of the CRL at the specified time. |
267 net::der::GeneralizedTime verification_time; | 264 net::der::GeneralizedTime verification_time; |
268 if (!net::der::EncodeTimeAsGeneralizedTime(time, &verification_time)) { | 265 if (!net::der::EncodeTimeAsGeneralizedTime(time, &verification_time)) { |
269 VLOG(2) << "CRL verification time malformed."; | 266 VLOG(2) << "CRL verification time malformed."; |
270 return false; | 267 return false; |
271 } | 268 } |
272 if ((verification_time < not_before_) || (verification_time > not_after_)) { | 269 if ((verification_time < not_before_) || (verification_time > not_after_)) { |
273 VLOG(2) << "CRL not time-valid. Perform hard fail."; | 270 VLOG(2) << "CRL not time-valid. Perform hard fail."; |
274 return false; | 271 return false; |
275 } | 272 } |
276 | 273 |
277 // Check revocation. Note that this loop has "+ 1" in order to also loop | 274 // Check revocation. This loop iterates over both certificates AND then the |
278 // over the trust anchor (which is treated specially). | 275 // trust anchor after exhausting the certs. |
279 for (size_t i = 0; i < trusted_chain.certs.size() + 1; ++i) { | 276 for (size_t i = 0; i < trusted_chain.certs.size(); ++i) { |
280 // This loop iterates over both certificates AND then the trust | 277 const net::der::Input& spki_tlv = trusted_chain.certs[i]->tbs().spki_tlv; |
281 // anchor after exhausing the certs. | |
282 net::der::Input spki_tlv; | |
283 if (i == trusted_chain.certs.size()) { | |
284 spki_tlv = trusted_chain.trust_anchor->spki(); | |
285 } else { | |
286 spki_tlv = trusted_chain.certs[i]->tbs().spki_tlv; | |
287 } | |
288 | 278 |
289 // Calculate the public key's hash to check for revocation. | 279 // Calculate the public key's hash to check for revocation. |
290 std::string spki_hash = crypto::SHA256HashString(spki_tlv.AsString()); | 280 std::string spki_hash = crypto::SHA256HashString(spki_tlv.AsString()); |
291 if (revoked_hashes_.find(spki_hash) != revoked_hashes_.end()) { | 281 if (revoked_hashes_.find(spki_hash) != revoked_hashes_.end()) { |
292 VLOG(2) << "Public key is revoked."; | 282 VLOG(2) << "Public key is revoked."; |
293 return false; | 283 return false; |
294 } | 284 } |
295 | 285 |
296 // Check if the subordinate certificate was revoked by serial number. | 286 // Check if the subordinate certificate was revoked by serial number. |
297 if (i > 0) { | 287 if (i > 0) { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 LOG(ERROR) << "CRL - Verification failed."; | 342 LOG(ERROR) << "CRL - Verification failed."; |
353 return nullptr; | 343 return nullptr; |
354 } | 344 } |
355 return base::MakeUnique<CastCRLImpl>(tbs_crl, overall_not_after); | 345 return base::MakeUnique<CastCRLImpl>(tbs_crl, overall_not_after); |
356 } | 346 } |
357 LOG(ERROR) << "No supported version of revocation data."; | 347 LOG(ERROR) << "No supported version of revocation data."; |
358 return nullptr; | 348 return nullptr; |
359 } | 349 } |
360 | 350 |
361 } // namespace cast_certificate | 351 } // namespace cast_certificate |
OLD | NEW |