Merge pull request #3143 from yougotwill/fix/ses-2519/set_password_without_restart

pull/3144/head
Will G 9 months ago committed by GitHub
commit 35ae0b9be4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -69,8 +69,9 @@
"changeNicknameMessage": "Enter a nickname for this user", "changeNicknameMessage": "Enter a nickname for this user",
"changePassword": "Change Password", "changePassword": "Change Password",
"changePasswordInvalid": "The old password you entered is incorrect", "changePasswordInvalid": "The old password you entered is incorrect",
"changePasswordFail": "Failed to change password",
"changePasswordTitle": "Password Changed", "changePasswordTitle": "Password Changed",
"changePasswordToastDescription": "Your password has been changed. Please keep it safe and restart Session.", "changePasswordToastDescription": "Your password has been changed. Please keep it safe.",
"chooseAnAction": "Choose an action to start a conversation", "chooseAnAction": "Choose an action to start a conversation",
"classicDarkThemeTitle": "Classic Dark", "classicDarkThemeTitle": "Classic Dark",
"classicLightThemeTitle": "Classic Light", "classicLightThemeTitle": "Classic Light",
@ -442,8 +443,9 @@
"removeModerators": "Remove Admins", "removeModerators": "Remove Admins",
"removePassword": "Remove Password", "removePassword": "Remove Password",
"removePasswordInvalid": "Incorrect password", "removePasswordInvalid": "Incorrect password",
"removePasswordFail": "Failed to remove password",
"removePasswordTitle": "Password Removed", "removePasswordTitle": "Password Removed",
"removePasswordToastDescription": "Your password has been removed. Please restart Session.", "removePasswordToastDescription": "Your password has been removed.",
"removeResidueMembers": "Clicking ok will also remove those members as they left the group.", "removeResidueMembers": "Clicking ok will also remove those members as they left the group.",
"replyingToMessage": "Replying to:", "replyingToMessage": "Replying to:",
"replyToMessage": "Reply", "replyToMessage": "Reply",
@ -480,7 +482,7 @@
"setPasswordFail": "Failed to set password", "setPasswordFail": "Failed to set password",
"setPasswordInvalid": "Passwords do not match", "setPasswordInvalid": "Passwords do not match",
"setPasswordTitle": "Password Set", "setPasswordTitle": "Password Set",
"setPasswordToastDescription": "Your password has been set. Please keep it safe and restart Session", "setPasswordToastDescription": "Your password has been set. Please keep it safe.",
"settingAppliesToEveryone": "This setting applies to everyone in this conversation.", "settingAppliesToEveryone": "This setting applies to everyone in this conversation.",
"settingAppliesToYourMessages": "This setting applies to messages you send in this conversation.", "settingAppliesToYourMessages": "This setting applies to messages you send in this conversation.",
"settingsHeader": "Settings", "settingsHeader": "Settings",

@ -63,13 +63,11 @@ window.setZoomFactor = number => {
// Set the password for the database // Set the password for the database
window.setPassword = async (passPhrase, oldPhrase) => window.setPassword = async (passPhrase, oldPhrase) =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
ipc.once('set-password-response', (_event, error) => { ipc.once('set-password-response', (_event, response) => {
if (error) { if (!response) {
reject(error); return reject('window.setPassword: No response from main process');
return;
} }
resolve(undefined); return resolve(response);
return;
}); });
ipc.send('set-password', passPhrase, oldPhrase); ipc.send('set-password', passPhrase, oldPhrase);
}); });

@ -8,7 +8,7 @@ import { LocalizerKeys } from '../../types/LocalizerKeys';
import type { PasswordAction } from '../../types/ReduxTypes'; import type { PasswordAction } from '../../types/ReduxTypes';
import { assertUnreachable } from '../../types/sqlSharedTypes'; import { assertUnreachable } from '../../types/sqlSharedTypes';
import { matchesHash, validatePassword } from '../../util/passwordUtils'; import { matchesHash, validatePassword } from '../../util/passwordUtils';
import { getPasswordHash } from '../../util/storage'; import { getPasswordHash, Storage } from '../../util/storage';
import { SessionWrapperModal } from '../SessionWrapperModal'; import { SessionWrapperModal } from '../SessionWrapperModal';
import { SessionButton, SessionButtonColor, SessionButtonType } from '../basic/SessionButton'; import { SessionButton, SessionButtonColor, SessionButtonType } from '../basic/SessionButton';
import { SpacerSM } from '../basic/Text'; import { SpacerSM } from '../basic/Text';
@ -193,15 +193,25 @@ export class SessionSetPasswordDialog extends Component<Props, State> {
this.showError(); this.showError();
return; return;
} }
await window.setPassword(enteredPassword, null); try {
ToastUtils.pushToastSuccess( const updatedHash = await window.setPassword(enteredPassword, null);
'setPasswordSuccessToast', await Storage.put('passHash', updatedHash);
window.i18n('setPasswordTitle'),
window.i18n('setPasswordToastDescription') ToastUtils.pushToastSuccess(
); 'setPasswordSuccessToast',
window.i18n('setPasswordTitle'),
this.props.onOk(); window.i18n('setPasswordToastDescription')
this.closeDialog(); );
this.props.onOk();
this.closeDialog();
} catch (err) {
window.log.error(err);
this.setState({
error: window.i18n('setPasswordFail'),
});
this.showError();
}
} }
private async handleActionChange( private async handleActionChange(
@ -232,16 +242,26 @@ export class SessionSetPasswordDialog extends Component<Props, State> {
this.showError(); this.showError();
return; return;
} }
await window.setPassword(newPassword, oldPassword);
ToastUtils.pushToastSuccess( try {
'setPasswordSuccessToast', const updatedHash = await window.setPassword(newPassword, oldPassword);
window.i18n('changePasswordTitle'), await Storage.put('passHash', updatedHash);
window.i18n('changePasswordToastDescription')
);
this.props.onOk(); ToastUtils.pushToastSuccess(
this.closeDialog(); 'setPasswordSuccessToast',
window.i18n('changePasswordTitle'),
window.i18n('changePasswordToastDescription')
);
this.props.onOk();
this.closeDialog();
} catch (err) {
window.log.error(err);
this.setState({
error: window.i18n('changePasswordFail'),
});
this.showError();
}
} }
private async handleActionRemove(oldPassword: string) { private async handleActionRemove(oldPassword: string) {
@ -254,16 +274,26 @@ export class SessionSetPasswordDialog extends Component<Props, State> {
this.showError(); this.showError();
return; return;
} }
await window.setPassword(null, oldPassword);
ToastUtils.pushToastWarning( try {
'setPasswordSuccessToast', await window.setPassword(null, oldPassword);
window.i18n('removePasswordTitle'), await Storage.remove('passHash');
window.i18n('removePasswordToastDescription')
);
this.props.onOk(); ToastUtils.pushToastWarning(
this.closeDialog(); 'setPasswordSuccessToast',
window.i18n('removePasswordTitle'),
window.i18n('removePasswordToastDescription')
);
this.props.onOk();
this.closeDialog();
} catch (err) {
window.log.error(err);
this.setState({
error: window.i18n('removePasswordFail'),
});
this.showError();
}
} }
private async onEnterPressed(event: any) { private async onEnterPressed(event: any) {

@ -113,6 +113,7 @@ export const SettingsCategoryPrivacy = (props: {
description={window.i18n('setAccountPasswordDescription')} description={window.i18n('setAccountPasswordDescription')}
onClick={() => { onClick={() => {
displayPasswordModal('set', props.onPasswordUpdated); displayPasswordModal('set', props.onPasswordUpdated);
forceUpdate();
}} }}
buttonText={window.i18n('setPassword')} buttonText={window.i18n('setPassword')}
dataTestId={'set-password-button'} dataTestId={'set-password-button'}
@ -125,6 +126,7 @@ export const SettingsCategoryPrivacy = (props: {
description={window.i18n('changeAccountPasswordDescription')} description={window.i18n('changeAccountPasswordDescription')}
onClick={() => { onClick={() => {
displayPasswordModal('change', props.onPasswordUpdated); displayPasswordModal('change', props.onPasswordUpdated);
forceUpdate();
}} }}
buttonText={window.i18n('changePassword')} buttonText={window.i18n('changePassword')}
dataTestId="change-password-settings-button" dataTestId="change-password-settings-button"
@ -134,6 +136,7 @@ export const SettingsCategoryPrivacy = (props: {
description={window.i18n('removeAccountPasswordDescription')} description={window.i18n('removeAccountPasswordDescription')}
onClick={() => { onClick={() => {
displayPasswordModal('remove', props.onPasswordUpdated); displayPasswordModal('remove', props.onPasswordUpdated);
forceUpdate();
}} }}
buttonColor={SessionButtonColor.Danger} buttonColor={SessionButtonColor.Danger}
buttonText={window.i18n('removePassword')} buttonText={window.i18n('removePassword')}

@ -1064,13 +1064,15 @@ ipc.on('set-password', async (event, passPhrase, oldPhrase) => {
sqlNode.setSQLPassword(defaultKey); sqlNode.setSQLPassword(defaultKey);
sqlNode.removePasswordHash(); sqlNode.removePasswordHash();
userConfig.set('dbHasPassword', false); userConfig.set('dbHasPassword', false);
sendResponse(undefined);
} else { } else {
sqlNode.setSQLPassword(passPhrase); sqlNode.setSQLPassword(passPhrase);
const newHash = PasswordUtil.generateHash(passPhrase); const newHash = PasswordUtil.generateHash(passPhrase);
sqlNode.savePasswordHash(newHash); sqlNode.savePasswordHash(newHash);
const updatedHash = sqlNode.getPasswordHash();
userConfig.set('dbHasPassword', true); userConfig.set('dbHasPassword', true);
sendResponse(updatedHash);
} }
sendResponse(undefined);
} catch (e) { } catch (e) {
const localisedError = locale.messages.setPasswordFail; const localisedError = locale.messages.setPasswordFail;
sendResponse(localisedError || 'Failed to set password'); sendResponse(localisedError || 'Failed to set password');

@ -253,6 +253,7 @@ function getPasswordHash() {
const item = getItemById(PASS_HASH_ID); const item = getItemById(PASS_HASH_ID);
return item && item.value; return item && item.value;
} }
function savePasswordHash(hash: string) { function savePasswordHash(hash: string) {
if (isEmpty(hash)) { if (isEmpty(hash)) {
removePasswordHash(); removePasswordHash();
@ -262,6 +263,7 @@ function savePasswordHash(hash: string) {
const data = { id: PASS_HASH_ID, value: hash }; const data = { id: PASS_HASH_ID, value: hash };
createOrUpdateItem(data); createOrUpdateItem(data);
} }
function removePasswordHash() { function removePasswordHash() {
removeItemById(PASS_HASH_ID); removeItemById(PASS_HASH_ID);
} }

@ -68,6 +68,7 @@ export type LocalizerKeys =
| 'changeNickname' | 'changeNickname'
| 'changeNicknameMessage' | 'changeNicknameMessage'
| 'changePassword' | 'changePassword'
| 'changePasswordFail'
| 'changePasswordInvalid' | 'changePasswordInvalid'
| 'changePasswordTitle' | 'changePasswordTitle'
| 'changePasswordToastDescription' | 'changePasswordToastDescription'
@ -441,6 +442,7 @@ export type LocalizerKeys =
| 'removeFromModerators' | 'removeFromModerators'
| 'removeModerators' | 'removeModerators'
| 'removePassword' | 'removePassword'
| 'removePasswordFail'
| 'removePasswordInvalid' | 'removePasswordInvalid'
| 'removePasswordTitle' | 'removePasswordTitle'
| 'removePasswordToastDescription' | 'removePasswordToastDescription'

2
ts/window.d.ts vendored

@ -47,7 +47,7 @@ declare global {
persistStore?: Persistor; persistStore?: Persistor;
restart: () => void; restart: () => void;
getSeedNodeList: () => Array<string> | undefined; getSeedNodeList: () => Array<string> | undefined;
setPassword: (newPassword: string | null, oldPassword: string | null) => Promise<void>; setPassword: (newPassword: string | null, oldPassword: string | null) => Promise<string>;
isOnline: boolean; isOnline: boolean;
toggleMediaPermissions: () => Promise<void>; toggleMediaPermissions: () => Promise<void>;
toggleCallMediaPermissionsTo: (enabled: boolean) => Promise<void>; toggleCallMediaPermissionsTo: (enabled: boolean) => Promise<void>;

Loading…
Cancel
Save