diff --git a/lib/components/keyserver-connection-handler.js b/lib/components/keyserver-connection-handler.js --- a/lib/components/keyserver-connection-handler.js +++ b/lib/components/keyserver-connection-handler.js @@ -161,7 +161,7 @@ : logInActionSources.keyserverAuthFromNative, keyserverData: { [keyserverID]: { - initialContentEncryptedMessage: contentSession, + initialContentEncryptedMessage: contentSession.message, initialNotificationsEncryptedMessage: notifsSession, }, }, diff --git a/lib/handlers/peer-to-peer-message-handler.js b/lib/handlers/peer-to-peer-message-handler.js --- a/lib/handlers/peer-to-peer-message-handler.js +++ b/lib/handlers/peer-to-peer-message-handler.js @@ -17,7 +17,7 @@ const { olmAPI } = getConfig(); if (message.type === peerToPeerMessageTypes.OUTBOUND_SESSION_CREATION) { try { - const { senderInfo, encryptedContent } = message; + const { senderInfo, encryptedData } = message; const { keys } = await identityClient.getInboundKeysForUser( senderInfo.userID, ); @@ -33,7 +33,7 @@ await olmAPI.initializeCryptoAccount(); const result = await olmAPI.contentInboundSessionCreator( deviceKeys.identityKeysBlob.primaryIdentityPublicKeys, - encryptedContent, + encryptedData, ); console.log( 'Created inbound session with device ' + 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 @@ -144,12 +144,12 @@ +decrypt: (encryptedData: EncryptedData, deviceID: string) => Promise, +contentInboundSessionCreator: ( contentIdentityKeys: OLMIdentityKeys, - initialEncryptedContent: string, + initialEncryptedData: EncryptedData, ) => Promise, +contentOutboundSessionCreator: ( contentIdentityKeys: OLMIdentityKeys, contentInitializationInfo: OlmSessionInitializationInfo, - ) => Promise, + ) => Promise, +notificationsSessionCreator: ( cookie: ?string, notificationsIdentityKeys: OLMIdentityKeys, diff --git a/lib/types/tunnelbroker/peer-to-peer-message-types.js b/lib/types/tunnelbroker/peer-to-peer-message-types.js --- a/lib/types/tunnelbroker/peer-to-peer-message-types.js +++ b/lib/types/tunnelbroker/peer-to-peer-message-types.js @@ -30,13 +30,13 @@ export type OutboundSessionCreation = { +type: 'OutboundSessionCreation', +senderInfo: SenderInfo, - +encryptedContent: string, + +encryptedData: EncryptedData, }; export const outboundSessionCreationValidator: TInterface = tShape({ type: tString(peerToPeerMessageTypes.OUTBOUND_SESSION_CREATION), senderInfo: senderInfoValidator, - encryptedContent: t.String, + encryptedData: encryptedDataValidator, }); export type EncryptedMessage = { 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 @@ -78,7 +78,7 @@ continue; } try { - const encryptedContent = await olmAPI.contentOutboundSessionCreator( + const encryptedData = await olmAPI.contentOutboundSessionCreator( primaryIdentityPublicKeys, keys.contentInitializationInfo, ); @@ -89,7 +89,7 @@ userID, deviceID, }, - encryptedContent, + encryptedData, }; await sendMessage({ 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 @@ -6,6 +6,8 @@ type OneTimeKeysResultValues, type OlmAPI, type OLMIdentityKeys, + type EncryptedData, + olmEncryptedMessageTypes, } from 'lib/types/crypto-types.js'; import type { OlmSessionInitializationInfo } from 'lib/types/request-types.js'; @@ -20,7 +22,7 @@ decrypt: commCoreModule.decrypt, async contentInboundSessionCreator( contentIdentityKeys: OLMIdentityKeys, - initialEncryptedContent: string, + initialEncryptedData: EncryptedData, ): Promise { const identityKeys = JSON.stringify({ curve25519: contentIdentityKeys.curve25519, @@ -28,27 +30,31 @@ }); return commCoreModule.initializeContentInboundSession( identityKeys, - initialEncryptedContent, + initialEncryptedData.message, contentIdentityKeys.ed25519, ); }, async contentOutboundSessionCreator( contentIdentityKeys: OLMIdentityKeys, contentInitializationInfo: OlmSessionInitializationInfo, - ): Promise { + ): Promise { const { prekey, prekeySignature, oneTimeKey } = contentInitializationInfo; const identityKeys = JSON.stringify({ curve25519: contentIdentityKeys.curve25519, ed25519: contentIdentityKeys.ed25519, }); - return commCoreModule.initializeContentOutboundSession( + const message = await commCoreModule.initializeContentOutboundSession( identityKeys, prekey, prekeySignature, oneTimeKey, contentIdentityKeys.ed25519, ); + return { + message, + messageType: olmEncryptedMessageTypes.PREKEY, + }; }, notificationsSessionCreator( cookie: ?string, 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 @@ -7,7 +7,6 @@ import { initialEncryptedMessageContent } from 'lib/shared/crypto-utils.js'; import { hasMinCodeVersion } from 'lib/shared/version-utils.js'; import { - olmEncryptedMessageTypes, type OLMIdentityKeys, type PickledOLMAccount, type IdentityKeysBlob, @@ -407,7 +406,7 @@ }, async contentInboundSessionCreator( contentIdentityKeys: OLMIdentityKeys, - initialEncryptedContent: string, + initialEncryptedData: EncryptedData, ): Promise { if (!cryptoStore) { throw new Error('Crypto account not initialized'); @@ -418,13 +417,13 @@ session.create_inbound_from( contentAccount, contentIdentityKeys.curve25519, - initialEncryptedContent, + initialEncryptedData.message, ); contentAccount.remove_one_time_keys(session); const initialEncryptedMessage = session.decrypt( - olmEncryptedMessageTypes.PREKEY, - initialEncryptedContent, + initialEncryptedData.messageType, + initialEncryptedData.message, ); contentSessions[contentIdentityKeys.ed25519] = session; @@ -435,7 +434,7 @@ async contentOutboundSessionCreator( contentIdentityKeys: OLMIdentityKeys, contentInitializationInfo: OlmSessionInitializationInfo, - ): Promise { + ): Promise { if (!cryptoStore) { throw new Error('Crypto account not initialized'); } @@ -450,14 +449,17 @@ contentInitializationInfo.prekeySignature, contentInitializationInfo.oneTimeKey, ); - const { body: initialContentEncryptedMessage } = session.encrypt( + const initialEncryptedData = session.encrypt( JSON.stringify(initialEncryptedMessageContent), ); contentSessions[contentIdentityKeys.ed25519] = session; persistCryptoStore(); - return initialContentEncryptedMessage; + return { + message: initialEncryptedData.body, + messageType: initialEncryptedData.type, + }; }, async notificationsSessionCreator( cookie: ?string,