From 7e808dccb0d24e55d5dbfbf186110139deb9b49d Mon Sep 17 00:00:00 2001 From: janrembold Date: Fri, 23 Feb 2024 11:54:51 +0100 Subject: [PATCH 1/2] fix: remove e2eeEnabled check --- .../passwordReset/PasswordReset.tsx | 53 +++++++++---------- 1 file changed, 25 insertions(+), 28 deletions(-) diff --git a/src/components/passwordReset/PasswordReset.tsx b/src/components/passwordReset/PasswordReset.tsx index e8317c5b2..5e3ee0e95 100644 --- a/src/components/passwordReset/PasswordReset.tsx +++ b/src/components/passwordReset/PasswordReset.tsx @@ -213,25 +213,25 @@ export const PasswordReset = () => { apiUpdatePassword(oldPassword, newPassword) .then(async () => { try { - if (isE2eeEnabled) { - // create new masterkey from newPassword - const newMasterKey = - await deriveMasterKeyFromPassword( - rcUid, - newPassword - ); - // encrypt private key with new masterkey - const encryptedPrivateKey = await encryptPrivateKey( - sessionStorage.getItem('private_key'), - newMasterKey - ); - // save with rocket chat - await apiRocketChatSetUserKeys( - sessionStorage.getItem('public_key'), - encryptedPrivateKey - ); - } - // TODO Update masterkey in localstorage same logic as autoLogin + // always execute reset logic to ensure master key is updated even if E2ee is enabled or not + + // create new masterkey from newPassword + const newMasterKey = await deriveMasterKeyFromPassword( + rcUid, + newPassword + ); + + // encrypt private key with new masterkey + const encryptedPrivateKey = await encryptPrivateKey( + sessionStorage.getItem('private_key'), + newMasterKey + ); + + // save with rocket chat + await apiRocketChatSetUserKeys( + sessionStorage.getItem('public_key'), + encryptedPrivateKey + ); isConsultant && featureAppointmentsEnabled && @@ -244,17 +244,14 @@ export const PasswordReset = () => { setIsRequestInProgress(false); logout(false, settings.urls.toLogin); } catch (e) { - if (isE2eeEnabled) { - // rechange password to the old password - await apiUpdatePassword( - newPassword, - oldPassword - ).catch(() => { + // rechange password to the old password + await apiUpdatePassword(newPassword, oldPassword).catch( + () => { // if an error happens here we keep the newPassword but don't upgrade the masterKey // and hope it works next login attempt - }); - setHasMasterKeyError(true); - } + } + ); + setHasMasterKeyError(true); featureAppointmentsEnabled && apiUpdatePasswordAppointments( From 78d016e44aa2d20e0e60dd12a49d84f300842b2e Mon Sep 17 00:00:00 2001 From: janrembold Date: Fri, 23 Feb 2024 12:02:20 +0100 Subject: [PATCH 2/2] fix: remove all flags --- src/components/passwordReset/PasswordReset.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/components/passwordReset/PasswordReset.tsx b/src/components/passwordReset/PasswordReset.tsx index 5e3ee0e95..0f6923604 100644 --- a/src/components/passwordReset/PasswordReset.tsx +++ b/src/components/passwordReset/PasswordReset.tsx @@ -21,7 +21,6 @@ import { apiRocketChatSetUserKeys } from '../../api/apiRocketChatSetUserKeys'; import { getValueFromCookie } from '../sessionCookie/accessSessionCookie'; import { AUTHORITIES, - E2EEContext, hasUserAuthority, UserDataContext } from '../../globalState'; @@ -60,8 +59,6 @@ export const PasswordReset = () => { const [overlayActive, setOverlayActive] = useState(false); const [isRequestInProgress, setIsRequestInProgress] = useState(false); - const { isE2eeEnabled } = useContext(E2EEContext); - const overlayItem: OverlayItem = { svg: CheckIcon, headline: translate( @@ -331,7 +328,7 @@ export const PasswordReset = () => { - {isE2eeEnabled && hasMasterKeyError && ( + {hasMasterKeyError && (
{translate('profile.functions.masterKey.saveError')}