diff --git a/pass.xcodeproj/project.pbxproj b/pass.xcodeproj/project.pbxproj index c5f3f66..334022d 100644 --- a/pass.xcodeproj/project.pbxproj +++ b/pass.xcodeproj/project.pbxproj @@ -20,6 +20,7 @@ 3032327422C7F710009EBD9C /* KeyFileManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3032327322C7F710009EBD9C /* KeyFileManager.swift */; }; 3032328A22C9FBA2009EBD9C /* KeyFileManagerTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3032328922C9FBA2009EBD9C /* KeyFileManagerTest.swift */; }; 3032328E22CBD4CD009EBD9C /* CryptographicKeys.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3032328D22CBD4CD009EBD9C /* CryptographicKeys.swift */; }; + 30650E7123F82AF8005CCD5E /* SSHKeyFileImportTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30650E7023F82AF8005CCD5E /* SSHKeyFileImportTableViewController.swift */; }; 30650E7323F847FC005CCD5E /* KeyImporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30650E7223F847FC005CCD5E /* KeyImporter.swift */; }; 3066AD6823EE0D6500F65535 /* PGPKeyImporter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3066AD6723EE0D6500F65535 /* PGPKeyImporter.swift */; }; 30697C2A21F63C5A0064FCAC /* NotificationNames.swift in Sources */ = {isa = PBXBuildFile; fileRef = 30697C2321F63C580064FCAC /* NotificationNames.swift */; }; @@ -242,6 +243,7 @@ 3032327322C7F710009EBD9C /* KeyFileManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyFileManager.swift; sourceTree = ""; }; 3032328922C9FBA2009EBD9C /* KeyFileManagerTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyFileManagerTest.swift; sourceTree = ""; }; 3032328D22CBD4CD009EBD9C /* CryptographicKeys.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CryptographicKeys.swift; sourceTree = ""; }; + 30650E7023F82AF8005CCD5E /* SSHKeyFileImportTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SSHKeyFileImportTableViewController.swift; sourceTree = ""; }; 30650E7223F847FC005CCD5E /* KeyImporter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = KeyImporter.swift; sourceTree = ""; }; 3066AD6723EE0D6500F65535 /* PGPKeyImporter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PGPKeyImporter.swift; sourceTree = ""; }; 30697C2321F63C580064FCAC /* NotificationNames.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NotificationNames.swift; sourceTree = ""; }; @@ -721,6 +723,7 @@ DCAAF7441E2FA66800AB94BC /* SettingsTableViewController.swift */, DC037CA91E4B8EAE00609409 /* SpecialThanksTableViewController.swift */, DCC441531E916382008A90C4 /* SSHKeyArmorImportTableViewController.swift */, + 30650E7023F82AF8005CCD5E /* SSHKeyFileImportTableViewController.swift */, DC8963BF1E38EEB900828B09 /* SSHKeyUrlImportTableViewController.swift */, ); path = Controllers; @@ -1383,6 +1386,7 @@ A2A61C201EEFABAD00CFE063 /* UtilsExtension.swift in Sources */, DC8963C01E38EEB900828B09 /* SSHKeyUrlImportTableViewController.swift in Sources */, 3066AD6823EE0D6500F65535 /* PGPKeyImporter.swift in Sources */, + 30650E7123F82AF8005CCD5E /* SSHKeyFileImportTableViewController.swift in Sources */, DC193FFA1E49B4430077E0A3 /* AdvancedSettingsTableViewController.swift in Sources */, DCFB77AB1E503729008DE471 /* ContentProvider.swift in Sources */, DCA0499C1E3362F400522E8F /* PGPKeyUrlImportTableViewController.swift in Sources */, diff --git a/pass/Base.lproj/Main.storyboard b/pass/Base.lproj/Main.storyboard index 167d447..de1ea7d 100644 --- a/pass/Base.lproj/Main.storyboard +++ b/pass/Base.lproj/Main.storyboard @@ -496,6 +496,7 @@ + @@ -1878,6 +1879,87 @@ Secret Question 1: What is your childhood best friend's most bizarre superhero f + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pass/Controllers/GitRepositorySettingsTableViewController.swift b/pass/Controllers/GitRepositorySettingsTableViewController.swift index 8bc2eda..b1ccaf7 100644 --- a/pass/Controllers/GitRepositorySettingsTableViewController.swift +++ b/pass/Controllers/GitRepositorySettingsTableViewController.swift @@ -247,6 +247,9 @@ class GitRepositorySettingsTableViewController: UITableViewController { optionMenu.addAction(UIAlertAction(title: SSHKeyArmorImportTableViewController.menuLabel, style: .default) { _ in self.performSegue(withIdentifier: "setGitSSHKeyByArmorSegue", sender: self) }) + optionMenu.addAction(UIAlertAction(title: SSHKeyFileImportTableViewController.menuLabel, style: .default) { _ in + self.performSegue(withIdentifier: "setGitSSHKeyByFileSegue", sender: self) + }) if isReadyToUse() { optionMenu.addAction(UIAlertAction(title: "\(Self.menuLabel) (\("Import".localize()))", style: .default) { _ in diff --git a/pass/Controllers/SSHKeyFileImportTableViewController.swift b/pass/Controllers/SSHKeyFileImportTableViewController.swift new file mode 100644 index 0000000..944b31c --- /dev/null +++ b/pass/Controllers/SSHKeyFileImportTableViewController.swift @@ -0,0 +1,72 @@ +// +// SSHKeyFileImportTableViewController.swift +// pass +// +// Created by Danny Moesch on 15.02.20. +// Copyright © 2020 Bob Sun. All rights reserved. +// + +import passKit +import SVProgressHUD + +class SSHKeyFileImportTableViewController: AutoCellHeightUITableViewController { + + @IBOutlet weak var sshPrivateKeyFile: UITableViewCell! + + private var privateKey: String? = nil + + @IBAction func doneButtonTapped(_ sender: Any) { + performSegue(withIdentifier: "importSSHKeySegue", sender: self) + } + + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + let cell = tableView.cellForRow(at: indexPath) + let picker = UIDocumentPickerViewController(documentTypes: ["public.data"], in: .open) + cell?.isSelected = false + guard cell == sshPrivateKeyFile else { + return + } + picker.delegate = self + if #available(iOS 13.0, *) { + picker.shouldShowFileExtensions = true + } + present(picker, animated: true, completion: nil) + } +} + +extension SSHKeyFileImportTableViewController: UIDocumentPickerDelegate { + + func documentPicker(_: UIDocumentPickerViewController, didPickDocumentsAt url: [URL]) { + guard let url = url.first else { + return + } + let fileName = url.lastPathComponent + do { + privateKey = try String(contentsOf: url, encoding: .ascii) + sshPrivateKeyFile.textLabel?.text = fileName + } catch { + Utils.alert(title: "CannotImportFile".localize(), message: "FileCannotBeImported.".localize(fileName), controller: self) + } + } +} + +extension SSHKeyFileImportTableViewController: KeyImporter { + + static let keySource = KeySource.file + static let label = "LoadFromFiles".localize() + + func isReadyToUse() -> Bool { + guard privateKey != nil else { + Utils.alert(title: "CannotSave".localize(), message: "SetPrivateKeyUrl.".localize(), controller: self) + return false + } + return true + } + + func importKeys() throws { + guard let privateKey = privateKey else { + return + } + try KeyFileManager.PrivateSsh.importKey(from: privateKey) + } +} diff --git a/pass/de.lproj/Localizable.strings b/pass/de.lproj/Localizable.strings index a54eeaf..813d7e8 100644 --- a/pass/de.lproj/Localizable.strings +++ b/pass/de.lproj/Localizable.strings @@ -280,6 +280,12 @@ gibt den Schlüssel in diesem speziellen Format aus. Die Zwischenablage wird nac gibt den Schlüssel in diesem speziellen Format aus. Kopiere ihn so zu einem Key-Server."; +"SshAsciiArmorFileExplanation." = "Das Format \"ASCII-Armor\" ist anders als das Binärformat eine einfache Zeichenkette. Der Befehl + + $ cat ~/.ssh/id_rsa + +gibt den Schlüssel in diesem speziellen Format aus. Kopiere ihn so zu einem Speicherort, der für die Dateien-App zugänglich ist."; + "GpgAsciiArmorCopyExplanation." = "GnuPG unterstützt die Kommandozeilenoption \"-a\", welche die Schlüssel im Format \"ASCII-Armor\" ausgibt. Es ist anders als das Binärformat eine einfache Zeichenkette. Die Befehle $ gpg --export -a KEY_ID diff --git a/pass/de.lproj/Main.strings b/pass/de.lproj/Main.strings index b7a47be..a085ef5 100644 --- a/pass/de.lproj/Main.strings +++ b/pass/de.lproj/Main.strings @@ -23,6 +23,9 @@ /* Class = "UIBarButtonItem"; title = "Back"; ObjectID = "9yM-Mg-Cg8"; */ "9yM-Mg-Cg8.title" = "Zurück"; +/* Class = "UILabel"; text = "Select file ..."; ObjectID = "9KE-VA-cx2"; */ +"9KE-VA-cx2.text" = "Datei auswählen ..."; + /* Class = "UILabel"; text = "Private Key URL"; ObjectID = "C2w-dd-roS"; */ "C2w-dd-roS.text" = "URL des privaten Schlüssels"; diff --git a/pass/en.lproj/Localizable.strings b/pass/en.lproj/Localizable.strings index 395eda1..df7b8c9 100644 --- a/pass/en.lproj/Localizable.strings +++ b/pass/en.lproj/Localizable.strings @@ -280,6 +280,12 @@ to get the key in this specific format. The clipboard will be cleared 45s after to get the key in this specific format. Subsequently, copy it to your secured key server."; +"SshAsciiArmorFileExplanation." = "The ASCII-armored key format is similar to unencoded documents rather than the binary format. Use + + $ cat ~/.ssh/id_rsa + +to get the key in this specific format. Subsequently, copy it to a location accessible by the Files app."; + "GpgAsciiArmorCopyExplanation." = "GnuPG supports the command-line option \"-a\" that causes output to be generated in an ASCII-armored format similar to unencoded documents rather than the binary format. Use $ gpg --export -a KEY_ID diff --git a/pass/en.lproj/Main.strings b/pass/en.lproj/Main.strings index 94c443a..dcbda31 100644 Binary files a/pass/en.lproj/Main.strings and b/pass/en.lproj/Main.strings differ