diff --git a/enzevalos_iphone.xcodeproj/project.pbxproj b/enzevalos_iphone.xcodeproj/project.pbxproj index a47f5f7f3fa9f01c75a9407c07d6994be2348271..34dcb6fa8ffff919fa670b27e7981687edebcfe3 100644 --- a/enzevalos_iphone.xcodeproj/project.pbxproj +++ b/enzevalos_iphone.xcodeproj/project.pbxproj @@ -49,7 +49,6 @@ 4751C6FC2344C8D1006B2A4D /* KeyTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4751C6FB2344C8D1006B2A4D /* KeyTableViewController.swift */; }; 4751C7002344D37C006B2A4D /* SecretKey+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4751C6FE2344D37C006B2A4D /* SecretKey+CoreDataClass.swift */; }; 4751C7012344D37C006B2A4D /* SecretKey+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4751C6FF2344D37C006B2A4D /* SecretKey+CoreDataProperties.swift */; }; - 4751C70523474525006B2A4D /* ImportKeyOverviewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4751C70423474525006B2A4D /* ImportKeyOverviewController.swift */; }; 4756DE0E20402F8E00452288 /* invitationTextCensor.html in Resources */ = {isa = PBXBuildFile; fileRef = 4756DE0D20402F8E00452288 /* invitationTextCensor.html */; }; 475B00331F7B9565006CDD41 /* SwiftPGP.swift in Sources */ = {isa = PBXBuildFile; fileRef = 475B00301F7B9565006CDD41 /* SwiftPGP.swift */; }; 475B00341F7B9565006CDD41 /* Cryptography.swift in Sources */ = {isa = PBXBuildFile; fileRef = 475B00311F7B9565006CDD41 /* Cryptography.swift */; }; @@ -98,6 +97,7 @@ 479C649B21F45DAF00A01071 /* PasswordToggleVisibilityView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 479C649921F45DAF00A01071 /* PasswordToggleVisibilityView.swift */; }; 47A5D6E22294BF3B0084F81D /* TempKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47A5D6E12294BF3A0084F81D /* TempKey.swift */; }; 47A5D6E42294BFF50084F81D /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47A5D6E32294BFF50084F81D /* Logger.swift */; }; + 47C036FF2347C0F5006295E8 /* ImportKeyOverviewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47C036FE2347C0F4006295E8 /* ImportKeyOverviewController.swift */; }; 47C22281218AFD6300BD2C2B /* AutocryptTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 47C22280218AFD6300BD2C2B /* AutocryptTest.swift */; }; 47C22283218B02C700BD2C2B /* autocryptSimpleExample1.eml in Resources */ = {isa = PBXBuildFile; fileRef = 47C22282218B02C700BD2C2B /* autocryptSimpleExample1.eml */; }; 47CD5AAA2012368D00E771A1 /* logging_pk.asc in Resources */ = {isa = PBXBuildFile; fileRef = 47CD5AA82012368D00E771A1 /* logging_pk.asc */; }; @@ -302,7 +302,6 @@ 4751C6FD2344D169006B2A4D /* enzevalos_iphone 8.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "enzevalos_iphone 8.xcdatamodel"; sourceTree = "<group>"; }; 4751C6FE2344D37C006B2A4D /* SecretKey+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SecretKey+CoreDataClass.swift"; sourceTree = "<group>"; }; 4751C6FF2344D37C006B2A4D /* SecretKey+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "SecretKey+CoreDataProperties.swift"; sourceTree = "<group>"; }; - 4751C70423474525006B2A4D /* ImportKeyOverviewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImportKeyOverviewController.swift; sourceTree = "<group>"; }; 4756DE0D20402F8E00452288 /* invitationTextCensor.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; name = invitationTextCensor.html; path = Invitation/invitationTextCensor.html; sourceTree = "<group>"; }; 475B00301F7B9565006CDD41 /* SwiftPGP.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftPGP.swift; sourceTree = "<group>"; }; 475B00311F7B9565006CDD41 /* Cryptography.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Cryptography.swift; sourceTree = "<group>"; }; @@ -353,6 +352,7 @@ 47A5D6E12294BF3A0084F81D /* TempKey.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TempKey.swift; sourceTree = "<group>"; }; 47A5D6E32294BFF50084F81D /* Logger.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; }; 47B2318A1F0D458100961B28 /* enzevalos_iphone 2.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "enzevalos_iphone 2.xcdatamodel"; sourceTree = "<group>"; }; + 47C036FE2347C0F4006295E8 /* ImportKeyOverviewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ImportKeyOverviewController.swift; sourceTree = "<group>"; }; 47C22280218AFD6300BD2C2B /* AutocryptTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AutocryptTest.swift; sourceTree = "<group>"; }; 47C22282218B02C700BD2C2B /* autocryptSimpleExample1.eml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = autocryptSimpleExample1.eml; sourceTree = "<group>"; }; 47CD5AA82012368D00E771A1 /* logging_pk.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = logging_pk.asc; path = keys/logging_pk.asc; sourceTree = "<group>"; }; @@ -1058,7 +1058,7 @@ 47E737732284610E00972401 /* KeyCell.xib */, 47E737752284632F00972401 /* KeyCell.swift */, 4751C6FB2344C8D1006B2A4D /* KeyTableViewController.swift */, - 4751C70423474525006B2A4D /* ImportKeyOverviewController.swift */, + 47C036FE2347C0F4006295E8 /* ImportKeyOverviewController.swift */, ); name = keyView; sourceTree = "<group>"; @@ -1557,7 +1557,6 @@ 4707096D1F8F9F4900657F41 /* ExportViewController.swift in Sources */, F12060801DA540FE00F6EF37 /* RefreshControlExtension.swift in Sources */, 4751C6FC2344C8D1006B2A4D /* KeyTableViewController.swift in Sources */, - 4751C70523474525006B2A4D /* ImportKeyOverviewController.swift in Sources */, A13526811D955BDF00D3BFE1 /* enzevalos_iphone.xcdatamodeld in Sources */, 472F39821E1E5347009260FB /* Mail_Address+CoreDataProperties.swift in Sources */, 477548E221F77466000B22A8 /* SecurityIndicator.swift in Sources */, @@ -1596,6 +1595,7 @@ A1EB057C1D956838008659C1 /* MailHandler.swift in Sources */, A182182E21E50D8D00918A29 /* IntroButtonViewController.swift in Sources */, 478AF715222FD5C600AEF69E /* IncomingMail.swift in Sources */, + 47C036FF2347C0F5006295E8 /* ImportKeyOverviewController.swift in Sources */, A1EB05881D956879008659C1 /* AddressHandler.swift in Sources */, 472F39701E14F75C009260FB /* DataHandler.swift in Sources */, A1C62E9A2018F716000E5273 /* OnboardingValueState.swift in Sources */, diff --git a/enzevalos_iphone/Base.lproj/Main.storyboard b/enzevalos_iphone/Base.lproj/Main.storyboard index b66bb1fbc1957859dcf2d826d3794beb1e2da9a5..3caf658d1352ab8b9639bceca6d9510b4d68b6ca 100644 --- a/enzevalos_iphone/Base.lproj/Main.storyboard +++ b/enzevalos_iphone/Base.lproj/Main.storyboard @@ -566,18 +566,27 @@ <!--Key Table View Controller--> <scene sceneID="bHW-51-a9S"> <objects> - <tableViewController storyboardIdentifier="KeyListViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="RgH-L9-huP" customClass="KeyTableViewController" customModule="enzevalos_iphone" customModuleProvider="target" sceneMemberID="viewController"> + <tableViewController storyboardIdentifier="KeyTableViewController" useStoryboardIdentifierAsRestorationIdentifier="YES" id="RgH-L9-huP" customClass="KeyTableViewController" customModule="enzevalos_iphone" customModuleProvider="target" sceneMemberID="viewController"> <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="fNn-RC-Nym"> <rect key="frame" x="0.0" y="0.0" width="414" height="896"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> <prototypes> - <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" id="onA-1Q-yTD"> + <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" restorationIdentifier="InfoCell" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="InfoCell" textLabel="mRi-8e-Y4K" style="IBUITableViewCellStyleDefault" id="onA-1Q-yTD"> <rect key="frame" x="0.0" y="28" width="414" height="44"/> <autoresizingMask key="autoresizingMask"/> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="onA-1Q-yTD" id="gXC-FG-GZS"> <rect key="frame" x="0.0" y="0.0" width="414" height="43.666666666666664"/> <autoresizingMask key="autoresizingMask"/> + <subviews> + <label opaque="NO" multipleTouchEnabled="YES" contentMode="left" insetsLayoutMarginsFromSafeArea="NO" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" numberOfLines="0" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="mRi-8e-Y4K"> + <rect key="frame" x="20" y="0.0" width="374" height="43.666666666666664"/> + <autoresizingMask key="autoresizingMask"/> + <fontDescription key="fontDescription" type="system" pointSize="17"/> + <nil key="textColor"/> + <nil key="highlightedColor"/> + </label> + </subviews> </tableViewCellContentView> </tableViewCell> </prototypes> @@ -595,13 +604,13 @@ <scene sceneID="hig-sG-hkl"> <objects> <tableViewController storyboardIdentifier="ImportKeyOverview" useStoryboardIdentifierAsRestorationIdentifier="YES" id="6Ib-ya-r4X" customClass="ImportKeyOverviewController" customModule="enzevalos_iphone" customModuleProvider="target" sceneMemberID="viewController"> - <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="28" sectionFooterHeight="28" id="0W5-nq-uJy"> + <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="default" allowsMultipleSelection="YES" rowHeight="-1" estimatedRowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" id="0W5-nq-uJy"> <rect key="frame" x="0.0" y="0.0" width="414" height="896"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> - <color key="backgroundColor" white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/> + <color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/> <prototypes> <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" restorationIdentifier="InfoText" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="InfoText" textLabel="RzJ-lh-4Kh" style="IBUITableViewCellStyleDefault" id="Qj6-zf-zg2"> - <rect key="frame" x="0.0" y="28" width="414" height="44"/> + <rect key="frame" x="0.0" y="55.333333333333343" width="414" height="44"/> <autoresizingMask key="autoresizingMask"/> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="Qj6-zf-zg2" id="q93-0z-hqB"> <rect key="frame" x="0.0" y="0.0" width="414" height="43.666666666666664"/> @@ -617,22 +626,6 @@ </subviews> </tableViewCellContentView> </tableViewCell> - <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" restorationIdentifier="iTunesButton" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="iTunesButton" id="cyz-Hr-lcc" customClass="ButtonCell" customModule="enzevalos_iphone" customModuleProvider="target"> - <rect key="frame" x="0.0" y="72" width="414" height="44"/> - <autoresizingMask key="autoresizingMask"/> - <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="cyz-Hr-lcc" id="1To-y3-zpU"> - <rect key="frame" x="0.0" y="0.0" width="414" height="43.666666666666664"/> - <autoresizingMask key="autoresizingMask"/> - </tableViewCellContentView> - </tableViewCell> - <tableViewCell clipsSubviews="YES" contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" selectionStyle="default" indentationWidth="10" reuseIdentifier="PasteButton" id="nu9-Sv-yyP" customClass="ButtonCell" customModule="enzevalos_iphone" customModuleProvider="target"> - <rect key="frame" x="0.0" y="116" width="414" height="44"/> - <autoresizingMask key="autoresizingMask"/> - <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" preservesSuperviewLayoutMargins="YES" insetsLayoutMarginsFromSafeArea="NO" tableViewCell="nu9-Sv-yyP" id="RtY-T7-d0c"> - <rect key="frame" x="0.0" y="0.0" width="414" height="43.666666666666664"/> - <autoresizingMask key="autoresizingMask"/> - </tableViewCellContentView> - </tableViewCell> </prototypes> <connections> <outlet property="dataSource" destination="6Ib-ya-r4X" id="wbc-5C-BFq"/> @@ -914,7 +907,7 @@ <objects> <tableViewController storyboardIdentifier="UITableViewController-8Di-x2-cWQ" useStoryboardIdentifierAsRestorationIdentifier="YES" id="8Di-x2-cWQ" customClass="ContactViewController" customModule="enzevalos_iphone" customModuleProvider="target" sceneMemberID="viewController"> <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="grouped" separatorStyle="default" rowHeight="44" sectionHeaderHeight="18" sectionFooterHeight="18" id="lK7-ug-OyQ"> - <rect key="frame" x="0.0" y="0.0" width="414" height="808"/> + <rect key="frame" x="0.0" y="0.0" width="414" height="896"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/> <prototypes> @@ -1290,7 +1283,7 @@ <rect key="frame" x="0.0" y="809.33333333333337" width="414" height="44"/> <autoresizingMask key="autoresizingMask"/> <tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="hTc-vs-AIl" id="pJ9-4e-7at"> - <rect key="frame" x="0.0" y="0.0" width="388" height="43.666666666666664"/> + <rect key="frame" x="0.0" y="0.0" width="376" height="43.666666666666664"/> <autoresizingMask key="autoresizingMask"/> <subviews> <imageView userInteractionEnabled="NO" contentMode="scaleToFill" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="Ll6-yF-xkq"> @@ -1542,7 +1535,7 @@ <objects> <tableViewController storyboardIdentifier="exportInfoViewController" id="7Pd-d5-0wz" customClass="ExportInfoViewController" customModule="enzevalos_iphone" customModuleProvider="target" sceneMemberID="viewController"> <tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" showsHorizontalScrollIndicator="NO" dataMode="prototypes" style="grouped" separatorStyle="default" sectionIndexMinimumDisplayRowCount="1" rowHeight="-1" sectionHeaderHeight="18" sectionFooterHeight="18" id="2Uv-bd-pB1"> - <rect key="frame" x="0.0" y="0.0" width="414" height="808"/> + <rect key="frame" x="0.0" y="0.0" width="414" height="896"/> <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> <color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/> <prototypes> @@ -2030,7 +2023,7 @@ Um deine sicheren E-Mails auch auf einem anderen Gerät lesen zu können, muss d </connections> </barButtonItem> <button key="titleView" opaque="NO" contentMode="scaleToFill" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="roundedRect" lineBreakMode="middleTruncation" id="iUk-lk-1LN"> - <rect key="frame" x="162" y="6" width="91" height="32"/> + <rect key="frame" x="161.66666666666666" y="6" width="91" height="32"/> <autoresizingMask key="autoresizingMask" flexibleMinX="YES" flexibleMaxX="YES" flexibleMaxY="YES"/> <connections> <action selector="iconButtonPressed:" destination="4Ey-v4-VeB" eventType="touchUpInside" id="Opj-Y1-Vtg"/> diff --git a/enzevalos_iphone/ButtonCell.swift b/enzevalos_iphone/ButtonCell.swift index 17c39f180f3904b8ac47e9f04aeee4e398b0fdcf..d368dcf82b6b1b3713ee7726ac36c0acb6a37660 100644 --- a/enzevalos_iphone/ButtonCell.swift +++ b/enzevalos_iphone/ButtonCell.swift @@ -12,6 +12,24 @@ class ButtonCell: UITableViewCell { @IBOutlet weak var button: UIButton! var listener: ButtonCellHandler? var id = 0 + + static func createButtonCell(tableView: UITableView, normalTitle: String, id: Int, listener: ButtonCellHandler) -> ButtonCell { + var cell: ButtonCell + if let tmpCell = tableView.dequeueReusableCell(withIdentifier: "ButtonCell") as? ButtonCell{ + cell = tmpCell + } else { + tableView.register(UINib.init(nibName: "ButtonCell", bundle: nil), forCellReuseIdentifier: "ButtonCell") + cell = tableView.dequeueReusableCell(withIdentifier: "ButtonCell") as! ButtonCell + } + cell.button.setTitle(normalTitle, for: .normal) + cell.id = id + cell.listener = listener + cell.button.adjustsImageWhenHighlighted = true + cell.button.showsTouchWhenHighlighted = true + + return cell + } + var isEnabled: Bool { set { button.isEnabled = newValue @@ -30,6 +48,10 @@ class ButtonCell: UITableViewCell { } } + + func isEmpty() -> Bool { + return button == nil + } } diff --git a/enzevalos_iphone/CryptoManagementViewController.swift b/enzevalos_iphone/CryptoManagementViewController.swift index 78d9fcd8b4b490fc8f7fe25067e90d207bc50f8a..2643b333891999326f765a8a9ccaafeaa45b9f28 100644 --- a/enzevalos_iphone/CryptoManagementViewController.swift +++ b/enzevalos_iphone/CryptoManagementViewController.swift @@ -167,7 +167,10 @@ class CryptoManagementViewController: UITableViewController { // Pass the selected object to the new view controller. if segue.identifier == "showOtherID2" || segue.identifier == "showOtherID" { let destinationViewController = segue.destination as! KeyTableViewController - destinationViewController.showYourIDs = false + destinationViewController.type = .PublicKey + } else { + let destinationViewController = segue.destination as! KeyTableViewController + destinationViewController.type = .SecretKey } if let cell = sender as? UITableViewCell { cell.selectionStyle = .none diff --git a/enzevalos_iphone/ImportKeyOverviewController.swift b/enzevalos_iphone/ImportKeyOverviewController.swift index 16007b53cd8e398be0fa799ef9f44def7d188cf5..fac0d8ae4adc3c73be8234d9aae0b20f1a632824 100644 --- a/enzevalos_iphone/ImportKeyOverviewController.swift +++ b/enzevalos_iphone/ImportKeyOverviewController.swift @@ -8,7 +8,10 @@ import UIKit -class ImportKeyOverviewController: UITableViewController { +class ImportKeyOverviewController: UITableViewController, ButtonCellHandler { + enum KeyActions { + case iTunes, Paste + } override func viewDidLoad() { super.viewDidLoad() @@ -34,79 +37,21 @@ class ImportKeyOverviewController: UITableViewController { cell.textLabel?.text = "Eigentlich werden die Schlüssel zu den Identitäten in Mails gefunden. Aber du kannst auch Schlüssel mittels iTunes hinzufügen oder als Text einfügen. Letzteres kann verwendet werden um zum Beispiel einen PGP-Schlüssel von der Webseite einer Person zu importieren. Diese beginnen mit ======== Begin Public KEY ========...." return cell } else if indexPath.section == 1 { - // iTunes import - identifier = "iTunesButton" - if let cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath) as? ButtonCell { - cell.button.setTitle(NSLocalizedString("Import.Button.Itunes", comment: "import from iTunes"), for: .disabled) - cell.id = KeyActions.Copy.hashValue - // cell.listener = self - // copyButton = cell - return cell - - } - - + return ButtonCell.createButtonCell(tableView: tableView, normalTitle: NSLocalizedString("Import.Button.Itunes", comment: "import from iTunes"), id: KeyActions.iTunes.hashValue, listener: self) } else { // paste import - identifier = "PasteButton" - if let cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath) as? ButtonCell { - cell.button.setTitle(NSLocalizedString("Import.Button.Paste", comment: "import from clipboard"), for: .disabled) - cell.id = KeyActions.Copy.hashValue - // cell.listener = self - // copyButton = cell - return cell - - } + return ButtonCell.createButtonCell(tableView: tableView, normalTitle: NSLocalizedString("Import.Button.Paste", comment: "paste key"), id: KeyActions.Paste.hashValue, listener: self) } - // Configure the cell... - let cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath) - return cell } + func touchDown(id: Int) { + if id == KeyActions.iTunes.hashValue { + // Call iTunes field + _ = KeyTableViewController.pushKeyTableView(navigationController: self.navigationController, type: .ImportKey) + } else if id == KeyActions.Paste.hashValue { + // open Textfield to paste key + } + } - /* - // Override to support conditional editing of the table view. - override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool { - // Return false if you do not want the specified item to be editable. - return true - } - */ - - /* - // Override to support editing the table view. - override func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) { - if editingStyle == .delete { - // Delete the row from the data source - tableView.deleteRows(at: [indexPath], with: .fade) - } else if editingStyle == .insert { - // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view - } - } - */ - - /* - // Override to support rearranging the table view. - override func tableView(_ tableView: UITableView, moveRowAt fromIndexPath: IndexPath, to: IndexPath) { - - } - */ - - /* - // Override to support conditional rearranging of the table view. - override func tableView(_ tableView: UITableView, canMoveRowAt indexPath: IndexPath) -> Bool { - // Return false if you do not want the item to be re-orderable. - return true - } - */ - - /* - // MARK: - Navigation - - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destination. - // Pass the selected object to the new view controller. - } - */ } diff --git a/enzevalos_iphone/ItunesHandler.swift b/enzevalos_iphone/ItunesHandler.swift index 397c628f195c20fecc6ab9deee725959566a4b21..2d9713932d16a0b8840f392879f64f452681b33c 100644 --- a/enzevalos_iphone/ItunesHandler.swift +++ b/enzevalos_iphone/ItunesHandler.swift @@ -35,8 +35,8 @@ class ItunesKeyHandling { var newSecretKeys: [TempKey] { get { var knownIDs = DataHandler.handler.findSecretKeys().map{$0.keyID} - knownIDs = knownIDs.filter{return !($0 == "" || $0 == nil)} - var newSecretKeys = storedKeys.filter{$0.isSecret} + knownIDs = knownIDs.filter{return !($0 == "")} + let newSecretKeys = storedKeys.filter{$0.isSecret} newSecretKeys = newSecretKeys.filter{!knownIDs.contains($0.keyID)} return newSecretKeys } diff --git a/enzevalos_iphone/KeyCell.swift b/enzevalos_iphone/KeyCell.swift index c83c79f36847e1d0b4a7cf8609258c32212c46d3..82d6b6f7348b8682776bc82b71628afd4c2f819f 100644 --- a/enzevalos_iphone/KeyCell.swift +++ b/enzevalos_iphone/KeyCell.swift @@ -51,6 +51,10 @@ class KeyCell: UITableViewCell { setLabels(id: id, addr: mail, date: date, origin: nil, pref: pref) } + func setLabels(key: DisplayKey) { + setLabels(id: key.keyID, addr: nil, date: key.importDate, origin: nil, pref: false) + } + private func setLabels(id: String, addr: String?, date: Date?, origin: String?, pref: Bool) { idLabel.text = id if let addr = addr { diff --git a/enzevalos_iphone/KeyTableViewController.swift b/enzevalos_iphone/KeyTableViewController.swift index 98b00f70cfed2c9cc1a73f48b9a6fd463d2bbef7..cc3162d7b213aa68e520ea16e5501c5042e9c1e2 100644 --- a/enzevalos_iphone/KeyTableViewController.swift +++ b/enzevalos_iphone/KeyTableViewController.swift @@ -10,27 +10,60 @@ import UIKit class KeyTableViewController: UITableViewController { - var showYourIDs = true + enum KeyType { + case PublicKey, SecretKey, ImportKey + } + + static func pushKeyTableView(navigationController: UINavigationController?, type:KeyType) -> KeyTableViewController? { + let mainStoryboard = UIStoryboard(name: "Main", bundle: Bundle.main) + if let viewController = mainStoryboard.instantiateViewController(withIdentifier: "KeyTableViewController") as? KeyTableViewController { + viewController.type = type + navigationController?.pushViewController(viewController, animated: true) + return viewController + } + return nil + } + + var type: KeyType = .SecretKey var publicKeys: [PersistentKey] = [] var secretKeys: [SecretKey] = [] - + var importableKeys: [TempKey] = [] + var secretKeyPasswordField: UITextField? = nil + override func viewDidLoad() { super.viewDidLoad() var title = "Your IDs" - if showYourIDs { - secretKeys = DataHandler.handler.findSecretKeys() - } - else { - publicKeys = DataHandler.handler.findPublicKeys() + var showAddButton = false + var onlyOneRow = false + switch type { + case .PublicKey: title = "Other people's IDs" + publicKeys = DataHandler.handler.findPublicKeys() + showAddButton = true + case .SecretKey: + title = "Your IDs" + secretKeys = DataHandler.handler.findSecretKeys() + showAddButton = true + case .ImportKey: + title = "New Secret Keys" + importableKeys = ItunesKeyHandling.iTunesKeyHandler.newSecretKeys + if importableKeys.count == 0 { + onlyOneRow = true + } } self.title = title - self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addButton(btn:))) + if showAddButton { + self.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .add, target: self, action: #selector(addButton(btn:))) + } + if onlyOneRow { + self.tableView = UITableView.init(frame: CGRect.zero, style: .grouped) + } + } @objc private func addButton(btn: UIBarButtonItem) { - if !showYourIDs { + if type == .SecretKey { let mainStoryboard = UIStoryboard(name: "Main", bundle: Bundle.main) if let viewController = mainStoryboard.instantiateViewController(withIdentifier: "ImportKeyOverview") as? ImportKeyOverviewController { self.navigationController?.pushViewController(viewController, animated: true) @@ -45,41 +78,74 @@ class KeyTableViewController: UITableViewController { } override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { - if showYourIDs { - return secretKeys.count - } else { + switch type { + case .PublicKey: return publicKeys.count + case .SecretKey: + return secretKeys.count + case .ImportKey: + if importableKeys.count == 0 { + // Add warning to copy key in iTunes folder + return 1 + } + return importableKeys.count } } override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { var cell: KeyCell - if let tmpCell = tableView.dequeueReusableCell(withIdentifier: "KeyCell") as? KeyCell { cell = tmpCell } else { tableView.register(UINib.init(nibName: "KeyCell", bundle: nil), forCellReuseIdentifier: "KeyCell") cell = tableView.dequeueReusableCell(withIdentifier: "KeyCell") as! KeyCell } - - if showYourIDs { - cell.setLabels(key: secretKeys[indexPath.row]) - } else { + switch type { + case .PublicKey: cell.setLabels(key: publicKeys[indexPath.row]) + case .SecretKey: + cell.setLabels(key: secretKeys[indexPath.row]) + case .ImportKey: + if importableKeys.count == 0 { + let cell = UITableViewCell(style: .default, reuseIdentifier: "InfoCell") + cell.accessoryType = .none + cell.textLabel?.numberOfLines = 0 + cell.textLabel?.text = "No keys to import. Please, add a key file (.asc or .gpg) via iTunes in the Letterbox folder." + tableView.isUserInteractionEnabled = false + return cell + } else { + let key = importableKeys[indexPath.row] + cell.setLabels(key: key) + cell.mailAddress.isHidden = false + cell.dateLabel.isHidden = true + cell.dateName.isHidden = true + + if key.isNew() { + cell.accessoryType = .none + cell.mailAddress.text = "Click here to import" + }else { + cell.accessoryType = .checkmark + cell.mailAddress.text = "Already imported" + } + + } } - return cell } override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { let keyID: String let addr: String - if showYourIDs { + var pushView = true + tableView.cellForRow(at: indexPath)?.selectionStyle = .default + tableView.reloadRows(at: [indexPath], with: .automatic) + switch type { + case .SecretKey: let key = secretKeys[indexPath.row] keyID = key.keyID addr = UserManager.loadUserValue(.userAddr) as? String ?? keyID - } else { + case .PublicKey: let key = publicKeys[indexPath.row] keyID = key.keyID var mail: String? @@ -92,14 +158,76 @@ class KeyTableViewController: UITableViewController { } } addr = mail ?? keyID + case .ImportKey: + // Try to import key + importKey(key: importableKeys[indexPath.row], indexPath: indexPath) + pushView = false + return } - let mainStoryboard = UIStoryboard(name: "Main", bundle: Bundle.main) - if let viewController = mainStoryboard.instantiateViewController(withIdentifier: "UITableViewController-8Di-x2-cWQ") as? ContactViewController { + if pushView, let viewController = mainStoryboard.instantiateViewController(withIdentifier: "UITableViewController-8Di-x2-cWQ") as? ContactViewController { viewController.keyRecord = DataHandler.handler.getKeyRecord(addr: addr, keyID: keyID) self.navigationController?.pushViewController(viewController, animated: true) } - tableView.cellForRow(at: indexPath)?.selectionStyle = .default - tableView.reloadRows(at: [indexPath], with: .automatic) + } + + private func importKey(key: DisplayKey, indexPath: IndexPath) { + let pgp = SwiftPGP.init() + if pgp.checkPasswordFor(secretKeyID: key.keyID, password: nil, secretkey: key.pgpKey) { + // import key + _ = storeKey(indexPath: indexPath) + } + else { + // PW input. + inputPassword(first: true, pgp: pgp, pgpKey: key.pgpKey, id: key.keyID, indexPath: indexPath) + return + } + } + + /* + Import key stuff... + We generate a simple password field for asking the password of the secret key etc. + */ + private func inputPassword(first: Bool, pgp: SwiftPGP, pgpKey: Key?, id: String, indexPath: IndexPath) { + var message = String(format: NSLocalizedString("Read.Import.Secret.Body.PW", comment: "NewSecretKeyMessage"), id) + if !first { + message = NSLocalizedString("Read.Import.Secret.Body.Wrong", comment: "NewSecretKeyMessage") + } + let alert = UIAlertController(title: NSLocalizedString("Read.Import.Secret.Title", comment: "NewSecretKeyTitle"), message: message, preferredStyle: UIAlertController.Style.alert) + alert.addAction(UIAlertAction(title: NSLocalizedString("Cancel", comment: "NoSecretKeyImport"), style: UIAlertAction.Style.destructive, handler: { (_: UIAlertAction) -> Void in + return self.stopImportKey(indexPath: indexPath) + })) + + alert.addAction(UIAlertAction(title: NSLocalizedString("Read.Import.Secret.Ok", comment: "Import secret Key"), style: UIAlertAction.Style.default, handler: {(_:UIAlertAction) -> Void in + if let pw = self.secretKeyPasswordField?.text, pgp.checkPasswordFor(secretKeyID: id, password: pw, secretkey: pgpKey ) { + _ = self.storeKey(indexPath: indexPath) + } + else { + self.inputPassword(first: false, pgp: pgp, pgpKey: pgpKey, id: id, indexPath: indexPath) + } + })) + alert.addTextField(configurationHandler: newSecretkeyPassword(textField:)) + self.present(alert, animated: true, completion: nil) + } + + private func stopImportKey(indexPath: IndexPath) { + self.tableView.reloadRows(at: [indexPath], with: .automatic) + } + + private func storeKey(indexPath: IndexPath) -> Bool { + let key = importableKeys[indexPath.row] + if key.save() != nil { + tableView.cellForRow(at: indexPath)?.accessoryType = .checkmark + self.tableView.reloadRows(at: [indexPath], with: .automatic) + return true + } + return false + } + + private func newSecretkeyPassword(textField: UITextField!) { + if let tField = textField { + tField.isSecureTextEntry = true + secretKeyPasswordField = tField + } } } diff --git a/enzevalos_iphone/SwiftPGP.swift b/enzevalos_iphone/SwiftPGP.swift index 3e3b7e12b7e0e3240228a59bb8c3f662be78f0f6..10e5b2019866e5eefd8e7fb2ecd4d9b4dd547f8b 100644 --- a/enzevalos_iphone/SwiftPGP.swift +++ b/enzevalos_iphone/SwiftPGP.swift @@ -712,6 +712,7 @@ class SwiftPGP: Encryption { else { return false } + //TODO: Problem overwrite password? if let pw = password { pwKeyChain[key.keyID.longIdentifier] = pw } diff --git a/enzevalos_iphone/TempKey.swift b/enzevalos_iphone/TempKey.swift index 33979b6de98c03ad2a1534591279e0ed205674df..cf6445eaca90b520574e5ba268a6fdeeaaedc117 100644 --- a/enzevalos_iphone/TempKey.swift +++ b/enzevalos_iphone/TempKey.swift @@ -95,6 +95,10 @@ class TempKey: DisplayKey { return false } + func isNew() -> Bool { + return DataHandler.handler.findKey(keyID: keyID) == nil && DataHandler.handler.findSecretKey(keyID: keyID) == nil + } + func save() -> SecretKey? { let keyIDs = SwiftPGP.init().store(tempKeys: [self]) let sk = DataHandler.handler.newSecretKeys(keyIds: keyIDs, addPKs: true)