From 4e4e8805a689efd252e57612df8089caae912c45 Mon Sep 17 00:00:00 2001 From: Roma Sosnovsky Date: Wed, 26 Jan 2022 14:58:18 +0200 Subject: [PATCH 1/4] #1253 add fesUrl to RawClientConfiguration --- .../Controllers/Compose/ComposeViewController.swift | 4 +--- .../Encrypted Storage/EncryptedStorage.swift | 5 ++++- .../Functionality/Error Handling/ErrorHandler.swift | 2 +- FlowCrypt/Functionality/Services/AppStartup.swift | 2 +- .../ClientConfiguration.swift | 4 ++++ .../ClientConfigurationService.swift | 3 ++- .../LocalClientConfiguration.swift | 11 ++++++++--- FlowCrypt/Models/Common/RawClientConfiguration.swift | 12 ++++-------- .../ClientConfigurationRealmObject.swift | 6 +++++- Podfile.lock | 4 ++-- 10 files changed, 32 insertions(+), 21 deletions(-) diff --git a/FlowCrypt/Controllers/Compose/ComposeViewController.swift b/FlowCrypt/Controllers/Compose/ComposeViewController.swift index 5c33fb595..7479fe755 100644 --- a/FlowCrypt/Controllers/Compose/ComposeViewController.swift +++ b/FlowCrypt/Controllers/Compose/ComposeViewController.swift @@ -58,9 +58,7 @@ final class ComposeViewController: TableNodeViewController { private let email: String private var isMessagePasswordSupported: Bool { - guard let domain = email.emailParts?.domain else { return false } - let senderDomainsWithMessagePasswordSupport = ["flowcrypt.com"] - return senderDomainsWithMessagePasswordSupport.contains(domain) + return clientConfiguration.isUsingFes } private let search = PassthroughSubject() diff --git a/FlowCrypt/Functionality/DataManager/Encrypted Storage/EncryptedStorage.swift b/FlowCrypt/Functionality/DataManager/Encrypted Storage/EncryptedStorage.swift index bff3279a5..9d2bae604 100644 --- a/FlowCrypt/Functionality/DataManager/Encrypted Storage/EncryptedStorage.swift +++ b/FlowCrypt/Functionality/DataManager/Encrypted Storage/EncryptedStorage.swift @@ -39,6 +39,7 @@ final class EncryptedStorage: EncryptedStorageType { case initial case version5 case version6 + case version7 var version: SchemaVersion { switch self { @@ -48,6 +49,8 @@ final class EncryptedStorage: EncryptedStorageType { return SchemaVersion(appVersion: "0.2.0", dbSchemaVersion: 5) case .version6: return SchemaVersion(appVersion: "0.2.0", dbSchemaVersion: 6) + case .version7: + return SchemaVersion(appVersion: "0.2.0", dbSchemaVersion: 7) } } } @@ -59,7 +62,7 @@ final class EncryptedStorage: EncryptedStorageType { private lazy var migrationLogger = Logger.nested(in: Self.self, with: .migration) private lazy var logger = Logger.nested(Self.self) - private let currentSchema: EncryptedStorageSchema = .version6 + private let currentSchema: EncryptedStorageSchema = .version7 private let supportedSchemas = EncryptedStorageSchema.allCases private let storageEncryptionKey: Data diff --git a/FlowCrypt/Functionality/Error Handling/ErrorHandler.swift b/FlowCrypt/Functionality/Error Handling/ErrorHandler.swift index ea0988f16..96a21ac13 100644 --- a/FlowCrypt/Functionality/Error Handling/ErrorHandler.swift +++ b/FlowCrypt/Functionality/Error Handling/ErrorHandler.swift @@ -34,7 +34,7 @@ private struct ComposedErrorHandler: ErrorHandler { static let shared: ComposedErrorHandler = ComposedErrorHandler( handlers: [ KeyServiceErrorHandler(), - BackupServiceErrorHandler(), + BackupServiceErrorHandler() ] ) diff --git a/FlowCrypt/Functionality/Services/AppStartup.swift b/FlowCrypt/Functionality/Services/AppStartup.swift index 7b0ea9d97..a7f354f68 100644 --- a/FlowCrypt/Functionality/Services/AppStartup.swift +++ b/FlowCrypt/Functionality/Services/AppStartup.swift @@ -91,7 +91,7 @@ struct AppStartup { logger.logInfo("User with session \(session) -> setupFlow") return .setupFlow(userId) } else { - logger.logInfo("User us not signed in -> mainFlow") + logger.logInfo("User is not signed in -> mainFlow") return .signIn } } diff --git a/FlowCrypt/Functionality/Services/Client Configuration Service/ClientConfiguration.swift b/FlowCrypt/Functionality/Services/Client Configuration Service/ClientConfiguration.swift index 250ccabd7..639938ef1 100644 --- a/FlowCrypt/Functionality/Services/Client Configuration Service/ClientConfiguration.swift +++ b/FlowCrypt/Functionality/Services/Client Configuration Service/ClientConfiguration.swift @@ -53,6 +53,10 @@ class ClientConfiguration { return URL(string: urlString) != nil } + var isUsingFes: Bool { + raw.fesUrl != nil + } + /// Enforce a key algo for keygen, eg rsa2048,rsa4096,curve25519 var enforcedKeygenAlgo: String? { raw.enforceKeygenAlgo diff --git a/FlowCrypt/Functionality/Services/Client Configuration Service/ClientConfigurationService.swift b/FlowCrypt/Functionality/Services/Client Configuration Service/ClientConfigurationService.swift index d411577f2..7617bcdcd 100644 --- a/FlowCrypt/Functionality/Services/Client Configuration Service/ClientConfigurationService.swift +++ b/FlowCrypt/Functionality/Services/Client Configuration Service/ClientConfigurationService.swift @@ -34,7 +34,8 @@ extension ClientConfigurationService: ClientConfigurationServiceType { func fetch(for user: User) async throws -> ClientConfiguration { do { let raw = try await server.getClientConfiguration(for: user.email) - try local.save(for: user, raw: raw) + let fesUrl = try await server.getActiveFesUrl(for: user.email) + try local.save(for: user, raw: raw, fesUrl: fesUrl) return ClientConfiguration(raw: raw) } catch { guard let raw = local.load(for: user.email) else { diff --git a/FlowCrypt/Functionality/Services/Client Configuration Service/LocalClientConfiguration.swift b/FlowCrypt/Functionality/Services/Client Configuration Service/LocalClientConfiguration.swift index 2e8e6a66b..60e885414 100644 --- a/FlowCrypt/Functionality/Services/Client Configuration Service/LocalClientConfiguration.swift +++ b/FlowCrypt/Functionality/Services/Client Configuration Service/LocalClientConfiguration.swift @@ -12,7 +12,7 @@ import RealmSwift protocol LocalClientConfigurationType { func load(for user: String) -> RawClientConfiguration? func remove(for user: String) throws - func save(for user: User, raw: RawClientConfiguration) throws + func save(for user: User, raw: RawClientConfiguration, fesUrl: String?) throws } final class LocalClientConfiguration { @@ -44,8 +44,13 @@ extension LocalClientConfiguration: LocalClientConfigurationType { } } - func save(for user: User, raw: RawClientConfiguration) throws { - let object = ClientConfigurationRealmObject(configuration: raw, user: user) + func save(for user: User, raw: RawClientConfiguration, fesUrl: String?) throws { + let object = ClientConfigurationRealmObject( + configuration: raw, + user: user, + fesUrl: fesUrl + ) + try storage.write { storage.add(object, update: .modified) } diff --git a/FlowCrypt/Models/Common/RawClientConfiguration.swift b/FlowCrypt/Models/Common/RawClientConfiguration.swift index 582ed6788..5980f7c6f 100644 --- a/FlowCrypt/Models/Common/RawClientConfiguration.swift +++ b/FlowCrypt/Models/Common/RawClientConfiguration.swift @@ -34,6 +34,7 @@ struct RawClientConfiguration: Codable, Equatable { let flags: [ClientConfigurationFlag]? let customKeyserverUrl: String? let keyManagerUrl: String? + let fesUrl: String? let disallowAttesterSearchForDomains: [String]? let enforceKeygenAlgo: String? let enforceKeygenExpireMonths: Int? @@ -42,6 +43,7 @@ struct RawClientConfiguration: Codable, Equatable { flags: [ClientConfigurationFlag]? = nil, customKeyserverUrl: String? = nil, keyManagerUrl: String? = nil, + fesUrl: String? = nil, disallowAttesterSearchForDomains: [String]? = nil, enforceKeygenAlgo: String? = nil, enforceKeygenExpireMonths: Int? = nil @@ -49,6 +51,7 @@ struct RawClientConfiguration: Codable, Equatable { self.flags = flags self.customKeyserverUrl = customKeyserverUrl self.keyManagerUrl = keyManagerUrl + self.fesUrl = fesUrl self.disallowAttesterSearchForDomains = disallowAttesterSearchForDomains self.enforceKeygenAlgo = enforceKeygenAlgo self.enforceKeygenExpireMonths = enforceKeygenExpireMonths @@ -58,14 +61,7 @@ struct RawClientConfiguration: Codable, Equatable { // MARK: - Empty model extension RawClientConfiguration { static var empty: RawClientConfiguration { - return RawClientConfiguration( - flags: [], - customKeyserverUrl: nil, - keyManagerUrl: nil, - disallowAttesterSearchForDomains: nil, - enforceKeygenAlgo: nil, - enforceKeygenExpireMonths: nil - ) + return RawClientConfiguration() } } diff --git a/FlowCrypt/Models/Realm Models/ClientConfigurationRealmObject.swift b/FlowCrypt/Models/Realm Models/ClientConfigurationRealmObject.swift index 1b4b23c48..ab2850c2b 100644 --- a/FlowCrypt/Models/Realm Models/ClientConfigurationRealmObject.swift +++ b/FlowCrypt/Models/Realm Models/ClientConfigurationRealmObject.swift @@ -14,6 +14,7 @@ final class ClientConfigurationRealmObject: Object { @Persisted var flags: Data? @Persisted var customKeyserverUrl: String? @Persisted var keyManagerUrl: String? + @Persisted var fesUrl: String? @Persisted var disallowAttesterSearchForDomains: Data? @Persisted var enforceKeygenAlgo: String? @Persisted var enforceKeygenExpireMonths: Int @@ -23,6 +24,7 @@ final class ClientConfigurationRealmObject: Object { flags: [String]?, customKeyserverUrl: String?, keyManagerUrl: String?, + fesUrl: String?, disallowAttesterSearchForDomains: [String]?, enforceKeygenAlgo: String?, enforceKeygenExpireMonths: Int?, @@ -34,6 +36,7 @@ final class ClientConfigurationRealmObject: Object { } self.customKeyserverUrl = customKeyserverUrl self.keyManagerUrl = keyManagerUrl + self.fesUrl = fesUrl if let disallowAttesterSearchForDomains = disallowAttesterSearchForDomains { self.disallowAttesterSearchForDomains = try? JSONEncoder().encode(disallowAttesterSearchForDomains) } @@ -45,11 +48,12 @@ final class ClientConfigurationRealmObject: Object { } extension ClientConfigurationRealmObject { - convenience init(configuration: RawClientConfiguration, user: User) { + convenience init(configuration: RawClientConfiguration, user: User, fesUrl: String?) { self.init( flags: configuration.flags?.map(\.rawValue), customKeyserverUrl: configuration.customKeyserverUrl, keyManagerUrl: configuration.keyManagerUrl, + fesUrl: fesUrl, disallowAttesterSearchForDomains: configuration.disallowAttesterSearchForDomains, enforceKeygenAlgo: configuration.enforceKeygenAlgo, enforceKeygenExpireMonths: configuration.enforceKeygenExpireMonths, diff --git a/Podfile.lock b/Podfile.lock index c9ee828b6..4cbc19c1a 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -16,7 +16,7 @@ PODS: - PINCache (~> 3.0.3) - PINRemoteImage/Core - SwiftFormat/CLI (0.49.2) - - SwiftLint (0.45.1) + - SwiftLint (0.46.1) - SwiftyRSA (1.7.0): - SwiftyRSA/ObjC (= 1.7.0) - SwiftyRSA/ObjC (1.7.0) @@ -65,7 +65,7 @@ SPEC CHECKSUMS: PINOperation: 00c935935f1e8cf0d1e2d6b542e75b88fc3e5e20 PINRemoteImage: f1295b29f8c5e640e25335a1b2bd9d805171bd01 SwiftFormat: dca5803d3e2120aed5614f1653d252e62ac33be1 - SwiftLint: 06ac37e4d38c7068e0935bb30cda95f093bec761 + SwiftLint: aaa29a9f649316095a9079595cb60906bd899353 SwiftyRSA: 8c6dd1ea7db1b8dc4fb517a202f88bb1354bc2c6 Texture: 2e8ab2519452515f7f5a520f5a8f7e0a413abfa3 From 421c5f3a7d7c3dfc9e1f12feb5d2ff7e9e6d021f Mon Sep 17 00:00:00 2001 From: Roma Sosnovsky Date: Wed, 26 Jan 2022 17:35:25 +0200 Subject: [PATCH 2/4] add testIsUsingFes test --- FlowCrypt/Models/Common/RawClientConfiguration.swift | 1 + .../ClientConfigurationTests.swift | 4 ++++ .../Mocks/ClientConfigurationProviderMock.swift | 2 +- .../Mocks/EnterpriseServerApiMock.swift | 4 ++-- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/FlowCrypt/Models/Common/RawClientConfiguration.swift b/FlowCrypt/Models/Common/RawClientConfiguration.swift index 5980f7c6f..cf1a12eb1 100644 --- a/FlowCrypt/Models/Common/RawClientConfiguration.swift +++ b/FlowCrypt/Models/Common/RawClientConfiguration.swift @@ -87,6 +87,7 @@ extension RawClientConfiguration { flags: decodedFlags?.compactMap(ClientConfigurationFlag.init), customKeyserverUrl: unwrappedObject.customKeyserverUrl, keyManagerUrl: unwrappedObject.keyManagerUrl, + fesUrl: unwrappedObject.fesUrl, disallowAttesterSearchForDomains: decodedDisallowAttesterSearchForDomains, enforceKeygenAlgo: unwrappedObject.enforceKeygenAlgo, enforceKeygenExpireMonths: unwrappedObject.enforceKeygenExpireMonths diff --git a/FlowCryptAppTests/Functionality/Services/Client Configuration Service/ClientConfigurationTests.swift b/FlowCryptAppTests/Functionality/Services/Client Configuration Service/ClientConfigurationTests.swift index 2761fb8fd..94adea6e0 100644 --- a/FlowCryptAppTests/Functionality/Services/Client Configuration Service/ClientConfigurationTests.swift +++ b/FlowCryptAppTests/Functionality/Services/Client Configuration Service/ClientConfigurationTests.swift @@ -25,6 +25,10 @@ class ClientConfigurationTests: XCTestCase { XCTAssertFalse(ClientConfiguration(raw: RawClientConfiguration(keyManagerUrl: "not a url string")).isKeyManagerUrlValid) } + func testIsUsingFes() { + XCTAssertTrue(ClientConfiguration(raw: RawClientConfiguration(fesUrl: "https://fes.flowcrypt.com") ).isUsingFes) + } + func testMustAutoImportOrAutogenPrvWithKeyManager() { XCTAssertTrue(ClientConfiguration(raw: RawClientConfiguration( flags: [.privateKeyAutoimportOrAutogen], diff --git a/FlowCryptAppTests/Functionality/Services/Client Configuration Service/Mocks/ClientConfigurationProviderMock.swift b/FlowCryptAppTests/Functionality/Services/Client Configuration Service/Mocks/ClientConfigurationProviderMock.swift index 6234f866c..cb9471ff1 100644 --- a/FlowCryptAppTests/Functionality/Services/Client Configuration Service/Mocks/ClientConfigurationProviderMock.swift +++ b/FlowCryptAppTests/Functionality/Services/Client Configuration Service/Mocks/ClientConfigurationProviderMock.swift @@ -33,7 +33,7 @@ class LocalClientConfigurationMock: LocalClientConfigurationType { var saveCount = 0 var saveCall: (RawClientConfiguration) -> Void = { clientConfiguration in } - func save(for user: User, raw: RawClientConfiguration) { + func save(for user: User, raw: RawClientConfiguration, fesUrl: String?) { saveInvoked = true saveCount += 1 saveCall(raw) diff --git a/FlowCryptAppTests/Functionality/Services/Client Configuration Service/Mocks/EnterpriseServerApiMock.swift b/FlowCryptAppTests/Functionality/Services/Client Configuration Service/Mocks/EnterpriseServerApiMock.swift index dc5f50f05..47c935568 100644 --- a/FlowCryptAppTests/Functionality/Services/Client Configuration Service/Mocks/EnterpriseServerApiMock.swift +++ b/FlowCryptAppTests/Functionality/Services/Client Configuration Service/Mocks/EnterpriseServerApiMock.swift @@ -12,8 +12,8 @@ import Foundation final class EnterpriseServerApiMock: EnterpriseServerApiType { var getActiveFesUrlInvoked = false var getActiveFesUrlInvokedCount = 0 - var getActiveFesUrlCall: (String) throws -> String? = { _ in - throw OrganisationalRulesServiceError.getActiveFesUrlCall + var getActiveFesUrlCall: (String) -> String? = { _ in + return nil } func getActiveFesUrl(for email: String) async throws -> String? { getActiveFesUrlInvoked = true From 4eb84dc658d114cc0552281c5909a175497c45c1 Mon Sep 17 00:00:00 2001 From: Roma Sosnovsky Date: Thu, 27 Jan 2022 12:33:04 +0200 Subject: [PATCH 3/4] merge updates --- .../xcshareddata/swiftpm/Package.resolved | 8 ++++---- Podfile.lock | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/FlowCrypt.xcworkspace/xcshareddata/swiftpm/Package.resolved b/FlowCrypt.xcworkspace/xcshareddata/swiftpm/Package.resolved index 6528023d1..9b379cb07 100644 --- a/FlowCrypt.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/FlowCrypt.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -87,8 +87,8 @@ "repositoryURL": "https://github.com/realm/realm-cocoa", "state": { "branch": null, - "revision": "39177714b95bb5b1b29fffe28f1c7da77eef8e8b", - "version": "10.21.1" + "revision": "9dff9f2862240d521ad6ad599541269177ddb993", + "version": "10.22.0" } }, { @@ -96,8 +96,8 @@ "repositoryURL": "https://github.com/realm/realm-core", "state": { "branch": null, - "revision": "f1976f0d96d9b06fbe0afbd60090b1c3966b1e23", - "version": "11.8.0" + "revision": "6b81f1a7a2d421f9e0b9e7f04e76bcf736a54409", + "version": "11.9.0" } }, { diff --git a/Podfile.lock b/Podfile.lock index 4cbc19c1a..e04d6e530 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -15,7 +15,7 @@ PODS: - PINRemoteImage/PINCache (3.0.3): - PINCache (~> 3.0.3) - PINRemoteImage/Core - - SwiftFormat/CLI (0.49.2) + - SwiftFormat/CLI (0.49.3) - SwiftLint (0.46.1) - SwiftyRSA (1.7.0): - SwiftyRSA/ObjC (= 1.7.0) @@ -64,7 +64,7 @@ SPEC CHECKSUMS: PINCache: 7a8fc1a691173d21dbddbf86cd515de6efa55086 PINOperation: 00c935935f1e8cf0d1e2d6b542e75b88fc3e5e20 PINRemoteImage: f1295b29f8c5e640e25335a1b2bd9d805171bd01 - SwiftFormat: dca5803d3e2120aed5614f1653d252e62ac33be1 + SwiftFormat: a3b79e8b5f8ecdec7a716b998aee230d08512894 SwiftLint: aaa29a9f649316095a9079595cb60906bd899353 SwiftyRSA: 8c6dd1ea7db1b8dc4fb517a202f88bb1354bc2c6 Texture: 2e8ab2519452515f7f5a520f5a8f7e0a413abfa3 From 57c43b9c958187152078b67e8022ffad5599ee23 Mon Sep 17 00:00:00 2001 From: Roma Sosnovsky Date: Mon, 31 Jan 2022 21:43:52 +0200 Subject: [PATCH 4/4] #1352 temporary disable simctl on semaphore --- .semaphore/semaphore.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.semaphore/semaphore.yml b/.semaphore/semaphore.yml index ef590ff8b..616856b66 100644 --- a/.semaphore/semaphore.yml +++ b/.semaphore/semaphore.yml @@ -30,6 +30,10 @@ blocks: - cache restore && make dependencies && cache store - mv ~/appium-env ~/git/flowcrypt-ios/appium/.env - sem-version node 16 && cache restore appium-npm && cd ./appium && npm i && cd .. && cache store appium-npm appium/node_modules + # temporary disabled because of https://github.com/ios-control/simctl/issues/30 + # - brew install ideviceinstaller + # - npm install ios-deploy -g --unsafe-perm=true --allow-root + # - npm install ios-sim -g --unsafe-perm=true --allow-root jobs: - name: Appium UI tests commands: