From 74ed93a966d85dbf96b051932ff740fb89eb8fd9 Mon Sep 17 00:00:00 2001 From: Davide Date: Tue, 19 Nov 2024 20:51:55 +0100 Subject: [PATCH] Check provider requirements before connecting (#896) E.g. interactive login must be presented afterwards. --- .../xcshareddata/swiftpm/Package.resolved | 2 +- Passepartout/Library/Package.swift | 2 +- .../UILibrary/L10n/AppError+L10n.swift | 3 + .../Views/UI/TunnelToggleButton.swift | 57 +++++++++++-------- 4 files changed, 38 insertions(+), 26 deletions(-) diff --git a/Passepartout.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved b/Passepartout.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved index 18f6e455..09b8eb0e 100644 --- a/Passepartout.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved +++ b/Passepartout.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved @@ -41,7 +41,7 @@ "kind" : "remoteSourceControl", "location" : "git@github.com:passepartoutvpn/passepartoutkit-source", "state" : { - "revision" : "db02de5247d0231ff06fb3c4d166645a434255be" + "revision" : "d11036e59b65601b617120471dc9a469567388f5" } }, { diff --git a/Passepartout/Library/Package.swift b/Passepartout/Library/Package.swift index 52441ebc..4f72850b 100644 --- a/Passepartout/Library/Package.swift +++ b/Passepartout/Library/Package.swift @@ -44,7 +44,7 @@ let package = Package( ], dependencies: [ // .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", from: "0.11.0"), - .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", revision: "db02de5247d0231ff06fb3c4d166645a434255be"), + .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source", revision: "d11036e59b65601b617120471dc9a469567388f5"), // .package(path: "../../../passepartoutkit-source"), .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", from: "0.9.1"), // .package(url: "git@github.com:passepartoutvpn/passepartoutkit-source-openvpn-openssl", revision: "031863a1cd683962a7dfe68e20b91fa820a1ecce"), diff --git a/Passepartout/Library/Sources/UILibrary/L10n/AppError+L10n.swift b/Passepartout/Library/Sources/UILibrary/L10n/AppError+L10n.swift index 9a4fe017..a126825a 100644 --- a/Passepartout/Library/Sources/UILibrary/L10n/AppError+L10n.swift +++ b/Passepartout/Library/Sources/UILibrary/L10n/AppError+L10n.swift @@ -83,6 +83,9 @@ extension PassepartoutError: @retroactive LocalizedError { .compactMap { $0 } .joined(separator: " ") + case .missingProviderEntity: + return Strings.Errors.App.Passepartout.missingProviderEntity + case .noActiveModules: return Strings.Errors.App.Passepartout.noActiveModules diff --git a/Passepartout/Library/Sources/UILibrary/Views/UI/TunnelToggleButton.swift b/Passepartout/Library/Sources/UILibrary/Views/UI/TunnelToggleButton.swift index 2d455d20..65e218c0 100644 --- a/Passepartout/Library/Sources/UILibrary/Views/UI/TunnelToggleButton.swift +++ b/Passepartout/Library/Sources/UILibrary/Views/UI/TunnelToggleButton.swift @@ -110,16 +110,40 @@ private extension TunnelToggleButton { nextProfileId = nil } } - if canConnect && profile.isInteractive { - do { - try iapManager.verify(profile) - pp_log(.app, .notice, "Present interactive login") - interactiveManager.present(with: profile) { - await perform(with: $0) + if canConnect { + + // provider module -> check requirements + if let providerModule = profile.firstProviderModule, + providerModule.isProviderRequired { + + // missing required provider -> show error + guard let provider = providerModule.provider else { + errorHandler.handle( + PassepartoutError(.providerRequired), + title: Strings.Global.connection + ) + return + } + + // missing provider entity -> show selector + guard provider.entity != nil else { + onProviderEntityRequired(profile) + return + } + } + + // interactive login -> show interactive view + if profile.isInteractive { + do { + try iapManager.verify(profile) + pp_log(.app, .notice, "Present interactive login") + interactiveManager.present(with: profile) { + await perform(with: $0) + } + return + } catch { + pp_log(.app, .error, "Verification failed for profile \(profile.id), suppress interactive login: \(error)") } - return - } catch { - pp_log(.app, .notice, "Ineligible, suppress interactive login") } } await perform(with: profile) @@ -142,21 +166,6 @@ private extension TunnelToggleButton { } catch is CancellationError { // } catch { - switch (error as? PassepartoutError)?.code { - case .missingProviderEntity: - onProviderEntityRequired(profile) - return - - case .providerRequired: - errorHandler.handle( - error, - title: Strings.Global.connection - ) - return - - default: - break - } errorHandler.handle( error, title: Strings.Global.connection,