diff --git a/web/crypto/opaque-utils.js b/web/crypto/opaque-utils.js --- a/web/crypto/opaque-utils.js +++ b/web/crypto/opaque-utils.js @@ -6,12 +6,13 @@ let opaqueKeLoadingState: void | true | Promise; -function initOpaque(): Promise { +function initOpaque(overrideOpaqueURL?: ?string): Promise { + const finalOpaqueURL = overrideOpaqueURL ?? opaqueURL; if (opaqueKeLoadingState === true) { return Promise.resolve(); } if (!opaqueKeLoadingState) { - opaqueKeLoadingState = initOpaqueKe(opaqueURL); + opaqueKeLoadingState = initOpaqueKe(finalOpaqueURL); } return opaqueKeLoadingState; } diff --git a/web/grpc/identity-service-client-wrapper.js b/web/grpc/identity-service-client-wrapper.js --- a/web/grpc/identity-service-client-wrapper.js +++ b/web/grpc/identity-service-client-wrapper.js @@ -7,6 +7,7 @@ OneTimeKeysResultValues, SignedPrekeys, } from 'lib/types/crypto-types.js'; +import type { PlatformDetails } from 'lib/types/device-types.js'; import { type IdentityServiceAuthLayer, type IdentityServiceClient, @@ -41,19 +42,26 @@ import * as IdentityUnauthClient from '../protobufs/identity-unauth.cjs'; class IdentityServiceClientWrapper implements IdentityServiceClient { + overridedOpaqueFilepath: ?string; authClient: ?IdentityAuthClient.IdentityClientServicePromiseClient; unauthClient: IdentityUnauthClient.IdentityClientServicePromiseClient; getDeviceKeyUpload: () => Promise; constructor( + platformDetails: PlatformDetails, + overridedOpaqueFilepath: ?string, authLayer: ?IdentityServiceAuthLayer, getDeviceKeyUpload: () => Promise, ) { + this.overridedOpaqueFilepath = overridedOpaqueFilepath; if (authLayer) { - this.authClient = - IdentityServiceClientWrapper.createAuthClient(authLayer); + this.authClient = IdentityServiceClientWrapper.createAuthClient( + platformDetails, + authLayer, + ); } - this.unauthClient = IdentityServiceClientWrapper.createUnauthClient(); + this.unauthClient = + IdentityServiceClientWrapper.createUnauthClient(platformDetails); this.getDeviceKeyUpload = getDeviceKeyUpload; } @@ -62,6 +70,7 @@ } static createAuthClient( + platformDetails: PlatformDetails, authLayer: IdentityServiceAuthLayer, ): IdentityAuthClient.IdentityClientServicePromiseClient { const { userID, deviceID, commServicesAccessToken } = authLayer; @@ -69,7 +78,9 @@ const identitySocketAddr = IdentityServiceClientWrapper.determineSocketAddr(); - const versionInterceptor = new VersionInterceptor(); + const versionInterceptor = new VersionInterceptor( + platformDetails, + ); const authInterceptor = new AuthInterceptor( userID, deviceID, @@ -87,11 +98,15 @@ ); } - static createUnauthClient(): IdentityUnauthClient.IdentityClientServicePromiseClient { + static createUnauthClient( + platformDetails: PlatformDetails, + ): IdentityUnauthClient.IdentityClientServicePromiseClient { const identitySocketAddr = IdentityServiceClientWrapper.determineSocketAddr(); - const versionInterceptor = new VersionInterceptor(); + const versionInterceptor = new VersionInterceptor( + platformDetails, + ); const unauthClientOpts = { unaryInterceptors: [versionInterceptor], @@ -329,7 +344,7 @@ const [identityDeviceKeyUpload] = await Promise.all([ this.getDeviceKeyUpload(), - initOpaque(), + initOpaque(this.overridedOpaqueFilepath), ]); const opaqueLogin = new Login(); diff --git a/web/grpc/identity-service-context-provider.react.js b/web/grpc/identity-service-context-provider.react.js --- a/web/grpc/identity-service-context-provider.react.js +++ b/web/grpc/identity-service-context-provider.react.js @@ -6,6 +6,7 @@ IdentityClientContext, type AuthMetadata, } from 'lib/shared/identity-client-context.js'; +import { getConfig } from 'lib/utils/config.js'; import { IdentityServiceClientWrapper } from './identity-service-client-wrapper.js'; import { useGetDeviceKeyUpload } from '../account/account-hooks.js'; @@ -33,7 +34,12 @@ commServicesAccessToken: accessToken, }; } - return new IdentityServiceClientWrapper(authLayer, getDeviceKeyUpload); + return new IdentityServiceClientWrapper( + getConfig().platformDetails, + null, + authLayer, + getDeviceKeyUpload, + ); }, [accessToken, deviceID, getDeviceKeyUpload, userID]); const getAuthMetadata = React.useCallback<() => Promise>( diff --git a/web/grpc/interceptor.js b/web/grpc/interceptor.js --- a/web/grpc/interceptor.js +++ b/web/grpc/interceptor.js @@ -2,9 +2,15 @@ import * as grpcWeb from 'grpc-web'; -import { getConfig } from 'lib/utils/config.js'; +import type { PlatformDetails } from 'lib/types/device-types.js'; class VersionInterceptor { + platformDetails: PlatformDetails; + + constructor(platformDetails: PlatformDetails) { + this.platformDetails = platformDetails; + } + intercept( request: grpcWeb.Request, invoker: ( @@ -12,9 +18,8 @@ ) => Promise>, ): Promise> { const metadata = request.getMetadata(); - const config = getConfig(); - const codeVersion = config.platformDetails.codeVersion; - const deviceType = config.platformDetails.platform; + const codeVersion = this.platformDetails.codeVersion; + const deviceType = this.platformDetails.platform; if (codeVersion) { metadata['code_version'] = codeVersion.toString(); }