Changeset View
Changeset View
Standalone View
Standalone View
keyserver/src/socket/tunnelbroker.js
// @flow | // @flow | ||||
import WebSocket from 'ws'; | import WebSocket from 'ws'; | ||||
import { type TBKeyserverConnectionInitializationMessage } from 'lib/types/tunnelbroker-messages.js'; | import { type TBKeyserverConnectionInitializationMessage } from 'lib/types/tunnelbroker-messages.js'; | ||||
import { fetchOlmAccount } from '../updaters/olm-account-updater.js'; | |||||
async function getDeviceID(): Promise<string> { | |||||
const info = await fetchOlmAccount('content'); | |||||
return JSON.parse(info.account.identity_keys()).curve25519; | |||||
ashoat: Aren't we using the signing key (`ed25519`) for the "device ID", or did I get this wrong? Isn't… | |||||
jonAuthorUnsubmitted Done Inline Actionsno, you're right. Got confused jon: no, you're right. Got confused | |||||
} | |||||
function createTunnelbrokerWebsocket() { | function createTunnelbrokerWebsocket() { | ||||
ashoatUnsubmitted Done Inline ActionsI was wondering whether we really need to fetch the deviceID on every Tunnelbroker connection, so I spent some time thinking about what scenarios might lead to a reconnect I came up with two scenarios:
Since we'll need some code to handle the first case anyways (forcing a disconnect and reconnecting to Tunnelbroker with the new device ID), I wonder if we can avoid having to fetchOlmAccount on every connection. Here's what I'm thinking:
What do you think? ashoat: I was wondering whether we really need to fetch the `deviceID` on every Tunnelbroker connection… | |||||
jonAuthorUnsubmitted Done Inline ActionsYea, sounds good, I'll refactor this. jon: Yea, sounds good, I'll refactor this. | |||||
try { | try { | ||||
const tunnelbrokerSocket = new WebSocket('ws://localhost:51001'); | const tunnelbrokerSocket = new WebSocket('ws://localhost:51001'); | ||||
tunnelbrokerSocket.on('open', () => { | tunnelbrokerSocket.on('open', async () => { | ||||
// TODO: Replace keyserver details with actual details | const [deviceID] = await Promise.all([getDeviceID()]); | ||||
ashoatUnsubmitted Done Inline ActionsPromise.all isn't doing anything here ashoat: `Promise.all` isn't doing anything here | |||||
jonAuthorUnsubmitted Done Inline ActionsI intended to extend this with grabbing the user_id and access token as well. I'll refactor this to have the local fetching done before attempting the session. jon: I intended to extend this with grabbing the user_id and access token as well.
I'll refactor… | |||||
// TODO: Replace accessToken and userID details with actual details | |||||
const message: TBKeyserverConnectionInitializationMessage = { | const message: TBKeyserverConnectionInitializationMessage = { | ||||
type: 'sessionRequest', | type: 'sessionRequest', | ||||
accessToken: 'foobar', | accessToken: 'foobar', | ||||
deviceID: 'foo', | deviceID, | ||||
deviceType: 'keyserver', | deviceType: 'keyserver', | ||||
userID: 'alice', | userID: 'alice', | ||||
}; | }; | ||||
console.log( | console.log( | ||||
'Sending message to tunnelbroker: ' + JSON.stringify(message), | 'Sending message to tunnelbroker: ' + JSON.stringify(message), | ||||
); | ); | ||||
tunnelbrokerSocket.send(JSON.stringify(message)); | tunnelbrokerSocket.send(JSON.stringify(message)); | ||||
}); | }); | ||||
Show All 14 Lines |
Aren't we using the signing key (ed25519) for the "device ID", or did I get this wrong? Isn't that the key that is signing the rest of the keys, so it should be considered the "root of trust"?