OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/verified_contents.h" | 5 #include "extensions/browser/verified_contents.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/base64url.h" | 9 #include "base/base64url.h" |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 // } | 90 // } |
91 // ] | 91 // ] |
92 // } | 92 // } |
93 bool VerifiedContents::InitFrom(const base::FilePath& path, | 93 bool VerifiedContents::InitFrom(const base::FilePath& path, |
94 bool ignore_invalid_signature) { | 94 bool ignore_invalid_signature) { |
95 std::string payload; | 95 std::string payload; |
96 if (!GetPayload(path, &payload, ignore_invalid_signature)) | 96 if (!GetPayload(path, &payload, ignore_invalid_signature)) |
97 return false; | 97 return false; |
98 | 98 |
99 std::unique_ptr<base::Value> value(base::JSONReader::Read(payload)); | 99 std::unique_ptr<base::Value> value(base::JSONReader::Read(payload)); |
100 if (!value.get() || !value->IsType(Value::TYPE_DICTIONARY)) | 100 if (!value.get() || !value->IsType(Value::Type::DICTIONARY)) |
101 return false; | 101 return false; |
102 DictionaryValue* dictionary = static_cast<DictionaryValue*>(value.get()); | 102 DictionaryValue* dictionary = static_cast<DictionaryValue*>(value.get()); |
103 | 103 |
104 std::string item_id; | 104 std::string item_id; |
105 if (!dictionary->GetString(kItemIdKey, &item_id) || | 105 if (!dictionary->GetString(kItemIdKey, &item_id) || |
106 !crx_file::id_util::IdIsValid(item_id)) | 106 !crx_file::id_util::IdIsValid(item_id)) |
107 return false; | 107 return false; |
108 extension_id_ = item_id; | 108 extension_id_ = item_id; |
109 | 109 |
110 std::string version_string; | 110 std::string version_string; |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 // that it is for a given extension), but in the future we may validate using | 229 // that it is for a given extension), but in the future we may validate using |
230 // the extension's key too (eg for non-webstore hosted extensions such as | 230 // the extension's key too (eg for non-webstore hosted extensions such as |
231 // enterprise installs). | 231 // enterprise installs). |
232 bool VerifiedContents::GetPayload(const base::FilePath& path, | 232 bool VerifiedContents::GetPayload(const base::FilePath& path, |
233 std::string* payload, | 233 std::string* payload, |
234 bool ignore_invalid_signature) { | 234 bool ignore_invalid_signature) { |
235 std::string contents; | 235 std::string contents; |
236 if (!base::ReadFileToString(path, &contents)) | 236 if (!base::ReadFileToString(path, &contents)) |
237 return false; | 237 return false; |
238 std::unique_ptr<base::Value> value(base::JSONReader::Read(contents)); | 238 std::unique_ptr<base::Value> value(base::JSONReader::Read(contents)); |
239 if (!value.get() || !value->IsType(Value::TYPE_LIST)) | 239 if (!value.get() || !value->IsType(Value::Type::LIST)) |
240 return false; | 240 return false; |
241 ListValue* top_list = static_cast<ListValue*>(value.get()); | 241 ListValue* top_list = static_cast<ListValue*>(value.get()); |
242 | 242 |
243 // Find the "treehash per file" signed content, e.g. | 243 // Find the "treehash per file" signed content, e.g. |
244 // [ | 244 // [ |
245 // { | 245 // { |
246 // "description": "treehash per file", | 246 // "description": "treehash per file", |
247 // "signed_content": { | 247 // "signed_content": { |
248 // "signatures": [ ... ], | 248 // "signatures": [ ... ], |
249 // "payload": "..." | 249 // "payload": "..." |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
319 reinterpret_cast<const uint8_t*>(payload.data()), payload.size()); | 319 reinterpret_cast<const uint8_t*>(payload.data()), payload.size()); |
320 | 320 |
321 if (!signature_verifier.VerifyFinal()) { | 321 if (!signature_verifier.VerifyFinal()) { |
322 VLOG(1) << "Could not verify signature - VerifyFinal failure"; | 322 VLOG(1) << "Could not verify signature - VerifyFinal failure"; |
323 return false; | 323 return false; |
324 } | 324 } |
325 return true; | 325 return true; |
326 } | 326 } |
327 | 327 |
328 } // namespace extensions | 328 } // namespace extensions |
OLD | NEW |