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

Next

uuid init

  • Loading branch information
darkdh committed Nov 13, 2019
commit 4e5ed880e4577ffb4d2992c7c116d01e78adcdb8
@@ -3,6 +3,7 @@
const crypto = require('brave-crypto')
const messages = require('./constants/messages')
const {syncVersion} = require('./config')
const uuidv4 = require('uuid/v4')

/**
* Initializes crypto and device ID
@@ -12,12 +13,14 @@ module.exports.init = function () {
return new Promise((resolve, reject) => {
const ipc = window.chrome.ipcRenderer
ipc.send(messages.GET_INIT_DATA, syncVersion)
ipc.once(messages.GOT_INIT_DATA, (e, seed, deviceId, config) => {
ipc.once(messages.GOT_INIT_DATA, (e, seed, deviceId, config, deviceUuid) => {
if (seed === null) {
// Generate a new "persona"
seed = crypto.getSeed() // 32 bytes
deviceId = new Uint8Array([0])
ipc.send(messages.SAVE_INIT_DATA, seed, deviceId)
// dash is reserved for s3 key delimiters
deviceUuid = uuidv4().replace(/(-)/g, '_')
ipc.send(messages.SAVE_INIT_DATA, seed, deviceId, deviceUuid)
// TODO: The background process should listen for SAVE_INIT_DATA and emit
// GOT_INIT_DATA once the save is successful
}
@@ -28,7 +31,7 @@ module.exports.init = function () {
reject(new Error('Invalid crypto seed'))
return
}
resolve({seed, deviceId, config})
resolve({seed, deviceId, config, deviceUuid})
})
})
}
@@ -342,9 +342,10 @@ RequestUtil.prototype.sqsName = function (deviceId, category) {
/**
* Creates SQS for the current device.
* @param {string} deviceId
* @param {string} deviceUuid
* @returns {Promise}
*/
RequestUtil.prototype.createAndSubscribeSQS = function (deviceId) {
RequestUtil.prototype.createAndSubscribeSQS = function (deviceId, deviceUuid) {
// Creating a query for the current userId
if (!deviceId) {
throw new Error('createSQS failed. deviceId is null!')
@@ -8,6 +8,7 @@ const messages = require('./constants/messages')
const proto = require('./constants/proto')
const serializer = require('../lib/serializer')
const {deriveKeys} = require('../lib/crypto')
const uuidv4 = require('uuid/v4')

let ipc = window.chrome.ipcRenderer

@@ -18,6 +19,7 @@ const ERROR = 2
const logElement = document.querySelector('#output')

var clientDeviceId = null
var clientDeviceUuid = null
var clientUserId = null
var clientKeys = {}
var config = {}
@@ -71,7 +73,9 @@ const maybeSetDeviceId = (requester) => {
})
}
clientDeviceId = new Uint8Array([maxId + 1])
ipc.send(messages.SAVE_INIT_DATA, seed, clientDeviceId)
// dash is reserved for s3 key delimiters
clientDeviceUuid = uuidv4().replace(/(-)/g, '_')
ipc.send(messages.SAVE_INIT_DATA, seed, clientDeviceId, clientDeviceUuid)
return Promise.resolve(requester)
})
}
@@ -252,6 +256,8 @@ const main = () => {
const clientSerializer = values[0]
const keys = deriveKeys(values[1].seed)
const deviceId = values[1].deviceId
const deviceUuid = values[1].deviceUuid
logSync(`deviceUUID ${deviceUuid}`)
seed = values[1].seed
clientKeys = keys
config = values[1].config
@@ -288,8 +294,8 @@ const main = () => {
})
.then((requester) => {
if (clientDeviceId !== null && requester && requester.s3) {
logSync('set device ID: ' + clientDeviceId)
requester.createAndSubscribeSQS(clientDeviceId).then(() => {
logSync('set device ID: ' + clientDeviceId + ' device UUID: ' + clientDeviceUuid)
requester.createAndSubscribeSQS(clientDeviceId, clientDeviceUuid).then(() => {
startSync(requester)
})
.catch((e) => {
@@ -82,6 +82,7 @@ message SyncRecord {
}
message Device {
string name = 1;
string uuid = 2;
}
Action action = 1;
bytes deviceId = 2;
@@ -2970,6 +2970,7 @@
* @memberof api.SyncRecord
* @interface IDevice
* @property {string|null} [name] Device name
* @property {string|null} [uuid] Device uuid
*/

/**
@@ -2995,6 +2996,14 @@
*/
Device.prototype.name = "";

/**
* Device uuid.
* @member {string} uuid
* @memberof api.SyncRecord.Device
* @instance
*/
Device.prototype.uuid = "";

/**
* Creates a new Device instance using the specified properties.
* @function create
@@ -3021,6 +3030,8 @@
writer = $Writer.create();
if (message.name != null && message.hasOwnProperty("name"))
writer.uint32(/* id 1, wireType 2 =*/10).string(message.name);
if (message.uuid != null && message.hasOwnProperty("uuid"))
writer.uint32(/* id 2, wireType 2 =*/18).string(message.uuid);
return writer;
};

@@ -3058,6 +3069,9 @@
case 1:
message.name = reader.string();
break;
case 2:
message.uuid = reader.string();
break;
default:
reader.skipType(tag & 7);
break;
@@ -3096,6 +3110,9 @@
if (message.name != null && message.hasOwnProperty("name"))
if (!$util.isString(message.name))
return "name: string expected";
if (message.uuid != null && message.hasOwnProperty("uuid"))
if (!$util.isString(message.uuid))
return "uuid: string expected";
return null;
};

@@ -3113,6 +3130,8 @@
var message = new $root.api.SyncRecord.Device();
if (object.name != null)
message.name = String(object.name);
if (object.uuid != null)
message.uuid = String(object.uuid);
return message;
};

@@ -3129,10 +3148,14 @@
if (!options)
options = {};
var object = {};
if (options.defaults)
if (options.defaults) {
object.name = "";
object.uuid = "";
}
if (message.name != null && message.hasOwnProperty("name"))
object.name = message.name;
if (message.uuid != null && message.hasOwnProperty("uuid"))
object.uuid = message.uuid;
return object;
};

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.