diff --git a/package.json b/package.json index 127b90cd0f5..4314872c970 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "@peculiar/x509": "1.9.6", "@wireapp/avs": "9.6.9", "@wireapp/commons": "5.2.4", - "@wireapp/core": "43.7.1", + "@wireapp/core": "43.8.0", "@wireapp/react-ui-kit": "9.12.7", "@wireapp/store-engine-dexie": "2.1.7", "@wireapp/webapp-events": "0.20.1", diff --git a/src/script/E2EIdentity/E2EIdentityEnrollment.test.ts b/src/script/E2EIdentity/E2EIdentityEnrollment.test.ts index 03896280eab..00ad95b2f20 100644 --- a/src/script/E2EIdentity/E2EIdentityEnrollment.test.ts +++ b/src/script/E2EIdentity/E2EIdentityEnrollment.test.ts @@ -85,7 +85,7 @@ function wait(ms: number) { describe('E2EIHandler', () => { const params = {discoveryUrl: 'http://example.com', gracePeriodInSeconds: 30}; - const user = {name: () => 'John Doe', username: () => 'johndoe'}; + const user = {name: () => 'John Doe', username: () => 'johndoe', teamId: 'team'}; beforeEach(() => { jest.spyOn(util, 'supportsMLS').mockReturnValue(true); @@ -100,10 +100,8 @@ describe('E2EIHandler', () => { jest.spyOn(PrimaryModal, 'show'); - jest - .spyOn(container.resolve(UserState), 'self') - .mockReturnValue({name: () => 'John Doe', username: () => 'johndoe'}); - jest.spyOn(container.resolve(Core), 'enrollE2EI').mockResolvedValue(true); + jest.spyOn(container.resolve(UserState), 'self').mockReturnValue(user); + jest.spyOn(container.resolve(Core), 'enrollE2EI').mockResolvedValue({status: 'successful'}); container.resolve(Core).key = new Uint8Array(); }); @@ -128,11 +126,7 @@ describe('E2EIHandler', () => { }); it('should set currentStep to SUCCESS when enrollE2EI is called and enrollment succeeds', async () => { - jest - .spyOn(container.resolve(UserState), 'self') - .mockReturnValue({name: () => 'John Doe', username: () => 'johndoe'}); - - jest.spyOn(container.resolve(Core), 'enrollE2EI').mockResolvedValueOnce(true); + jest.spyOn(container.resolve(Core), 'enrollE2EI').mockResolvedValueOnce({status: 'successful'}); const instance = await E2EIHandler.getInstance().initialize(params); void instance['enroll'](); @@ -143,7 +137,6 @@ describe('E2EIHandler', () => { it('should set currentStep to ERROR when enrolE2EI is called and enrolment fails', async () => { // Mock the Core service to return an error jest.spyOn(container.resolve(Core), 'enrollE2EI').mockImplementationOnce(jest.fn(() => Promise.reject())); - jest.spyOn(container.resolve(UserState), 'self').mockImplementationOnce(() => user); const instance = await E2EIHandler.getInstance().initialize(params); void instance['enroll'](); @@ -180,7 +173,7 @@ describe('E2EIHandler', () => { }); it('should display success message when enrollment is done', async () => { - jest.spyOn(container.resolve(Core), 'enrollE2EI').mockResolvedValueOnce(true); + jest.spyOn(container.resolve(Core), 'enrollE2EI').mockResolvedValueOnce({status: 'successful'}); const handler = await E2EIHandler.getInstance().initialize(params); handler['showLoadingMessage'] = jest.fn(); diff --git a/src/script/E2EIdentity/E2EIdentityEnrollment.ts b/src/script/E2EIdentity/E2EIdentityEnrollment.ts index 865e0988a3c..ec1ee762978 100644 --- a/src/script/E2EIdentity/E2EIdentityEnrollment.ts +++ b/src/script/E2EIdentity/E2EIdentityEnrollment.ts @@ -18,7 +18,6 @@ */ import {TimeInMillis} from '@wireapp/commons/lib/util/TimeUtil'; -import {KeyAuth} from '@wireapp/core/lib/messagingProtocols/mls'; import {amplify} from 'amplify'; import {User} from 'oidc-client-ts'; import {container} from 'tsyringe'; @@ -74,7 +73,6 @@ export class E2EIHandler extends TypedEventEmitter { private config?: EnrollmentConfig; private currentStep: E2EIHandlerStep = E2EIHandlerStep.UNINITIALIZED; private oidcService?: OIDCService; - private isEnrollmentInProgress = false; private get coreE2EIService() { const e2eiService = this.core.service?.e2eIdentity; @@ -230,21 +228,6 @@ export class E2EIHandler extends TypedEventEmitter { return renewalDate; } - private async storeRedirectTargetAndRedirect( - targetURL: string, - keyAuth: KeyAuth, - challengeURL: string, - ): Promise { - try { - // store the target url in the persistent oidc service store, since the oidc service will be destroyed after the redirect - OIDCServiceStore.store.targetURL(targetURL); - this.oidcService = this.createOIDCService(); - await this.oidcService.authenticate(keyAuth, challengeURL); - } catch (error) { - this.logger.error('Failed to store redirect target and redirect', error); - } - } - /** * Used to clean the state/storage after a failed run */ @@ -262,10 +245,6 @@ export class E2EIHandler extends TypedEventEmitter { if (!this.config) { throw new Error('Trying to enroll for E2EI without initializing the E2EIHandler'); } - if (this.isEnrollmentInProgress) { - return; - } - this.isEnrollmentInProgress = true; try { // Notify user about E2EI enrolment in progress this.currentStep = E2EIHandlerStep.ENROLL; @@ -287,24 +266,26 @@ export class E2EIHandler extends TypedEventEmitter { const displayName = this.userState.self()?.name(); const handle = this.userState.self()?.username(); + const teamId = this.userState.self()?.teamId; // If the user has no username or handle, we cannot enroll - if (!displayName || !handle) { - throw new Error('Username or handle not found'); + if (!displayName || !handle || !teamId) { + throw new Error('Username, handle or teamId not found'); } - const data = await this.core.enrollE2EI({ + const enrollmentState = await this.core.enrollE2EI({ discoveryUrl: this.config.discoveryUrl, displayName, handle, + teamId, oAuthIdToken, }); // If the data is false or we dont get the ACMEChallenge, enrolment failed - if (!data) { - throw new Error('E2EI enrolment failed'); - } - // Check if the data is a boolean, if not, we need to handle the oauth redirect - if (typeof data !== 'boolean') { - await this.storeRedirectTargetAndRedirect(data.challenge.target, data.keyAuth, data.challenge.url); + if (enrollmentState.status === 'authentication') { + // If the data is authentication flow data, we need to kick off the oauth flow to get an oauth token + const {challenge, keyAuth} = enrollmentState.authenticationChallenge; + OIDCServiceStore.store.targetURL(challenge.target); + this.oidcService = this.createOIDCService(); + await this.oidcService.authenticate(keyAuth, challenge.url); } // Notify user about E2EI enrolment success @@ -322,8 +303,6 @@ export class E2EIHandler extends TypedEventEmitter { setTimeout(removeCurrentModal, 0); await this.showErrorMessage(); - } finally { - this.isEnrollmentInProgress = false; } } diff --git a/yarn.lock b/yarn.lock index ccbb4f8c589..9a20e17f3c9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4812,9 +4812,9 @@ __metadata: languageName: node linkType: hard -"@wireapp/api-client@npm:^26.10.0": - version: 26.10.0 - resolution: "@wireapp/api-client@npm:26.10.0" +"@wireapp/api-client@npm:^26.10.1": + version: 26.10.1 + resolution: "@wireapp/api-client@npm:26.10.1" dependencies: "@wireapp/commons": ^5.2.4 "@wireapp/priority-queue": ^2.1.4 @@ -4830,7 +4830,7 @@ __metadata: tough-cookie: 4.1.3 ws: 8.16.0 zod: 3.22.4 - checksum: 9023270f8688887a1adef7188e8889e243a3fd3171576a988c79cbb3a2fdbb50541fd32be3b6dee91b4126f299df81cbd2773c410dde378fa96c74e1b06ce42e + checksum: 896affd13be653b7dfe1bf67b028c32f91b03ce446da0e5019e50a8524532cb31c8c6d06b46927bea379a0ddf6b5f12f68f7d29e5ecda6445bfcd8f435472802 languageName: node linkType: hard @@ -4876,20 +4876,20 @@ __metadata: languageName: node linkType: hard -"@wireapp/core-crypto@npm:1.0.0-rc.30": - version: 1.0.0-rc.30 - resolution: "@wireapp/core-crypto@npm:1.0.0-rc.30" - checksum: 3787dd855cc091a63d526e73fe289a1ba93742cd159895f70c08e3e2537b8055754fb49881105b2a20e35695cd223c383fbc7af1585262a3acd599aad53d050d +"@wireapp/core-crypto@npm:1.0.0-rc.31": + version: 1.0.0-rc.31 + resolution: "@wireapp/core-crypto@npm:1.0.0-rc.31" + checksum: c869b324957f5dfdbbb98789f5eebf73f51d759539bfb75a0e0adaeda8897ba71c9a218d7d5a2dfda88f8ea9b2f0c3e83905caf6680f63c4d64cb9839249649d languageName: node linkType: hard -"@wireapp/core@npm:43.7.1": - version: 43.7.1 - resolution: "@wireapp/core@npm:43.7.1" +"@wireapp/core@npm:43.8.0": + version: 43.8.0 + resolution: "@wireapp/core@npm:43.8.0" dependencies: - "@wireapp/api-client": ^26.10.0 + "@wireapp/api-client": ^26.10.1 "@wireapp/commons": ^5.2.4 - "@wireapp/core-crypto": 1.0.0-rc.30 + "@wireapp/core-crypto": 1.0.0-rc.31 "@wireapp/cryptobox": 12.8.0 "@wireapp/promise-queue": ^2.2.9 "@wireapp/protocol-messaging": 1.44.0 @@ -4905,7 +4905,7 @@ __metadata: long: ^5.2.0 uuidjs: 4.2.13 zod: 3.22.4 - checksum: e143f09d5106d98f40bcd1e66b77baac4ea6be1321c3a96e2d541340ba56f704a99b13a30a7d28861d2c5a1e1eaeccadc74f26ed7af8f56e577500cc0413b532 + checksum: 50bd4821ee983a96dd8ce84d39400e07975f99b35138502d6772daa7b69a91c4b3e2bd9c5023e00d91b62e45b1e4ac8f84a10416cdb634e669ea527cef4f2a35 languageName: node linkType: hard @@ -17602,7 +17602,7 @@ __metadata: "@wireapp/avs": 9.6.9 "@wireapp/commons": 5.2.4 "@wireapp/copy-config": 2.1.14 - "@wireapp/core": 43.7.1 + "@wireapp/core": 43.8.0 "@wireapp/eslint-config": 3.0.5 "@wireapp/prettier-config": 0.6.3 "@wireapp/react-ui-kit": 9.12.7