Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3366295
D12131.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D12131.diff
View Options
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
Details
Attached
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)
Attached To
Mode
D12131: [lib] creating `olm` session with device
Attached
Detach File
Event Timeline
Log In to Comment