mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-11 18:24:43 +02:00
Desktop: Improved master password state handling in Encryption screen
This commit is contained in:
parent
8d09ed3bac
commit
7d62df8906
@ -5,7 +5,7 @@ import { _ } from '@joplin/lib/locale';
|
|||||||
import time from '@joplin/lib/time';
|
import time from '@joplin/lib/time';
|
||||||
import shim from '@joplin/lib/shim';
|
import shim from '@joplin/lib/shim';
|
||||||
import dialogs from '../dialogs';
|
import dialogs from '../dialogs';
|
||||||
import { decryptedStatText, dontReencryptData, enableEncryptionConfirmationMessages, onSavePasswordClick, onToggleEnabledClick, reencryptData, upgradeMasterKey, useInputPasswords, usePasswordChecker, useStats, useToggleShowDisabledMasterKeys } from '@joplin/lib/components/EncryptionConfigScreen/utils';
|
import { decryptedStatText, dontReencryptData, enableEncryptionConfirmationMessages, onSavePasswordClick, onToggleEnabledClick, reencryptData, upgradeMasterKey, useInputPasswords, useNeedMasterPassword, usePasswordChecker, useStats, useToggleShowDisabledMasterKeys } from '@joplin/lib/components/EncryptionConfigScreen/utils';
|
||||||
import { MasterKeyEntity } from '@joplin/lib/services/e2ee/types';
|
import { MasterKeyEntity } from '@joplin/lib/services/e2ee/types';
|
||||||
import { getEncryptionEnabled, masterKeyEnabled, SyncInfo } from '@joplin/lib/services/synchronizer/syncInfoUtils';
|
import { getEncryptionEnabled, masterKeyEnabled, SyncInfo } from '@joplin/lib/services/synchronizer/syncInfoUtils';
|
||||||
import { getDefaultMasterKey, getMasterPasswordStatusMessage, masterPasswordIsValid, toggleAndSetupEncryption } from '@joplin/lib/services/e2ee/utils';
|
import { getDefaultMasterKey, getMasterPasswordStatusMessage, masterPasswordIsValid, toggleAndSetupEncryption } from '@joplin/lib/services/e2ee/utils';
|
||||||
@ -39,6 +39,7 @@ const EncryptionConfigScreen = (props: Props) => {
|
|||||||
const stats = useStats();
|
const stats = useStats();
|
||||||
const { passwordChecks, masterPasswordKeys, masterPasswordStatus } = usePasswordChecker(props.masterKeys, props.activeMasterKeyId, props.masterPassword, props.passwords);
|
const { passwordChecks, masterPasswordKeys, masterPasswordStatus } = usePasswordChecker(props.masterKeys, props.activeMasterKeyId, props.masterPassword, props.passwords);
|
||||||
const { showDisabledMasterKeys, toggleShowDisabledMasterKeys } = useToggleShowDisabledMasterKeys();
|
const { showDisabledMasterKeys, toggleShowDisabledMasterKeys } = useToggleShowDisabledMasterKeys();
|
||||||
|
const needMasterPassword = useNeedMasterPassword(passwordChecks, props.masterKeys);
|
||||||
|
|
||||||
const onUpgradeMasterKey = useCallback((mk: MasterKeyEntity) => {
|
const onUpgradeMasterKey = useCallback((mk: MasterKeyEntity) => {
|
||||||
void upgradeMasterKey(mk, passwordChecks, props.passwords);
|
void upgradeMasterKey(mk, passwordChecks, props.passwords);
|
||||||
@ -263,9 +264,8 @@ const EncryptionConfigScreen = (props: Props) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const buttonTitle = CommandService.instance().label('openMasterPasswordDialog');
|
const buttonTitle = CommandService.instance().label('openMasterPasswordDialog');
|
||||||
const needPassword = Object.values(passwordChecks).includes(false);
|
|
||||||
|
|
||||||
const needPasswordMessage = !needPassword ? null : (
|
const needPasswordMessage = !needMasterPassword ? null : (
|
||||||
<p className="needpassword">{_('Your master password is needed to decrypt some of your data.')}<br/>{_('Please click on "%s" to proceed', buttonTitle)}</p>
|
<p className="needpassword">{_('Your master password is needed to decrypt some of your data.')}<br/>{_('Please click on "%s" to proceed', buttonTitle)}</p>
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -275,7 +275,7 @@ const EncryptionConfigScreen = (props: Props) => {
|
|||||||
<h2>{_('Master password')}</h2>
|
<h2>{_('Master password')}</h2>
|
||||||
<p className="status"><span>{_('Master password:')}</span> <span className="bold">{getMasterPasswordStatusMessage(masterPasswordStatus)}</span></p>
|
<p className="status"><span>{_('Master password:')}</span> <span className="bold">{getMasterPasswordStatusMessage(masterPasswordStatus)}</span></p>
|
||||||
{needPasswordMessage}
|
{needPasswordMessage}
|
||||||
<Button className="managebutton" level={needPassword ? ButtonLevel.Primary : ButtonLevel.Secondary} onClick={onManageMasterPassword} title={buttonTitle} />
|
<Button className="managebutton" level={needMasterPassword ? ButtonLevel.Primary : ButtonLevel.Secondary} onClick={onManageMasterPassword} title={buttonTitle} />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -146,6 +146,7 @@ export default function(props: Props) {
|
|||||||
|
|
||||||
const renderResetMasterPasswordLink = () => {
|
const renderResetMasterPasswordLink = () => {
|
||||||
if (mode === Mode.Reset) return null;
|
if (mode === Mode.Reset) return null;
|
||||||
|
if (status === MasterPasswordStatus.Valid) return null;
|
||||||
return <p><a href="#" onClick={onToggleMode}>Reset master password</a></p>;
|
return <p><a href="#" onClick={onToggleMode}>Reset master password</a></p>;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -188,6 +188,16 @@ export const usePasswordChecker = (masterKeys: MasterKeyEntity[], activeMasterKe
|
|||||||
return { passwordChecks, masterPasswordKeys, masterPasswordStatus };
|
return { passwordChecks, masterPasswordKeys, masterPasswordStatus };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useNeedMasterPassword = (passwordChecks: PasswordChecks, masterKeys: MasterKeyEntity[]) => {
|
||||||
|
for (const [mkId, valid] of Object.entries(passwordChecks)) {
|
||||||
|
const mk = masterKeys.find(mk => mk.id === mkId);
|
||||||
|
if (!mk) continue;
|
||||||
|
if (!masterKeyEnabled(mk)) continue;
|
||||||
|
if (!valid) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
export const upgradeMasterKey = async (masterKey: MasterKeyEntity, passwordChecks: PasswordChecks, passwords: Record<string, string>): Promise<string> => {
|
export const upgradeMasterKey = async (masterKey: MasterKeyEntity, passwordChecks: PasswordChecks, passwords: Record<string, string>): Promise<string> => {
|
||||||
const passwordCheck = passwordChecks[masterKey.id];
|
const passwordCheck = passwordChecks[masterKey.id];
|
||||||
if (!passwordCheck) {
|
if (!passwordCheck) {
|
||||||
|
Loading…
Reference in New Issue
Block a user