| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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_cert_validator.h" | 5 #include "components/cast_certificate/cast_cert_validator.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 | 60 |
| 61 CastTrustStore() { | 61 CastTrustStore() { |
| 62 AddAnchor(kCastRootCaDer); | 62 AddAnchor(kCastRootCaDer); |
| 63 AddAnchor(kEurekaRootCaDer); | 63 AddAnchor(kEurekaRootCaDer); |
| 64 } | 64 } |
| 65 | 65 |
| 66 // Adds a trust anchor given a DER-encoded certificate from static | 66 // Adds a trust anchor given a DER-encoded certificate from static |
| 67 // storage. | 67 // storage. |
| 68 template <size_t N> | 68 template <size_t N> |
| 69 void AddAnchor(const uint8_t (&data)[N]) { | 69 void AddAnchor(const uint8_t (&data)[N]) { |
| 70 net::CertErrors errors; |
| 70 scoped_refptr<net::ParsedCertificate> cert = | 71 scoped_refptr<net::ParsedCertificate> cert = |
| 71 net::ParsedCertificate::CreateFromCertificateData( | 72 net::ParsedCertificate::CreateWithoutCopyingUnsafe(data, N, {}, |
| 72 data, N, net::ParsedCertificate::DataSource::EXTERNAL_REFERENCE, | 73 &errors); |
| 73 {}); | 74 CHECK(cert) << errors.ToDebugString(); |
| 74 CHECK(cert); | |
| 75 // Enforce pathlen constraints and policies defined on the root certificate. | 75 // Enforce pathlen constraints and policies defined on the root certificate. |
| 76 scoped_refptr<net::TrustAnchor> anchor = | 76 scoped_refptr<net::TrustAnchor> anchor = |
| 77 net::TrustAnchor::CreateFromCertificateWithConstraints(std::move(cert)); | 77 net::TrustAnchor::CreateFromCertificateWithConstraints(std::move(cert)); |
| 78 store_.AddTrustAnchor(std::move(anchor)); | 78 store_.AddTrustAnchor(std::move(anchor)); |
| 79 } | 79 } |
| 80 | 80 |
| 81 net::TrustStoreInMemory store_; | 81 net::TrustStoreInMemory store_; |
| 82 DISALLOW_COPY_AND_ASSIGN(CastTrustStore); | 82 DISALLOW_COPY_AND_ASSIGN(CastTrustStore); |
| 83 }; | 83 }; |
| 84 | 84 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 // INTEGER (non-minimal encoding). | 248 // INTEGER (non-minimal encoding). |
| 249 // | 249 // |
| 250 // Allow these sorts of serial numbers. | 250 // Allow these sorts of serial numbers. |
| 251 // | 251 // |
| 252 // TODO(eroman): At some point in the future this workaround will no longer be | 252 // TODO(eroman): At some point in the future this workaround will no longer be |
| 253 // necessary. Should revisit this for removal in 2017 if not earlier. | 253 // necessary. Should revisit this for removal in 2017 if not earlier. |
| 254 options.allow_invalid_serial_numbers = true; | 254 options.allow_invalid_serial_numbers = true; |
| 255 return options; | 255 return options; |
| 256 } | 256 } |
| 257 | 257 |
| 258 // Verifies a cast device certficate given a chain of DER-encoded certificates. | 258 // Verifies a cast device certificate given a chain of DER-encoded certificates. |
| 259 bool VerifyDeviceCert(const std::vector<std::string>& certs, | 259 bool VerifyDeviceCert(const std::vector<std::string>& certs, |
| 260 const base::Time& time, | 260 const base::Time& time, |
| 261 std::unique_ptr<CertVerificationContext>* context, | 261 std::unique_ptr<CertVerificationContext>* context, |
| 262 CastDeviceCertPolicy* policy, | 262 CastDeviceCertPolicy* policy, |
| 263 const CastCRL* crl, | 263 const CastCRL* crl, |
| 264 CRLPolicy crl_policy, | 264 CRLPolicy crl_policy, |
| 265 net::TrustStore* trust_store) { | 265 net::TrustStore* trust_store) { |
| 266 if (certs.empty()) | 266 if (certs.empty()) |
| 267 return false; | 267 return false; |
| 268 | 268 |
| 269 // No reference to these ParsedCertificates is kept past the end of this | 269 net::CertErrors errors; |
| 270 // function, so using EXTERNAL_REFERENCE here is safe. | |
| 271 scoped_refptr<net::ParsedCertificate> target_cert; | 270 scoped_refptr<net::ParsedCertificate> target_cert; |
| 272 net::CertIssuerSourceStatic intermediate_cert_issuer_source; | 271 net::CertIssuerSourceStatic intermediate_cert_issuer_source; |
| 273 for (size_t i = 0; i < certs.size(); ++i) { | 272 for (size_t i = 0; i < certs.size(); ++i) { |
| 274 scoped_refptr<net::ParsedCertificate> cert( | 273 scoped_refptr<net::ParsedCertificate> cert(net::ParsedCertificate::Create( |
| 275 net::ParsedCertificate::CreateFromCertificateData( | 274 certs[i], GetCertParsingOptions(), &errors)); |
| 276 reinterpret_cast<const uint8_t*>(certs[i].data()), certs[i].size(), | 275 // TODO(eroman): Propagate/log these parsing errors. |
| 277 net::ParsedCertificate::DataSource::EXTERNAL_REFERENCE, | |
| 278 GetCertParsingOptions())); | |
| 279 if (!cert) | 276 if (!cert) |
| 280 return false; | 277 return false; |
| 281 | 278 |
| 282 if (i == 0) | 279 if (i == 0) |
| 283 target_cert = std::move(cert); | 280 target_cert = std::move(cert); |
| 284 else | 281 else |
| 285 intermediate_cert_issuer_source.AddCert(std::move(cert)); | 282 intermediate_cert_issuer_source.AddCert(std::move(cert)); |
| 286 } | 283 } |
| 287 | 284 |
| 288 // Use a signature policy compatible with Cast's PKI. | 285 // Use a signature policy compatible with Cast's PKI. |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 348 | 345 |
| 349 std::unique_ptr<CertVerificationContext> CertVerificationContextImplForTest( | 346 std::unique_ptr<CertVerificationContext> CertVerificationContextImplForTest( |
| 350 const base::StringPiece& spki) { | 347 const base::StringPiece& spki) { |
| 351 // Use a bogus CommonName, since this is just exposed for testing signature | 348 // Use a bogus CommonName, since this is just exposed for testing signature |
| 352 // verification by unittests. | 349 // verification by unittests. |
| 353 return base::MakeUnique<CertVerificationContextImpl>(net::der::Input(spki), | 350 return base::MakeUnique<CertVerificationContextImpl>(net::der::Input(spki), |
| 354 "CommonName"); | 351 "CommonName"); |
| 355 } | 352 } |
| 356 | 353 |
| 357 } // namespace cast_certificate | 354 } // namespace cast_certificate |
| OLD | NEW |