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/component_updater/component_unpacker.h" | 5 #include "chrome/browser/component_updater/component_unpacker.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/files/scoped_file.h" |
13 #include "base/json/json_file_value_serializer.h" | 14 #include "base/json/json_file_value_serializer.h" |
14 #include "base/location.h" | 15 #include "base/location.h" |
15 #include "base/logging.h" | 16 #include "base/logging.h" |
16 #include "base/memory/scoped_handle.h" | |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/strings/stringprintf.h" | 18 #include "base/strings/stringprintf.h" |
19 #include "base/values.h" | 19 #include "base/values.h" |
20 #include "chrome/browser/component_updater/component_patcher.h" | 20 #include "chrome/browser/component_updater/component_patcher.h" |
21 #include "chrome/browser/component_updater/component_updater_service.h" | 21 #include "chrome/browser/component_updater/component_updater_service.h" |
22 #include "crypto/secure_hash.h" | 22 #include "crypto/secure_hash.h" |
23 #include "crypto/signature_verifier.h" | 23 #include "crypto/signature_verifier.h" |
24 #include "extensions/common/constants.h" | 24 #include "extensions/common/constants.h" |
25 #include "extensions/common/crx_file.h" | 25 #include "extensions/common/crx_file.h" |
26 #include "third_party/zlib/google/zip.h" | 26 #include "third_party/zlib/google/zip.h" |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 } | 145 } |
146 | 146 |
147 bool ComponentUnpacker::Verify() { | 147 bool ComponentUnpacker::Verify() { |
148 VLOG(1) << "Verifying component: " << path_.value(); | 148 VLOG(1) << "Verifying component: " << path_.value(); |
149 if (pk_hash_.empty() || path_.empty()) { | 149 if (pk_hash_.empty() || path_.empty()) { |
150 error_ = kInvalidParams; | 150 error_ = kInvalidParams; |
151 return false; | 151 return false; |
152 } | 152 } |
153 // First, validate the CRX header and signature. As of today | 153 // First, validate the CRX header and signature. As of today |
154 // this is SHA1 with RSA 1024. | 154 // this is SHA1 with RSA 1024. |
155 ScopedStdioHandle file(base::OpenFile(path_, "rb")); | 155 base::ScopedFILE file(base::OpenFile(path_, "rb")); |
156 if (!file.get()) { | 156 if (!file.get()) { |
157 error_ = kInvalidFile; | 157 error_ = kInvalidFile; |
158 return false; | 158 return false; |
159 } | 159 } |
160 CRXValidator validator(file.get()); | 160 CRXValidator validator(file.get()); |
161 file.Close(); | 161 file.reset(); |
162 if (!validator.valid()) { | 162 if (!validator.valid()) { |
163 error_ = kInvalidFile; | 163 error_ = kInvalidFile; |
164 return false; | 164 return false; |
165 } | 165 } |
166 is_delta_ = validator.is_delta(); | 166 is_delta_ = validator.is_delta(); |
167 | 167 |
168 // File is valid and the digital signature matches. Now make sure | 168 // File is valid and the digital signature matches. Now make sure |
169 // the public key hash matches the expected hash. If they do we fully | 169 // the public key hash matches the expected hash. If they do we fully |
170 // trust this CRX. | 170 // trust this CRX. |
171 uint8 hash[32] = {}; | 171 uint8 hash[32] = {}; |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 base::DeleteFile(unpack_diff_path_, true); | 274 base::DeleteFile(unpack_diff_path_, true); |
275 if (!unpack_path_.empty()) | 275 if (!unpack_path_.empty()) |
276 base::DeleteFile(unpack_path_, true); | 276 base::DeleteFile(unpack_path_, true); |
277 callback_.Run(error_, extended_error_); | 277 callback_.Run(error_, extended_error_); |
278 } | 278 } |
279 | 279 |
280 ComponentUnpacker::~ComponentUnpacker() { | 280 ComponentUnpacker::~ComponentUnpacker() { |
281 } | 281 } |
282 | 282 |
283 } // namespace component_updater | 283 } // namespace component_updater |
OLD | NEW |