Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade CoreCrypto to rc31 #16598

Merged
merged 3 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
17 changes: 5 additions & 12 deletions src/script/E2EIdentity/E2EIdentityEnrollment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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();
});

Expand All @@ -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']();
Expand All @@ -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']();
Expand Down Expand Up @@ -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();
Expand Down
43 changes: 11 additions & 32 deletions src/script/E2EIdentity/E2EIdentityEnrollment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -74,7 +73,6 @@ export class E2EIHandler extends TypedEventEmitter<Events> {
private config?: EnrollmentConfig;
private currentStep: E2EIHandlerStep = E2EIHandlerStep.UNINITIALIZED;
private oidcService?: OIDCService;
private isEnrollmentInProgress = false;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is breaking the softLock feature as, under certain condition, we could let the app fully load before enrolling


private get coreE2EIService() {
const e2eiService = this.core.service?.e2eIdentity;
Expand Down Expand Up @@ -230,21 +228,6 @@ export class E2EIHandler extends TypedEventEmitter<Events> {
return renewalDate;
}

private async storeRedirectTargetAndRedirect(
targetURL: string,
keyAuth: KeyAuth,
challengeURL: string,
): Promise<void> {
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
*/
Expand All @@ -262,10 +245,6 @@ export class E2EIHandler extends TypedEventEmitter<Events> {
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;
Expand All @@ -287,24 +266,26 @@ export class E2EIHandler extends TypedEventEmitter<Events> {

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
Expand All @@ -322,8 +303,6 @@ export class E2EIHandler extends TypedEventEmitter<Events> {

setTimeout(removeCurrentModal, 0);
await this.showErrorMessage();
} finally {
this.isEnrollmentInProgress = false;
}
}

Expand Down
30 changes: 15 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
Loading