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

Subscription keychain sharing for access token #690

Merged
merged 15 commits into from
Mar 6, 2024

Conversation

graeme
Copy link
Contributor

@graeme graeme commented Feb 29, 2024

Please review the release process for BrowserServicesKit here.

Required:

Task/Issue URL: https://app.asana.com/0/414235014887631/1206564116141608/f
iOS PR: duckduckgo/iOS#2538
macOS PR: duckduckgo/macos-browser#2292
What kind of version bump will this require?: Major

Optional:

Tech Design URL: https://app.asana.com/0/481882893211075/1206591576458107/f
CC: @quanganhdo @diegoreymendez

Description:

For the macOS: Recheck entitlements and display error messaging for cancelled subscriptions we need to make sure the VPN is no longer usable once their entitlement to use it are withdrawn. In iOS: Integrate with Subscription, we’re already checking the entitlements intermittently and on rekey, disabling the VPN*.

To authenticate the VPN's register requests (to receive a server + keypair for the tunnel configuration), the PacketTunnelProvider (central component of the VPN extension) needs an access token which is to be provided by the Subscription library built in O-1. This can be pulled accessed directly from the library and, in the iOS and macOS AppStore case, shared between processes (the app, the VPN agent, the VPN extension) using a keychain group. We would like the fetching and lifecycle to be managed exclusively by the Subscription library.

We will need to share / delete the subscription access token between processes, so this task covers:

  • Adding a new subscriptions app group
  • Injecting this app group into the subscriptions library to be used to create keychain entries.

Steps to test this PR:
Generally make sure subscriptions flow still works. But to test with migration of token for existing internal users:

  1. Check out main first.
  2. Build DDG Privacy Pro.
  3. Check out this branch.
  4. Build DDG Privacy Pro again
  5. Make sure you’re still logged in
  6. (Remaining steps in DEBUG only) Open the console and start logging
  7. Connect to Network Protection.
  8. After the macOS menu item has appeared, check the console and ensure there is a log saying "VPN Agent found token”

OS Testing:

  • iOS 14
  • iOS 15
  • iOS 16
  • macOS 10.15
  • macOS 11
  • macOS 12

Internal references:

Software Engineering Expectations
Technical Design Template

// This migration is to prevent breaking internal tests and should be removed before launch
do {
if let newAccessToken = try accessTokenStorage.getAccessToken() {
throw MigrationError.noMigrationNeeded
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not breaking functionality but this throw is caught down below and turned into throw MigrationError.migrationFailed

@miasma13 miasma13 assigned miasma13 and unassigned miasma13 Mar 2, 2024
@quanganhdo quanganhdo force-pushed the graeme/subscription-keychain-sharing branch from cb11e54 to 1eb0850 Compare March 5, 2024 14:30
@quanganhdo
Copy link
Member

Rebased on main for latest changes.

@graeme graeme changed the title Graeme/subscription keychain sharing Subscription keychain sharing for access token Mar 5, 2024
@graeme graeme marked this pull request as ready for review March 5, 2024 17:15
*/
enum AccountKeychainField: String, CaseIterable {
case accessToken = "subscription.account.accessToken"
case testString = "subscription.account.testString"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer needed ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops!

@@ -34,15 +34,15 @@ public final class AppStoreRestoreFlow {
case subscriptionExpired(accountDetails: RestoredAccountDetails)
}

public static func restoreAccountFromPastPurchase() async -> Result<Void, AppStoreRestoreFlow.Error> {
public static func restoreAccountFromPastPurchase(appGroup: String) async -> Result<Void, AppStoreRestoreFlow.Error> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@quanganhdo Spotted this discrepancy, the param probably should be subscriptionAppGroup for consistency.

@graeme graeme merged commit 5a6c7b6 into main Mar 6, 2024
7 checks passed
@graeme graeme deleted the graeme/subscription-keychain-sharing branch March 6, 2024 19:04
graeme added a commit to duckduckgo/macos-browser that referenced this pull request Mar 6, 2024
Task/Issue URL:
https://app.asana.com/0/414235014887631/1206564116141608/f
iOS PR: duckduckgo/iOS#2538
BSK PR: duckduckgo/BrowserServicesKit#690

**Optional**:

Tech Design URL:
https://app.asana.com/0/481882893211075/1206591576458107/f
CC: @quanganhdo @diegoreymendez 

**Description**:

For the macOS: Recheck entitlements and display error messaging for
cancelled subscriptions we need to make sure the VPN is no longer usable
once their entitlement to use it are withdrawn. In [iOS: Integrate with
Subscription](https://app.asana.com/0/0/1204886111391114), we’re already
checking the entitlements intermittently and on rekey, disabling the
VPN*.

To authenticate the VPN's register requests (to receive a server +
keypair for the tunnel configuration), the PacketTunnelProvider (central
component of the VPN extension) needs an access token which is to be
provided by the Subscription library built in O-1. This can be pulled
accessed directly from the library and, in the iOS and macOS AppStore
case, shared between processes (the app, the VPN agent, the VPN
extension) using a keychain group. We would like the fetching and
lifecycle to be managed exclusively by the Subscription library.

We will need to share / delete the subscription access token between
processes, so this task covers:
- Adding a new subscriptions app group
- Injecting this app group into the subscriptions library to be used to
create keychain entries.

**Steps to test this PR**:
1. Make sure subscriptions flow still works (don’t attempt to connect
VPN yet)
2. (Remaining steps in DEBUG only) Open the console and start logging
3. Connect to Network Protection.
4. After the macOS menu item has appeared, check the console and ensure
there is a log saying "VPN Agent found token"

---
###### Internal references:
[Pull Request Review
Checklist](https://app.asana.com/0/1202500774821704/1203764234894239/f)
[Software Engineering
Expectations](https://app.asana.com/0/59792373528535/199064865822552)
[Technical Design
Template](https://app.asana.com/0/59792373528535/184709971311943)
[Pull Request
Documentation](https://app.asana.com/0/1202500774821704/1204012835277482/f)
samsymons added a commit that referenced this pull request Mar 6, 2024
* main:
  Subscription keychain sharing for access token (#690)
samsymons added a commit that referenced this pull request Mar 8, 2024
* main:
  Changes to 114.1.0-1 hotfix branch (#706)
  Navigation: Improve same-document navigation handling (#702)
  Add pixels for our main VPN funnels (#698)
  Remove Autoconsent subfeature (#697)
  #URL macro (#657)
  Handle expired entitlement in NetP (#692)
  Remove isSubscriptionEnabled check when attempting to delete NetP token (#701)
  Remove CGNAT range. (#691)
  Subscription keychain sharing for access token (#690)
  Integrate confirm entitlements endpoint (#700)
  fix bundle name in breakByRaisingSigInt (#699)
  Adds support for deleting all logins (#672)
  Bump C-S-S to 5.2.0 (#695)
  Update xcode-version to 15.2. (#688)
  Bump Tests/BrowserServicesKitTests/Resources/privacy-reference-tests (#687)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants