diff --git a/enzevalos_iphone.xcodeproj/project.pbxproj b/enzevalos_iphone.xcodeproj/project.pbxproj index 1f8e69f340d4dff730c9a2bd336846fb555e67a5..fedbb84ca73a3da5fec316c2d1d95e1a634f9307 100644 --- a/enzevalos_iphone.xcodeproj/project.pbxproj +++ b/enzevalos_iphone.xcodeproj/project.pbxproj @@ -62,6 +62,12 @@ 476EEF9922A872BF00BB4EF7 /* enzevalos_iphoneUITests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 476EEF9822A872BF00BB4EF7 /* enzevalos_iphoneUITests.swift */; }; 476EEFA122A873A800BB4EF7 /* OnboardingTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 476EEFA022A873A800BB4EF7 /* OnboardingTest.swift */; }; 476EEFA722A87B9800BB4EF7 /* accounts.json in Resources */ = {isa = PBXBuildFile; fileRef = 476EEFA622A87B9800BB4EF7 /* accounts.json */; }; + 4774DD7322CFFD0E00BD8CF6 /* AliceMultiIDs (439EE43C) – Public.asc in Resources */ = {isa = PBXBuildFile; fileRef = 4774DD7222CFFD0E00BD8CF6 /* AliceMultiIDs (439EE43C) – Public.asc */; }; + 4774DD7522D0015F00BD8CF6 /* multiIDs.eml in Resources */ = {isa = PBXBuildFile; fileRef = 4774DD7422D0015F00BD8CF6 /* multiIDs.eml */; }; + 4774DD7B22D3F5D100BD8CF6 /* multiIDs2.eml in Resources */ = {isa = PBXBuildFile; fileRef = 4774DD7A22D3F5D100BD8CF6 /* multiIDs2.eml */; }; + 4774DD7E22D4062200BD8CF6 /* Bob Letterbox (0B6CD0A0) – Secret.asc in Resources */ = {isa = PBXBuildFile; fileRef = 4774DD7C22D4062200BD8CF6 /* Bob Letterbox (0B6CD0A0) – Secret.asc */; }; + 4774DD7F22D4062200BD8CF6 /* Alice Letterbox (439EE43C) – Public.asc in Resources */ = {isa = PBXBuildFile; fileRef = 4774DD7D22D4062200BD8CF6 /* Alice Letterbox (439EE43C) – Public.asc */; }; + 4774DD8122D4067E00BD8CF6 /* signedEncMailFromApple.eml in Resources */ = {isa = PBXBuildFile; fileRef = 4774DD8022D4067D00BD8CF6 /* signedEncMailFromApple.eml */; }; 477548DE21F5DABE000B22A8 /* MailServerConnectionError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 477548DD21F5DABE000B22A8 /* MailServerConnectionError.swift */; }; 477548E221F77466000B22A8 /* SecurityIndicator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 477548E121F77466000B22A8 /* SecurityIndicator.swift */; }; 477548E421F77BA0000B22A8 /* StudyParameterProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 477548E321F77BA0000B22A8 /* StudyParameterProtocol.swift */; }; @@ -301,6 +307,12 @@ 476EEF9A22A872BF00BB4EF7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; 476EEFA022A873A800BB4EF7 /* OnboardingTest.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = OnboardingTest.swift; sourceTree = "<group>"; }; 476EEFA622A87B9800BB4EF7 /* accounts.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = accounts.json; sourceTree = "<group>"; }; + 4774DD7222CFFD0E00BD8CF6 /* AliceMultiIDs (439EE43C) – Public.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "AliceMultiIDs (439EE43C) – Public.asc"; sourceTree = "<group>"; }; + 4774DD7422D0015F00BD8CF6 /* multiIDs.eml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = multiIDs.eml; sourceTree = "<group>"; }; + 4774DD7A22D3F5D100BD8CF6 /* multiIDs2.eml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = multiIDs2.eml; sourceTree = "<group>"; }; + 4774DD7C22D4062200BD8CF6 /* Bob Letterbox (0B6CD0A0) – Secret.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "Bob Letterbox (0B6CD0A0) – Secret.asc"; sourceTree = "<group>"; }; + 4774DD7D22D4062200BD8CF6 /* Alice Letterbox (439EE43C) – Public.asc */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = "Alice Letterbox (439EE43C) – Public.asc"; sourceTree = "<group>"; }; + 4774DD8022D4067D00BD8CF6 /* signedEncMailFromApple.eml */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = signedEncMailFromApple.eml; sourceTree = "<group>"; }; 477548DD21F5DABE000B22A8 /* MailServerConnectionError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MailServerConnectionError.swift; sourceTree = "<group>"; }; 477548E121F77466000B22A8 /* SecurityIndicator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SecurityIndicator.swift; sourceTree = "<group>"; }; 477548E321F77BA0000B22A8 /* StudyParameterProtocol.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StudyParameterProtocol.swift; sourceTree = "<group>"; }; @@ -566,6 +578,9 @@ 470709112189BB4A00DF71A3 /* testMails */ = { isa = PBXGroup; children = ( + 4774DD7422D0015F00BD8CF6 /* multiIDs.eml */, + 4774DD7A22D3F5D100BD8CF6 /* multiIDs2.eml */, + 4774DD8022D4067D00BD8CF6 /* signedEncMailFromApple.eml */, A15D215C223BE614003E0CE0 /* attachment.eml */, 47E7BE622232BD0A00C8EF94 /* SignedEncMailFromMac.eml */, 47E7BE5A22319B6900C8EF94 /* EncMailFromMac.eml */, @@ -587,7 +602,10 @@ 470709202189C24800DF71A3 /* testKeys */ = { isa = PBXGroup; children = ( + 4774DD7222CFFD0E00BD8CF6 /* AliceMultiIDs (439EE43C) – Public.asc */, 4707092C2189C74200DF71A3 /* alicePublic.asc */, + 4774DD7D22D4062200BD8CF6 /* Alice Letterbox (439EE43C) – Public.asc */, + 4774DD7C22D4062200BD8CF6 /* Bob Letterbox (0B6CD0A0) – Secret.asc */, 471876F5223FACA900912135 /* BobPWTEST1234.asc */, 479AFDA122571AB90063A332 /* EccAlice(777879D4)–Public.asc */, 471876F6223FACA900912135 /* BobWithoutPW.asc */, @@ -1212,6 +1230,7 @@ developmentRegion = English; hasScannedForEncodings = 0; knownRegions = ( + English, en, Base, de, @@ -1288,14 +1307,20 @@ 4707092D2189C74200DF71A3 /* bobSecret.asc in Resources */, 47F0376E22A7278A0005C9DE /* accounts.json in Resources */, 47E7BE5B22319B6900C8EF94 /* EncMailFromMac.eml in Resources */, + 4774DD7522D0015F00BD8CF6 /* multiIDs.eml in Resources */, + 4774DD7322CFFD0E00BD8CF6 /* AliceMultiIDs (439EE43C) – Public.asc in Resources */, 4707091E2189BC3500DF71A3 /* plainThunderbird.eml in Resources */, 4707092E2189C74200DF71A3 /* alicePublic.asc in Resources */, 4707092A2189C73900DF71A3 /* signedThunderbird.eml in Resources */, + 4774DD7E22D4062200BD8CF6 /* Bob Letterbox (0B6CD0A0) – Secret.asc in Resources */, A15D215D223BE614003E0CE0 /* attachment.eml in Resources */, 47C22283218B02C700BD2C2B /* autocryptSimpleExample1.eml in Resources */, 471876F7223FACA900912135 /* BobPWTEST1234.asc in Resources */, + 4774DD7F22D4062200BD8CF6 /* Alice Letterbox (439EE43C) – Public.asc in Resources */, 470709302189E1C100DF71A3 /* enc+signedThunderbird.eml in Resources */, 47E7BE6122319B8F00C8EF94 /* PlainMailFromMac.eml in Resources */, + 4774DD8122D4067E00BD8CF6 /* signedEncMailFromApple.eml in Resources */, + 4774DD7B22D3F5D100BD8CF6 /* multiIDs2.eml in Resources */, 470709272189C73900DF71A3 /* encThunderbird.eml in Resources */, 47E7BE5D22319B7100C8EF94 /* SignedMailFromMac.eml in Resources */, 47E7BE5F22319B7D00C8EF94 /* SecureMailFromMac.eml in Resources */, diff --git a/enzevalos_iphone/Autocrypt.swift b/enzevalos_iphone/Autocrypt.swift index e2a4b5d17e12688ebe8070e885447d8eea664995..b9479a14dd0abd5d7c6bff65c4ff7b1b1aff156d 100644 --- a/enzevalos_iphone/Autocrypt.swift +++ b/enzevalos_iphone/Autocrypt.swift @@ -80,7 +80,15 @@ class Autocrypt { self.init(addr: addr, type: type, prefer_encryption: pref, key: key) } - + private func addArmor() -> Bool{ + let header = "-----BEGIN PGP PUBLIC KEY BLOCK-----" + guard !key.isEmpty && !key.starts(with: header), let data = key.toBase64() else { + return false + } + key = Armor.armored(data, as: .publicKey) + return true + } + func setPrefer_encryption(_ input: String){ let pref = input.lowercased() if pref == "yes" || pref == "mutual" || pref == EncState.MUTUAL.name { diff --git a/enzevalos_iphone/Base.lproj/Main.storyboard b/enzevalos_iphone/Base.lproj/Main.storyboard index 18c85237d214517ddadab9076c0d5f2d850fe86d..52f63cca82a0c4cc34668f961f703508137016e9 100644 --- a/enzevalos_iphone/Base.lproj/Main.storyboard +++ b/enzevalos_iphone/Base.lproj/Main.storyboard @@ -1,11 +1,11 @@ <?xml version="1.0" encoding="UTF-8"?> -<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14460.31" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Amm-QN-vA7"> +<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="14490.70" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Amm-QN-vA7"> <device id="retina4_0" orientation="portrait"> <adaptation id="fullscreen"/> </device> <dependencies> <deployment identifier="iOS"/> - <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14460.20"/> + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="14490.49"/> <capability name="Safe area layout guides" minToolsVersion="9.0"/> <capability name="Stack View standard spacing" minToolsVersion="9.0"/> <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> @@ -576,8 +576,8 @@ <constraint firstAttribute="width" constant="15" id="ons-Pp-k3n"/> </constraints> </imageView> - <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" translatesAutoresizingMaskIntoConstraints="NO" id="sfv-2Q-95I"> - <rect key="frame" x="0.0" y="18" width="15" height="15"/> + <imageView userInteractionEnabled="NO" contentMode="scaleAspectFit" horizontalHuggingPriority="251" verticalHuggingPriority="251" ambiguous="YES" translatesAutoresizingMaskIntoConstraints="NO" id="sfv-2Q-95I"> + <rect key="frame" x="0.0" y="15" width="15" height="18"/> <constraints> <constraint firstAttribute="height" constant="15" id="SmT-9e-ovi"/> <constraint firstAttribute="width" constant="15" id="uKU-PK-flD"/> diff --git a/enzevalos_iphone/CryptoObject.swift b/enzevalos_iphone/CryptoObject.swift index a295183e46b763cef459c77f4cd58a1305446a1a..3486804c7c46d4e031318377a544b9501f705f66 100644 --- a/enzevalos_iphone/CryptoObject.swift +++ b/enzevalos_iphone/CryptoObject.swift @@ -8,9 +8,9 @@ import Foundation enum SignatureState: Int16 { - case NoSignature = 0 - case NoPublicKey = 1 - case InvalidSignature = -1 + case NoSignature = 0 // -> no authenticity -> no actions possible + case NoPublicKey = 1 // -> no authenticity -> Possible actions: Ask sender to send keys, import key, Would be nice to verify mails later. + case InvalidSignature = -1 // -> ERROR -> context is manipulated (either attack or MTA...) case ValidSignature = 2 var name: String { diff --git a/enzevalos_iphone/DataHandler.swift b/enzevalos_iphone/DataHandler.swift index d30a19b84d4bca7829a897c051a17a295adea60f..93272eba369e6d68439b661d5787211e0232d827 100644 --- a/enzevalos_iphone/DataHandler.swift +++ b/enzevalos_iphone/DataHandler.swift @@ -840,9 +840,13 @@ class DataHandler { // -------- End handle to, cc, from addresses -------- func createMail(_ uid: UInt64, sender: MCOAddress?, receivers: [MCOAddress], cc: [MCOAddress], time: Date, received: Bool, subject: String, body: String?, readableAttachments: Set<TempAttachment> = Set<TempAttachment>(), flags: MCOMessageFlag, record: KeyRecord?, autocrypt: Autocrypt?, decryptedData: CryptoObject?, folderPath: String, secretKey: String?, references: [String] = [], mailagent: String? = nil, messageID: String? = nil, encryptedBody: String?, storeEncrypted: Bool = false) -> PersistentMail? { + + guard let sender = sender else { + return nil + } let myfolder = findFolder(with: folderPath) as Folder let finding = findNum("PersistentMail", type: "uid", search: uid) - + let mail: PersistentMail var mails: [PersistentMail] = [] @@ -886,9 +890,8 @@ class DataHandler { mail.received = received - if sender != nil { - handleFromAddress(sender!, fromMail: mail, autocrypt: autocrypt) - } + handleFromAddress(sender, fromMail: mail, autocrypt: autocrypt) + handleToAddresses(receivers, mail: mail) handleCCAddresses(cc, mail: mail) diff --git a/enzevalos_iphone/MailSession.swift b/enzevalos_iphone/MailSession.swift index b1230ac6f0fe54b970211ba868f86563d66f7133..ad224f43beb60d54d1a3ead43af183ec8544a035 100644 --- a/enzevalos_iphone/MailSession.swift +++ b/enzevalos_iphone/MailSession.swift @@ -397,7 +397,7 @@ class MailServer: Comparable { self.sendCallback = true self.callback(nil, self) } - print("SMTP works!") + print("SMTP works for \(self.username)!") }) self.startWaiting() return true @@ -447,10 +447,13 @@ class MailServer: Comparable { session.checkAccountOperation().start({(error: Error?) -> () in if let error = error { let conError = MailServerConnectionError.findErrorCode(error: error) - - if conError != MailServerConnectionError.AuthenticationError && (!self.receivedAuthTypes || !self.possibleAuthTypes.isEmpty) { - // Just downgrade authencation type and try again... - self.testAuthTypes() + if !self.receivedAuthTypes && !self.possibleAuthTypes.isEmpty { + self.authType = self.possibleAuthTypes.removeLast() + self.testUsernameAndPW() + } + else if conError != MailServerConnectionError.AuthenticationError && (!self.receivedAuthTypes || !self.possibleAuthTypes.isEmpty) && !self.possibleAuthTypes.isEmpty{ + self.authType = self.possibleAuthTypes.removeLast() + self.testUsernameAndPW() } else if !self.sendCallback { self.sendCallback = true @@ -463,7 +466,7 @@ class MailServer: Comparable { self.sendCallback = true self.callback(nil, self) } - print("IMAP works!") + print("IMAP works for \(self.username)") } }) } diff --git a/enzevalos_iphone/Mail_Address+CoreDataClass.swift b/enzevalos_iphone/Mail_Address+CoreDataClass.swift index c4c9f94f0d5d9be795d9e0878738873094e0395b..c7eb9a9b672de92199d398b9f6537c94352ee4dc 100644 --- a/enzevalos_iphone/Mail_Address+CoreDataClass.swift +++ b/enzevalos_iphone/Mail_Address+CoreDataClass.swift @@ -55,8 +55,6 @@ open class Mail_Address: NSManagedObject, MailAddress { return CNLabeledValue.init(label: CNLabelOther, value: address as NSString) } - - open var hasKey: Bool { if publicKeys.count > 0 { return true diff --git a/enzevalos_iphone/PersistentMail +CoreDataClass.swift b/enzevalos_iphone/PersistentMail +CoreDataClass.swift index 8e210a89adc8d75a9f44164005473184b7944823..e1ce1fe37b895448c5be58219c83468cb495d4ec 100644 --- a/enzevalos_iphone/PersistentMail +CoreDataClass.swift +++ b/enzevalos_iphone/PersistentMail +CoreDataClass.swift @@ -65,6 +65,17 @@ open class PersistentMail: NSManagedObject, Mail { } } + + var isNewPubKey: Bool { + guard let signedKey = self.signedKey else { + return false + } + + if signedKey.counterSignedMails < 2 && self.from.publicKeys.count > 1 && signedKey.fingerprint != self.from.primaryKey?.fingerprint { + return true + } + return false + } var isRead: Bool { get { diff --git a/enzevalos_iphone/ReadViewController.swift b/enzevalos_iphone/ReadViewController.swift index fc0b70c06b56642c1a3733040cc80b707ff8c385..a168fc71ff4eb2491f58122eb4e61d71f92f5934 100644 --- a/enzevalos_iphone/ReadViewController.swift +++ b/enzevalos_iphone/ReadViewController.swift @@ -61,16 +61,7 @@ class ReadViewController: UITableViewController { var secretKeyPasswordField: UITextField? = nil var infoState = LogData.WarningType.none - var isNewPubKey: Bool? { - guard let mail = mail, let signedKey = mail.signedKey else { - return nil - } - - if signedKey.counterSignedMails < 2 && mail.from.publicKeys.count > 1 { - return true - } - return false - } + var deletedWhileTravel: Bool { guard let mail = mail else { @@ -217,7 +208,7 @@ class ReadViewController: UITableViewController { /// Bool indicating whether a info section is shown with the exception of trouble mails where the message is not shown (because we need only 2 sections in that case) func showInfoSection(mail: PersistentMail) -> Bool { - return (mail.trouble && mail.showMessage) || (!mail.trouble && !mail.isSecure && mail.from.hasKey && mail.date > keyDiscoveryDate ?? Date() && !isDraft && !isInSentFolder) || (!mail.trouble && mail.isEncrypted && mail.unableToDecrypt) || isNewPubKey ?? false && !StudySettings.hideWarning || deletedWhileTravel + return (mail.trouble && mail.showMessage) || (!mail.trouble && !mail.isSecure && mail.from.hasKey && mail.date > keyDiscoveryDate ?? Date() && !isDraft && !isInSentFolder) || (!mail.trouble && mail.isEncrypted && mail.unableToDecrypt) || mail.isNewPubKey && !StudySettings.hideWarning || deletedWhileTravel } func showInfoButton(mail: PersistentMail) -> Bool { @@ -526,7 +517,7 @@ class ReadViewController: UITableViewController { infoText.text = NSLocalizedString("couldNotDecryptText", comment: "Message could not be decrypted") } - } else if (isNewPubKey ?? false) && !deletedWhileTravel { + } else if (mail.isNewPubKey) && !deletedWhileTravel { infoState = .newKey infoSymbol.text = "!" infoSymbol.textColor = ThemeManager.orange diff --git a/enzevalos_iphone/StringExtension.swift b/enzevalos_iphone/StringExtension.swift index 591371c86a639e7648091279ce0fb60d0bc32527..184c4b8ea23f58f6ebd1c902af4ddbc98d30a233 100644 --- a/enzevalos_iphone/StringExtension.swift +++ b/enzevalos_iphone/StringExtension.swift @@ -45,6 +45,12 @@ extension String { return components.filter { !$0.isEmpty }.joined(separator: " ") } + func toBase64() -> Data? { + let components = self.components(separatedBy: .whitespacesAndNewlines) + let res = components.filter { !$0.isEmpty }.joined(separator: "") + return Data(base64Encoded: res) + } + func remove(seperatedBy: CharacterSet) -> String { let components = self.components(separatedBy: seperatedBy) return components.filter { !$0.isEmpty }.joined(separator: " ") diff --git a/enzevalos_iphone/SwiftPGP.swift b/enzevalos_iphone/SwiftPGP.swift index ec954e9a1c58e96672fd167047e9ece2df61817e..7a40e4e8a6468a090ba2aadde07594d9a3a9c1d1 100644 --- a/enzevalos_iphone/SwiftPGP.swift +++ b/enzevalos_iphone/SwiftPGP.swift @@ -251,10 +251,11 @@ class SwiftPGP: Encryption { var keys = [Key]() var keyData: [Data] = [] if autocrypt{ - var key = key - key = key.trimmed() - key = key.replacingOccurrences(of: " ", with: "") - keyData.append(ObjectivePGP.transformKey(key)) + if let keyD = try? Armor.readArmored(key) { + keyData.append(keyD) + } else if let keyD = key.toBase64() { + keyData.append(keyD) + } } else { var keyStrings = PGPPart.PUBLICKEY.findPGPPartInString(content: key) @@ -336,7 +337,7 @@ class SwiftPGP: Encryption { func exportKey(id: String, isSecretkey isSecretKey: Bool, autocrypt: Bool, newPasscode: Bool = false) -> String?{ if let key = exportKeyData(id: id, isSecretkey: isSecretKey){ if !isSecretKey && autocrypt{ - return key.base64EncodedString(options: .lineLength64Characters) + return key.base64EncodedString(options: .init(arrayLiteral: .lineLength76Characters, .endLineWithLineFeed)) } else{ var armoredKey : String @@ -472,7 +473,8 @@ class SwiftPGP: Encryption { } } if !signedAdr.contains(fromAdr) && sigState == SignatureState.ValidSignature { - sigState = .InvalidSignature + //sigState = .MissingFromAddr + // TODO: Have we } return CryptoObject(chiphertext: data, plaintext: nil, decryptedData: nil, sigState: sigState, encState: encState, signKey: sigKeyID, encType: .PGP, signedAdrs: signedAdr) } @@ -488,6 +490,11 @@ class SwiftPGP: Encryption { } func decrypt(data: Data, attachedSignature: Data? = nil, decKeyIDs: [String], signatureIDs: [String], fromAddr: String) -> CryptoObject{ + print("Signature key ids") + for key in signatureIDs { + print(key) + } + print("##############") let prefKey = DataHandler.handler.prefSecretKey() var plaindata: Data? = nil var plaintext: String? = nil @@ -586,16 +593,12 @@ class SwiftPGP: Encryption { if let dataString = String(data: data, encoding: .utf8) { do { let unarmored = try Armor.readArmored(dataString) - if let plain = try? ObjectivePGP.decrypt(unarmored, andVerifySignature: true, using: keys, passphraseForKey: loadPassword){ - if encForCurrentSK{ - return (plain, EncryptionState.ValidedEncryptedWithCurrentKey) - } - else{ - return(plain, EncryptionState.ValidEncryptedWithOldKey) - } + let plain = try ObjectivePGP.decrypt(unarmored, andVerifySignature: true, using: keys, passphraseForKey: loadPassword) + if encForCurrentSK{ + return (plain, EncryptionState.ValidedEncryptedWithCurrentKey) } else{ - return (nil, EncryptionState.UnableToDecrypt) + return(plain, EncryptionState.ValidEncryptedWithOldKey) } } catch { let nsError = error as NSError @@ -631,11 +634,16 @@ class SwiftPGP: Encryption { sigData = unarmored } let pubKeys = keys.filter{$0.isPublic} + + var hasCorrectKey = false do{ try ObjectivePGP.verify(sigData, withSignature: attachedSignature, using: pubKeys, passphraseForKey: loadPassword) sigState = SignatureState.ValidSignature } catch { let nsError = error as NSError + if hasCorrectKey { + print(error) + } switch nsError.code { case 7: // no public key sigState = SignatureState.NoPublicKey @@ -737,7 +745,7 @@ class SwiftPGP: Encryption { chiphers.append(Armor.armored(chipher, as: PGPArmorType.message)) } else{ - chiphers.append(chipher.base64EncodedString()) + chiphers.append(chipher.base64EncodedString(options: .init(arrayLiteral: .lineLength76Characters, .endLineWithLineFeed))) } } } diff --git a/enzevalos_iphone/mail/IncomingMail.swift b/enzevalos_iphone/mail/IncomingMail.swift index c7cd0b23332a49c660d7a664ceb95284d8b6b4df..d745b213158948a86772f83e48747187079481e0 100644 --- a/enzevalos_iphone/mail/IncomingMail.swift +++ b/enzevalos_iphone/mail/IncomingMail.swift @@ -349,7 +349,7 @@ class IncomingMail { } else if isSigned { var inlineSigned = false - var signedStrings = extractSignedParts(data: msgParser.data()) + var signedStrings = extractSignedParts(text: msgParser.plainTextBodyRendering()) if signedStrings.isEmpty { signedStrings = IncomingMail.extractSignedMessage(text: body) inlineSigned = true @@ -362,7 +362,7 @@ class IncomingMail { else if signedStrings.count > 1 { text = signedStrings.joined(separator: "\r\n") } - if let signedData = text?.data(using: .utf8){ + if let signedData = text?.data(using: .utf8){ // No Signed Data! for sig in signaturesRaw { if let signature = try? Armor.readArmored(sig), let adr = from?.mailbox { for id in fromKeyIds { @@ -656,12 +656,6 @@ class IncomingMail { if (mimetype == .travelUse || mimetype == .travelRepeal) && !sentEncrypted { continue } - print(attachment.filename) - print(attachment.data.count) - print(mimetype) - print(attachment.decodedString()) - print(attachment.contentID) - print(attachment.description) var name = "untitled" if let n = attachment.filename { name = n @@ -673,13 +667,6 @@ class IncomingMail { } - private func extractSignedParts(data: Data) -> [String] { - if let text = String(data: data, encoding: .utf8) { - return extractSignedParts(text: text) - } - return [String] () - } - private func extractSignedParts(text: String) -> [String] { var parts: [String] = [] var boundary = IncomingMail.findBoundary(text: text) @@ -754,9 +741,9 @@ class IncomingMail { // TODO: What about more signatures? } } + return (extractSignedParts(text: parser.plainTextBodyRendering()), sig) } - - return (extractSignedParts(data: data), sig) + return ([], sig) } private static func importPublicKeys(attachment: MCOAttachment) -> [String] { @@ -775,7 +762,8 @@ class IncomingMail { private static func findKeys(attachment: MCOAttachment, type: PGPPart) -> [String]{ var keys: [String] = [] - if let content = String(data: attachment.data, encoding: .utf8) { + // Maybe String(data: attachment.data, encoding: .utf8) ? + if let content = attachment.decodedString() { keys.append(contentsOf: type.findPGPPartInString(content: content)) } else if let content = attachment.decodedString() { @@ -809,7 +797,10 @@ class IncomingMail { } private static func extractPGPSignature(attachment: MCOAttachment) -> [String] { - if let content = String(data: attachment.data, encoding: .utf8) { + if let content = attachment.decodedString() { + return PGPPart.SIGNATURE.findPGPPartInString(content: content) + } + else if let content = String(data: attachment.data, encoding: .ascii){ return PGPPart.SIGNATURE.findPGPPartInString(content: content) } return [] diff --git a/enzevalos_iphone/providers.json b/enzevalos_iphone/providers.json index 2b2e8986c1b77d72c37ba73c8646377a447a67f2..64e1e28b107b4ea2c2974886cd21436dc4018a16 100644 --- a/enzevalos_iphone/providers.json +++ b/enzevalos_iphone/providers.json @@ -85,7 +85,7 @@ "port":587, "hostname":"mail.zedat.fu-berlin.de", "starttls":true, - "auth":"saslPlain" + "auth":"none" } ] },