Page MenuHomePhabricator

D12131.diff
No OneTemporary

D12131.diff

diff --git a/lib/utils/crypto-utils.js b/lib/utils/crypto-utils.js
--- a/lib/utils/crypto-utils.js
+++ b/lib/utils/crypto-utils.js
@@ -110,9 +110,70 @@
}
}
+async function createOlmSessionWithPeer(
+ authMetadata: AuthMetadata,
+ identityClient: IdentityServiceClient,
+ sendMessage: (message: TunnelbrokerClientMessageToDevice) => Promise<void>,
+ userID: string,
+ deviceID: string,
+): Promise<void> {
+ const { olmAPI } = getConfig();
+ await olmAPI.initializeCryptoAccount();
+
+ const {
+ userID: authUserID,
+ deviceID: authDeviceID,
+ accessToken,
+ } = authMetadata;
+ if (!authUserID || !authDeviceID || !accessToken) {
+ throw new Error('CommServicesAuthMetadata is missing');
+ }
+
+ const keysResponse = await identityClient.getOutboundKeysForUser(userID);
+ const deviceKeysResponse = keysResponse.find(
+ keys => keys.deviceID === deviceID,
+ );
+ if (!deviceKeysResponse || !deviceKeysResponse.keys) {
+ throw new Error(`Keys missing for device ${deviceID}`);
+ }
+ const { keys } = deviceKeysResponse;
+
+ const { primaryIdentityPublicKeys } = keys.identityKeysBlob;
+ const recipientDeviceID = primaryIdentityPublicKeys.ed25519;
+
+ if (!keys.contentInitializationInfo.oneTimeKey) {
+ throw new Error(`One-time key is missing for device ${recipientDeviceID}`);
+ }
+
+ const { sessionVersion, encryptedData } =
+ await olmAPI.contentOutboundSessionCreator(
+ primaryIdentityPublicKeys,
+ keys.contentInitializationInfo,
+ );
+
+ const sessionCreationMessage: OutboundSessionCreation = {
+ type: peerToPeerMessageTypes.OUTBOUND_SESSION_CREATION,
+ senderInfo: {
+ userID: authUserID,
+ deviceID: authDeviceID,
+ },
+ encryptedData,
+ sessionVersion,
+ };
+
+ await sendMessage({
+ deviceID: recipientDeviceID,
+ payload: JSON.stringify(sessionCreationMessage),
+ });
+ console.log(
+ `Request to create a session with device ${recipientDeviceID} sent.`,
+ );
+}
+
export {
signedIdentityKeysBlobValidator,
identityKeysBlobValidator,
getContentSigningKey,
createOlmSessionsWithOwnDevices,
+ createOlmSessionWithPeer,
};

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 26, 10:41 AM (20 h, 41 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2584304
Default Alt Text
D12131.diff (2 KB)

Event Timeline