aboutsummaryrefslogtreecommitdiff
path: root/cast/common/certificate/cast_trust_store.cc
blob: 93db49ba034ae19cefac3ed2506b98a81593a50b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "cast/common/certificate/cast_trust_store.h"

#include "util/osp_logging.h"

namespace openscreen {
namespace cast {
namespace {

// -------------------------------------------------------------------------
// Cast trust anchors.
// -------------------------------------------------------------------------

// There are two trusted roots for Cast certificate chains:
//
//   (1) CN=Cast Root CA    (kCastRootCaDer)
//   (2) CN=Eureka Root CA  (kEurekaRootCaDer)
//
// These constants are defined by the files included next:

#include "cast/common/certificate/cast_root_ca_cert_der-inc.h"
#include "cast/common/certificate/eureka_root_ca_der-inc.h"

}  // namespace

// static
CastTrustStore* CastTrustStore::GetInstance() {
  if (!store_) {
    store_ = new CastTrustStore();
  }
  return store_;
}

// static
void CastTrustStore::ResetInstance() {
  delete store_;
  store_ = nullptr;
}

// static
CastTrustStore* CastTrustStore::CreateInstanceForTest(
    const std::vector<uint8_t>& trust_anchor_der) {
  OSP_DCHECK(!store_);
  store_ = new CastTrustStore(trust_anchor_der);
  return store_;
}

CastTrustStore::CastTrustStore() {
  trust_store_.certs.emplace_back(MakeTrustAnchor(kCastRootCaDer));
  trust_store_.certs.emplace_back(MakeTrustAnchor(kEurekaRootCaDer));
}

CastTrustStore::CastTrustStore(const std::vector<uint8_t>& trust_anchor_der) {
  trust_store_.certs.emplace_back(MakeTrustAnchor(trust_anchor_der));
}

CastTrustStore::~CastTrustStore() = default;

// static
CastTrustStore* CastTrustStore::store_ = nullptr;

}  // namespace cast
}  // namespace openscreen