diff --git a/enzevalos_iphone/DataHandler.swift b/enzevalos_iphone/DataHandler.swift index 402f99c00c383dced15b6323e628c6a4c7ec60c5..c3f22f4c655dfa15235ae34bb2d69983c97c6403 100644 --- a/enzevalos_iphone/DataHandler.swift +++ b/enzevalos_iphone/DataHandler.swift @@ -1119,19 +1119,17 @@ class DataHandler { return [] } + /** + Filters all Presistent Mails with encState == EncryptionState.UnableToDecrypt + */ func getAllNotDecryptedPersistentMail() -> [PersistentMail] { let result = getAllPersistentMails().filter({ $0.encState == EncryptionState.UnableToDecrypt }) return result } - // filter all presistent mails without public key - func getAllNoPublicKeyPersistentMail() -> [PersistentMail] { - let result = getAllPersistentMails().filter({ $0.sigState == SignatureState.NoPublicKey }) - return result - } - - - + /** + Filters all Presistent Mails with sigState == SignatureState.NoPublicKey + */ func getAllNotSignedPersistentMail() -> [PersistentMail] { let result = getAllPersistentMails().filter({ $0.sigState == SignatureState.NoPublicKey }) return result diff --git a/enzevalos_iphone/SwiftPGP.swift b/enzevalos_iphone/SwiftPGP.swift index c240656c81588ab3c53557a52ff18c4c8f1e4368..8d566aa811b098b6fab39b26a3fd1e5656971e93 100644 --- a/enzevalos_iphone/SwiftPGP.swift +++ b/enzevalos_iphone/SwiftPGP.swift @@ -596,7 +596,10 @@ class SwiftPGP: Encryption { return CryptoObject(chiphertext: data, plaintext: plaintext, decryptedData: plaindata, sigState: sigState, encState: encState, signKey: sigKeyID, encType: CryptoScheme.PGP, signedAdrs: signedAdr) } - // A help function for findMailForSecrectKey and findNotSignedMailForPublicKey + /** + A help function for findMailForSecrectKey and findNotSignedMailForPublicKey + Receives a keyID as String and returns the corresponding key as a [Key] List. + */ func keyAsKeyList(keyID: String) -> [Key] { var keyList = [Key]() if let key: Key = loadKey(id: keyID) { @@ -605,7 +608,9 @@ class SwiftPGP: Encryption { return keyList } - // Finds undecrypted mails in persistent mails and and tries to decrypt with the incoming secret key + /** + Receives a keyID as String and searches for undecrypted mails in persistent mails and and tries to decrypt them with the incoming secret key. + */ func findMailForSecretKey(keyID: String) { var encState = EncryptionState.UnableToDecrypt var plaindata: Data? = nil @@ -655,7 +660,9 @@ class SwiftPGP: Encryption { return (nil, EncryptionState.NoEncryption) } - // Finds unsigned mails in persistent mails and and tries to verify them with the incoming public key + /** + Receives a keyID as String and searches for unsigned mails in persistent mails and and tries to verify them with the incoming public key. + */ func findNotSignedMailForPublicKey(keyID: String) { var sigState = SignatureState.NoPublicKey let key: [Key] = keyAsKeyList(keyID: keyID) diff --git a/enzevalos_iphoneTests/CoreDataTests.swift b/enzevalos_iphoneTests/CoreDataTests.swift index 1386de55de99d70db3269cc90691135afb542dc4..9d041ae6345f5180efbaa42cd7883e68aaf7cdf2 100644 --- a/enzevalos_iphoneTests/CoreDataTests.swift +++ b/enzevalos_iphoneTests/CoreDataTests.swift @@ -104,52 +104,6 @@ class CoraDataTests: XCTestCase { } } - // Generate a test secret key - func testkey() -> (String){ - let testsender = createUser() - let testkeyID = pgp.generateKey(adr: testsender.mailbox, new: true) - return testkeyID - - } - - // Test decryption of all undecrypted mails with new secret key - func testfindMailForSecretKey() { - let testkeyID = testkey() - let swiftpgp = SwiftPGP() - - // E-Mail generieren - guard let from = MCOAddress(mailbox: "sender@example.com") else { - return - } - - // Create test Mail - guard let m1 = testMail(from: from, to: [user], cc: [], bcc: []) else { - XCTFail("No test mail") - return - } - - // Create Ciphertext - let body = "encrypted text" - let senderPGP = SwiftPGP() - let encryptedObject = senderPGP.encrypt(plaintext: body, ids: [testkeyID], myId: "") - XCTAssert(encryptedObject.encryptionState == .ValidedEncryptedWithCurrentKey && encryptedObject.signatureState == .NoSignature) - - guard let cipher = encryptedObject.chiperString else { - XCTFail("No chipher data") - return - } - - // Change Mail - m1.unableToDecrypt = true - m1.body = cipher - - datahandler.save(during: "") - - swiftpgp.findMailForSecretKey(keyID: testkeyID) - XCTAssertEqual(m1.body, "encrypted text") - XCTAssertFalse(m1.unableToDecrypt) - } - func createUser(adr: String = String.random().lowercased(), name: String = String.random()) -> MCOAddress { return MCOAddress.init(displayName: name, mailbox: adr.lowercased()) } diff --git a/enzevalos_iphoneTests/CryptoTests.swift b/enzevalos_iphoneTests/CryptoTests.swift index 06cbf1c028d152034c6a43823869733a5ea7082e..84e8b1487f9358edaba0e61c387d27242f82315e 100644 --- a/enzevalos_iphoneTests/CryptoTests.swift +++ b/enzevalos_iphoneTests/CryptoTests.swift @@ -610,7 +610,54 @@ class CryptoTests: XCTestCase { return mail } - // Not finished yet + /** + Generate a test secret key + */ + func testkey() -> (String){ + let testsender = createUser() + let testkeyID = pgp.generateKey(adr: testsender.mailbox, new: true) + return testkeyID + } + + func testfindMailForSecretKey() { + let testkeyID = testkey() + + // E-Mail generieren + guard let from = MCOAddress(mailbox: "sender@example.com") else { + return + } + + // Create test Mail + guard let m1 = testMail(from: from, to: [user], cc: [], bcc: []) else { + XCTFail("No test mail") + return + } + + // Create Ciphertext + let body = "encrypted text" + let senderPGP = SwiftPGP() + let encryptedObject = senderPGP.encrypt(plaintext: body, ids: [testkeyID], myId: "") + XCTAssert(encryptedObject.encryptionState == .ValidedEncryptedWithCurrentKey && encryptedObject.signatureState == .NoSignature) + + guard let cipher = encryptedObject.chiperString else { + XCTFail("No chipher data") + return + } + + // Change Mail + m1.unableToDecrypt = true + m1.body = cipher + + datahandler.save(during: "") + + pgp.findMailForSecretKey(keyID: testkeyID) + XCTAssertEqual(m1.body, "encrypted text") + XCTAssertFalse(m1.unableToDecrypt) + } + + /* + !!!!! Not finished yet !!!!! + */ func testfindNotSignedMailForPublicKey() { // E-Mail generieren guard let from = MCOAddress(mailbox: "alice@example.com") else { diff --git a/enzevalos_iphoneTests/phishing/UrlStringExtensionTests.swift b/enzevalos_iphoneTests/phishing/UrlStringExtensionTests.swift index 742e63872269541e2cf662ad8516f099816205fe..2ea8a380a3f5e581e10d4606dab59eee6c0dd2d3 100644 --- a/enzevalos_iphoneTests/phishing/UrlStringExtensionTests.swift +++ b/enzevalos_iphoneTests/phishing/UrlStringExtensionTests.swift @@ -109,21 +109,6 @@ class UrlStringExtensionTests: XCTestCase { XCTAssertEqual(sld[2], finalSLD[2]) XCTAssertEqual(sld[3], finalSLD[3]) } - - func testIsValidRD(){ - let pattern = testMailText.isValidRD() - XCTAssertNotNil(pattern) - XCTAssertEqual(pattern[0], vaildRD[0]) - XCTAssertEqual(pattern[1], vaildRD[1]) - XCTAssertEqual(pattern[2], vaildRD[2]) - XCTAssertEqual(pattern[3], vaildRD[3]) - XCTAssertEqual(pattern[4], vaildRD[4]) - XCTAssertEqual(pattern[5], vaildRD[5]) - XCTAssertEqual(pattern[6], vaildRD[6]) - XCTAssertEqual(pattern[7], vaildRD[7]) - XCTAssertEqual(pattern[8], vaildRD[8]) - XCTAssertEqual(pattern[9], vaildRD[9]) - } func testIsAllowedDistance() { let str = "google"