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

Introduce device id v2 #362

Merged
merged 5 commits into from Dec 23, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Emit SAVE_INIT_DATA for existing devices to update deviceIdV2

  • Loading branch information
darkdh committed Nov 28, 2019
commit 77af1794c25d79bbb64b70bfcea0a0effd611798
@@ -1,7 +1,7 @@
'use strict'

const crypto = require('brave-crypto')
const libCrypto = require('../lib/crypto')
const {generateDeviceIdV2} = require('../lib/crypto')
const messages = require('./constants/messages')
const {syncVersion} = require('./config')

@@ -14,18 +14,16 @@ module.exports.init = function () {
const ipc = window.chrome.ipcRenderer
ipc.send(messages.GET_INIT_DATA, syncVersion)
ipc.once(messages.GOT_INIT_DATA, (e, seed, deviceId, config, deviceIdV2) => {
// TODO(darkdh): save uuid for migrated devices
if (deviceIdV2.length === 0) {
deviceIdV2 = Buffer.from(libCrypto.randomBytes(3)).toString('hex')
}
if (seed === null) {
// Generate a new "persona"
seed = crypto.getSeed() // 32 bytes
deviceId = new Uint8Array([0])
deviceIdV2 = generateDeviceIdV2()
ipc.send(messages.SAVE_INIT_DATA, seed, deviceId, deviceIdV2)
// TODO: The background process should listen for SAVE_INIT_DATA and emit
// GOT_INIT_DATA once the save is successful
}

// XXX: workaround #17
seed = seed instanceof Array ? new Uint8Array(seed) : seed
deviceId = deviceId instanceof Array ? new Uint8Array(deviceId) : deviceId
@@ -420,8 +420,7 @@ RequestUtil.prototype.createAndSubscribeSQS = function (deviceId, deviceIdV2) {
var createSQSPromises = []
// Simple for loop instead foreach to capture 'this'
for (var i = 0; i < CATEGORIES_FOR_SQS.length; ++i) {
// Doesn't have to create about to deprecate quques
// createSQSPromises.push(createAndSubscribeSQSforCategory(deviceId, CATEGORIES_FOR_SQS[i], this))
// Doesn't have to create about to deprecated queues
createSQSPromises.push(subscribeOldSQSforCategory(deviceId, CATEGORIES_FOR_SQS[i], this))
createSQSPromises.push(createAndSubscribeSQSforCategory(deviceIdV2, CATEGORIES_FOR_SQS[i], this))
// TODO(darkdh): encode into base64
@@ -7,7 +7,7 @@ const recordUtil = require('./recordUtil')
const messages = require('./constants/messages')
const proto = require('./constants/proto')
const serializer = require('../lib/serializer')
const {deriveKeys} = require('../lib/crypto')
const {deriveKeys, generateDeviceIdV2} = require('../lib/crypto')

let ipc = window.chrome.ipcRenderer

@@ -52,7 +52,7 @@ const logSync = (message, logLevel = DEBUG) => {
* @returns {Promise}
*/
const maybeSetDeviceId = (requester) => {
if (clientDeviceId !== null) {
if (clientDeviceId !== null && clientDeviceIdV2.length !== 0 ) {
return Promise.resolve(requester)
}
if (!requester || !requester.s3) {
@@ -72,6 +72,7 @@ const maybeSetDeviceId = (requester) => {
})
}
clientDeviceId = new Uint8Array([maxId + 1])
clientDeviceIdV2 = generateDeviceIdV2()
ipc.send(messages.SAVE_INIT_DATA, seed, clientDeviceId, clientDeviceIdV2)
return Promise.resolve(requester)
})
@@ -112,3 +112,7 @@ module.exports.decrypt = function (ciphertext/* : Uint8Array */,
nonce/* : Uint8Array */, secretboxKey/* : Uint8Array */) {
return nacl.secretbox.open(ciphertext, nonce, secretboxKey)
}

module.exports.generateDeviceIdV2 = function() {
return Buffer.from(nacl.randomBytes(3)).toString('hex')
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.