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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
|
// Copyright (c) 2012 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 "chrome/browser/net/crl_set_fetcher.h"
#include "base/bind.h"
#include "base/file_util.h"
#include "base/path_service.h"
#include "base/rand_util.h"
#include "base/string_number_conversions.h"
#include "base/time.h"
#include "chrome/browser/component_updater/component_updater_service.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_paths.h"
#include "content/public/browser/browser_thread.h"
#include "net/base/crl_set.h"
#include "net/base/ssl_config_service.h"
using content::BrowserThread;
CRLSetFetcher::CRLSetFetcher() : cus_(NULL) {}
bool CRLSetFetcher::GetCRLSetFilePath(FilePath* path) const {
bool ok = PathService::Get(chrome::DIR_USER_DATA, path);
if (!ok) {
NOTREACHED();
return false;
}
*path = path->Append(chrome::kCRLSetFilename);
return true;
}
void CRLSetFetcher::StartInitialLoad(ComponentUpdateService* cus) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
cus_ = cus;
if (!BrowserThread::PostTask(
BrowserThread::FILE, FROM_HERE,
base::Bind(&CRLSetFetcher::DoInitialLoadFromDisk, this))) {
NOTREACHED();
}
}
void CRLSetFetcher::DoInitialLoadFromDisk() {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
FilePath crl_set_file_path;
if (!GetCRLSetFilePath(&crl_set_file_path))
return;
LoadFromDisk(crl_set_file_path, &crl_set_);
uint32 sequence_of_loaded_crl = 0;
if (crl_set_.get())
sequence_of_loaded_crl = crl_set_->sequence();
// Get updates, advertising the sequence number of the CRL set that we just
// loaded, if any.
if (!BrowserThread::PostTask(
BrowserThread::UI, FROM_HERE,
base::Bind(
&CRLSetFetcher::RegisterComponent,
this,
sequence_of_loaded_crl))) {
NOTREACHED();
}
}
void CRLSetFetcher::LoadFromDisk(FilePath path,
scoped_refptr<net::CRLSet>* out_crl_set) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
std::string crl_set_bytes;
if (!file_util::ReadFileToString(path, &crl_set_bytes))
return;
if (!net::CRLSet::Parse(crl_set_bytes, out_crl_set)) {
LOG(WARNING) << "Failed to parse CRL set from " << path.MaybeAsASCII();
return;
}
VLOG(1) << "Loaded " << crl_set_bytes.size() << " bytes of CRL set from disk";
if (!BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(
&CRLSetFetcher::SetCRLSetIfNewer, this, *out_crl_set))) {
NOTREACHED();
}
}
void CRLSetFetcher::SetCRLSetIfNewer(
scoped_refptr<net::CRLSet> crl_set) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
scoped_refptr<net::CRLSet> old_crl_set(net::SSLConfigService::GetCRLSet());
if (old_crl_set.get() && old_crl_set->sequence() > crl_set->sequence()) {
LOG(WARNING) << "Refusing to downgrade CRL set from #"
<< old_crl_set->sequence()
<< "to #"
<< crl_set->sequence();
} else {
net::SSLConfigService::SetCRLSet(crl_set);
VLOG(1) << "Installed CRL set #" << crl_set->sequence();
}
}
// kPublicKeySHA256 is the SHA256 hash of the SubjectPublicKeyInfo of the key
// that's used to sign generated CRL sets.
static const uint8 kPublicKeySHA256[32] = {
0x75, 0xda, 0xf8, 0xcb, 0x77, 0x68, 0x40, 0x33,
0x65, 0x4c, 0x97, 0xe5, 0xc5, 0x1b, 0xcd, 0x81,
0x7b, 0x1e, 0xeb, 0x11, 0x2c, 0xe1, 0xa4, 0x33,
0x8c, 0xf5, 0x72, 0x5e, 0xed, 0xb8, 0x43, 0x97,
};
void CRLSetFetcher::RegisterComponent(uint32 sequence_of_loaded_crl) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
CrxComponent component;
component.pk_hash.assign(kPublicKeySHA256,
kPublicKeySHA256 + sizeof(kPublicKeySHA256));
component.installer = this;
component.name = "CRLSet";
component.version = Version(base::UintToString(sequence_of_loaded_crl));
if (!component.version.IsValid()) {
NOTREACHED();
component.version = Version("0");
}
if (cus_->RegisterComponent(component) !=
ComponentUpdateService::kOk) {
NOTREACHED() << "RegisterComponent returned error";
}
}
void CRLSetFetcher::OnUpdateError(int error) {
LOG(WARNING) << "CRLSetFetcher got error " << error
<< " from component installer";
}
bool CRLSetFetcher::Install(base::DictionaryValue* manifest,
const FilePath& unpack_path) {
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE));
FilePath crl_set_file_path = unpack_path.Append(FILE_PATH_LITERAL("crl-set"));
FilePath save_to;
if (!GetCRLSetFilePath(&save_to))
return true;
std::string crl_set_bytes;
if (!file_util::ReadFileToString(crl_set_file_path, &crl_set_bytes)) {
LOG(WARNING) << "Failed to find crl-set file inside CRX";
return false;
}
bool is_delta;
if (!net::CRLSet::GetIsDeltaUpdate(crl_set_bytes, &is_delta)) {
LOG(WARNING) << "GetIsDeltaUpdate failed on CRL set from update CRX";
return false;
}
if (!is_delta) {
if (!net::CRLSet::Parse(crl_set_bytes, &crl_set_)) {
LOG(WARNING) << "Failed to parse CRL set from update CRX";
return false;
}
if (!file_util::WriteFile(save_to, crl_set_bytes.data(),
crl_set_bytes.size())) {
LOG(WARNING) << "Failed to save new CRL set to disk";
// We don't return false here because we can still use this CRL set. When
// we restart we might revert to an older version, then we'll
// advertise the older version to Omaha and everything will still work.
}
} else {
scoped_refptr<net::CRLSet> new_crl_set;
if (!crl_set_->ApplyDelta(crl_set_bytes, &new_crl_set)) {
LOG(WARNING) << "Failed to parse delta CRL set";
return false;
}
VLOG(1) << "Applied CRL set delta #" << crl_set_->sequence()
<< "->#" << new_crl_set->sequence();
const std::string new_crl_set_bytes = new_crl_set->Serialize();
if (!file_util::WriteFile(save_to, new_crl_set_bytes.data(),
new_crl_set_bytes.size())) {
LOG(WARNING) << "Failed to save new CRL set to disk";
// We don't return false here because we can still use this CRL set. When
// we restart we might revert to an older version, then we'll
// advertise the older version to Omaha and everything will still work.
}
crl_set_ = new_crl_set;
}
if (!BrowserThread::PostTask(
BrowserThread::IO, FROM_HERE,
base::Bind(
&CRLSetFetcher::SetCRLSetIfNewer, this, crl_set_))) {
NOTREACHED();
}
return true;
}
CRLSetFetcher::~CRLSetFetcher() {}
|