Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F33068803
D8752.1768441161.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
5 KB
Referenced Files
None
Subscribers
None
D8752.1768441161.diff
View Options
diff --git a/keyserver/src/keyserver.js b/keyserver/src/keyserver.js
--- a/keyserver/src/keyserver.js
+++ b/keyserver/src/keyserver.js
@@ -64,13 +64,13 @@
// Allow login to be optional until staging environment is available
try {
- // We await here to ensure Keyserver has been provisioned a
- // "commServicesAccessToken". In the future, this will be necessary for
- // many Keyserver operations.
+ // We await here to ensure the keyserver has been provisioned a
+ // commServicesAccessToken. In the future, this will be necessary for
+ // many keyserver operations.
const identityInfo = await verifyUserLoggedIn();
// We don't await here, as Tunnelbroker communication is not needed for
- // normal Keyserver behavior. In addition, this doesn't return information
- // useful for other Keyserver functions.
+ // normal keyserver behavior yet. In addition, this doesn't return
+ // information useful for other keyserver functions.
handleAsyncPromise(createAndMaintainTunnelbrokerWebsocket(identityInfo));
} catch (e) {
console.warn('failed_identity_login');
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
@@ -1,26 +1,44 @@
// @flow
+import invariant from 'invariant';
import WebSocket from 'ws';
-import { type TBKeyserverConnectionInitializationMessage } from 'lib/types/tunnelbroker-messages.js';
+import {
+ type TBKeyserverConnectionInitializationMessage,
+ type TBMessage,
+} from 'lib/types/tunnelbroker-messages.js';
import sleep from 'lib/utils/sleep.js';
import { fetchOlmAccount } from '../updaters/olm-account-updater.js';
-import type { IdentityInfo } from '../user/identity.js';
+import { type IdentityInfo } from '../user/identity.js';
+import { uploadNewOneTimeKeys } from '../utils/olm-utils.js';
async function createAndMaintainTunnelbrokerWebsocket(
identityInfo: IdentityInfo,
) {
const accountInfo = await fetchOlmAccount('content');
- const deviceId = JSON.parse(accountInfo.account.identity_keys()).curve25519;
+ const deviceID = JSON.parse(accountInfo.account.identity_keys()).curve25519;
openTunnelbrokerConnection(
- deviceId,
+ deviceID,
identityInfo.userId,
identityInfo.accessToken,
);
}
+function handleTBMessageEvent(event: MessageEvent): Promise<void> {
+ invariant(
+ typeof event.data === 'string',
+ 'Messages from tunnelbroker should be a string',
+ );
+
+ // Currently, there is only one message type which is sent from tunnelbroker
+ const content: string = event.data;
+ const message: TBMessage = JSON.parse(content);
+
+ return uploadNewOneTimeKeys(message.numberOfKeys);
+}
+
function openTunnelbrokerConnection(
deviceID: string,
userID: string,
@@ -52,6 +70,8 @@
tunnelbrokerSocket.on('error', (error: Error) => {
console.error('Tunnelbroker socket error: ' + error.message);
});
+
+ tunnelbrokerSocket.on('message', handleTBMessageEvent);
} catch {
console.log('Failed to open connection with Tunnelbroker');
}
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,8 +13,10 @@
olmEncryptedMessageTypes,
type OLMOneTimeKeys,
} from 'lib/types/crypto-types.js';
+import { ServerError } from 'lib/utils/errors.js';
import { values } from 'lib/utils/objects.js';
+import { fetchCallUpdateOlmAccount } from '../updaters/olm-account-updater.js';
import { fetchIdentityInfo } from '../user/identity.js';
type PickledOlmAccount = {
@@ -177,6 +179,45 @@
notifAccount.mark_prekey_as_published();
}
+async function uploadNewOneTimeKeys(numberOfKeys: number) {
+ const [rustAPI, identityInfo] = await Promise.all([
+ getRustAPI(),
+ fetchIdentityInfo(),
+ ]);
+
+ if (!identityInfo) {
+ throw new ServerError('missing_identity_info');
+ }
+
+ await fetchCallUpdateOlmAccount('content', (contentAccount: OlmAccount) => {
+ contentAccount.generate_one_time_keys(numberOfKeys);
+ const contentOneTimeKeys = getOneTimeKeyValues(
+ contentAccount.one_time_keys(),
+ );
+ const deviceID = JSON.parse(contentAccount.identity_keys()).curve25519;
+
+ return fetchCallUpdateOlmAccount(
+ 'notifications',
+ async (notifAccount: OlmAccount) => {
+ notifAccount.generate_one_time_keys(numberOfKeys);
+ const notifOneTimeKeys = getOneTimeKeyValues(
+ notifAccount.one_time_keys(),
+ );
+ await rustAPI.uploadOneTimeKeys(
+ identityInfo.userId,
+ deviceID,
+ identityInfo.accessToken,
+ contentOneTimeKeys,
+ notifOneTimeKeys,
+ );
+
+ notifAccount.mark_keys_as_published();
+ contentAccount.mark_keys_as_published();
+ },
+ );
+ });
+}
+
// DEPRECATED: revalidateAccountPrekeys should be used instead
function validateAccountPrekey(account: OlmAccount) {
if (shouldRotatePrekey(account)) {
@@ -200,4 +241,5 @@
validateAccountPrekey,
revalidateAccountPrekeys,
publishNewPrekeys,
+ uploadNewOneTimeKeys,
};
diff --git a/lib/types/tunnelbroker-messages.js b/lib/types/tunnelbroker-messages.js
--- a/lib/types/tunnelbroker-messages.js
+++ b/lib/types/tunnelbroker-messages.js
@@ -28,3 +28,13 @@
| TBKeyserverConnectionInitializationMessage
| TBClientConnectionInitializationMessage
| TBNotifyClientConnectionInitializationMessage;
+
+export type TBRefreshKeysRequest = {
+ +type: 'refreshKeysRequest',
+ +deviceId: string,
+ +numberOfKeys: number,
+};
+
+// Disjoint enumeration of all messages
+// Currently, only a single message
+export type TBMessage = TBRefreshKeysRequest;
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Thu, Jan 15, 1:39 AM (10 h, 39 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5935188
Default Alt Text
D8752.1768441161.diff (5 KB)
Attached To
Mode
D8752: [Keyserver] Upload new onetime keys to identity service when requested
Attached
Detach File
Event Timeline
Log In to Comment