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/extensions/sandboxed_unpacker.h" | 5 #include "chrome/browser/extensions/sandboxed_unpacker.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/file_util.h" | 12 #include "base/file_util.h" |
13 #include "base/files/file_util_proxy.h" | 13 #include "base/files/file_util_proxy.h" |
14 #include "base/json/json_string_value_serializer.h" | 14 #include "base/json/json_string_value_serializer.h" |
15 #include "base/memory/scoped_handle.h" | 15 #include "base/memory/scoped_handle.h" |
16 #include "base/message_loop.h" | 16 #include "base/message_loop.h" |
17 #include "base/metrics/histogram.h" | 17 #include "base/metrics/histogram.h" |
18 #include "base/path_service.h" | 18 #include "base/path_service.h" |
19 #include "base/sequenced_task_runner.h" | 19 #include "base/sequenced_task_runner.h" |
20 #include "base/utf_string_conversions.h" // TODO(viettrungluu): delete me. | 20 #include "base/utf_string_conversions.h" // TODO(viettrungluu): delete me. |
21 #include "chrome/browser/extensions/crx_file.h" | |
22 #include "chrome/browser/extensions/extension_service.h" | 21 #include "chrome/browser/extensions/extension_service.h" |
23 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
24 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
25 #include "chrome/common/chrome_utility_messages.h" | 24 #include "chrome/common/chrome_utility_messages.h" |
26 #include "chrome/common/extensions/extension.h" | 25 #include "chrome/common/extensions/extension.h" |
27 #include "chrome/common/extensions/extension_file_util.h" | 26 #include "chrome/common/extensions/extension_file_util.h" |
28 #include "chrome/common/extensions/extension_l10n_util.h" | 27 #include "chrome/common/extensions/extension_l10n_util.h" |
29 #include "chrome/common/extensions/extension_manifest_constants.h" | 28 #include "chrome/common/extensions/extension_manifest_constants.h" |
30 #include "chrome/common/extensions/extension_manifest_constants.h" | 29 #include "chrome/common/extensions/extension_manifest_constants.h" |
31 #include "chrome/common/extensions/unpacker.h" | 30 #include "chrome/common/extensions/unpacker.h" |
32 #include "content/public/browser/browser_thread.h" | 31 #include "content/public/browser/browser_thread.h" |
33 #include "content/public/browser/utility_process_host.h" | 32 #include "content/public/browser/utility_process_host.h" |
34 #include "crypto/signature_verifier.h" | 33 #include "crypto/signature_verifier.h" |
| 34 #include "extensions/common/constants.h" |
| 35 #include "extensions/common/crx_file.h" |
| 36 #include "extensions/common/id_util.h" |
35 #include "grit/generated_resources.h" | 37 #include "grit/generated_resources.h" |
36 #include "third_party/skia/include/core/SkBitmap.h" | 38 #include "third_party/skia/include/core/SkBitmap.h" |
37 #include "ui/base/l10n/l10n_util.h" | 39 #include "ui/base/l10n/l10n_util.h" |
38 #include "ui/gfx/codec/png_codec.h" | 40 #include "ui/gfx/codec/png_codec.h" |
39 | 41 |
40 using content::BrowserThread; | 42 using content::BrowserThread; |
41 using content::UtilityProcessHost; | 43 using content::UtilityProcessHost; |
42 | 44 |
43 // The following macro makes histograms that record the length of paths | 45 // The following macro makes histograms that record the length of paths |
44 // in this file much easier to read. | 46 // in this file much easier to read. |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 l10n_util::GetStringFUTF16( | 552 l10n_util::GetStringFUTF16( |
551 IDS_EXTENSION_PACKAGE_ERROR_CODE, | 553 IDS_EXTENSION_PACKAGE_ERROR_CODE, |
552 ASCIIToUTF16("CRX_SIGNATURE_VERIFICATION_FAILED"))); | 554 ASCIIToUTF16("CRX_SIGNATURE_VERIFICATION_FAILED"))); |
553 return false; | 555 return false; |
554 } | 556 } |
555 | 557 |
556 std::string public_key = | 558 std::string public_key = |
557 std::string(reinterpret_cast<char*>(&key.front()), key.size()); | 559 std::string(reinterpret_cast<char*>(&key.front()), key.size()); |
558 base::Base64Encode(public_key, &public_key_); | 560 base::Base64Encode(public_key, &public_key_); |
559 | 561 |
560 if (!Extension::GenerateId(public_key, &extension_id_)) | 562 extension_id_ = id_util::GenerateId(public_key); |
561 return false; | |
562 | 563 |
563 return true; | 564 return true; |
564 } | 565 } |
565 | 566 |
566 void SandboxedUnpacker::ReportFailure(FailureReason reason, | 567 void SandboxedUnpacker::ReportFailure(FailureReason reason, |
567 const string16& error) { | 568 const string16& error) { |
568 UMA_HISTOGRAM_ENUMERATION("Extensions.SandboxUnpackFailureReason", | 569 UMA_HISTOGRAM_ENUMERATION("Extensions.SandboxUnpackFailureReason", |
569 reason, NUM_FAILURE_REASONS); | 570 reason, NUM_FAILURE_REASONS); |
570 UMA_HISTOGRAM_TIMES("Extensions.SandboxUnpackFailureTime", | 571 UMA_HISTOGRAM_TIMES("Extensions.SandboxUnpackFailureTime", |
571 base::TimeTicks::Now() - unpack_start_time_); | 572 base::TimeTicks::Now() - unpack_start_time_); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
603 // Error serializing manifest.json. | 604 // Error serializing manifest.json. |
604 ReportFailure( | 605 ReportFailure( |
605 ERROR_SERIALIZING_MANIFEST_JSON, | 606 ERROR_SERIALIZING_MANIFEST_JSON, |
606 l10n_util::GetStringFUTF16( | 607 l10n_util::GetStringFUTF16( |
607 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 608 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
608 ASCIIToUTF16("ERROR_SERIALIZING_MANIFEST_JSON"))); | 609 ASCIIToUTF16("ERROR_SERIALIZING_MANIFEST_JSON"))); |
609 return NULL; | 610 return NULL; |
610 } | 611 } |
611 | 612 |
612 base::FilePath manifest_path = | 613 base::FilePath manifest_path = |
613 extension_root_.Append(Extension::kManifestFilename); | 614 extension_root_.Append(kManifestFilename); |
614 if (!file_util::WriteFile(manifest_path, | 615 if (!file_util::WriteFile(manifest_path, |
615 manifest_json.data(), manifest_json.size())) { | 616 manifest_json.data(), manifest_json.size())) { |
616 // Error saving manifest.json. | 617 // Error saving manifest.json. |
617 ReportFailure( | 618 ReportFailure( |
618 ERROR_SAVING_MANIFEST_JSON, | 619 ERROR_SAVING_MANIFEST_JSON, |
619 l10n_util::GetStringFUTF16( | 620 l10n_util::GetStringFUTF16( |
620 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 621 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
621 ASCIIToUTF16("ERROR_SAVING_MANIFEST_JSON"))); | 622 ASCIIToUTF16("ERROR_SAVING_MANIFEST_JSON"))); |
622 return NULL; | 623 return NULL; |
623 } | 624 } |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
742 l10n_util::GetStringFUTF16( | 743 l10n_util::GetStringFUTF16( |
743 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 744 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
744 ASCIIToUTF16("INVALID_CATALOG_DATA"))); | 745 ASCIIToUTF16("INVALID_CATALOG_DATA"))); |
745 return false; | 746 return false; |
746 } | 747 } |
747 | 748 |
748 // TODO(viettrungluu): Fix the |FilePath::FromWStringHack(UTF8ToWide())| | 749 // TODO(viettrungluu): Fix the |FilePath::FromWStringHack(UTF8ToWide())| |
749 // hack and remove the corresponding #include. | 750 // hack and remove the corresponding #include. |
750 base::FilePath relative_path = | 751 base::FilePath relative_path = |
751 base::FilePath::FromWStringHack(UTF8ToWide(it.key())); | 752 base::FilePath::FromWStringHack(UTF8ToWide(it.key())); |
752 relative_path = relative_path.Append(Extension::kMessagesFilename); | 753 relative_path = relative_path.Append(kMessagesFilename); |
753 if (relative_path.IsAbsolute() || relative_path.ReferencesParent()) { | 754 if (relative_path.IsAbsolute() || relative_path.ReferencesParent()) { |
754 // Invalid path for catalog. | 755 // Invalid path for catalog. |
755 ReportFailure( | 756 ReportFailure( |
756 INVALID_PATH_FOR_CATALOG, | 757 INVALID_PATH_FOR_CATALOG, |
757 l10n_util::GetStringFUTF16( | 758 l10n_util::GetStringFUTF16( |
758 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, | 759 IDS_EXTENSION_PACKAGE_INSTALL_ERROR, |
759 ASCIIToUTF16("INVALID_PATH_FOR_CATALOG"))); | 760 ASCIIToUTF16("INVALID_PATH_FOR_CATALOG"))); |
760 return false; | 761 return false; |
761 } | 762 } |
762 base::FilePath path = extension_root_.Append(relative_path); | 763 base::FilePath path = extension_root_.Append(relative_path); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
794 | 795 |
795 void SandboxedUnpacker::Cleanup() { | 796 void SandboxedUnpacker::Cleanup() { |
796 DCHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); | 797 DCHECK(unpacker_io_task_runner_->RunsTasksOnCurrentThread()); |
797 if (!temp_dir_.Delete()) { | 798 if (!temp_dir_.Delete()) { |
798 LOG(WARNING) << "Can not delete temp directory at " | 799 LOG(WARNING) << "Can not delete temp directory at " |
799 << temp_dir_.path().value(); | 800 << temp_dir_.path().value(); |
800 } | 801 } |
801 } | 802 } |
802 | 803 |
803 } // namespace extensions | 804 } // namespace extensions |
OLD | NEW |