Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions FlowCrypt.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
04B472951ECE29F600B8266F /* MyMenuViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04B472921ECE29F600B8266F /* MyMenuViewController.swift */; };
04B472961ECE29F600B8266F /* SideMenuNavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 04B472931ECE29F600B8266F /* SideMenuNavigationController.swift */; };
211392A5266511E6009202EC /* PubLookup.swift in Sources */ = {isa = PBXBuildFile; fileRef = 211392A4266511E6009202EC /* PubLookup.swift */; };
21C7DF0526697DA500C44800 /* PromiseKitExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21C7DF0426697DA500C44800 /* PromiseKitExtension.swift */; };
21C7DEFC26669A3700C44800 /* CalendarExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21C7DEFB26669A3700C44800 /* CalendarExtension.swift */; };
21C7DEFE26669CE100C44800 /* DateFormattingExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F56BD3723438C7000A7371A /* DateFormattingExtensions.swift */; };
21C7DF0526697DA500C44800 /* PromiseKitExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21C7DF0426697DA500C44800 /* PromiseKitExtension.swift */; };
21CE25E62650070300ADFF4B /* WKDURLsConstructor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21CE25E52650070300ADFF4B /* WKDURLsConstructor.swift */; };
21EA3B2326565B5D00691848 /* DomainRulesTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 21EA3B2226565B5D00691848 /* DomainRulesTests.swift */; };
21EA3B2F26565B7400691848 /* domain_rules.json in Resources */ = {isa = PBXBuildFile; fileRef = 21EA3B2E26565B7400691848 /* domain_rules.json */; };
Expand Down Expand Up @@ -234,7 +234,6 @@
D274724124F97C5C006BA6EF /* CacheService.swift in Sources */ = {isa = PBXBuildFile; fileRef = D274724024F97C5C006BA6EF /* CacheService.swift */; };
D274724424FD1932006BA6EF /* FolderObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = D274724324FD1932006BA6EF /* FolderObject.swift */; };
D27B911924EFE79F002DF0A1 /* LocalContactsProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = D27B911824EFE79F002DF0A1 /* LocalContactsProvider.swift */; };
D27B911B24EFE7BE002DF0A1 /* RemoteContactsProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = D27B911A24EFE7BE002DF0A1 /* RemoteContactsProvider.swift */; };
D27B911D24EFE806002DF0A1 /* ContactObject.swift in Sources */ = {isa = PBXBuildFile; fileRef = D27B911C24EFE806002DF0A1 /* ContactObject.swift */; };
D27B911F24EFE828002DF0A1 /* Contact.swift in Sources */ = {isa = PBXBuildFile; fileRef = D27B911E24EFE828002DF0A1 /* Contact.swift */; };
D28325DD24895F5700D311BD /* Colors.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 949ED9412303E3B400530579 /* Colors.xcassets */; };
Expand Down Expand Up @@ -361,8 +360,8 @@
113F04B20ECC35FC59A81A6C /* Pods-FlowCryptTests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FlowCryptTests.release.xcconfig"; path = "Target Support Files/Pods-FlowCryptTests/Pods-FlowCryptTests.release.xcconfig"; sourceTree = "<group>"; };
11C1375F41411882DC4C9431 /* Pods-FlowCryptUIApplication.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-FlowCryptUIApplication.release.xcconfig"; path = "Target Support Files/Pods-FlowCryptUIApplication/Pods-FlowCryptUIApplication.release.xcconfig"; sourceTree = "<group>"; };
211392A4266511E6009202EC /* PubLookup.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PubLookup.swift; sourceTree = "<group>"; };
21C7DF0426697DA500C44800 /* PromiseKitExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PromiseKitExtension.swift; sourceTree = "<group>"; };
21C7DEFB26669A3700C44800 /* CalendarExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CalendarExtension.swift; sourceTree = "<group>"; };
21C7DF0426697DA500C44800 /* PromiseKitExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PromiseKitExtension.swift; sourceTree = "<group>"; };
21CE25E52650070300ADFF4B /* WKDURLsConstructor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WKDURLsConstructor.swift; sourceTree = "<group>"; };
21EA3B15265647C400691848 /* OrganisationalRule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrganisationalRule.swift; sourceTree = "<group>"; };
21EA3B2226565B5D00691848 /* DomainRulesTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DomainRulesTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -604,7 +603,6 @@
D274724024F97C5C006BA6EF /* CacheService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CacheService.swift; sourceTree = "<group>"; };
D274724324FD1932006BA6EF /* FolderObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FolderObject.swift; sourceTree = "<group>"; };
D27B911824EFE79F002DF0A1 /* LocalContactsProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalContactsProvider.swift; sourceTree = "<group>"; };
D27B911A24EFE7BE002DF0A1 /* RemoteContactsProvider.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoteContactsProvider.swift; sourceTree = "<group>"; };
D27B911C24EFE806002DF0A1 /* ContactObject.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContactObject.swift; sourceTree = "<group>"; };
D27B911E24EFE828002DF0A1 /* Contact.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Contact.swift; sourceTree = "<group>"; };
D28655922423B4EE0066F52E /* MyMenuViewDecorator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MyMenuViewDecorator.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1510,7 +1508,6 @@
children = (
D2FC1C0524D82C9F003B949D /* ContactsService.swift */,
D27B911824EFE79F002DF0A1 /* LocalContactsProvider.swift */,
D27B911A24EFE7BE002DF0A1 /* RemoteContactsProvider.swift */,
D27B912024EFE842002DF0A1 /* Models */,
);
path = "Contacts Services";
Expand Down Expand Up @@ -2396,7 +2393,6 @@
9F31ABA0232C071700CF87EA /* GlobalRouter.swift in Sources */,
9F5C2A92257E94DF00DE9B4B /* Imap+MessageOperations.swift in Sources */,
D27B911F24EFE828002DF0A1 /* Contact.swift in Sources */,
D27B911B24EFE7BE002DF0A1 /* RemoteContactsProvider.swift in Sources */,
32DCA1414EEA727B86C337D5 /* Core.swift in Sources */,
9FB22CF725715DC50026EE64 /* KeyServiceErrorHandler.swift in Sources */,
9F8220D526336626004B2009 /* Logger.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extension GmailService: BackupProvider {
Logger.logVerbose("[GmailService] searching done, found \(backupMessages.count) backup messages")
let uniqueMessages = Set(backupMessages)
let attachments = uniqueMessages
.compactMap { (message) -> [(String, String)]? in
.compactMap { message -> [(String, String)]? in
Logger.logVerbose("[GmailService] processing backup '\(message.subject ?? "-")' with \(message.attachmentIds.count) attachments")
guard let identifier = message.identifier.stringId else {
Logger.logVerbose("[GmailService] skipping this last backup?")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ enum ContactsError: Error {
protocol ContactsServiceType: PublicKeyProvider, ContactsProviderType {
}

protocol ContactsProviderType {
func searchContact(with email: String) -> Promise<Contact>
}

protocol PublicKeyProvider {
func retrievePubKey(for email: String) -> String?
}
Expand All @@ -25,14 +29,14 @@ protocol PublicKeyProvider {

struct ContactsService: ContactsServiceType {
let localContactsProvider: LocalContactsProviderType
let remoteContactsProvider: ContactsProviderType
let pubLookup: PubLookupType

init(
localContactsProvider: LocalContactsProviderType = LocalContactsProvider(storage: DataService.shared.storage),
remoteContactsProvider: ContactsProviderType = RemoteContactsProvider()
pubLookup: PubLookupType = PubLookup()
) {
self.localContactsProvider = localContactsProvider
self.remoteContactsProvider = remoteContactsProvider
self.pubLookup = pubLookup
}
}

Expand All @@ -45,8 +49,8 @@ extension ContactsService: ContactsProviderType {
}

private func searchRemote(for email: String) -> Promise<Contact> {
remoteContactsProvider
.searchContact(with: email)
pubLookup
.lookup(with: email)
.then { contact in
self.localContactsProvider.save(contact: contact)
}
Expand Down

This file was deleted.

43 changes: 40 additions & 3 deletions FlowCrypt/Functionality/WKDURLs/PubLookup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
import Promises

protocol PubLookupType {
func lookupEmail(_ email: String) -> Promise<[String]>
func lookup(with email: String) -> Promise<Contact>
}

class PubLookup {
class PubLookup: PubLookupType {
private let wkd: WKDURLsApiType
private let attesterApi: AttesterApiType

Expand All @@ -24,7 +24,15 @@ class PubLookup {
self.attesterApi = attesterApi
}

func lookupEmail(_ email: String) -> Promise<[KeyDetails]> {
func lookup(with email: String) -> Promise<Contact> {
Promise<Contact> { resolve, _ in
let keyDetails = try awaitPromise(self.getKeyDetails(email))
let contact = try awaitPromise(self.parseKey(keyDetails: keyDetails, for: email))
resolve(contact)
}
}

private func getKeyDetails(_ email: String) -> Promise<[KeyDetails]> {

Promise<[KeyDetails]> { [weak self] resolve, _ in
guard let self = self else {
Expand All @@ -41,4 +49,33 @@ class PubLookup {
resolve(attesterResult)
}
}

private func parseKey(keyDetails: [KeyDetails], for email: String) -> Promise<Contact> {

// TODO: - we are blindly choosing .first public key, in the future we should return [Contact]
// and have some intelligent code in the consumers to choose the right public key
// for whatever purpose it's used for.
guard let keyDetail = keyDetails.first else {
return Promise(ContactsError.keyMissing)
}

let keyIds = keyDetails.flatMap(\.ids)
let longids = keyIds.map(\.longid)
let fingerprints = keyIds.map(\.fingerprint)

let contact = Contact(
email: email,
name: keyDetail.users.first ?? email,
pubKey: keyDetail.public,
pubKeyLastSig: nil, // TODO: - will be provided later
pubkeyLastChecked: Date(),
pubkeyExpiresOn: nil, // TODO: - will be provided later
longids: longids,
lastUsed: nil,
fingerprints: fingerprints,
pubkeyCreated: Date(timeIntervalSince1970: Double(keyDetail.created)),
algo: keyDetail.algo
)
return Promise(contact)
}
}