mirror of
https://github.com/vrtmrz/obsidian-livesync.git
synced 2026-10-27 11:33:21 +00:00
Add independent ID key configuration and recovery
This commit is contained in:
1 parent
126d6eadb8
commit
bf7822f20b
51 files changed
+2572
-168
No files matched your search
@@ -47,6 +47,12 @@ function getSettingsFromEditingSettings(editingSettings: AllSettings): ObsidianL
|
||||
}
|
||||
return workObj;
|
||||
}
|
||||
|
||||
function syncIdDerivationSettings(target: Partial<ObsidianLiveSyncSettings>, source: ObsidianLiveSyncSettings): void {
|
||||
target.idDerivationVersion = source.idDerivationVersion;
|
||||
target.idDerivationKey = source.idDerivationKey;
|
||||
}
|
||||
|
||||
function createRemoteConfigurationId(): string {
|
||||
return `remote-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
||||
}
|
||||
@@ -116,6 +122,8 @@ export function paneRemoteConfig(
|
||||
.onClick(async () => {
|
||||
const setupManager = this.core.getModule(SetupManager);
|
||||
const originalSettings = getSettingsFromEditingSettings(this.editingSettings);
|
||||
const originalIdDerivationVersion = this.core.settings.idDerivationVersion;
|
||||
const originalIdDerivationKey = this.core.settings.idDerivationKey;
|
||||
const applied = await setupManager.onlyE2EEConfiguration(UserMode.Update, originalSettings);
|
||||
if (applied) {
|
||||
this.editingSettings.encryptInternalMetadata =
|
||||
@@ -126,6 +134,16 @@ export function paneRemoteConfig(
|
||||
}
|
||||
this.requestUpdate();
|
||||
}
|
||||
if (
|
||||
this.core.settings.idDerivationVersion !== originalIdDerivationVersion ||
|
||||
this.core.settings.idDerivationKey !== originalIdDerivationKey
|
||||
) {
|
||||
syncIdDerivationSettings(this.editingSettings, this.core.settings);
|
||||
if (this.initialSettings) {
|
||||
syncIdDerivationSettings(this.initialSettings, this.core.settings);
|
||||
}
|
||||
this.requestUpdate();
|
||||
}
|
||||
updateE2EESummary();
|
||||
})
|
||||
.setButtonText("Configure")
|
||||
@@ -164,9 +182,11 @@ export function paneRemoteConfig(
|
||||
const currentConfigs = cloneRemoteConfigurations(this.core.settings.remoteConfigurations);
|
||||
this.editingSettings.remoteConfigurations = currentConfigs;
|
||||
this.editingSettings.activeConfigurationId = this.core.settings.activeConfigurationId;
|
||||
syncIdDerivationSettings(this.editingSettings, this.core.settings);
|
||||
if (this.initialSettings) {
|
||||
this.initialSettings.remoteConfigurations = cloneRemoteConfigurations(currentConfigs);
|
||||
this.initialSettings.activeConfigurationId = this.core.settings.activeConfigurationId;
|
||||
syncIdDerivationSettings(this.initialSettings, this.core.settings);
|
||||
}
|
||||
};
|
||||
const persistRemoteConfigurations = async (synchroniseActiveRemote: boolean = false) => {
|
||||
@@ -254,6 +274,8 @@ export function paneRemoteConfig(
|
||||
usePathObfuscation: this.editingSettings.usePathObfuscation,
|
||||
encryptInternalMetadata: this.editingSettings.encryptInternalMetadata,
|
||||
passphrase: this.editingSettings.passphrase,
|
||||
idDerivationVersion: this.editingSettings.idDerivationVersion,
|
||||
idDerivationKey: this.editingSettings.idDerivationKey,
|
||||
configPassphraseStore: this.editingSettings.configPassphraseStore,
|
||||
});
|
||||
const addRemoteConfiguration = async () => {
|
||||
|
||||
@@ -194,4 +194,51 @@ describe("paneRemoteConfig", () => {
|
||||
expect(host.initialSettings.encryptInternalMetadata).toBe(true);
|
||||
expect(host.requestUpdate).toHaveBeenCalledOnce();
|
||||
});
|
||||
|
||||
it("copies applied ID derivation settings into both dialogue buffers", async () => {
|
||||
const nextIdKey = "ab".repeat(32);
|
||||
const originalSettings = {
|
||||
encrypt: true,
|
||||
passphrase: "passphrase",
|
||||
E2EEAlgorithm: "v2",
|
||||
usePathObfuscation: true,
|
||||
encryptInternalMetadata: false,
|
||||
idDerivationVersion: 0,
|
||||
idDerivationKey: "",
|
||||
remoteConfigurations: {},
|
||||
};
|
||||
const setupManager = {
|
||||
onlyE2EEConfiguration: vi.fn(() => {
|
||||
host.core.settings.idDerivationVersion = 1;
|
||||
host.core.settings.idDerivationKey = nextIdKey;
|
||||
return Promise.resolve(false);
|
||||
}),
|
||||
};
|
||||
const host = {
|
||||
editingSettings: { ...originalSettings },
|
||||
initialSettings: { ...originalSettings },
|
||||
core: {
|
||||
settings: { ...originalSettings },
|
||||
getModule: vi.fn(() => setupManager),
|
||||
},
|
||||
lifetimeComponent: { register: vi.fn() },
|
||||
requestUpdate: vi.fn(),
|
||||
};
|
||||
const addPanel = vi.fn((_parent: HTMLElement, heading: string) => ({
|
||||
then(callback: (paneEl: HTMLElement) => void) {
|
||||
if (heading === "E2EE Configuration") {
|
||||
callback(createPanelElement());
|
||||
}
|
||||
},
|
||||
}));
|
||||
|
||||
paneRemoteConfig.call(host as never, {} as HTMLElement, { addPanel } as never);
|
||||
await runtime.clickHandlers[0]();
|
||||
|
||||
expect(host.editingSettings.idDerivationVersion).toBe(1);
|
||||
expect(host.editingSettings.idDerivationKey).toBe(nextIdKey);
|
||||
expect(host.initialSettings.idDerivationVersion).toBe(1);
|
||||
expect(host.initialSettings.idDerivationKey).toBe(nextIdKey);
|
||||
expect(host.requestUpdate).toHaveBeenCalledOnce();
|
||||
});
|
||||
});
|
||||
@@ -68,6 +68,7 @@ export function getE2EEConfigSummary(setting: ObsidianLiveSyncSettings, showAdva
|
||||
export function getSummaryFromPartialSettings(setting: Partial<ObsidianLiveSyncSettings>, showAdvanced = false) {
|
||||
const outputSummary: Record<string, string> = {};
|
||||
for (const key of Object.keys(setting) as (keyof ObsidianLiveSyncSettings)[]) {
|
||||
if (key === "idDerivationKey" || key === "encryptedIdDerivationKey") continue;
|
||||
const config = getConfig(key as AllSettingItemKey);
|
||||
if (!config) continue;
|
||||
if (config.isAdvanced && !showAdvanced) continue;
|
||||
|
||||
Reference in new issue
Block a user