OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/net/crl_set_fetcher.h" | 5 #include "chrome/browser/net/crl_set_fetcher.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
| 9 #include "base/numerics/safe_conversions.h" |
9 #include "base/path_service.h" | 10 #include "base/path_service.h" |
10 #include "base/rand_util.h" | 11 #include "base/rand_util.h" |
11 #include "base/safe_numerics.h" | |
12 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "chrome/browser/component_updater/component_updater_service.h" | 14 #include "chrome/browser/component_updater/component_updater_service.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/common/chrome_constants.h" | 16 #include "chrome/common/chrome_constants.h" |
17 #include "chrome/common/chrome_paths.h" | 17 #include "chrome/common/chrome_paths.h" |
18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
19 #include "net/cert/crl_set.h" | 19 #include "net/cert/crl_set.h" |
20 #include "net/ssl/ssl_config_service.h" | 20 #include "net/ssl/ssl_config_service.h" |
21 | 21 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 if (!net::CRLSet::GetIsDeltaUpdate(crl_set_bytes, &is_delta)) { | 161 if (!net::CRLSet::GetIsDeltaUpdate(crl_set_bytes, &is_delta)) { |
162 LOG(WARNING) << "GetIsDeltaUpdate failed on CRL set from update CRX"; | 162 LOG(WARNING) << "GetIsDeltaUpdate failed on CRL set from update CRX"; |
163 return false; | 163 return false; |
164 } | 164 } |
165 | 165 |
166 if (!is_delta) { | 166 if (!is_delta) { |
167 if (!net::CRLSet::Parse(crl_set_bytes, &crl_set_)) { | 167 if (!net::CRLSet::Parse(crl_set_bytes, &crl_set_)) { |
168 LOG(WARNING) << "Failed to parse CRL set from update CRX"; | 168 LOG(WARNING) << "Failed to parse CRL set from update CRX"; |
169 return false; | 169 return false; |
170 } | 170 } |
171 int size = base::checked_numeric_cast<int>(crl_set_bytes.size()); | 171 int size = base::checked_cast<int>(crl_set_bytes.size()); |
172 if (file_util::WriteFile(save_to, crl_set_bytes.data(), size) != size) { | 172 if (file_util::WriteFile(save_to, crl_set_bytes.data(), size) != size) { |
173 LOG(WARNING) << "Failed to save new CRL set to disk"; | 173 LOG(WARNING) << "Failed to save new CRL set to disk"; |
174 // We don't return false here because we can still use this CRL set. When | 174 // We don't return false here because we can still use this CRL set. When |
175 // we restart we might revert to an older version, then we'll | 175 // we restart we might revert to an older version, then we'll |
176 // advertise the older version to Omaha and everything will still work. | 176 // advertise the older version to Omaha and everything will still work. |
177 } | 177 } |
178 } else { | 178 } else { |
179 scoped_refptr<net::CRLSet> new_crl_set; | 179 scoped_refptr<net::CRLSet> new_crl_set; |
180 if (!crl_set_->ApplyDelta(crl_set_bytes, &new_crl_set)) { | 180 if (!crl_set_->ApplyDelta(crl_set_bytes, &new_crl_set)) { |
181 LOG(WARNING) << "Failed to parse delta CRL set"; | 181 LOG(WARNING) << "Failed to parse delta CRL set"; |
182 return false; | 182 return false; |
183 } | 183 } |
184 VLOG(1) << "Applied CRL set delta #" << crl_set_->sequence() | 184 VLOG(1) << "Applied CRL set delta #" << crl_set_->sequence() |
185 << "->#" << new_crl_set->sequence(); | 185 << "->#" << new_crl_set->sequence(); |
186 const std::string new_crl_set_bytes = new_crl_set->Serialize(); | 186 const std::string new_crl_set_bytes = new_crl_set->Serialize(); |
187 int size = base::checked_numeric_cast<int>(new_crl_set_bytes.size()); | 187 int size = base::checked_cast<int>(new_crl_set_bytes.size()); |
188 if (file_util::WriteFile(save_to, new_crl_set_bytes.data(), size) != size) { | 188 if (file_util::WriteFile(save_to, new_crl_set_bytes.data(), size) != size) { |
189 LOG(WARNING) << "Failed to save new CRL set to disk"; | 189 LOG(WARNING) << "Failed to save new CRL set to disk"; |
190 // We don't return false here because we can still use this CRL set. When | 190 // We don't return false here because we can still use this CRL set. When |
191 // we restart we might revert to an older version, then we'll | 191 // we restart we might revert to an older version, then we'll |
192 // advertise the older version to Omaha and everything will still work. | 192 // advertise the older version to Omaha and everything will still work. |
193 } | 193 } |
194 crl_set_ = new_crl_set; | 194 crl_set_ = new_crl_set; |
195 } | 195 } |
196 | 196 |
197 if (!BrowserThread::PostTask( | 197 if (!BrowserThread::PostTask( |
198 BrowserThread::IO, FROM_HERE, | 198 BrowserThread::IO, FROM_HERE, |
199 base::Bind( | 199 base::Bind( |
200 &CRLSetFetcher::SetCRLSetIfNewer, this, crl_set_))) { | 200 &CRLSetFetcher::SetCRLSetIfNewer, this, crl_set_))) { |
201 NOTREACHED(); | 201 NOTREACHED(); |
202 } | 202 } |
203 | 203 |
204 return true; | 204 return true; |
205 } | 205 } |
206 | 206 |
207 bool CRLSetFetcher::GetInstalledFile( | 207 bool CRLSetFetcher::GetInstalledFile( |
208 const std::string& file, base::FilePath* installed_file) { | 208 const std::string& file, base::FilePath* installed_file) { |
209 return false; | 209 return false; |
210 } | 210 } |
211 | 211 |
212 CRLSetFetcher::~CRLSetFetcher() {} | 212 CRLSetFetcher::~CRLSetFetcher() {} |
OLD | NEW |