mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Desktop: Fixed button to upgrade a master key
This commit is contained in:
parent
0de6e9ed11
commit
725c79d1ec
@ -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, useNeedMasterPassword, usePasswordChecker, useStats, useToggleShowDisabledMasterKeys } from '@joplin/lib/components/EncryptionConfigScreen/utils';
|
import { decryptedStatText, determineKeyPassword, 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';
|
||||||
@ -41,9 +41,11 @@ const EncryptionConfigScreen = (props: Props) => {
|
|||||||
const { showDisabledMasterKeys, toggleShowDisabledMasterKeys } = useToggleShowDisabledMasterKeys();
|
const { showDisabledMasterKeys, toggleShowDisabledMasterKeys } = useToggleShowDisabledMasterKeys();
|
||||||
const needMasterPassword = useNeedMasterPassword(passwordChecks, props.masterKeys);
|
const needMasterPassword = useNeedMasterPassword(passwordChecks, props.masterKeys);
|
||||||
|
|
||||||
const onUpgradeMasterKey = useCallback((mk: MasterKeyEntity) => {
|
const onUpgradeMasterKey = useCallback(async (mk: MasterKeyEntity) => {
|
||||||
void upgradeMasterKey(mk, passwordChecks, props.passwords);
|
const password = determineKeyPassword(mk.id, masterPasswordKeys, props.masterPassword, props.passwords);
|
||||||
}, [passwordChecks, props.passwords]);
|
const result = await upgradeMasterKey(mk, password);
|
||||||
|
alert(result);
|
||||||
|
}, [props.passwords, masterPasswordKeys, props.masterPassword]);
|
||||||
|
|
||||||
const renderNeedUpgradeSection = () => {
|
const renderNeedUpgradeSection = () => {
|
||||||
if (!shim.isElectron()) return null;
|
if (!shim.isElectron()) return null;
|
||||||
|
@ -198,14 +198,19 @@ export const useNeedMasterPassword = (passwordChecks: PasswordChecks, masterKeys
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const upgradeMasterKey = async (masterKey: MasterKeyEntity, passwordChecks: PasswordChecks, passwords: Record<string, string>): Promise<string> => {
|
export const determineKeyPassword = (masterKeyId: string, masterPasswordKeys: PasswordChecks, masterPassword: string, passwords: Record<string, string>): string => {
|
||||||
const passwordCheck = passwordChecks[masterKey.id];
|
if (masterPasswordKeys[masterKeyId]) return masterPassword;
|
||||||
if (!passwordCheck) {
|
return passwords[masterKeyId];
|
||||||
|
};
|
||||||
|
|
||||||
|
export const upgradeMasterKey = async (masterKey: MasterKeyEntity, password: string): Promise<string> => {
|
||||||
|
if (!password) {
|
||||||
return _('Please enter your password in the master key list below before upgrading the key.');
|
return _('Please enter your password in the master key list below before upgrading the key.');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const password = passwords[masterKey.id];
|
// Just re-encrypt the master key, but using the new encryption method
|
||||||
|
// (which would be the default).
|
||||||
const newMasterKey = await EncryptionService.instance().reencryptMasterKey(masterKey, password, password);
|
const newMasterKey = await EncryptionService.instance().reencryptMasterKey(masterKey, password, password);
|
||||||
await MasterKey.save(newMasterKey);
|
await MasterKey.save(newMasterKey);
|
||||||
void reg.waitForSyncFinishedThenSync();
|
void reg.waitForSyncFinishedThenSync();
|
||||||
|
Loading…
Reference in New Issue
Block a user