Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes TunnelVision using enforceRoutes #3460

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
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
5 changes: 5 additions & 0 deletions Core/FeatureFlag.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public enum FeatureFlag: String {

/// https://app.asana.com/0/72649045549333/1208231259093710/f
case networkProtectionUserTips

/// /// https://app.asana.com/0/72649045549333/1208617860225199/f
case networkProtectionEnforceRoutes
}

extension FeatureFlag: FeatureFlagSourceProviding {
Expand Down Expand Up @@ -100,6 +103,8 @@ extension FeatureFlag: FeatureFlagSourceProviding {
return .remoteReleasable(.feature(.autocompleteTabs))
case .networkProtectionUserTips:
return .remoteReleasable(.subfeature(NetworkProtectionSubfeature.userTips))
case .networkProtectionEnforceRoutes:
return .remoteDevelopment(.subfeature(NetworkProtectionSubfeature.enforceRoutes))
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1651,6 +1651,7 @@
6FEC0B842C999352006B4F6E /* FavoriteItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoriteItem.swift; sourceTree = "<group>"; };
6FEC0B872C999961006B4F6E /* FavoritesListInteractingAdapter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoritesListInteractingAdapter.swift; sourceTree = "<group>"; };
6FF915802B88E0750042AC87 /* AdAttributionFetcherTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdAttributionFetcherTests.swift; sourceTree = "<group>"; };
7B84C2852CCA68A700401102 /* BrowserServicesKit */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = BrowserServicesKit; path = ../BrowserServicesKit; sourceTree = SOURCE_ROOT; };
7BC5711F2BDBB877003B0CCE /* VPNActivationDateStore.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = VPNActivationDateStore.swift; sourceTree = "<group>"; };
83004E7F2193BB8200DA013C /* WKNavigationExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WKNavigationExtension.swift; sourceTree = "<group>"; };
83004E832193E14C00DA013C /* UIAlertControllerExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = UIAlertControllerExtension.swift; path = ../Core/UIAlertControllerExtension.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3686,6 +3687,7 @@
85875B5F29912A2D00115F05 /* SyncUI */,
37FCAACB2993149A000E420A /* Waitlist */,
31794BFF2821DFB600F18633 /* DuckUI */,
7B84C2852CCA68A700401102 /* BrowserServicesKit */,
);
path = LocalPackages;
sourceTree = "<group>";
Expand Down Expand Up @@ -10965,8 +10967,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 200.2.0;
kind = revision;
revision = a817b6e2c205f56b4b1e86c5db27a75a44029101;
};
};
9F8FE9472BAE50E50071E372 /* XCRemoteSwiftPackageReference "lottie-spm" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,6 @@
"version" : "3.0.0"
}
},
{
"identity" : "browserserviceskit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/DuckDuckGo/BrowserServicesKit",
"state" : {
"revision" : "a7de5bc2fe128444495e6e8345026c8974076ad7",
"version" : "200.2.0"
}
},
{
"identity" : "content-scope-scripts",
"kind" : "remoteSourceControl",
Expand Down
15 changes: 6 additions & 9 deletions DuckDuckGo/AppDependencyProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ final class AppDependencyProvider: DependencyProvider {
entitlementsCache: entitlementsCache,
subscriptionEndpointService: subscriptionService,
authEndpointService: authService)

let subscriptionManager = DefaultSubscriptionManager(storePurchaseManager: DefaultStorePurchaseManager(),
accountManager: accountManager,
subscriptionEndpointService: subscriptionService,
Expand All @@ -124,17 +124,14 @@ final class AppDependencyProvider: DependencyProvider {
let accessTokenProvider: () -> String? = {
return { accountManager.accessToken }
}()
#if os(macOS)
networkProtectionKeychainTokenStore = NetworkProtectionKeychainTokenStore(keychainType: .dataProtection(.unspecified),
serviceName: "\(Bundle.main.bundleIdentifier!).authToken",
errorEvents: .networkProtectionAppDebugEvents,
accessTokenProvider: accessTokenProvider)
#else

networkProtectionKeychainTokenStore = NetworkProtectionKeychainTokenStore(accessTokenProvider: accessTokenProvider)
#endif

networkProtectionTunnelController = NetworkProtectionTunnelController(accountManager: accountManager,
tokenStore: networkProtectionKeychainTokenStore,
persistentPixel: persistentPixel)
featureFlagger: featureFlagger,
persistentPixel: persistentPixel,
settings: vpnSettings)
vpnFeatureVisibility = DefaultNetworkProtectionVisibility(userDefaults: .networkProtectionGroupDefaults,
accountManager: accountManager)
}
Expand Down
12 changes: 12 additions & 0 deletions DuckDuckGo/NetworkProtectionDebugViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ final class NetworkProtectionDebugViewController: UITableViewController {

enum DebugFeatureRows: Int, CaseIterable {
case toggleAlwaysOn
case enforceRoutes
}

enum SimulateFailureRows: Int, CaseIterable {
Expand Down Expand Up @@ -324,6 +325,14 @@ final class NetworkProtectionDebugViewController: UITableViewController {
} else {
cell.accessoryType = .checkmark
}
case .enforceRoutes:
cell.textLabel?.text = "Enforce Routes"

if !AppDependencyProvider.shared.vpnSettings.enforceRoutes {
cell.accessoryType = .none
} else {
cell.accessoryType = .checkmark
}
default:
break
}
Expand All @@ -334,6 +343,9 @@ final class NetworkProtectionDebugViewController: UITableViewController {
case .toggleAlwaysOn:
debugFeatures.alwaysOnDisabled.toggle()
tableView.reloadRows(at: [indexPath], with: .none)
case .enforceRoutes:
AppDependencyProvider.shared.vpnSettings.enforceRoutes.toggle()
tableView.reloadRows(at: [indexPath], with: .none)
default:
break
}
Expand Down
40 changes: 37 additions & 3 deletions DuckDuckGo/NetworkProtectionTunnelController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
// limitations under the License.
//

import Foundation
import BrowserServicesKit
import Combine
import Core
import Foundation
import NetworkExtension
import NetworkProtection
import Subscription
Expand All @@ -34,6 +35,7 @@ enum VPNConfigurationRemovalReason: String {
final class NetworkProtectionTunnelController: TunnelController, TunnelSessionProvider {
static var shouldSimulateFailure: Bool = false

private let featureFlagger: FeatureFlagger
private var internalManager: NETunnelProviderManager?
private let debugFeatures = NetworkProtectionDebugFeatures()
private let tokenStore: NetworkProtectionKeychainTokenStore
Expand All @@ -42,6 +44,7 @@ final class NetworkProtectionTunnelController: TunnelController, TunnelSessionPr
private let notificationCenter: NotificationCenter = .default
private var previousStatus: NEVPNStatus = .invalid
private let persistentPixel: PersistentPixelFiring
private let settings: VPNSettings
private var cancellables = Set<AnyCancellable>()

// MARK: - Manager, Session, & Connection
Expand Down Expand Up @@ -119,9 +122,26 @@ final class NetworkProtectionTunnelController: TunnelController, TunnelSessionPr
}
}

init(accountManager: AccountManager, tokenStore: NetworkProtectionKeychainTokenStore, persistentPixel: PersistentPixelFiring) {
self.tokenStore = tokenStore
// MARK: - Enforce Routes

private var enforceRoutes: Bool {
featureFlagger.isFeatureOn(.networkProtectionEnforceRoutes)
&& settings.enforceRoutes
}

// MARK: - Initializers

init(accountManager: AccountManager,
tokenStore: NetworkProtectionKeychainTokenStore,
featureFlagger: FeatureFlagger,
persistentPixel: PersistentPixelFiring,
settings: VPNSettings) {

self.featureFlagger = featureFlagger
self.persistentPixel = persistentPixel
self.settings = settings
self.tokenStore = tokenStore

subscribeToSnoozeTimingChanges()
subscribeToStatusChanges()
subscribeToConfigurationChanges()
Expand Down Expand Up @@ -293,6 +313,7 @@ final class NetworkProtectionTunnelController: TunnelController, TunnelSessionPr
return tunnelManager
}

@MainActor
private func setupAndSave(_ tunnelManager: NETunnelProviderManager) async throws {
setup(tunnelManager)

Expand All @@ -319,6 +340,7 @@ final class NetworkProtectionTunnelController: TunnelController, TunnelSessionPr

/// Setups the tunnel manager if it's not set up already.
///
@MainActor
private func setup(_ tunnelManager: NETunnelProviderManager) {
tunnelManager.localizedDescription = "DuckDuckGo VPN"
tunnelManager.isEnabled = true
Expand All @@ -327,9 +349,21 @@ final class NetworkProtectionTunnelController: TunnelController, TunnelSessionPr
let protocolConfiguration = NETunnelProviderProtocol()
protocolConfiguration.serverAddress = "127.0.0.1" // Dummy address... the NetP service will take care of grabbing a real server

protocolConfiguration.providerConfiguration = [:]

// always-on
protocolConfiguration.disconnectOnSleep = false

// kill switch (limited to internal users currently)
protocolConfiguration.enforceRoutes = enforceRoutes

#if DEBUG
if #available(iOS 17.4, *) {
// This is useful to ensure debugging is never blocked by the VPN
protocolConfiguration.excludeDeviceCommunication = true
}
#endif

return protocolConfiguration
}()

Expand Down