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

Cached guardian's subscriber credentials #15702

Merged
merged 3 commits into from
Nov 2, 2022

Conversation

simonhong
Copy link
Member

@simonhong simonhong commented Oct 28, 2022

fix brave/brave-browser#26254

With this caching, we only need to ask skus credentials when subscriber credential is expired.

Resolves

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally: npm run test -- brave_browser_tests, npm run test -- brave_unit_tests, npm run lint, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

npm run test brave_unit_tests -- --filter=*VPN*

@simonhong simonhong force-pushed the cache_vpn_subscriber_credential branch 7 times, most recently from e8de062 to e4b88c9 Compare October 28, 2022 07:56
@simonhong simonhong requested review from spylogsster and bsclifton and removed request for spylogsster October 28, 2022 08:06
@simonhong simonhong force-pushed the cache_vpn_subscriber_credential branch from e4b88c9 to 6bfe394 Compare October 28, 2022 08:20
@simonhong simonhong force-pushed the cache_vpn_subscriber_credential branch from 6bfe394 to 4e3573e Compare October 31, 2022 02:26
@simonhong simonhong requested a review from deeppandya October 31, 2022 02:27
@simonhong simonhong changed the title WIP: Cached guardian's subscriber credentials Cached guardian's subscriber credentials Oct 31, 2022
@simonhong simonhong marked this pull request as ready for review October 31, 2022 09:04
@simonhong simonhong force-pushed the cache_vpn_subscriber_credential branch 2 times, most recently from 5511339 to c9afbcf Compare October 31, 2022 10:18
#else
GetBraveVPNConnectionAPI()->SetSkusCredential(skus_credential_);
if (subscriber_credential == kTokenNoLongerValid) {
Copy link
Member Author

Choose a reason for hiding this comment

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

@spylogsster Curious kTokenNoLongerValid is only effective on desktop?

Copy link
Contributor

@spylogsster spylogsster Nov 1, 2022

Choose a reason for hiding this comment

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

I did not check on mobile, maybe @deeppandya can help?

Copy link
Member

Choose a reason for hiding this comment

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

Code is consistent with before at least - so if it was used on mobile, it's continuing to be used 👍 And for expired case, we default to showing in-app-purchase again on mobile

GetBraveVPNPaymentsEnv(GetCurrentEnvironment()));
// Caller can get valid subscriber credential only in purchased state.
// Otherwise, false is passed to |callback| as success param.
std::move(callback).Run(::brave_vpn::GetSubscriberCredential(local_prefs_),
Copy link
Member Author

@simonhong simonhong Nov 1, 2022

Choose a reason for hiding this comment

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

@deeppandya @bsclifton , As we cache subscriber credential in local state, we can return subscriber credential to caller directly. Previously, we fetch subscriber credential whenever this method is called with stored skus_credential_.
As this PR stores subscriber credential in local state with its expiration date, we don't refetch subscriber credential if expiration date is not passed. So, most of ReloadPurchasedState() will be no-op.

Previously, skus subscriber credential is fetched on every android app open and maybe it has sufficient expiration time because ReloadPurchasedState() is called on app open.
One behavioral change from this PR for android is, subscriber credential is not refreshed on every app open.
Instead, stored credential is reused if not expired. and maybe this could affect on Android?

Caller will got false as a success param when stored subscriber credential is already expired.

Copy link
Member Author

Choose a reason for hiding this comment

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

@deeppandya I think we don't need to worry about expiration with this background refreshing - 5c17a6c

@@ -743,6 +749,36 @@ void BraveVpnService::OnGetSubscriberCredentialV12(
#endif
}

void BraveVpnService::ScheduleSubscriberCredentialRefresh() {
Copy link
Member Author

@simonhong simonhong Nov 1, 2022

Choose a reason for hiding this comment

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

@deeppandya With this background refreshing, BraveVpnService could use valid subscriber credential on Android and Desktop.

Copy link
Member

Choose a reason for hiding this comment

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

This is great and might solve the expiration problem for iOS too

fix brave/brave-browser#26254

With this caching, we only need to ask skus credentials when subscriber
credential is expired. and we only need to care about profile
credentials during the connecting.
@simonhong simonhong force-pushed the cache_vpn_subscriber_credential branch from f1c47de to 5c17a6c Compare November 1, 2022 05:56
Timer for getting new subscriber credential will be fired when current
credential is expired.
@simonhong simonhong force-pushed the cache_vpn_subscriber_credential branch from 5c17a6c to 9ab1d10 Compare November 1, 2022 06:46
and resolved some review comments.
Copy link
Member

@bsclifton bsclifton left a comment

Choose a reason for hiding this comment

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

This is working great! Tested a few scenarios (submitting ticket, changing servers). Verified code is persisting to local storage. And code looks great! This should fix Android as well as Desktop

@simonhong simonhong merged commit 588a834 into master Nov 2, 2022
@simonhong simonhong deleted the cache_vpn_subscriber_credential branch November 2, 2022 00:11
@github-actions github-actions bot added this to the 1.47.x - Nightly milestone Nov 2, 2022
brave-builds pushed a commit that referenced this pull request Nov 2, 2022
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.

Update VPNService logic to handle credentials v2
4 participants