diff --git a/keyserver/src/keyserver.js b/keyserver/src/keyserver.js --- a/keyserver/src/keyserver.js +++ b/keyserver/src/keyserver.js @@ -38,6 +38,7 @@ } from './uploads/uploads.js'; import { verifyUserLoggedIn } from './user/login.js'; import { initENSCache } from './utils/ens-cache.js'; +import { getContentSigningKey } from './utils/olm-utils.js'; import { prefetchAllURLFacts, getSquadCalURLFacts, @@ -85,7 +86,15 @@ if (shouldDisplayQRCodeInTerminal) { try { const aes256Key = crypto.randomBytes(32).toString('hex'); - const ed25519Key = 'ed25519Key'; + const ed25519Key = await getContentSigningKey(); + + console.log( + '\nOpen the Comm app on your phone and scan the QR code below\n', + ); + console.log('How to find the scanner:\n'); + console.log('Go to \x1b[1mProfile\x1b[0m'); + console.log('Select \x1b[1mLinked devices\x1b[0m'); + console.log('Click \x1b[1mAdd\x1b[0m on the top right'); const url = qrCodeLinkURL(aes256Key, ed25519Key); qrcode.toString(url, (error, encodedURL) => console.log(encodedURL)); diff --git a/keyserver/src/scripts/get-keyserver-public-key.js b/keyserver/src/scripts/get-keyserver-public-key.js --- a/keyserver/src/scripts/get-keyserver-public-key.js +++ b/keyserver/src/scripts/get-keyserver-public-key.js @@ -1,12 +1,12 @@ // @flow import { main } from './utils.js'; -import { fetchOlmAccount } from '../updaters/olm-account-updater.js'; +import { getContentSigningKey } from '../utils/olm-utils.js'; // Outputs the keyserver's signing ed25519 public key async function getKeyserverPublicKey() { - const info = await fetchOlmAccount('content'); - console.log(JSON.parse(info.account.identity_keys()).ed25519); + const contentSigningKey = await getContentSigningKey(); + console.log(contentSigningKey); } main([getKeyserverPublicKey]); diff --git a/keyserver/src/socket/tunnelbroker.js b/keyserver/src/socket/tunnelbroker.js --- a/keyserver/src/socket/tunnelbroker.js +++ b/keyserver/src/socket/tunnelbroker.js @@ -11,9 +11,11 @@ import { getCommConfig } from 'lib/utils/comm-config.js'; import { ServerError } from 'lib/utils/errors.js'; -import { fetchOlmAccount } from '../updaters/olm-account-updater.js'; import { type IdentityInfo } from '../user/identity.js'; -import { uploadNewOneTimeKeys } from '../utils/olm-utils.js'; +import { + uploadNewOneTimeKeys, + getContentSigningKey, +} from '../utils/olm-utils.js'; type TBConnectionInfo = { +url: string, @@ -38,13 +40,11 @@ async function createAndMaintainTunnelbrokerWebsocket( identityInfo: IdentityInfo, ) { - const [accountInfo, tbConnectionInfo] = await Promise.all([ - fetchOlmAccount('content'), + const [deviceID, tbConnectionInfo] = await Promise.all([ + getContentSigningKey(), getTBConnectionInfo(), ]); - const deviceID = JSON.parse(accountInfo.account.identity_keys()).ed25519; - openTunnelbrokerConnection( deviceID, identityInfo.userId, diff --git a/keyserver/src/utils/olm-utils.js b/keyserver/src/utils/olm-utils.js --- a/keyserver/src/utils/olm-utils.js +++ b/keyserver/src/utils/olm-utils.js @@ -13,7 +13,10 @@ import { olmEncryptedMessageTypes } from 'lib/types/crypto-types.js'; import { ServerError } from 'lib/utils/errors.js'; -import { fetchCallUpdateOlmAccount } from '../updaters/olm-account-updater.js'; +import { + fetchCallUpdateOlmAccount, + fetchOlmAccount, +} from '../updaters/olm-account-updater.js'; import { fetchIdentityInfo } from '../user/identity.js'; type PickledOlmAccount = { @@ -144,6 +147,11 @@ }); } +async function getContentSigningKey(): Promise { + const accountInfo = await fetchOlmAccount('content'); + return JSON.parse(accountInfo.account.identity_keys()).ed25519; +} + export { createPickledOlmAccount, createPickledOlmSession, @@ -152,4 +160,5 @@ unpickleOlmSession, validateAccountPrekey, uploadNewOneTimeKeys, + getContentSigningKey, };