Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: chrome/browser/ui/webui/options/certificate_manager_handler.cc

Issue 1423333006: Adding User Certificate (.crt) Import to Certificate Manager (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix header. Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/certificate_manager_model.cc ('k') | net/cert/cert_database_nss.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <map> 10 #include <map>
(...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
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");
Lei Zhang 2015/11/21 01:55:15 You may also consider adding a return here, and th
svaldez 2015/11/23 15:17:54 Done.
733 } else {
Lei Zhang 2015/11/19 22:23:59 Just to be clear, is this the .crt file case? Assu
svaldez 2015/11/20 15:01:52 This is for the '.crt' case, however there are oth
Lei Zhang 2015/11/21 01:55:15 Got it. Can you write a comment here to explain th
svaldez 2015/11/23 15:17:54 Done.
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);
787 ImportExportCleanup(); 820 ImportExportCleanup();
788 web_ui()->CallJavascriptFunction("CertificateRestoreOverlay.dismiss"); 821 web_ui()->CallJavascriptFunction("CertificateRestoreOverlay.dismiss");
789 int string_id; 822 int string_id;
790 switch (result) { 823 switch (result) {
791 case net::OK: 824 case net::OK:
792 return; 825 return;
793 case net::ERR_PKCS12_IMPORT_BAD_PASSWORD: 826 case net::ERR_PKCS12_IMPORT_BAD_PASSWORD:
794 // TODO(mattm): if the error was a bad password, we should reshow the 827 // TODO(mattm): if the error was a bad password, we should reshow the
795 // password dialog after the user dismisses the error dialog. 828 // password dialog after the user dismisses the error dialog.
796 string_id = IDS_CERT_MANAGER_BAD_PASSWORD; 829 string_id = IDS_CERT_MANAGER_BAD_PASSWORD;
797 break; 830 break;
798 case net::ERR_PKCS12_IMPORT_INVALID_MAC: 831 case net::ERR_PKCS12_IMPORT_INVALID_MAC:
799 string_id = IDS_CERT_MANAGER_PKCS12_IMPORT_INVALID_MAC; 832 string_id = IDS_CERT_MANAGER_IMPORT_INVALID_MAC;
800 break; 833 break;
801 case net::ERR_PKCS12_IMPORT_INVALID_FILE: 834 case net::ERR_PKCS12_IMPORT_INVALID_FILE:
802 string_id = IDS_CERT_MANAGER_PKCS12_IMPORT_INVALID_FILE; 835 string_id = IDS_CERT_MANAGER_IMPORT_INVALID_FILE;
803 break; 836 break;
804 case net::ERR_PKCS12_IMPORT_UNSUPPORTED: 837 case net::ERR_PKCS12_IMPORT_UNSUPPORTED:
805 string_id = IDS_CERT_MANAGER_PKCS12_IMPORT_UNSUPPORTED; 838 string_id = IDS_CERT_MANAGER_IMPORT_UNSUPPORTED;
806 break; 839 break;
807 default: 840 default:
808 string_id = IDS_CERT_MANAGER_UNKNOWN_ERROR; 841 string_id = IDS_CERT_MANAGER_UNKNOWN_ERROR;
809 break; 842 break;
810 } 843 }
811 ShowError( 844 ShowError(
812 l10n_util::GetStringUTF8(IDS_CERT_MANAGER_PKCS12_IMPORT_ERROR_TITLE), 845 l10n_util::GetStringUTF8(IDS_CERT_MANAGER_IMPORT_ERROR_TITLE),
813 l10n_util::GetStringUTF8(string_id)); 846 l10n_util::GetStringUTF8(string_id));
814 } 847 }
815 848
816 void CertificateManagerHandler::CancelImportExportProcess( 849 void CertificateManagerHandler::CancelImportExportProcess(
817 const base::ListValue* args) { 850 const base::ListValue* args) {
818 ImportExportCleanup(); 851 ImportExportCleanup();
819 } 852 }
820 853
821 void CertificateManagerHandler::ImportExportCleanup() { 854 void CertificateManagerHandler::ImportExportCleanup() {
822 file_path_.clear(); 855 file_path_.clear();
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « chrome/browser/certificate_manager_model.cc ('k') | net/cert/cert_database_nss.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698