diff --git a/packages/app-desktop/gui/EncryptionConfigScreen/EncryptionConfigScreen.tsx b/packages/app-desktop/gui/EncryptionConfigScreen/EncryptionConfigScreen.tsx index 3fa39cff8..8fd628e14 100644 --- a/packages/app-desktop/gui/EncryptionConfigScreen/EncryptionConfigScreen.tsx +++ b/packages/app-desktop/gui/EncryptionConfigScreen/EncryptionConfigScreen.tsx @@ -5,7 +5,7 @@ import { _ } from '@joplin/lib/locale'; import time from '@joplin/lib/time'; import shim from '@joplin/lib/shim'; 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 { getEncryptionEnabled, masterKeyEnabled, SyncInfo } from '@joplin/lib/services/synchronizer/syncInfoUtils'; import { getDefaultMasterKey, getMasterPasswordStatusMessage, masterPasswordIsValid, toggleAndSetupEncryption } from '@joplin/lib/services/e2ee/utils'; @@ -39,6 +39,7 @@ const EncryptionConfigScreen = (props: Props) => { const stats = useStats(); const { passwordChecks, masterPasswordKeys, masterPasswordStatus } = usePasswordChecker(props.masterKeys, props.activeMasterKeyId, props.masterPassword, props.passwords); const { showDisabledMasterKeys, toggleShowDisabledMasterKeys } = useToggleShowDisabledMasterKeys(); + const needMasterPassword = useNeedMasterPassword(passwordChecks, props.masterKeys); const onUpgradeMasterKey = useCallback((mk: MasterKeyEntity) => { void upgradeMasterKey(mk, passwordChecks, props.passwords); @@ -263,9 +264,8 @@ const EncryptionConfigScreen = (props: Props) => { }; const buttonTitle = CommandService.instance().label('openMasterPasswordDialog'); - const needPassword = Object.values(passwordChecks).includes(false); - const needPasswordMessage = !needPassword ? null : ( + const needPasswordMessage = !needMasterPassword ? null : (
{_('Your master password is needed to decrypt some of your data.')}
{_('Please click on "%s" to proceed', buttonTitle)}
{_('Master password:')} {getMasterPasswordStatusMessage(masterPasswordStatus)}
{needPasswordMessage} - + ); diff --git a/packages/app-desktop/gui/MasterPasswordDialog/Dialog.tsx b/packages/app-desktop/gui/MasterPasswordDialog/Dialog.tsx index b6bdab347..ee7b635da 100644 --- a/packages/app-desktop/gui/MasterPasswordDialog/Dialog.tsx +++ b/packages/app-desktop/gui/MasterPasswordDialog/Dialog.tsx @@ -146,6 +146,7 @@ export default function(props: Props) { const renderResetMasterPasswordLink = () => { if (mode === Mode.Reset) return null; + if (status === MasterPasswordStatus.Valid) return null; return ; }; diff --git a/packages/lib/components/EncryptionConfigScreen/utils.ts b/packages/lib/components/EncryptionConfigScreen/utils.ts index bede33a86..b39879ebf 100644 --- a/packages/lib/components/EncryptionConfigScreen/utils.ts +++ b/packages/lib/components/EncryptionConfigScreen/utils.ts @@ -188,6 +188,16 @@ export const usePasswordChecker = (masterKeys: MasterKeyEntity[], activeMasterKe 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