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/ui/webui/options/certificate_manager_handler.h" | 5 #include "chrome/browser/ui/webui/options/certificate_manager_handler.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
mattm
2015/11/10 21:59:41
unused?
svaldez
2015/11/11 14:53:14
Done.
mattm
2015/11/11 22:14:39
Nevermind, looks like that actually came in from a
| |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <map> | 10 #include <map> |
11 | 11 |
12 #include "base/bind.h" | 12 #include "base/bind.h" |
13 #include "base/bind_helpers.h" | 13 #include "base/bind_helpers.h" |
14 #include "base/files/file_util.h" // for FileAccessProvider | 14 #include "base/files/file_util.h" // for FileAccessProvider |
15 #include "base/i18n/string_compare.h" | 15 #include "base/i18n/string_compare.h" |
16 #include "base/id_map.h" | 16 #include "base/id_map.h" |
17 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" |
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
704 ui::SelectFileDialog::FileTypeInfo file_type_info; | 704 ui::SelectFileDialog::FileTypeInfo file_type_info; |
705 if (!args->GetBoolean(0, &use_hardware_backed_)) { | 705 if (!args->GetBoolean(0, &use_hardware_backed_)) { |
706 // Unable to retrieve the hardware backed attribute from the args, | 706 // Unable to retrieve the hardware backed attribute from the args, |
707 // so bail. | 707 // so bail. |
708 web_ui()->CallJavascriptFunction("CertificateRestoreOverlay.dismiss"); | 708 web_ui()->CallJavascriptFunction("CertificateRestoreOverlay.dismiss"); |
709 ImportExportCleanup(); | 709 ImportExportCleanup(); |
710 return; | 710 return; |
711 } | 711 } |
712 file_type_info.extensions.resize(1); | 712 file_type_info.extensions.resize(1); |
713 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("p12")); | 713 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("p12")); |
714 file_type_info.extensions[0].push_back(FILE_PATH_LITERAL("crt")); | |
714 file_type_info.extension_description_overrides.push_back( | 715 file_type_info.extension_description_overrides.push_back( |
715 l10n_util::GetStringUTF16(IDS_CERT_MANAGER_PKCS12_FILES)); | 716 l10n_util::GetStringUTF16(IDS_CERT_USAGE_SSL_CLIENT)); |
716 file_type_info.include_all_files = true; | 717 file_type_info.include_all_files = true; |
717 select_file_dialog_ = ui::SelectFileDialog::Create( | 718 select_file_dialog_ = ui::SelectFileDialog::Create( |
718 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents())); | 719 this, new ChromeSelectFilePolicy(web_ui()->GetWebContents())); |
719 select_file_dialog_->SelectFile( | 720 select_file_dialog_->SelectFile( |
720 ui::SelectFileDialog::SELECT_OPEN_FILE, base::string16(), | 721 ui::SelectFileDialog::SELECT_OPEN_FILE, base::string16(), |
721 base::FilePath(), &file_type_info, 1, FILE_PATH_LITERAL("p12"), | 722 base::FilePath(), &file_type_info, 1, FILE_PATH_LITERAL("p12"), |
722 GetParentWindow(), | 723 GetParentWindow(), |
723 reinterpret_cast<void*>(IMPORT_PERSONAL_FILE_SELECTED)); | 724 reinterpret_cast<void*>(IMPORT_PERSONAL_FILE_SELECTED)); |
724 } | 725 } |
725 | 726 |
726 void CertificateManagerHandler::ImportPersonalFileSelected( | 727 void CertificateManagerHandler::ImportPersonalFileSelected( |
727 const base::FilePath& path) { | 728 const base::FilePath& path) { |
728 file_path_ = path; | 729 file_path_ = path; |
729 web_ui()->CallJavascriptFunction( | 730 if (file_path_.MatchesExtension(FILE_PATH_LITERAL(".p12"))) { |
730 "CertificateManager.importPersonalAskPassword"); | 731 web_ui()->CallJavascriptFunction( |
732 "CertificateManager.importPersonalAskPassword"); | |
733 } else { | |
734 password_.clear(); | |
735 file_access_provider_->StartRead( | |
736 file_path_, | |
737 base::Bind(&CertificateManagerHandler::ImportPersonalFileRead, | |
738 base::Unretained(this)), | |
739 &tracker_); | |
740 } | |
731 } | 741 } |
732 | 742 |
733 void CertificateManagerHandler::ImportPersonalPasswordSelected( | 743 void CertificateManagerHandler::ImportPersonalPasswordSelected( |
734 const base::ListValue* args) { | 744 const base::ListValue* args) { |
735 if (!args->GetString(0, &password_)) { | 745 if (!args->GetString(0, &password_)) { |
736 web_ui()->CallJavascriptFunction("CertificateRestoreOverlay.dismiss"); | 746 web_ui()->CallJavascriptFunction("CertificateRestoreOverlay.dismiss"); |
737 ImportExportCleanup(); | 747 ImportExportCleanup(); |
738 return; | 748 return; |
739 } | 749 } |
740 file_access_provider_->StartRead( | 750 file_access_provider_->StartRead( |
741 file_path_, | 751 file_path_, |
742 base::Bind(&CertificateManagerHandler::ImportPersonalFileRead, | 752 base::Bind(&CertificateManagerHandler::ImportPersonalFileRead, |
743 base::Unretained(this)), | 753 base::Unretained(this)), |
744 &tracker_); | 754 &tracker_); |
745 } | 755 } |
746 | 756 |
747 void CertificateManagerHandler::ImportPersonalFileRead( | 757 void CertificateManagerHandler::ImportPersonalFileRead( |
748 const int* read_errno, const std::string* data) { | 758 const int* read_errno, const std::string* data) { |
749 if (*read_errno) { | 759 if (*read_errno) { |
750 ImportExportCleanup(); | 760 ImportExportCleanup(); |
751 web_ui()->CallJavascriptFunction("CertificateRestoreOverlay.dismiss"); | 761 web_ui()->CallJavascriptFunction("CertificateRestoreOverlay.dismiss"); |
752 ShowError( | 762 ShowError( |
753 l10n_util::GetStringUTF8(IDS_CERT_MANAGER_PKCS12_IMPORT_ERROR_TITLE), | 763 l10n_util::GetStringUTF8(IDS_CERT_MANAGER_IMPORT_ERROR_TITLE), |
754 l10n_util::GetStringFUTF8(IDS_CERT_MANAGER_READ_ERROR_FORMAT, | 764 l10n_util::GetStringFUTF8(IDS_CERT_MANAGER_READ_ERROR_FORMAT, |
755 UTF8ToUTF16( | 765 UTF8ToUTF16( |
756 base::safe_strerror(*read_errno)))); | 766 base::safe_strerror(*read_errno)))); |
757 return; | 767 return; |
758 } | 768 } |
759 | 769 |
760 file_data_ = *data; | 770 file_data_ = *data; |
761 | 771 |
762 if (use_hardware_backed_) { | 772 if (file_path_.MatchesExtension(FILE_PATH_LITERAL(".p12"))) { |
763 module_ = certificate_manager_model_->cert_db()->GetPrivateModule(); | 773 if (use_hardware_backed_) { |
774 module_ = certificate_manager_model_->cert_db()->GetPrivateModule(); | |
775 } else { | |
776 module_ = certificate_manager_model_->cert_db()->GetPublicModule(); | |
777 } | |
778 | |
779 net::CryptoModuleList modules; | |
780 modules.push_back(module_); | |
781 chrome::UnlockSlotsIfNecessary( | |
782 modules, | |
783 chrome::kCryptoModulePasswordCertImport, | |
784 net::HostPortPair(), // unused. | |
785 GetParentWindow(), | |
786 base::Bind(&CertificateManagerHandler::ImportPersonalSlotUnlocked, | |
787 base::Unretained(this))); | |
764 } else { | 788 } else { |
765 module_ = certificate_manager_model_->cert_db()->GetPublicModule(); | 789 int result = certificate_manager_model_->ImportUserCert(file_data_); |
790 ImportExportCleanup(); | |
791 web_ui()->CallJavascriptFunction("CertificateRestoreOverlay.dismiss"); | |
792 int string_id; | |
793 switch (result) { | |
794 case net::OK: | |
795 return; | |
796 case net::ERR_NO_PRIVATE_KEY_FOR_CERT: | |
797 string_id = IDS_CERT_MANAGER_IMPORT_MISSING_KEY; | |
798 break; | |
799 case net::ERR_CERT_INVALID: | |
800 string_id = IDS_CERT_MANAGER_READ_ERROR_FORMAT; | |
801 break; | |
802 default: | |
803 string_id = IDS_CERT_MANAGER_UNKNOWN_ERROR; | |
804 break; | |
805 } | |
806 ShowError( | |
807 l10n_util::GetStringUTF8(IDS_CERT_MANAGER_IMPORT_ERROR_TITLE), | |
808 l10n_util::GetStringUTF8(string_id)); | |
766 } | 809 } |
767 | |
768 net::CryptoModuleList modules; | |
769 modules.push_back(module_); | |
770 chrome::UnlockSlotsIfNecessary( | |
771 modules, | |
772 chrome::kCryptoModulePasswordCertImport, | |
773 net::HostPortPair(), // unused. | |
774 GetParentWindow(), | |
775 base::Bind(&CertificateManagerHandler::ImportPersonalSlotUnlocked, | |
776 base::Unretained(this))); | |
777 } | 810 } |
778 | 811 |
779 void CertificateManagerHandler::ImportPersonalSlotUnlocked() { | 812 void CertificateManagerHandler::ImportPersonalSlotUnlocked() { |
780 // Determine if the private key should be unextractable after the import. | 813 // Determine if the private key should be unextractable after the import. |
781 // We do this by checking the value of |use_hardware_backed_| which is set | 814 // We do this by checking the value of |use_hardware_backed_| which is set |
782 // to true if importing into a hardware module. Currently, this only happens | 815 // to true if importing into a hardware module. Currently, this only happens |
783 // for Chrome OS when the "Import and Bind" option is chosen. | 816 // for Chrome OS when the "Import and Bind" option is chosen. |
784 bool is_extractable = !use_hardware_backed_; | 817 bool is_extractable = !use_hardware_backed_; |
785 int result = certificate_manager_model_->ImportFromPKCS12( | 818 int result = certificate_manager_model_->ImportFromPKCS12( |
786 module_.get(), file_data_, password_, is_extractable); | 819 module_.get(), file_data_, password_, is_extractable); |
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1155 title_value, | 1188 title_value, |
1156 error_value, | 1189 error_value, |
1157 cert_error_list); | 1190 cert_error_list); |
1158 } | 1191 } |
1159 | 1192 |
1160 gfx::NativeWindow CertificateManagerHandler::GetParentWindow() const { | 1193 gfx::NativeWindow CertificateManagerHandler::GetParentWindow() const { |
1161 return web_ui()->GetWebContents()->GetTopLevelNativeWindow(); | 1194 return web_ui()->GetWebContents()->GetTopLevelNativeWindow(); |
1162 } | 1195 } |
1163 | 1196 |
1164 } // namespace options | 1197 } // namespace options |
OLD | NEW |