blob: d8ec513c0f0ec1a818f758569fd5e2b1afaa20f2 (
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
// 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 <utility>
#include "util/crypto/pem_helpers.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_;
}
// static
CastTrustStore* CastTrustStore::CreateInstanceFromPemFile(
absl::string_view file_path,
TrustStore::Mode mode) {
OSP_DCHECK(!store_);
store_ = new CastTrustStore();
store_->trust_store_ = TrustStore::CreateInstanceFromPemFile(file_path, mode);
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(TrustStore trust_store)
: trust_store_(std::move(trust_store)) {}
CastTrustStore::~CastTrustStore() = default;
// static
CastTrustStore* CastTrustStore::store_ = nullptr;
} // namespace cast
} // namespace openscreen
|