Index: extensions/common/cast/cast_cert_validator.cc |
diff --git a/extensions/common/cast/cast_cert_validator.cc b/extensions/common/cast/cast_cert_validator.cc |
index 2211bb653cf0525be8f80c236140a43317732415..f80b1063d132cecaa7cbd1f2dc177230e5d6f621 100644 |
--- a/extensions/common/cast/cast_cert_validator.cc |
+++ b/extensions/common/cast/cast_cert_validator.cc |
@@ -9,6 +9,7 @@ |
#include <algorithm> |
#include <utility> |
+#include "base/memory/singleton.h" |
#include "net/cert/internal/certificate_policies.h" |
#include "net/cert/internal/extended_key_usage.h" |
#include "net/cert/internal/parse_certificate.h" |
@@ -30,120 +31,38 @@ namespace { |
// There are two trusted roots for Cast certificate chains: |
// |
-// (1) CN=Cast Root CA |
-// (2) CN=Eureka Root CA |
+// (1) CN=Cast Root CA (kCastRootCaDer) |
+// (2) CN=Eureka Root CA (kEurekaRootCaDer) |
// |
-// Note that only the subject/spki are saved here, not the full certificate. |
-// See the TODO in CreateCastTrustStore(). |
- |
-unsigned char kCastRootCaSubjectDer[119] = { |
- 0x30, 0x75, 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, 0x15, 0x30, 0x13, 0x06, 0x03, 0x55, 0x04, 0x03, 0x0C, 0x0C, 0x43, |
- 0x61, 0x73, 0x74, 0x20, 0x52, 0x6F, 0x6F, 0x74, 0x20, 0x43, 0x41, |
-}; |
+// These constants are defined by the files included next: |
-unsigned char kCastRootCaSpkiDer[294] = { |
- 0x30, 0x82, 0x01, 0x22, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, |
- 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0F, 0x00, |
- 0x30, 0x82, 0x01, 0x0A, 0x02, 0x82, 0x01, 0x01, 0x00, 0xBA, 0xD9, 0x65, |
- 0x9D, 0xDA, 0x39, 0xD3, 0xC1, 0x77, 0xF6, 0xD4, 0xD0, 0xAE, 0x8F, 0x58, |
- 0x08, 0x68, 0x39, 0x4A, 0x95, 0xED, 0x70, 0xCF, 0xFD, 0x79, 0x08, 0xA9, |
- 0xAA, 0xE5, 0xE9, 0xB8, 0xA7, 0x2D, 0xA0, 0x67, 0x47, 0x8A, 0x9E, 0xC9, |
- 0xCF, 0x70, 0xB3, 0x05, 0x87, 0x69, 0x11, 0xEC, 0x70, 0x98, 0x97, 0xC3, |
- 0xE6, 0xC3, 0xC3, 0xEB, 0xBD, 0xC6, 0xB0, 0x3D, 0xFC, 0x4F, 0xC1, 0x5E, |
- 0x38, 0x9F, 0xDA, 0xCF, 0x73, 0x30, 0x06, 0x5B, 0x79, 0x37, 0xC1, 0x5E, |
- 0x8C, 0x87, 0x47, 0x94, 0x9A, 0x41, 0x92, 0x2A, 0xD6, 0x95, 0xC4, 0x71, |
- 0x5C, 0x27, 0x5D, 0x08, 0xB1, 0x80, 0xC6, 0x92, 0xBD, 0x1B, 0xE3, 0x41, |
- 0x97, 0xA1, 0xEC, 0x75, 0x9F, 0x55, 0x9E, 0x3E, 0x9F, 0x8F, 0x1C, 0xC7, |
- 0x65, 0x64, 0x07, 0xD3, 0xB3, 0x96, 0xA1, 0x04, 0x9F, 0x91, 0xC4, 0xDE, |
- 0x0A, 0x7B, 0x6C, 0xD9, 0xC8, 0xC0, 0x78, 0x31, 0xA0, 0x19, 0x42, 0xA9, |
- 0xE8, 0x83, 0xE3, 0xCE, 0xFC, 0xF1, 0xCE, 0xC2, 0x2E, 0x24, 0x46, 0x95, |
- 0x09, 0x19, 0xCA, 0xC0, 0x46, 0xB2, 0xE5, 0x01, 0xBA, 0xD7, 0x4F, 0xF3, |
- 0xBF, 0xF6, 0x69, 0xAD, 0x99, 0x04, 0xFA, 0xA0, 0x07, 0x39, 0x0E, 0xE6, |
- 0xDF, 0x51, 0x47, 0x07, 0xC0, 0xE4, 0xA9, 0x5C, 0x4B, 0x94, 0xC5, 0x2F, |
- 0xB3, 0xA0, 0x30, 0x7F, 0xE7, 0x95, 0x6B, 0xB2, 0xAF, 0x32, 0x0D, 0xF1, |
- 0x8C, 0xD5, 0x6D, 0xCB, 0x7B, 0x47, 0xA7, 0x08, 0xAB, 0xCB, 0x27, 0xA3, |
- 0x4D, 0xCF, 0x4A, 0x5A, 0xF1, 0x05, 0xD1, 0xF8, 0x62, 0xC5, 0x10, 0x2A, |
- 0x74, 0x69, 0xAA, 0xE6, 0x4B, 0x96, 0xFB, 0x9B, 0xD8, 0x63, 0xE4, 0x58, |
- 0x66, 0xD3, 0xAD, 0x8A, 0x6E, 0xFF, 0x7B, 0x5E, 0xF9, 0xA5, 0x56, 0x1E, |
- 0x2D, 0x82, 0x31, 0x5B, 0xF0, 0xE2, 0x24, 0xE6, 0x41, 0x4A, 0x1F, 0xAE, |
- 0x13, 0x02, 0x03, 0x01, 0x00, 0x01, |
-}; |
+#include "extensions/common/cast/cast_root_ca_cert_der-inc.h" |
+#include "extensions/common/cast/eureka_root_ca_der-inc.h" |
-unsigned char kEurekaRootCaSubjectDer[126] = { |
- 0x30, 0x7C, 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, 0x12, 0x30, |
- 0x10, 0x06, 0x03, 0x55, 0x04, 0x0B, 0x0C, 0x09, 0x47, 0x6F, 0x6F, 0x67, |
- 0x6C, 0x65, 0x20, 0x54, 0x56, 0x31, 0x17, 0x30, 0x15, 0x06, 0x03, 0x55, |
- 0x04, 0x03, 0x0C, 0x0E, 0x45, 0x75, 0x72, 0x65, 0x6B, 0x61, 0x20, 0x52, |
- 0x6F, 0x6F, 0x74, 0x20, 0x43, 0x41, |
-}; |
+// Singleton for the Cast trust store. |
+class CastTrustStore { |
+ public: |
+ static CastTrustStore* GetInstance() { |
+ return base::Singleton<CastTrustStore, |
+ base::LeakySingletonTraits<CastTrustStore>>::get(); |
+ } |
-unsigned char kEurekaRootCaSpkiDer[294] = { |
- 0x30, 0x82, 0x01, 0x22, 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, |
- 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00, 0x03, 0x82, 0x01, 0x0F, 0x00, |
- 0x30, 0x82, 0x01, 0x0A, 0x02, 0x82, 0x01, 0x01, 0x00, 0xB9, 0x11, 0xD0, |
- 0xEA, 0x12, 0xDC, 0x32, 0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F, |
- 0x89, 0xD6, 0xF2, 0x19, 0x78, 0x5C, 0x21, 0x8E, 0xB1, 0xB6, 0x57, 0xD8, |
- 0xC0, 0xE1, 0xEE, 0x7D, 0x6E, 0xDD, 0xF1, 0x3A, 0x0A, 0x6A, 0xF1, 0xBA, |
- 0xFF, 0xF9, 0x83, 0x2F, 0xDC, 0xB5, 0xA4, 0x20, 0x17, 0x63, 0x36, 0xEF, |
- 0xC8, 0x62, 0x19, 0xCC, 0x56, 0xCE, 0xB2, 0xEA, 0x31, 0x89, 0x4B, 0x78, |
- 0x58, 0xC1, 0xBF, 0x03, 0x13, 0x99, 0xE0, 0x12, 0xF2, 0x88, 0xAA, 0x9B, |
- 0x94, 0xDA, 0xDD, 0x76, 0x79, 0x17, 0x1E, 0x34, 0xD1, 0x0A, 0xC4, 0x07, |
- 0x45, 0x02, 0x03, 0x01, 0x00, 0x01, |
-}; |
+ static net::TrustStore& Get() { return GetInstance()->store_; } |
-// Helper function that creates and initializes a TrustAnchor struct given |
-// arrays for the subject's DER and the SPKI's DER. |
-template <size_t SubjectSize, size_t SpkiSize> |
-net::TrustAnchor CreateTrustAnchor(const uint8_t (&subject)[SubjectSize], |
- const uint8_t (&spki)[SpkiSize]) { |
- net::TrustAnchor anchor; |
- anchor.name = std::string(subject, subject + SubjectSize); |
- anchor.spki = std::string(spki, spki + SpkiSize); |
- return anchor; |
-} |
+ private: |
+ friend struct base::DefaultSingletonTraits<CastTrustStore>; |
+ |
+ CastTrustStore() { |
+ // Initialize the trust store with two root certificates. |
+ CHECK(store_.AddTrustedCertificateWithoutCopying(kCastRootCaDer, |
+ sizeof(kCastRootCaDer))); |
+ CHECK(store_.AddTrustedCertificateWithoutCopying(kEurekaRootCaDer, |
+ sizeof(kEurekaRootCaDer))); |
+ } |
-// Creates a trust store with the two Cast roots. |
-// |
-// TODO(eroman): The root certificates themselves are not included in the trust |
-// store (just their subject/SPKI). The problem with this approach is any |
-// restrictions encoded in their (like path length, or policy) are not known |
-// when verifying, and hence not enforced. |
-net::TrustStore CreateCastTrustStore() { |
- net::TrustStore store; |
- store.anchors.push_back( |
- CreateTrustAnchor(kEurekaRootCaSubjectDer, kEurekaRootCaSpkiDer)); |
- store.anchors.push_back( |
- CreateTrustAnchor(kCastRootCaSubjectDer, kCastRootCaSpkiDer)); |
- return store; |
-} |
+ net::TrustStore store_; |
+ DISALLOW_COPY_AND_ASSIGN(CastTrustStore); |
+}; |
using ExtensionsMap = std::map<net::der::Input, net::ParsedExtension>; |
@@ -340,14 +259,6 @@ bool VerifyDeviceCert(const std::vector<std::string>& certs, |
const base::Time::Exploded& time, |
scoped_ptr<CertVerificationContext>* context, |
CastDeviceCertPolicy* policy) { |
- // Initialize the trust store used for verifying Cast |
- // device certificates. |
- // |
- // Performance: This code is re-building a TrustStore object each |
- // time a chain needs to be verified rather than caching it, to |
- // avoid memory bloat. |
- auto trust_store = CreateCastTrustStore(); |
- |
// The underlying verification function expects a sequence of |
// der::Input, so wrap the data in it (cheap). |
std::vector<net::der::Input> input_chain; |
@@ -359,7 +270,7 @@ bool VerifyDeviceCert(const std::vector<std::string>& certs, |
// Do RFC 5280 compatible certificate verification using the two Cast |
// trust anchors and Cast signature policy. |
- if (!net::VerifyCertificateChain(input_chain, trust_store, |
+ if (!net::VerifyCertificateChain(input_chain, CastTrustStore::Get(), |
signature_policy.get(), |
ConvertExplodedTime(time))) { |
return false; |