| 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/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/json/json_file_value_serializer.h" | 11 #include "base/json/json_file_value_serializer.h" |
| 12 #include "base/logging.h" |
| 12 #include "base/memory/scoped_handle.h" | 13 #include "base/memory/scoped_handle.h" |
| 13 #include "base/strings/string_number_conversions.h" | 14 #include "base/strings/string_number_conversions.h" |
| 14 #include "base/strings/stringprintf.h" | 15 #include "base/strings/stringprintf.h" |
| 16 #include "base/values.h" |
| 15 #include "chrome/browser/component_updater/component_patcher.h" | 17 #include "chrome/browser/component_updater/component_patcher.h" |
| 16 #include "chrome/browser/component_updater/component_updater_service.h" | 18 #include "chrome/browser/component_updater/component_updater_service.h" |
| 17 #include "chrome/common/extensions/extension_constants.h" | 19 #include "chrome/common/extensions/extension_constants.h" |
| 18 #include "crypto/secure_hash.h" | 20 #include "crypto/secure_hash.h" |
| 19 #include "crypto/signature_verifier.h" | 21 #include "crypto/signature_verifier.h" |
| 20 #include "extensions/common/crx_file.h" | 22 #include "extensions/common/crx_file.h" |
| 21 #include "third_party/zlib/google/zip.h" | 23 #include "third_party/zlib/google/zip.h" |
| 22 | 24 |
| 23 using crypto::SecureHash; | 25 using crypto::SecureHash; |
| 24 | 26 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 bool delta() const { return delta_; } | 80 bool delta() const { return delta_; } |
| 79 | 81 |
| 80 const std::vector<uint8>& public_key() const { return public_key_; } | 82 const std::vector<uint8>& public_key() const { return public_key_; } |
| 81 | 83 |
| 82 private: | 84 private: |
| 83 bool valid_; | 85 bool valid_; |
| 84 bool delta_; | 86 bool delta_; |
| 85 std::vector<uint8> public_key_; | 87 std::vector<uint8> public_key_; |
| 86 }; | 88 }; |
| 87 | 89 |
| 88 // Deserialize the CRX manifest. The top level must be a dictionary. | 90 } // namespace. |
| 91 |
| 89 // TODO(cpu): add a specific attribute check to a component json that the | 92 // TODO(cpu): add a specific attribute check to a component json that the |
| 90 // extension unpacker will reject, so that a component cannot be installed | 93 // extension unpacker will reject, so that a component cannot be installed |
| 91 // as an extension. | 94 // as an extension. |
| 92 base::DictionaryValue* ReadManifest(const base::FilePath& unpack_path) { | 95 scoped_ptr<base::DictionaryValue> ReadManifest( |
| 96 const base::FilePath& unpack_path) { |
| 93 base::FilePath manifest = | 97 base::FilePath manifest = |
| 94 unpack_path.Append(FILE_PATH_LITERAL("manifest.json")); | 98 unpack_path.Append(FILE_PATH_LITERAL("manifest.json")); |
| 95 if (!base::PathExists(manifest)) | 99 if (!base::PathExists(manifest)) |
| 96 return NULL; | 100 return scoped_ptr<base::DictionaryValue>(); |
| 97 JSONFileValueSerializer serializer(manifest); | 101 JSONFileValueSerializer serializer(manifest); |
| 98 std::string error; | 102 std::string error; |
| 99 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, &error)); | 103 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, &error)); |
| 100 if (!root.get()) | 104 if (!root.get()) |
| 101 return NULL; | 105 return scoped_ptr<base::DictionaryValue>(); |
| 102 if (!root->IsType(base::Value::TYPE_DICTIONARY)) | 106 if (!root->IsType(base::Value::TYPE_DICTIONARY)) |
| 103 return NULL; | 107 return scoped_ptr<base::DictionaryValue>(); |
| 104 return static_cast<base::DictionaryValue*>(root.release()); | 108 return scoped_ptr<base::DictionaryValue>( |
| 109 static_cast<base::DictionaryValue*>(root.release())).Pass(); |
| 105 } | 110 } |
| 106 | 111 |
| 107 } // namespace. | |
| 108 | |
| 109 ComponentUnpacker::ComponentUnpacker(const std::vector<uint8>& pk_hash, | 112 ComponentUnpacker::ComponentUnpacker(const std::vector<uint8>& pk_hash, |
| 110 const base::FilePath& path, | 113 const base::FilePath& path, |
| 111 const std::string& fingerprint, | 114 const std::string& fingerprint, |
| 112 ComponentPatcher* patcher, | 115 ComponentPatcher* patcher, |
| 113 ComponentInstaller* installer) | 116 ComponentInstaller* installer) |
| 114 : error_(kNone), | 117 : error_(kNone), |
| 115 extended_error_(0) { | 118 extended_error_(0) { |
| 116 if (pk_hash.empty() || path.empty()) { | 119 if (pk_hash.empty() || path.empty()) { |
| 117 error_ = kInvalidParams; | 120 error_ = kInvalidParams; |
| 118 return; | 121 return; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 return; | 201 return; |
| 199 } | 202 } |
| 200 // Installation successful. The directory is not our concern now. | 203 // Installation successful. The directory is not our concern now. |
| 201 unpack_path_.clear(); | 204 unpack_path_.clear(); |
| 202 } | 205 } |
| 203 | 206 |
| 204 ComponentUnpacker::~ComponentUnpacker() { | 207 ComponentUnpacker::~ComponentUnpacker() { |
| 205 if (!unpack_path_.empty()) | 208 if (!unpack_path_.empty()) |
| 206 base::DeleteFile(unpack_path_, true); | 209 base::DeleteFile(unpack_path_, true); |
| 207 } | 210 } |
| OLD | NEW |