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

Sync v2 #5294

Merged
merged 80 commits into from
Jun 11, 2020
Merged

Sync v2 #5294

merged 80 commits into from
Jun 11, 2020

Conversation

darkdh
Copy link
Member

@darkdh darkdh commented Apr 20, 2020

Resolves brave/brave-browser#9989
Resolves brave/brave-browser#9241

This PR

  1. Removes all sync v1 codes
  2. Sync V2 UI
    2.1. Setup flow concept inherited from v1 will be in brave:///settings/braveSync as subpage
    2.2. Brings back about:sync-internals
    2.3. brave://sync will be redirect to brave:///settings/braveSync
    2.4. Client encryption is enforced in UI using bip39 seed.
  3. Sync V2 Engine
    3.1. Seed is encrypted using OSCrypt when stored in prefs
    3.2. ProfileSyncService monitor seed changes to decide reset sync chain or tell SyncAuthManger to derive signing key
    3.3. BraveSyncAuthManager will have a dummy SyncAccountInfo and create access tokenbase64(timestamp_hex|signed_timestamp_hex|public_key_hex), timestamp is from network time, if network time is not available, local time will be used. Each server response will update the network time by header Sane-Time-Millis
  4. Migration
    4.1. Strip off bookmark meta info used by v1 in BookmarkModel
    4.2 Stop engine to have a clean engine state in ProfileSyncService
  5. Tests
    5.1. upstream sync_auth_manager_unittest.cc
    5.2 brave_sync_auth_manager_unittest.cc
  6. Sync v2 will only be available on Nightly channel and development build

Submitter Checklist:

Test Plan:

Note that Sync v1 and v2 are incompatible so DONOT try to connect v1 and v2 devices, it won't work

Upgrade from v1

Migration

  1. Have v1 enabled profile and sync some bookmarks
  2. Upgrade to v2, we should be able to create sync chain
  3. Check profile/Default/Bookmarks and each bookmark will no longer have sync v1 meta info
  4. All the bookmarks are still there

Feature flag

  1. Disable brave://flags/#brave-sync in v1
  2. Upgrade to v2 and go to brave:///settings/braveSync
  3. We should see sync entry
  4. Go to brave://flags and there will only be brave://flags/#brave-sync-v2 and brave://flags/#brave-sync is gone

Infobar

#5804 (comment)

v2 test

Single device

  1. Enable sync v2 using fresh profile (brave:///settings/braveSync)
  2. Open about:sync-internals
    2.1. Make sure Passphrase Type is PassphraseType::kCustomPassphrase
    2.2. Encrypted Types include every types we support
    2.3. Has Token is true
  3. Check profile/Default/Preferences
    3.1. seed in brave_sync_v2 should not be your sync code (it is encrypted)
    3.2. v1_meta_info_cleared is true
    3.3. v1_migrated is true
  4. Type brave://sync/ in URL bar should take you to brave:///settings/braveSync
  5. Leave sync chain
  6. Open about:sync-internals, sync engine should stop

Multiple devices

  1. Create sync chain on A and make device B joined
  2. Check sync engines are running in both about:sync-internals
  3. Add a bookmark on A and toggle Always show bookmarks (Type Bookmarks & Preferences)
  4. device B should see the same thing in about 1 minute

Offline sync chain creation

  1. Turn off network
  2. Create sync chain
  3. Open about:sync-internals
  4. Turn network back on
  5. It should be able to connect to server in few retry

Client clock out of date

  1. Turn client clock to be at least 24 hours ahead of behind
  2. Create sync chain
  3. Open about:sync-internals
  4. It should be able to connect to server in few retry

Feature flag

  1. Enable sync v2
  2. Open about:sync-internals and make sure sync engine is running
  3. Go to brave://flags/#brave-sync-v2 and disable it
  4. After relaunch about:sync-internals should show Transport State is Sync service does not exist
  5. There should be no sync entry in brave:///settings/
  6. Go to brave://flags/#brave-sync-v2 and enable it
  7. After relaunch about:sync-internals will show sync engine is running

UI test

  • Test bad sync code
  • Test empty sync code
  • Test enable/disable different data types
    • Note that change will be saved only when you leave sync page
  • Close sync page when in the middle of sync setup

Reviewer Checklist:

  • New files have MPL-2.0 license header.
  • Request a security/privacy review as needed.
  • Adequate test coverage exists to prevent regressions
  • Verify test plan is specified in PR before merging to source

After-merge Checklist:

  • The associated issue milestone is set to the smallest version that the
    changes has landed on.
  • All relevant documentation has been updated.

@darkdh darkdh force-pushed the sync-v2 branch 3 times, most recently from 668915c to 3b5392f Compare April 21, 2020 22:30
@darkdh darkdh force-pushed the sync-v2 branch 2 times, most recently from de74c2a to 4fb0a66 Compare May 6, 2020 00:02
@darkdh darkdh self-assigned this May 22, 2020
@darkdh darkdh marked this pull request as ready for review May 22, 2020 23:19
@darkdh darkdh requested a review from bridiver as a code owner May 22, 2020 23:19
@darkdh darkdh changed the title [WIP] Sync v2 Sync v2 May 22, 2020
@darkdh darkdh force-pushed the sync-v2 branch 2 times, most recently from 5697bb2 to 02023d0 Compare June 2, 2020 00:38
@darkdh darkdh added CI/skip Do not run CI builds (except noplatform) and removed CI/skip Do not run CI builds (except noplatform) labels Jun 4, 2020
@darkdh darkdh force-pushed the sync-v2 branch 2 times, most recently from 4f791a2 to 08eb047 Compare June 7, 2020 22:22

bool IsSyncSubpage(const GURL& current_url) {
+ BRAVE_IS_SYNC_SUBPAGE
return current_url == chrome::GetSettingsUrl(chrome::kSyncSetupSubPage);
Copy link
Collaborator

Choose a reason for hiding this comment

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

GetSettingsUrl looks like something we could easily override

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed in b2fdf8c


+ BRAVE_PROFILE_SYNC_SERVICE_H_
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed b2fdf8c

void ResetRequestAccessTokenBackoffForTest();

private:
+ BRAVE_SYNC_AUTH_MANAGER_H_
Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed b2fdf8c

defines = [ "SYNC_USER_AGENT_PRODUCT=$sync_user_agent_product" ]

configs += [ "//build/config/compiler:wexit_time_destructors" ]
+
Copy link
Collaborator

Choose a reason for hiding this comment

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

don't add extra newlines in patches

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed in b2fdf8c

const syncCode = await this.braveBrowserProxy_.getSyncCode()
syncPrefs.setNewPassphrase = false;
syncPrefs.passphrase = syncCode;
console.debug('sync set encryption', syncPrefs)
Copy link
Collaborator

Choose a reason for hiding this comment

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

won't this leak the passphrase into the console (and potentially the log)?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed in 247a37c

return
}
const data = await this.syncBrowserProxy_.getQRCode(this.syncCode)
console.log('qr code', data)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think we should be outputting this kind of data on the console (and potentially logging to disk)

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed in 247a37c


std::vector<uint8_t> seed;
if (!brave_sync::crypto::PassphraseToBytes32(sync_code->GetString(), &seed)) {
LOG(ERROR) << "invalid sync code:" << sync_code->GetString();
Copy link
Collaborator

Choose a reason for hiding this comment

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

this is only logging invalid codes, but a user might just be using the wrong sync chain or something so we probably should log this

Copy link
Member

Choose a reason for hiding this comment

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

yea i think this could be sensitive info and shouldn't be logged

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed in 247a37c


std::vector<uint8_t> seed;
if (!brave_sync::crypto::PassphraseToBytes32(sync_code->GetString(), &seed)) {
LOG(ERROR) << "invalid sync code:" << sync_code->GetString();
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed in 247a37c

base::Time time;
if (network_time_tracker_->GetNetworkTime(&time, nullptr) !=
network_time::NetworkTimeTracker::NETWORK_TIME_AVAILABLE) {
LOG(WARNING) << "Network time not available, using local time";
Copy link
Collaborator

Choose a reason for hiding this comment

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

this seems like it should be a vlog

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed in b2fdf8c

CHECK(args->Get(1, &sync_code));

if (sync_code->GetString().empty()) {
LOG(ERROR) << "No sync code parameter provided!";
Copy link
Collaborator

Choose a reason for hiding this comment

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

seems like all of these should be VLOG

Copy link
Member

Choose a reason for hiding this comment

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

This one I think should stay as error since our code doesn't supply the wrong number of parameters so if it errors it will be a one off dev error when making a change

@darkdh
Copy link
Member Author

darkdh commented Jun 9, 2020

@petemill there are some html checks failed in sonar cloud
https://github.com/brave/brave-core/pull/5294/checks?check_run_id=755297176

Sync Settings
</message>
<message name="IDS_SETTINGS_BRAVE_SYNC_SETTINGS_SUBTITLE" desc="Brave Sync settings subtitle">
Manage what information you would like to sync between devices. These settings only effect this device.
Copy link
Member

Choose a reason for hiding this comment

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

affect not effect

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed in 4f4fa65

To start, you will need Brave installed on all the devices you plan to sync. Then, securely link them together with a sync code.
</message>
<message name="IDS_SETTINGS_BRAVE_SYNC_MANAGE_ACTION_LABEL" desc="Brave Sync manage action label">
Manage your sync'd devices
Copy link
Member

Choose a reason for hiding this comment

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

i think synced instead of sync'd looks more correct?

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed in 4f4fa65

Copy link
Member

Choose a reason for hiding this comment

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

FYI @bradleyrichter sync'd -> synced

base::Base64Encode(access_token, &encoded_access_token);
DCHECK(!encoded_access_token.empty());

VLOG(1) << "access_token= " << encoded_access_token;
Copy link
Member

Choose a reason for hiding this comment

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

did you mean to keep this VLOG? (access token is sensitive info)

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed in 5e3cc37

@@ -158,7 +172,7 @@ bool BraveMainDelegate::BasicStartupComplete(int* exit_code) {

// Brave's sync protocol does not use the sync service url
command_line.AppendSwitchASCII(switches::kSyncServiceURL,
"https://no-thanks.invalid");
kBraveSyncServiceURL);
Copy link
Collaborator

Choose a reason for hiding this comment

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

we should check to make sure the sync url is empty before setting it, otherwise you can't override

Copy link
Member Author

Choose a reason for hiding this comment

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

void BraveCommandLineHelper::AppendSwitch(const char* switch_key) {
  if (!command_line_.HasSwitch(switch_key))
    command_line_.AppendSwitch(switch_key);
}

our BraveCommandLineHelper already checks it

petemill and others added 3 commits June 11, 2020 11:10
The infobar displays a notice that sync v2 must be setup in order to continue syncing.
In this infobar, the user can
- perform an action to begin sync v2 setup, or;
- dismiss the infobar.
[sync-v2 base] Sync: Show an infobar at startup for sync v1 users
@darkdh
Copy link
Member Author

darkdh commented Jun 11, 2020

@petemill mentioned we can ignore the only error from SonarCloud
https://sonarcloud.io/organizations/brave/rules?languages=css&open=css%3AS4670
which will be disabled soon because it doesn't play nicely with Web Components

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.

Sync v2 New Sync v2 UI wiring
7 participants