Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F3364729
D11339.id38183.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D11339.id38183.diff
View Options
diff --git a/lib/types/crypto-types.js b/lib/types/crypto-types.js
--- a/lib/types/crypto-types.js
+++ b/lib/types/crypto-types.js
@@ -2,6 +2,7 @@
import t, { type TInterface } from 'tcomb';
+import type { OlmSessionInitializationInfo } from './request-types.js';
import { type AuthMetadata } from '../shared/identity-client-context.js';
import { tShape } from '../utils/validation-utils.js';
@@ -130,6 +131,10 @@
contentIdentityKeys: OLMIdentityKeys,
initialEncryptedContent: string,
) => Promise<string>,
+ +contentOutboundSessionCreator: (
+ contentIdentityKeys: OLMIdentityKeys,
+ contentInitializationInfo: OlmSessionInitializationInfo,
+ ) => Promise<string>,
+getOneTimeKeys: (numberOfKeys: number) => Promise<OneTimeKeysResultValues>,
+validateAndUploadPrekeys: (authMetadata: AuthMetadata) => Promise<void>,
};
diff --git a/lib/utils/__mocks__/config.js b/lib/utils/__mocks__/config.js
--- a/lib/utils/__mocks__/config.js
+++ b/lib/utils/__mocks__/config.js
@@ -17,6 +17,7 @@
encrypt: jest.fn(),
decrypt: jest.fn(),
contentInboundSessionCreator: jest.fn(),
+ contentOutboundSessionCreator: jest.fn(),
getOneTimeKeys: jest.fn(),
validateAndUploadPrekeys: jest.fn(),
},
diff --git a/native/crypto/olm-api.js b/native/crypto/olm-api.js
--- a/native/crypto/olm-api.js
+++ b/native/crypto/olm-api.js
@@ -7,6 +7,7 @@
OlmAPI,
OLMIdentityKeys,
} from 'lib/types/crypto-types';
+import type { OlmSessionInitializationInfo } from 'lib/types/request-types.js';
import { commCoreModule } from '../native-modules.js';
@@ -30,6 +31,24 @@
contentIdentityKeys.ed25519,
);
},
+ async contentOutboundSessionCreator(
+ contentIdentityKeys: OLMIdentityKeys,
+ contentInitializationInfo: OlmSessionInitializationInfo,
+ ): Promise<string> {
+ const { prekey, prekeySignature, oneTimeKey } = contentInitializationInfo;
+ const identityKeys = JSON.stringify({
+ curve25519: contentIdentityKeys.curve25519,
+ ed25519: contentIdentityKeys.ed25519,
+ });
+
+ return commCoreModule.initializeContentOutboundSession(
+ identityKeys,
+ prekey,
+ prekeySignature,
+ oneTimeKey,
+ contentIdentityKeys.ed25519,
+ );
+ },
async getOneTimeKeys(numberOfKeys: number): Promise<OneTimeKeysResultValues> {
const { contentOneTimeKeys, notificationsOneTimeKeys } =
await commCoreModule.getOneTimeKeys(numberOfKeys);
diff --git a/web/crypto/olm-api.js b/web/crypto/olm-api.js
--- a/web/crypto/olm-api.js
+++ b/web/crypto/olm-api.js
@@ -54,6 +54,7 @@
encrypt: proxyToWorker('encrypt'),
decrypt: proxyToWorker('decrypt'),
contentInboundSessionCreator: proxyToWorker('contentInboundSessionCreator'),
+ contentOutboundSessionCreator: proxyToWorker('contentOutboundSessionCreator'),
getOneTimeKeys: proxyToWorker('getOneTimeKeys'),
validateAndUploadPrekeys: proxyToWorker('validateAndUploadPrekeys'),
};
diff --git a/web/shared-worker/worker/worker-crypto.js b/web/shared-worker/worker/worker-crypto.js
--- a/web/shared-worker/worker/worker-crypto.js
+++ b/web/shared-worker/worker/worker-crypto.js
@@ -3,6 +3,7 @@
import olm from '@commapp/olm';
import uuid from 'uuid';
+import { initialEncryptedMessageContent } from 'lib/shared/crypto-utils.js';
import {
olmEncryptedMessageTypes,
type OLMIdentityKeys,
@@ -14,6 +15,7 @@
type OneTimeKeysResultValues,
} from 'lib/types/crypto-types.js';
import type { IdentityDeviceKeyUpload } from 'lib/types/identity-service-types.js';
+import type { OlmSessionInitializationInfo } from 'lib/types/request-types.js';
import { entries } from 'lib/utils/objects.js';
import {
retrieveAccountKeysSet,
@@ -360,6 +362,33 @@
return initialEncryptedMessage;
},
+ async contentOutboundSessionCreator(
+ contentIdentityKeys: OLMIdentityKeys,
+ contentInitializationInfo: OlmSessionInitializationInfo,
+ ): Promise<string> {
+ if (!cryptoStore) {
+ throw new Error('Crypto account not initialized');
+ }
+ const { contentAccount, contentSessions } = cryptoStore;
+
+ const session = new olm.Session();
+ session.create_outbound(
+ contentAccount,
+ contentIdentityKeys.curve25519,
+ contentIdentityKeys.ed25519,
+ contentInitializationInfo.prekey,
+ contentInitializationInfo.prekeySignature,
+ contentInitializationInfo.oneTimeKey,
+ );
+ const { body: initialContentEncryptedMessage } = session.encrypt(
+ JSON.stringify(initialEncryptedMessageContent),
+ );
+
+ contentSessions[contentIdentityKeys.ed25519] = session;
+ persistCryptoStore();
+
+ return initialContentEncryptedMessage;
+ },
async getOneTimeKeys(numberOfKeys: number): Promise<OneTimeKeysResultValues> {
if (!cryptoStore) {
throw new Error('Crypto account not initialized');
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 26, 4:54 AM (21 h, 37 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2582998
Default Alt Text
D11339.id38183.diff (4 KB)
Attached To
Mode
D11339: [web/native] Add content outbound session to olmAPI
Attached
Detach File
Event Timeline
Log In to Comment