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

Check entitlement while rekeying #2424

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5e8d6b0
Exchange access token for auth token
quanganhdo Jan 19, 2024
9254447
Fix typos
quanganhdo Jan 19, 2024
8e047ab
Merge branch 'main' into anh/netp-subscription
quanganhdo Jan 19, 2024
8263aed
Merge branch 'main' into anh/netp-check-entitlement
quanganhdo Jan 23, 2024
647f6ef
Just enough for AccountManager check
quanganhdo Jan 23, 2024
9dc98f1
Fix Alpha build not installing NetP
quanganhdo Jan 24, 2024
ea8d32c
Merge branch 'main' into anh/netp-check-entitlement
quanganhdo Jan 24, 2024
f837fae
Show last disconnect error in Debug view
quanganhdo Jan 25, 2024
770c0b8
Minor refactoring
quanganhdo Jan 26, 2024
eb64fe3
To be dropped
quanganhdo Jan 26, 2024
51de3a7
Merge branch 'main' into anh/netp-check-entitlement
quanganhdo Jan 26, 2024
461b700
Merge branch 'main' into anh/netp-check-entitlement
quanganhdo Jan 29, 2024
f91093d
Show notification
quanganhdo Jan 30, 2024
140992e
Merge branch 'main' into anh/netp-check-entitlement
quanganhdo Jan 31, 2024
d1ec958
Add ALPHA to Alpha Debug build
quanganhdo Feb 1, 2024
a0ee6c2
Populate isSubscriptionEnabled
quanganhdo Feb 1, 2024
7ece8fa
Use SubscriptionConfig instead
quanganhdo Feb 1, 2024
56e11bf
Update entitlement for Alpha Debug
quanganhdo Feb 1, 2024
6da1586
Use ddg:accessToken for NetP authentication
quanganhdo Feb 1, 2024
9fe8986
Clean up
quanganhdo Feb 1, 2024
4a9d0d0
Merge branch 'main' into anh/netp-check-entitlement
quanganhdo Feb 2, 2024
11ba78f
Update BSK
quanganhdo Feb 2, 2024
9c261ab
Update BSK
quanganhdo Feb 2, 2024
844e655
Update BSK
quanganhdo Feb 2, 2024
b655829
Merge branch 'main' into anh/netp-check-entitlement-while-rekeying
quanganhdo Feb 5, 2024
695f857
Add missing file
quanganhdo Feb 5, 2024
e53ce3d
Clean up
quanganhdo Feb 5, 2024
c67390c
Update BSK
quanganhdo Feb 6, 2024
e762552
Update BSK
quanganhdo Feb 7, 2024
3048c93
Merge branch 'main' into anh/netp-check-entitlement-while-rekeying
quanganhdo Feb 20, 2024
bba1c79
Update BSK
quanganhdo Feb 20, 2024
e5577d7
Address PR comments
quanganhdo Feb 20, 2024
67bebd0
Simplify subscription config
quanganhdo Feb 20, 2024
c0ff06c
Update BSK
quanganhdo Feb 20, 2024
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
1 change: 1 addition & 0 deletions Core/NetworkProtectionNotificationIdentifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ public enum NetworkProtectionNotificationIdentifier: String {
case connection = "network-protection.notification.connection"
case superseded = "network-protection.notification.superseded"
case test = "network-protection.notification.test"
case entitlement = "network-protection.notification.entitlement"
}
10 changes: 5 additions & 5 deletions DuckDuckGo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8903,7 +8903,7 @@
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG APP_TRACKING_PROTECTION NETWORK_PROTECTION SUBSCRIPTION";
SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG APP_TRACKING_PROTECTION NETWORK_PROTECTION SUBSCRIPTION ALPHA";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
TARGETED_DEVICE_FAMILY = "1,2";
VALID_ARCHS = "$(ARCHS_STANDARD_64_BIT)";
Expand All @@ -8915,7 +8915,7 @@
buildSettings = {
ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES;
ASSETCATALOG_COMPILER_APPICON_NAME = "DDG-AppIcon-Alpha";
CODE_SIGN_ENTITLEMENTS = DuckDuckGo/DuckDuckGo.entitlements;
CODE_SIGN_ENTITLEMENTS = DuckDuckGo/DuckDuckGoAlpha.entitlements;
CODE_SIGN_IDENTITY = "iPhone Distribution";
"CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer";
CURRENT_PROJECT_VERSION = 1;
Expand Down Expand Up @@ -9040,7 +9040,7 @@
CLANG_CXX_LANGUAGE_STANDARD = "gnu++20";
CLANG_ENABLE_OBJC_WEAK = YES;
CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE;
CODE_SIGN_ENTITLEMENTS = PacketTunnelProvider/PacketTunnelProvider.entitlements;
CODE_SIGN_ENTITLEMENTS = PacketTunnelProvider/PacketTunnelProviderAlpha.entitlements;
CODE_SIGN_IDENTITY = "Apple Development";
CODE_SIGN_STYLE = Automatic;
CURRENT_PROJECT_VERSION = 1;
Expand Down Expand Up @@ -9907,8 +9907,8 @@
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/DuckDuckGo/BrowserServicesKit";
requirement = {
kind = exactVersion;
version = 109.0.0;
branch = "anh/netp-check-entitlement-while-rekeying";
kind = branch;
};
};
C14882EB27F211A000D59F0C /* XCRemoteSwiftPackageReference "SwiftSoup" */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
{
"identity" : "browserserviceskit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/BrowserServicesKit",
"location" : "https://github.com/DuckDuckGo/BrowserServicesKit",
"state" : {
"revision" : "5ecf4fe56f334be6eaecb65f6d55632a6d53921c",
"version" : "109.0.0"
"branch" : "anh/netp-check-entitlement-while-rekeying",
"revision" : "edb3fc3b8fa61f98345185e775804dbfcefdedce"
}
},
{
Expand Down Expand Up @@ -50,8 +50,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/duckduckgo/duckduckgo-autofill.git",
"state" : {
"revision" : "03d3e3a959dd75afbe8c59b5a203ea676d37555d",
"version" : "10.1.0"
"revision" : "b972bc0ab6ee1d57a0a18a197dcc31e40ae6ac57",
"version" : "10.0.3"
}
},
{
Expand Down
2 changes: 2 additions & 0 deletions DuckDuckGo/EventMapping+NetworkProtectionError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ extension EventMapping where Event == NetworkProtectionError {
params[PixelParameters.keychainErrorCode] = String(status)
case .noAuthTokenFound:
pixelEvent = .networkProtectionNoAuthTokenFoundError
case .vpnAccessRevoked:
return
case
.noServerRegistrationInfo,
.couldNotSelectClosestServer,
Expand Down
23 changes: 4 additions & 19 deletions DuckDuckGo/MainViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1334,12 +1334,6 @@ class MainViewController: UIViewController {
self?.onNetworkProtectionAccountSignIn(notification)
}
.store(in: &netpCancellables)
NotificationCenter.default.publisher(for: .accountDidSignOut)
.receive(on: DispatchQueue.main)
.sink { [weak self] notification in
self?.onNetworkProtectionAccountSignOut(notification)
}
.store(in: &netpCancellables)
}

@objc
Expand All @@ -1351,23 +1345,14 @@ class MainViewController: UIViewController {

Task {
do {
try await NetworkProtectionCodeRedemptionCoordinator().exchange(accessToken: token)
print("[NetP Subscription] Exchanged access token for auth token successfully")
// todo - https://app.asana.com/0/0/1206541966681608/f
try NetworkProtectionKeychainTokenStore().store(NetworkProtectionKeychainTokenStore.makeToken(from: token))
quanganhdo marked this conversation as resolved.
Show resolved Hide resolved
print("[NetP Subscription] Stored derived NetP auth token")
} catch {
print("[NetP Subscription] Failed to exchange access token for auth token: \(error)")
print("[NetP Subscription] Failed to store derived NetP auth token: \(error)")
}
}
}

@objc
private func onNetworkProtectionAccountSignOut(_ notification: Notification) {
do {
try NetworkProtectionKeychainTokenStore().deleteToken()
print("[NetP Subscription] Deleted NetP auth token after signing out from Privacy Pro")
} catch {
print("[NetP Subscription] Failed to delete NetP auth token after signing out from Privacy Pro: \(error)")
}
}
#endif

@objc
Expand Down
9 changes: 6 additions & 3 deletions DuckDuckGo/NetworkProtectionConvenienceInitialisers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ extension NetworkProtectionKeychainTokenStore {
convenience init() {
self.init(keychainType: .dataProtection(.unspecified),
serviceName: "\(Bundle.main.bundleIdentifier!).authToken",
errorEvents: .networkProtectionAppDebugEvents)
errorEvents: .networkProtectionAppDebugEvents,
isSubscriptionEnabled: AppDependencyProvider.shared.featureFlagger.isFeatureOn(.subscription))
}
}

Expand All @@ -69,7 +70,8 @@ extension NetworkProtectionCodeRedemptionCoordinator {
environment: settings.selectedEnvironment,
tokenStore: NetworkProtectionKeychainTokenStore(),
isManualCodeRedemptionFlow: isManualCodeRedemptionFlow,
errorEvents: .networkProtectionAppDebugEvents
errorEvents: .networkProtectionAppDebugEvents,
isSubscriptionEnabled: AppDependencyProvider.shared.featureFlagger.isFeatureOn(.subscription)
)
}
}
Expand All @@ -95,7 +97,8 @@ extension NetworkProtectionLocationListCompositeRepository {
self.init(
environment: settings.selectedEnvironment,
tokenStore: NetworkProtectionKeychainTokenStore(),
errorEvents: .networkProtectionAppDebugEvents
errorEvents: .networkProtectionAppDebugEvents,
isSubscriptionEnabled: AppDependencyProvider.shared.featureFlagger.isFeatureOn(.subscription)
)
}
}
Expand Down
4 changes: 2 additions & 2 deletions DuckDuckGo/UserText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -922,10 +922,10 @@ But if you *do* want a peek under the hood, you can find more information about

static let networkProtectionNotificationPromptTitle = NSLocalizedString("network-protection.waitlist.notification-prompt-title", value: "Know the instant you're invited", comment: "Title for the alert to confirm enabling notifications")
static let networkProtectionNotificationPromptDescription = NSLocalizedString("network-protection.waitlist.notification-prompt-description", value: "Get a notification when your copy of Network Protection early access is ready.", comment: "Subtitle for the alert to confirm enabling notifications")

// MARK: Settings Screeen
public static let settingsTitle = NSLocalizedString("settings.title", value: "Settings", comment: "Title for the Settings View")

// General Section
public static let settingsSetDefault = NSLocalizedString("settings.default.browser", value: "Set as Default Browser", comment: "Settings screen cell text for setting the app as default browser")
public static let settingsAddToDock = NSLocalizedString("settings.add.to.dock", value: "Add App to Your Dock", comment: "Settings screen cell text for adding the app to the dock")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ final class NetworkProtectionPacketTunnelProvider: PacketTunnelProvider {
params[PixelParameters.wireguardErrorCode] = String(code)
case .noAuthTokenFound:
pixelEvent = .networkProtectionNoAuthTokenFoundError
case .vpnAccessRevoked:
return
case .unhandledError(function: let function, line: let line, error: let error):
pixelEvent = .networkProtectionUnhandledError
params[PixelParameters.function] = function
Expand Down Expand Up @@ -201,24 +203,31 @@ final class NetworkProtectionPacketTunnelProvider: PacketTunnelProvider {
}

@objc init() {
#if ALPHA
let isSubscriptionEnabled = true
#else
let isSubscriptionEnabled = false
#endif
let tokenStore = NetworkProtectionKeychainTokenStore(keychainType: .dataProtection(.unspecified),
errorEvents: nil)
errorEvents: nil,
isSubscriptionEnabled: isSubscriptionEnabled)
let errorStore = NetworkProtectionTunnelErrorStore()
let notificationsPresenter = NetworkProtectionUNNotificationPresenter()
let settings = VPNSettings(defaults: .networkProtectionGroupDefaults)
let nofificationsPresenterDecorator = NetworkProtectionNotificationsPresenterTogglableDecorator(
let notificationsPresenterDecorator = NetworkProtectionNotificationsPresenterTogglableDecorator(
settings: settings,
wrappee: notificationsPresenter
)
notificationsPresenter.requestAuthorization()
super.init(notificationsPresenter: nofificationsPresenterDecorator,
super.init(notificationsPresenter: notificationsPresenterDecorator,
tunnelHealthStore: NetworkProtectionTunnelHealthStore(),
controllerErrorStore: errorStore,
keychainType: .dataProtection(.unspecified),
tokenStore: tokenStore,
debugEvents: Self.networkProtectionDebugEvents(controllerErrorStore: errorStore),
providerEvents: Self.packetTunnelProviderEvents,
settings: settings)
settings: settings,
isSubscriptionEnabled: isSubscriptionEnabled)
startMonitoringMemoryPressureEvents()
observeServerChanges()
observeStatusChanges()
Expand Down Expand Up @@ -268,7 +277,6 @@ final class NetworkProtectionPacketTunnelProvider: PacketTunnelProvider {
}
.store(in: &cancellables)
}

}

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ final class NetworkProtectionUNNotificationPresenter: NSObject, NetworkProtectio
content.title = UserText.networkProtectionNotificationsTitle
content.body = body

if #available(iOSApplicationExtension 15.0, *) {
if #available(iOS 15.0, *) {
content.interruptionLevel = .timeSensitive
content.relevanceScore = 0
}
Expand Down Expand Up @@ -105,6 +105,11 @@ final class NetworkProtectionUNNotificationPresenter: NSObject, NetworkProtectio
func showSupersededNotification() {
}

func showExpiredEntitlementNotification() {
let content = notificationContent(body: UserText.networkProtectionEntitlementExpiredNotificationBody)
showNotification(.entitlement, content)
}

private func showNotification(_ identifier: NetworkProtectionNotificationIdentifier, _ content: UNNotificationContent) {
let request = UNNotificationRequest(identifier: identifier.rawValue, content: content, trigger: .none)

Expand Down
2 changes: 2 additions & 0 deletions PacketTunnelProvider/UserText.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ final class UserText {
static let networkProtectionConnectionInterruptedNotificationBody = NSLocalizedString("network.protection.interrupted.notification.body", value: "Network Protection was interrupted. Attempting to reconnect now...", comment: "The body of the notification shown when Network Protection's connection is interrupted")

static let networkProtectionConnectionFailureNotificationBody = NSLocalizedString("network.protection.failure.notification.body", value: "Network Protection failed to connect. Please try again later.", comment: "The body of the notification shown when Network Protection fails to reconnect")

static let networkProtectionEntitlementExpiredNotificationBody = NSLocalizedString("network.protection.entitlement.expired.notification.body", value: "VPN disconnected due to expired subscription. Subscribe to Privacy Pro to reconnect DuckDuckGo VPN.", comment: "The body of the notification when Privacy Pro subscription expired")
}
// swiftlint:enable line_length
3 changes: 3 additions & 0 deletions PacketTunnelProvider/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/* The body of the notification when Privacy Pro subscription expired */
"network.protection.entitlement.expired.notification.body" = "VPN disconnected due to expired subscription. Subscribe to Privacy Pro to reconnect DuckDuckGo VPN.";

/* The body of the notification shown when Network Protection fails to reconnect */
"network.protection.failure.notification.body" = "Network Protection failed to connect. Please try again later.";

Expand Down
Loading