Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F33070382
D8752.1768442704.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
4 KB
Referenced Files
None
Subscribers
None
D8752.1768442704.diff
View Options
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,12 +1,17 @@
// @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,
@@ -21,6 +26,19 @@
);
}
+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, 2:05 AM (16 h, 30 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5935285
Default Alt Text
D8752.1768442704.diff (4 KB)
Attached To
Mode
D8752: [Keyserver] Upload new onetime keys to identity service when requested
Attached
Detach File
Event Timeline
Log In to Comment