Skip to content

Commit

Permalink
Merge pull request #1010 from Onlineberatung/fix/OB-10087-reset-pw-fa…
Browse files Browse the repository at this point in the history
…il-pick

Fix/ob 10087 reset pw fail pick
  • Loading branch information
web-mi authored Feb 23, 2024
2 parents c75a6da + efdfbf4 commit 22afeb7
Showing 1 changed file with 26 additions and 32 deletions.
58 changes: 26 additions & 32 deletions src/components/passwordReset/PasswordReset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { apiRocketChatSetUserKeys } from '../../api/apiRocketChatSetUserKeys';
import { getValueFromCookie } from '../sessionCookie/accessSessionCookie';
import {
AUTHORITIES,
E2EEContext,
hasUserAuthority,
UserDataContext
} from '../../globalState';
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -213,25 +210,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 &&
Expand All @@ -244,17 +241,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(
Expand Down Expand Up @@ -334,7 +328,7 @@ export const PasswordReset = () => {
</div>
</div>

{isE2eeEnabled && hasMasterKeyError && (
{hasMasterKeyError && (
<div className="passwordReset__error">
{translate('profile.functions.masterKey.saveError')}
</div>
Expand Down

0 comments on commit 22afeb7

Please sign in to comment.