mirror of
https://github.com/laurent22/joplin.git
synced 2025-04-07 21:38:58 +02:00
All: Allow disabling any master key, including default or active one
Ref: https://discourse.joplinapp.org/t/syncing-error-with-joplin-cloud-and-e2ee-master-key-is-not-loaded/20115/5
This commit is contained in:
parent
8996a0159a
commit
9407efd8ec
packages
app-desktop/gui
app-mobile/components/screens
lib/services/synchronizer
@ -50,7 +50,7 @@ class EncryptionConfigScreenComponent extends React.Component<Props> {
|
|||||||
return shared.checkPasswords(this);
|
return shared.checkPasswords(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private renderMasterKey(mk: MasterKeyEntity, isDefault: boolean) {
|
private renderMasterKey(mk: MasterKeyEntity, _isDefault: boolean) {
|
||||||
const theme = themeStyle(this.props.themeId);
|
const theme = themeStyle(this.props.themeId);
|
||||||
|
|
||||||
const onToggleEnabledClick = () => {
|
const onToggleEnabledClick = () => {
|
||||||
@ -104,7 +104,7 @@ class EncryptionConfigScreenComponent extends React.Component<Props> {
|
|||||||
{renderPasswordInput(mk.id)}
|
{renderPasswordInput(mk.id)}
|
||||||
<td style={theme.textStyle}>{passwordOk}</td>
|
<td style={theme.textStyle}>{passwordOk}</td>
|
||||||
<td style={theme.textStyle}>
|
<td style={theme.textStyle}>
|
||||||
<button disabled={isActive || isDefault} style={theme.buttonStyle} onClick={() => onToggleEnabledClick()}>{masterKeyEnabled(mk) ? _('Disable') : _('Enable')}</button>
|
<button style={theme.buttonStyle} onClick={() => onToggleEnabledClick()}>{masterKeyEnabled(mk) ? _('Disable') : _('Enable')}</button>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
);
|
);
|
||||||
@ -270,7 +270,11 @@ class EncryptionConfigScreenComponent extends React.Component<Props> {
|
|||||||
|
|
||||||
const onToggleButtonClick = async () => {
|
const onToggleButtonClick = async () => {
|
||||||
const isEnabled = getEncryptionEnabled();
|
const isEnabled = getEncryptionEnabled();
|
||||||
const masterKey = getDefaultMasterKey();
|
let masterKey = getDefaultMasterKey();
|
||||||
|
|
||||||
|
// If the user has explicitly disabled the master key, we generate a
|
||||||
|
// new one. Needed for one the password has been forgotten.
|
||||||
|
if (!masterKey.enabled) masterKey = null;
|
||||||
|
|
||||||
let answer = null;
|
let answer = null;
|
||||||
if (isEnabled) {
|
if (isEnabled) {
|
||||||
|
@ -13,8 +13,7 @@ import shared from '@joplin/lib/components/shared/encryption-config-shared';
|
|||||||
import { MasterKeyEntity } from '@joplin/lib/services/e2ee/types';
|
import { MasterKeyEntity } from '@joplin/lib/services/e2ee/types';
|
||||||
import { State } from '@joplin/lib/reducer';
|
import { State } from '@joplin/lib/reducer';
|
||||||
import { SyncInfo } from '@joplin/lib/services/synchronizer/syncInfoUtils';
|
import { SyncInfo } from '@joplin/lib/services/synchronizer/syncInfoUtils';
|
||||||
import { setupAndDisableEncryption, toggleAndSetupEncryption } from '@joplin/lib/services/e2ee/utils';
|
import { getDefaultMasterKey, setupAndDisableEncryption, toggleAndSetupEncryption } from '@joplin/lib/services/e2ee/utils';
|
||||||
import MasterKey from '@joplin/lib/models/MasterKey';
|
|
||||||
|
|
||||||
interface Props {}
|
interface Props {}
|
||||||
|
|
||||||
@ -146,7 +145,11 @@ class EncryptionConfigScreenComponent extends BaseScreenComponent<Props> {
|
|||||||
|
|
||||||
passwordPromptComponent() {
|
passwordPromptComponent() {
|
||||||
const theme = themeStyle(this.props.themeId);
|
const theme = themeStyle(this.props.themeId);
|
||||||
const masterKey = MasterKey.latest();
|
let masterKey = getDefaultMasterKey();
|
||||||
|
|
||||||
|
// If the user has explicitly disabled the master key, we generate a
|
||||||
|
// new one. Needed for one the password has been forgotten.
|
||||||
|
if (!masterKey.enabled) masterKey = null;
|
||||||
|
|
||||||
const onEnableClick = async () => {
|
const onEnableClick = async () => {
|
||||||
try {
|
try {
|
||||||
|
@ -239,7 +239,10 @@ export function setMasterKeyEnabled(mkId: string, enabled: boolean = true) {
|
|||||||
const idx = s.masterKeys.findIndex(mk => mk.id === mkId);
|
const idx = s.masterKeys.findIndex(mk => mk.id === mkId);
|
||||||
if (idx < 0) throw new Error(`No such master key: ${mkId}`);
|
if (idx < 0) throw new Error(`No such master key: ${mkId}`);
|
||||||
|
|
||||||
if (mkId === getActiveMasterKeyId() && !enabled) throw new Error('The active master key cannot be disabled');
|
// Disabled for now as it's needed to disable even the main master key when the password has been forgotten
|
||||||
|
// https://discourse.joplinapp.org/t/syncing-error-with-joplin-cloud-and-e2ee-master-key-is-not-loaded/20115/5?u=laurent
|
||||||
|
//
|
||||||
|
// if (mkId === getActiveMasterKeyId() && !enabled) throw new Error('The active master key cannot be disabled');
|
||||||
|
|
||||||
s.masterKeys[idx] = {
|
s.masterKeys[idx] = {
|
||||||
...s.masterKeys[idx],
|
...s.masterKeys[idx],
|
||||||
|
Loading…
x
Reference in New Issue
Block a user