From 9bb9134f29474520492f23a3be34181ae1a443b4 Mon Sep 17 00:00:00 2001 From: Joscha <joscha@virtual-artz.de> Date: Wed, 14 Feb 2018 18:21:37 +0100 Subject: [PATCH] Fixes issue #184 and removed uncertainty when choosing to send insecurely to everyone. Also using correct links to olli's user page now. --- enzevalos_iphone/SendViewController.swift | 66 ++++++++++++++----- enzevalos_iphone/de.lproj/Localizable.strings | 7 +- localization_backup.strings | 7 +- 3 files changed, 60 insertions(+), 20 deletions(-) diff --git a/enzevalos_iphone/SendViewController.swift b/enzevalos_iphone/SendViewController.swift index ad3232eb..1f2bcd56 100644 --- a/enzevalos_iphone/SendViewController.swift +++ b/enzevalos_iphone/SendViewController.swift @@ -507,9 +507,14 @@ class SendViewController: UIViewController { //Navigationbar var currentSecurityState: Bool { - toSecure = toText.dataSource!.isSecure!(toText) //TODO: Add pref enc field. - ccSecure = ccText.dataSource!.isSecure!(ccText) - return toSecure && ccSecure + guard let toSource = toText.dataSource, let ccSource = ccText.dataSource else { + return true + } + + let toKey = toSource.allSecure(toText) + let ccKey = ccSource.allSecure(ccText) + + return toKey && ccKey } var someoneWithKeyPresent: Bool { @@ -523,6 +528,17 @@ class SendViewController: UIViewController { return toKey || ccKey } + var someoneWithoutKeyPresent: Bool { + guard let toSource = toText.dataSource, let ccSource = ccText.dataSource else { + return true + } + + let toKey = toSource.someInsecure(toText) + let ccKey = ccSource.someInsecure(ccText) + + return toKey || ccKey + } + func updateNavigationBar() { if currentSecurityState { self.navigationController?.navigationBar.barTintColor = ThemeManager.encryptedMessageColor() @@ -560,9 +576,9 @@ class SendViewController: UIViewController { let alert: UIAlertController let url: String if !UISecurityState { - alert = UIAlertController(title: NSLocalizedString("Postcard", comment: "Postcard label"), message: NSLocalizedString("SendInsecureInfo", comment: "Postcard infotext"), preferredStyle: .alert) - url = "https://enzevalos.org/infos/postcard" - if subjectText.inputText() != NSLocalizedString("inviteSubject", comment: "") { + alert = UIAlertController(title: NSLocalizedString("Postcard", comment: "Postcard label"), message: sendEncryptedIfPossible ? NSLocalizedString("SendInsecureInfo", comment: "Postcard infotext") : NSLocalizedString("SendInsecureInfoAll", comment: "Postcard infotext"), preferredStyle: .alert) + url = "https://userpage.fu-berlin.de/wieseoli/letterbox/faq.html#headingPostcard" + if subjectText.inputText() != NSLocalizedString("inviteSubject", comment: "") && !currentSecurityState { alert.addAction(UIAlertAction(title: NSLocalizedString("inviteContacts", comment: "Allows users to invite contacts without encryption key"), style: .default, handler: { (action: UIAlertAction) -> Void in // Logger.queue.async(flags: .barrier) { @@ -573,11 +589,11 @@ class SendViewController: UIViewController { } } else { alert = UIAlertController(title: NSLocalizedString("Letter", comment: "Letter label"), message: NSLocalizedString("SendSecureInfo", comment: "Letter infotext"), preferredStyle: .alert) - url = "https://enzevalos.org/infos/letter" + url = "https://userpage.fu-berlin.de/wieseoli/letterbox/faq.html#secureMail" } if someoneWithKeyPresent { if sendEncryptedIfPossible { - alert.addAction(UIAlertAction(title: NSLocalizedString("sendInsecure", comment: "This mail should be send insecurely"), style: .default, handler: { (action: UIAlertAction!) -> Void in + alert.addAction(UIAlertAction(title: someoneWithoutKeyPresent ? NSLocalizedString("sendInsecureAll", comment: "This mail should be send insecurely to everyone, including contacts with keys") : NSLocalizedString("sendInsecure", comment: "This mail should be send insecurely"), style: .default, handler: { (action: UIAlertAction!) -> Void in // Logger.queue.async(flags: .barrier) { Logger.log(close: url, mail: nil, action: "sendInsecure") // } @@ -585,7 +601,7 @@ class SendViewController: UIViewController { DispatchQueue.main.async { self.animateIfNeeded() } })) } else { - alert.addAction(UIAlertAction(title: NSLocalizedString("sendSecureIfPossible", comment: "This mail should be send securely"), style: .default, handler: { (action: UIAlertAction!) -> Void in + alert.addAction(UIAlertAction(title: someoneWithoutKeyPresent ? NSLocalizedString("sendSecureIfPossible", comment: "This mail should be send securely to people with keys") : NSLocalizedString("sendSecure", comment: "This mail should be send securely"), style: .default, handler: { (action: UIAlertAction!) -> Void in // Logger.queue.async(flags: .barrier) { Logger.log(close: url, mail: nil, action: "sendSecureIfPossible") // } @@ -699,15 +715,35 @@ extension SendViewController: UIGestureRecognizerDelegate { extension VENTokenFieldDataSource { func someSecure(_ tokenField: VENTokenField) -> Bool { - var secure = false for entry in tokenField.mailTokens { - var hasKey = false - if let madr = DataHandler.handler.findMailAddress(adr: entry as! String) { - hasKey = madr.hasKey + if let madr = DataHandler.handler.findMailAddress(adr: entry as! String), madr.hasKey { + return true } - secure = secure || hasKey } - return secure + return false + } + + func someInsecure(_ tokenField: VENTokenField) -> Bool { + for entry in tokenField.mailTokens { + if let madr = DataHandler.handler.findMailAddress(adr: entry as! String), !madr.hasKey { + return true + } + } + + return false + } + + /** + Returns a bool showing whether all contacts in the field have a key. Returns true if no contacts are present. + */ + func allSecure(_ tokenField: VENTokenField) -> Bool { + for entry in tokenField.mailTokens { + if let madr = DataHandler.handler.findMailAddress(adr: entry as! String), !madr.hasKey { + return false + } + } + + return true } } diff --git a/enzevalos_iphone/de.lproj/Localizable.strings b/enzevalos_iphone/de.lproj/Localizable.strings index a398f7d7..bffe4f01 100644 --- a/enzevalos_iphone/de.lproj/Localizable.strings +++ b/enzevalos_iphone/de.lproj/Localizable.strings @@ -98,6 +98,7 @@ "Send" = "Senden"; "SendError" = "Ein Fehler ist aufgetreten"; //mehr spezifizieren? "SendInsecureInfo" = "Diese Nachricht würde unsicher an alle orange eingefärbten Kontakte gesendet werden. Somit kann sie unterwegs von anderen gelesen oder manipuliert werden. Du könntest die orangen Kontakte einladen Enzavalos zu verwenden, um sicher mit ihnen zu kommunizieren."; //anstatt unterwegs: auf ihrem Weg +"SendInsecureInfoAll" = "Diese Nachricht würde unsicher an alle Kontakte gesendet werden. Somit kann sie unterwegs von anderen gelesen oder manipuliert werden. Du könntest die orangen Kontakte einladen Enzavalos zu verwenden, um sicher mit ihnen zu kommunizieren."; //anstatt unterwegs: auf ihrem Weg "SendSecureInfo" = "Super! Diese Nachricht würde sicher versendet werden. Somit ist ihr Inhalt vor neugierigen Augen geschützt und kann nicht manipuliert werden."; "SendSuccess" = "Erfolgreich gesendet"; "Sent" = "Gesendet"; @@ -155,8 +156,10 @@ "thisIsYou" = "Hier werden E-Mails, die du dir selber schickst, gesammelt"; "didYouSendThis" = "Hallo, haben Sie mir diese E-Mail geschickt?\nIch frage nur, weil die E-Mail unsicher versendet wurde.\n\n"; "reactButton" = "Bestätigung erfragen"; -"sendSecureIfPossible" = "Als Brief senden"; +"sendSecureIfPossible" = "Wenn möglich als Brief senden"; "sendInsecure" = "Als Postkarte senden"; +"sendInsecureAll" = "An alle als Postkarte senden"; +"sendSecure" = "Als Brief senden"; "verifyContact" = "Kontakt verifizieren"; "scanQRCode" = "Scanne den QR Code des Kontaktes"; "wrongQRCode" = "Kein passender QR Code gefunden"; @@ -174,5 +177,3 @@ "copied" = "Schloss wurde kopiert"; "copyKey" = "Schloss in Zwischenablage kopieren"; "NeverUpdated" = "Fehler bei Aktualisierung"; - - diff --git a/localization_backup.strings b/localization_backup.strings index 20e0a10e..80d6e993 100644 --- a/localization_backup.strings +++ b/localization_backup.strings @@ -97,6 +97,7 @@ "Send" = "Send"; "SendError" = "An error occured"; //mehr spezifizieren? "SendInsecureInfo" = "This Mail would be send insecurely to all orange contacts. So everybody could read and manipulate it. You could invite them to use Enzevalos to communicate securely."; +"SendInsecureInfoAll" = "This Mail would be send insecurely to all contacts. So everybody could read and manipulate it. You could invite them to use Enzevalos to communicate securely."; "SendSecureInfo" = "Congratulations! This Mail would be send securely. It is impossible for anybody to read or manipulate it."; "SendSuccess" = "Sent successfully"; "Sent" = "Sent"; @@ -152,8 +153,10 @@ "thisIsYou" = "Emails you sent yourself are collected here"; "didYouSendThis" = "Hey, did you send me this email?\nI'm just asking because it was sent insecurely.\n\n"; "reactButton" = "Request Confirmation"; -"sendSecureIfPossible" = "Send secure"; -"sendInsecure" = "Send insecure"; +"sendSecureIfPossible" = "Send as letter when possible"; +"sendInsecure" = "Send as postcard"; +"sendInsecureAll" = "Send as postcard to everyone"; +"sendSecure" = "Send as letter"; "verifyContact" = "Verify Contact"; "scanQRCode" = "Scan the QR Code of the Contact"; "wrongQRCode" = "Incompatible QR Code found"; -- GitLab