Chromium Code Reviews| 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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 309 } | 309 } |
| 310 } | 310 } |
| 311 } | 311 } |
| 312 } | 312 } |
| 313 } | 313 } |
| 314 return true; | 314 return true; |
| 315 } | 315 } |
| 316 | 316 |
| 317 // Parses and verifies the CRL used to verify the revocation status of | 317 // Parses and verifies the CRL used to verify the revocation status of |
| 318 // Cast device certificates. | 318 // Cast device certificates. |
| 319 std::unique_ptr<CastCRL> ParseAndVerifyCRL(const std::string& crl_proto, | 319 std::unique_ptr<CastCRL> ParseAndVerifyCRLImpl(const std::string& crl_proto, |
| 320 const base::Time& time, | 320 const base::Time& time, |
| 321 net::TrustStore* trust_store) { | 321 net::TrustStore* trust_store) { |
| 322 CrlBundle crl_bundle; | 322 CrlBundle crl_bundle; |
| 323 if (!crl_bundle.ParseFromString(crl_proto)) { | 323 if (!crl_bundle.ParseFromString(crl_proto)) { |
| 324 LOG(ERROR) << "CRL - Binary could not be parsed."; | 324 LOG(ERROR) << "CRL - Binary could not be parsed."; |
| 325 return nullptr; | 325 return nullptr; |
| 326 } | 326 } |
| 327 for (auto const& crl : crl_bundle.crls()) { | 327 for (auto const& crl : crl_bundle.crls()) { |
| 328 TbsCrl tbs_crl; | 328 TbsCrl tbs_crl; |
| 329 if (!tbs_crl.ParseFromString(crl.tbs_crl())) { | 329 if (!tbs_crl.ParseFromString(crl.tbs_crl())) { |
| 330 LOG(WARNING) << "Binary TBS CRL could not be parsed."; | 330 LOG(WARNING) << "Binary TBS CRL could not be parsed."; |
| 331 continue; | 331 continue; |
| 332 } | 332 } |
| 333 if (tbs_crl.version() != CRL_VERSION_0) { | 333 if (tbs_crl.version() != CRL_VERSION_0) { |
| 334 continue; | 334 continue; |
| 335 } | 335 } |
| 336 net::der::GeneralizedTime overall_not_after; | 336 net::der::GeneralizedTime overall_not_after; |
| 337 if (!VerifyCRL(crl, tbs_crl, time, trust_store, &overall_not_after)) { | 337 if (!VerifyCRL(crl, tbs_crl, time, trust_store, &overall_not_after)) { |
| 338 LOG(ERROR) << "CRL - Verification failed."; | 338 LOG(ERROR) << "CRL - Verification failed."; |
| 339 return nullptr; | 339 return nullptr; |
| 340 } | 340 } |
| 341 return base::WrapUnique(new CastCRLImpl(tbs_crl, overall_not_after)); | 341 return base::WrapUnique(new CastCRLImpl(tbs_crl, overall_not_after)); |
| 342 } | 342 } |
| 343 LOG(ERROR) << "No supported version of revocation data."; | 343 LOG(ERROR) << "No supported version of revocation data."; |
| 344 return nullptr; | 344 return nullptr; |
| 345 } | 345 } |
| 346 | 346 |
| 347 } // namespace | 347 } // namespace |
| 348 | 348 |
| 349 std::unique_ptr<CastCRL> ParseAndVerifyCRL(const std::string& crl_proto, | 349 std::unique_ptr<CastCRL> ParseAndVerifyCRL(const std::string& crl_proto, |
| 350 const base::Time& time) { | 350 const base::Time& time) { |
| 351 return ParseAndVerifyCRL(crl_proto, time, &CastCRLTrustStore::Get()); | 351 return ParseAndVerifyCRLImpl(crl_proto, time, &CastCRLTrustStore::Get()); |
| 352 } | 352 } |
| 353 | 353 |
| 354 std::unique_ptr<CastCRL> ParseAndVerifyCRLForTest( | 354 std::unique_ptr<CastCRL> ParseAndVerifyCRLUsingCustomTrustStore( |
|
sheretov
2016/09/10 00:26:57
Can we eliminate ParseAndVerifyCRLImpl, move all t
ryanchung
2016/09/10 00:50:09
Done.
| |
| 355 const std::string& crl_proto, | 355 const std::string& crl_proto, |
| 356 const base::Time& time, | 356 const base::Time& time, |
| 357 net::TrustStore* trust_store) { | 357 net::TrustStore* trust_store) { |
| 358 return ParseAndVerifyCRL(crl_proto, time, trust_store); | 358 if (!trust_store) |
| 359 return nullptr; | |
| 360 return ParseAndVerifyCRLImpl(crl_proto, time, trust_store); | |
| 359 } | 361 } |
| 360 | 362 |
| 361 } // namespace cast_certificate | 363 } // namespace cast_certificate |
| OLD | NEW |