diff --git a/lib/keyserver-conn/recovery-utils.js b/lib/keyserver-conn/recovery-utils.js --- a/lib/keyserver-conn/recovery-utils.js +++ b/lib/keyserver-conn/recovery-utils.js @@ -47,6 +47,7 @@ logInActionSource: LogInActionSource, keyserverID: string, getInitialNotificationsEncryptedMessage?: ( + keyserverID: string, options?: ?InitialNotifMessageOptions, ) => Promise, ): Promise { diff --git a/lib/selectors/socket-selectors.js b/lib/selectors/socket-selectors.js --- a/lib/selectors/socket-selectors.js +++ b/lib/selectors/socket-selectors.js @@ -28,6 +28,7 @@ import { getConfig } from '../utils/config.js'; import { minimumOneTimeKeysRequired } from '../utils/crypto-utils.js'; import { values } from '../utils/objects.js'; +import { ashoatKeyserverID } from '../utils/validation-utils.js'; const baseOpenSocketSelector: ( keyserverID: string, @@ -98,7 +99,9 @@ calendarActive: boolean, oneTimeKeyGenerator: ?OneTimeKeyGenerator, getSignedIdentityKeysBlob: () => Promise, - getInitialNotificationsEncryptedMessage: ?() => Promise, + getInitialNotificationsEncryptedMessage: ?( + keyserverID: string, + ) => Promise, serverRequests: $ReadOnlyArray, ) => Promise<$ReadOnlyArray> = createSelector( boundStateSyncSpecsSelector, @@ -111,7 +114,9 @@ calendarActive: boolean, oneTimeKeyGenerator: ?OneTimeKeyGenerator, getSignedIdentityKeysBlob: () => Promise, - getInitialNotificationsEncryptedMessage: ?() => Promise, + getInitialNotificationsEncryptedMessage: ?( + keyserverID: string, + ) => Promise, serverRequests: $ReadOnlyArray, ): Promise<$ReadOnlyArray> => { const clientResponses = []; @@ -209,7 +214,7 @@ getInitialNotificationsEncryptedMessage ) { const initialNotificationsEncryptedMessage = - await getInitialNotificationsEncryptedMessage(); + await getInitialNotificationsEncryptedMessage(ashoatKeyserverID); clientResponses.push({ type: serverRequestTypes.INITIAL_NOTIFICATIONS_ENCRYPTED_MESSAGE, initialNotificationsEncryptedMessage, diff --git a/lib/shared/crypto-utils.js b/lib/shared/crypto-utils.js --- a/lib/shared/crypto-utils.js +++ b/lib/shared/crypto-utils.js @@ -33,15 +33,19 @@ platformSpecificSessionCreator: ( notificationsIdentityKeys: OLMIdentityKeys, notificationsInitializationInfo: OlmSessionInitializationInfo, + keyserverID: string, ) => Promise, -): (options?: ?InitialNotifMessageOptions) => Promise { +): ( + keyserverID: string, + options?: ?InitialNotifMessageOptions, +) => Promise { const callGetOlmSessionInitializationData = useLegacyAshoatKeyserverCall( getOlmSessionInitializationData, ); const dispatchActionPromise = useDispatchActionPromise(); return React.useCallback( - async options => { + async (keyserverID, options) => { const callSingleKeyserverEndpoint = options?.callSingleKeyserverEndpoint; const callSingleKeyserverEndpointOptions = options?.callSingleKeyserverEndpointOptions; @@ -68,6 +72,7 @@ return await platformSpecificSessionCreator( notificationIdentityPublicKeys, notifInitializationInfo, + keyserverID, ); }, [ diff --git a/lib/socket/socket.react.js b/lib/socket/socket.react.js --- a/lib/socket/socket.react.js +++ b/lib/socket/socket.react.js @@ -110,6 +110,7 @@ +socketCrashLoopRecovery?: () => Promise, // keyserver olm sessions specific props +getInitialNotificationsEncryptedMessage?: ( + keyserverID: string, options?: ?InitialNotifMessageOptions, ) => Promise, }; diff --git a/lib/utils/config.js b/lib/utils/config.js --- a/lib/utils/config.js +++ b/lib/utils/config.js @@ -19,6 +19,7 @@ logInActionSource: LogInActionSource, keyserverID: string, getInitialNotificationsEncryptedMessage?: ( + keyserverID: string, options?: ?InitialNotifMessageOptions, ) => Promise, ) => Promise, diff --git a/native/account/legacy-recover-keyserver-session.js b/native/account/legacy-recover-keyserver-session.js --- a/native/account/legacy-recover-keyserver-session.js +++ b/native/account/legacy-recover-keyserver-session.js @@ -20,6 +20,7 @@ logInActionSource: LogInActionSource, keyserverID: string, getInitialNotificationsEncryptedMessage?: ( + keyserverID: string, ?InitialNotifMessageOptions, ) => Promise, ) { @@ -31,7 +32,7 @@ if (getInitialNotificationsEncryptedMessage) { const initialNotificationsEncryptedMessage = - await getInitialNotificationsEncryptedMessage({ + await getInitialNotificationsEncryptedMessage(keyserverID, { callSingleKeyserverEndpoint, }); extraInfo = { ...extraInfo, initialNotificationsEncryptedMessage }; diff --git a/native/account/log-in-panel.react.js b/native/account/log-in-panel.react.js --- a/native/account/log-in-panel.react.js +++ b/native/account/log-in-panel.react.js @@ -31,6 +31,7 @@ useDispatchActionPromise, type DispatchActionPromise, } from 'lib/utils/redux-promise-utils.js'; +import { ashoatKeyserverID } from 'lib/utils/validation-utils.js'; import { TextInput } from './modal-components.react.js'; import { @@ -63,7 +64,9 @@ +logInExtraInfo: () => Promise, +dispatchActionPromise: DispatchActionPromise, +logIn: (logInInfo: LogInInfo) => Promise, - +getInitialNotificationsEncryptedMessage: () => Promise, + +getInitialNotificationsEncryptedMessage: ( + keyserverID: string, + ) => Promise, }; class LogInPanel extends React.PureComponent { usernameInput: ?TextInput; @@ -238,7 +241,9 @@ Keyboard.dismiss(); const extraInfo = await this.props.logInExtraInfo(); const initialNotificationsEncryptedMessage = - await this.props.getInitialNotificationsEncryptedMessage(); + await this.props.getInitialNotificationsEncryptedMessage( + ashoatKeyserverID, + ); void this.props.dispatchActionPromise( logInActionTypes, diff --git a/native/account/logged-out-modal.react.js b/native/account/logged-out-modal.react.js --- a/native/account/logged-out-modal.react.js +++ b/native/account/logged-out-modal.react.js @@ -253,7 +253,9 @@ // Redux dispatch functions +dispatch: Dispatch, // Keyserver olm sessions functions - +getInitialNotificationsEncryptedMessage: () => Promise, + +getInitialNotificationsEncryptedMessage: ( + keyserverID: string, + ) => Promise, }; type State = { +mode: LoggedOutMode, diff --git a/native/account/register-panel.react.js b/native/account/register-panel.react.js --- a/native/account/register-panel.react.js +++ b/native/account/register-panel.react.js @@ -38,6 +38,7 @@ type DispatchActionPromise, } from 'lib/utils/redux-promise-utils.js'; import { useDispatch } from 'lib/utils/redux-utils.js'; +import { ashoatKeyserverID } from 'lib/utils/validation-utils.js'; import { TextInput } from './modal-components.react.js'; import { setNativeCredentials } from './native-credentials.js'; @@ -73,7 +74,9 @@ +dispatch: Dispatch, +dispatchActionPromise: DispatchActionPromise, +register: (registerInfo: RegisterInfo) => Promise, - +getInitialNotificationsEncryptedMessage: () => Promise, + +getInitialNotificationsEncryptedMessage: ( + keyserverID: string, + ) => Promise, }; type State = { +confirmPasswordFocused: boolean, @@ -307,7 +310,9 @@ Keyboard.dismiss(); const extraInfo = await this.props.logInExtraInfo(); const initialNotificationsEncryptedMessage = - await this.props.getInitialNotificationsEncryptedMessage(); + await this.props.getInitialNotificationsEncryptedMessage( + ashoatKeyserverID, + ); void this.props.dispatchActionPromise( keyserverRegisterActionTypes, this.registerAction({ diff --git a/native/account/siwe-hooks.js b/native/account/siwe-hooks.js --- a/native/account/siwe-hooks.js +++ b/native/account/siwe-hooks.js @@ -11,6 +11,7 @@ import { useLegacyAshoatKeyserverCall } from 'lib/utils/action-utils.js'; import type { CallSingleKeyserverEndpointOptions } from 'lib/utils/call-single-keyserver-endpoint.js'; import { useDispatchActionPromise } from 'lib/utils/redux-promise-utils.js'; +import { ashoatKeyserverID } from 'lib/utils/validation-utils.js'; import { useSelector } from '../redux/redux-utils.js'; import { nativeLogInExtraInfoSelector } from '../selectors/account-selectors.js'; @@ -59,7 +60,7 @@ ) => { const extraInfo = await logInExtraInfo(); const initialNotificationsEncryptedMessage = - await getInitialNotificationsEncryptedMessage({ + await getInitialNotificationsEncryptedMessage(ashoatKeyserverID, { callSingleKeyserverEndpointOptions, }); diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.h b/native/cpp/CommonCpp/NativeModules/CommCoreModule.h --- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.h +++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.h @@ -77,7 +77,8 @@ jsi::String identityKeys, jsi::String prekey, jsi::String prekeySignature, - jsi::String oneTimeKeys) override; + jsi::String oneTimeKeys, + jsi::String keyserverID) override; virtual jsi::Value isNotificationsSessionInitialized(jsi::Runtime &rt) override; virtual jsi::Value initializeContentOutboundSession( diff --git a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp --- a/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp +++ b/native/cpp/CommonCpp/NativeModules/CommCoreModule.cpp @@ -659,7 +659,8 @@ jsi::String identityKeys, jsi::String prekey, jsi::String prekeySignature, - jsi::String oneTimeKeys) { + jsi::String oneTimeKeys, + jsi::String keyserverID) { auto identityKeysCpp{identityKeys.utf8(rt)}; auto prekeyCpp{prekey.utf8(rt)}; auto prekeySignatureCpp{prekeySignature.utf8(rt)}; diff --git a/native/cpp/CommonCpp/_generated/commJSI-generated.cpp b/native/cpp/CommonCpp/_generated/commJSI-generated.cpp --- a/native/cpp/CommonCpp/_generated/commJSI-generated.cpp +++ b/native/cpp/CommonCpp/_generated/commJSI-generated.cpp @@ -76,7 +76,7 @@ return static_cast(&turboModule)->generateAndGetPrekeys(rt); } static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_initializeNotificationsSession(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { - return static_cast(&turboModule)->initializeNotificationsSession(rt, args[0].asString(rt), args[1].asString(rt), args[2].asString(rt), args[3].asString(rt)); + return static_cast(&turboModule)->initializeNotificationsSession(rt, args[0].asString(rt), args[1].asString(rt), args[2].asString(rt), args[3].asString(rt), args[4].asString(rt)); } static jsi::Value __hostFunction_CommCoreModuleSchemaCxxSpecJSI_isNotificationsSessionInitialized(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) { return static_cast(&turboModule)->isNotificationsSessionInitialized(rt); @@ -169,7 +169,7 @@ methodMap_["getPrimaryOneTimeKeys"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getPrimaryOneTimeKeys}; methodMap_["getNotificationsOneTimeKeys"] = MethodMetadata {1, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_getNotificationsOneTimeKeys}; methodMap_["generateAndGetPrekeys"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_generateAndGetPrekeys}; - methodMap_["initializeNotificationsSession"] = MethodMetadata {4, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_initializeNotificationsSession}; + methodMap_["initializeNotificationsSession"] = MethodMetadata {5, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_initializeNotificationsSession}; methodMap_["isNotificationsSessionInitialized"] = MethodMetadata {0, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_isNotificationsSessionInitialized}; methodMap_["initializeContentOutboundSession"] = MethodMetadata {5, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_initializeContentOutboundSession}; methodMap_["initializeContentInboundSession"] = MethodMetadata {3, __hostFunction_CommCoreModuleSchemaCxxSpecJSI_initializeContentInboundSession}; diff --git a/native/cpp/CommonCpp/_generated/commJSI.h b/native/cpp/CommonCpp/_generated/commJSI.h --- a/native/cpp/CommonCpp/_generated/commJSI.h +++ b/native/cpp/CommonCpp/_generated/commJSI.h @@ -40,7 +40,7 @@ virtual jsi::Value getPrimaryOneTimeKeys(jsi::Runtime &rt, double oneTimeKeysAmount) = 0; virtual jsi::Value getNotificationsOneTimeKeys(jsi::Runtime &rt, double oneTimeKeysAmount) = 0; virtual jsi::Value generateAndGetPrekeys(jsi::Runtime &rt) = 0; - virtual jsi::Value initializeNotificationsSession(jsi::Runtime &rt, jsi::String identityKeys, jsi::String prekey, jsi::String prekeySignature, jsi::String oneTimeKeys) = 0; + virtual jsi::Value initializeNotificationsSession(jsi::Runtime &rt, jsi::String identityKeys, jsi::String prekey, jsi::String prekeySignature, jsi::String oneTimeKeys, jsi::String keyserverID) = 0; virtual jsi::Value isNotificationsSessionInitialized(jsi::Runtime &rt) = 0; virtual jsi::Value initializeContentOutboundSession(jsi::Runtime &rt, jsi::String identityKeys, jsi::String prekey, jsi::String prekeySignature, jsi::String oneTimeKeys, jsi::String deviceID) = 0; virtual jsi::Value initializeContentInboundSession(jsi::Runtime &rt, jsi::String identityKeys, jsi::String encryptedMessage, jsi::String deviceID) = 0; @@ -244,13 +244,13 @@ return bridging::callFromJs( rt, &T::generateAndGetPrekeys, jsInvoker_, instance_); } - jsi::Value initializeNotificationsSession(jsi::Runtime &rt, jsi::String identityKeys, jsi::String prekey, jsi::String prekeySignature, jsi::String oneTimeKeys) override { + jsi::Value initializeNotificationsSession(jsi::Runtime &rt, jsi::String identityKeys, jsi::String prekey, jsi::String prekeySignature, jsi::String oneTimeKeys, jsi::String keyserverID) override { static_assert( - bridging::getParameterCount(&T::initializeNotificationsSession) == 5, - "Expected initializeNotificationsSession(...) to have 5 parameters"); + bridging::getParameterCount(&T::initializeNotificationsSession) == 6, + "Expected initializeNotificationsSession(...) to have 6 parameters"); return bridging::callFromJs( - rt, &T::initializeNotificationsSession, jsInvoker_, instance_, std::move(identityKeys), std::move(prekey), std::move(prekeySignature), std::move(oneTimeKeys)); + rt, &T::initializeNotificationsSession, jsInvoker_, instance_, std::move(identityKeys), std::move(prekey), std::move(prekeySignature), std::move(oneTimeKeys), std::move(keyserverID)); } jsi::Value isNotificationsSessionInitialized(jsi::Runtime &rt) override { static_assert( diff --git a/native/schema/CommCoreModuleSchema.js b/native/schema/CommCoreModuleSchema.js --- a/native/schema/CommCoreModuleSchema.js +++ b/native/schema/CommCoreModuleSchema.js @@ -87,6 +87,7 @@ prekey: string, prekeySignature: string, oneTimeKeys: string, + keyserverID: string, ) => Promise; +isNotificationsSessionInitialized: () => Promise; +initializeContentOutboundSession: ( diff --git a/native/selectors/socket-selectors.js b/native/selectors/socket-selectors.js --- a/native/selectors/socket-selectors.js +++ b/native/selectors/socket-selectors.js @@ -61,7 +61,9 @@ type NativeGetClientResponsesSelectorInputType = { ...NavPlusRedux, - getInitialNotificationsEncryptedMessage: () => Promise, + getInitialNotificationsEncryptedMessage: ( + keyserverID: string, + ) => Promise, }; const nativeGetClientResponsesSelector: ( @@ -80,11 +82,15 @@ calendarActive: boolean, oneTimeKeyGenerator: ?OneTimeKeyGenerator, getSignedIdentityKeysBlob: () => Promise, - getInitialNotificationsEncryptedMessage: ?() => Promise, + getInitialNotificationsEncryptedMessage: ?( + keyserverID: string, + ) => Promise, serverRequests: $ReadOnlyArray, ) => Promise<$ReadOnlyArray>, calendarActive: boolean, - getInitialNotificationsEncryptedMessage: () => Promise, + getInitialNotificationsEncryptedMessage: ( + keyserverID: string, + ) => Promise, ) => (serverRequests: $ReadOnlyArray) => getClientResponsesFunc( diff --git a/native/utils/crypto-utils.js b/native/utils/crypto-utils.js --- a/native/utils/crypto-utils.js +++ b/native/utils/crypto-utils.js @@ -20,6 +20,7 @@ function nativeNotificationsSessionCreator( notificationsIdentityKeys: OLMIdentityKeys, notificationsInitializationInfo: OlmSessionInitializationInfo, + keyserverID: string, ): Promise { const { prekey, prekeySignature, oneTimeKey } = notificationsInitializationInfo; @@ -28,6 +29,7 @@ prekey, prekeySignature, oneTimeKey, + keyserverID, ); } diff --git a/web/selectors/socket-selectors.js b/web/selectors/socket-selectors.js --- a/web/selectors/socket-selectors.js +++ b/web/selectors/socket-selectors.js @@ -45,7 +45,9 @@ type WebGetClientResponsesSelectorInputType = { +state: AppState, +getSignedIdentityKeysBlob: () => Promise, - +getInitialNotificationsEncryptedMessage: () => Promise, + +getInitialNotificationsEncryptedMessage: ( + keyserverID: string, + ) => Promise, }; const webGetClientResponsesSelector: ( @@ -66,12 +68,16 @@ calendarActive: boolean, oneTimeKeyGenerator: ?OneTimeKeyGenerator, getSignedIdentityKeysBlob: () => Promise, - getInitialNotificationsEncryptedMessage: () => Promise, + getInitialNotificationsEncryptedMessage: ( + keyserverID: string, + ) => Promise, serverRequests: $ReadOnlyArray, ) => Promise<$ReadOnlyArray>, getSignedIdentityKeysBlob: () => Promise, calendarActive: boolean, - getInitialNotificationsEncryptedMessage: () => Promise, + getInitialNotificationsEncryptedMessage: ( + keyserverID: string, + ) => Promise, ) => (serverRequests: $ReadOnlyArray) => getClientResponsesFunc(