• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2020 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "cast/common/certificate/cast_trust_store.h"
6 
7 #include <utility>
8 
9 #include "util/crypto/pem_helpers.h"
10 #include "util/osp_logging.h"
11 
12 namespace openscreen {
13 namespace cast {
14 namespace {
15 
16 // -------------------------------------------------------------------------
17 // Cast trust anchors.
18 // -------------------------------------------------------------------------
19 
20 // There are two trusted roots for Cast certificate chains:
21 //
22 //   (1) CN=Cast Root CA    (kCastRootCaDer)
23 //   (2) CN=Eureka Root CA  (kEurekaRootCaDer)
24 //
25 // These constants are defined by the files included next:
26 
27 #include "cast/common/certificate/cast_root_ca_cert_der-inc.h"
28 #include "cast/common/certificate/eureka_root_ca_der-inc.h"
29 
30 }  // namespace
31 
32 // static
GetInstance()33 CastTrustStore* CastTrustStore::GetInstance() {
34   if (!store_) {
35     store_ = new CastTrustStore();
36   }
37   return store_;
38 }
39 
40 // static
ResetInstance()41 void CastTrustStore::ResetInstance() {
42   delete store_;
43   store_ = nullptr;
44 }
45 
46 // static
CreateInstanceForTest(const std::vector<uint8_t> & trust_anchor_der)47 CastTrustStore* CastTrustStore::CreateInstanceForTest(
48     const std::vector<uint8_t>& trust_anchor_der) {
49   OSP_DCHECK(!store_);
50   store_ = new CastTrustStore(trust_anchor_der);
51   return store_;
52 }
53 
54 // static
CreateInstanceFromPemFile(absl::string_view file_path)55 CastTrustStore* CastTrustStore::CreateInstanceFromPemFile(
56     absl::string_view file_path) {
57   OSP_DCHECK(!store_);
58 
59   store_ = new CastTrustStore();
60   store_->trust_store_ = TrustStore::CreateInstanceFromPemFile(file_path);
61   return store_;
62 }
63 
CastTrustStore()64 CastTrustStore::CastTrustStore() {
65   trust_store_.certs.emplace_back(MakeTrustAnchor(kCastRootCaDer));
66   trust_store_.certs.emplace_back(MakeTrustAnchor(kEurekaRootCaDer));
67 }
68 
CastTrustStore(const std::vector<uint8_t> & trust_anchor_der)69 CastTrustStore::CastTrustStore(const std::vector<uint8_t>& trust_anchor_der) {
70   trust_store_.certs.emplace_back(MakeTrustAnchor(trust_anchor_der));
71 }
72 
CastTrustStore(TrustStore trust_store)73 CastTrustStore::CastTrustStore(TrustStore trust_store)
74     : trust_store_(std::move(trust_store)) {}
75 
76 CastTrustStore::~CastTrustStore() = default;
77 
78 // static
79 CastTrustStore* CastTrustStore::store_ = nullptr;
80 
81 }  // namespace cast
82 }  // namespace openscreen
83