From 73d5bc5e44b0f57d9e85f3738a8a758b1e563a0f Mon Sep 17 00:00:00 2001 From: Bernd Schoolmann Date: Wed, 13 Nov 2024 15:47:42 +0100 Subject: [PATCH] Force ssh key creation when creating new ssh item while filtering to ssh keys in desktop --- .../src/vault/app/vault/add-edit.component.ts | 31 +++++++++++++------ .../src/vault/models/view/ssh-key.view.ts | 4 +++ 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/apps/desktop/src/vault/app/vault/add-edit.component.ts b/apps/desktop/src/vault/app/vault/add-edit.component.ts index a3a9c929159..015a7c6b21b 100644 --- a/apps/desktop/src/vault/app/vault/add-edit.component.ts +++ b/apps/desktop/src/vault/app/vault/add-edit.component.ts @@ -111,9 +111,19 @@ export class AddEditComponent extends BaseAddEditComponent implements OnInit, On ) { this.cipher = null; } - // FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling. - // eslint-disable-next-line @typescript-eslint/no-floating-promises - super.load(); + + await super.load(); + + if (!this.editMode || this.cloneMode) { + // Creating an ssh key directly while filtering to the ssh key category + // must force a key to be set. SSH keys must never be created with an empty private key field + if ( + this.cipher.type === CipherType.SshKey && + (this.cipher.sshKey.privateKey == null || this.cipher.sshKey.privateKey === "") + ) { + await this.generateSshKey(false); + } + } } onWindowHidden() { @@ -145,16 +155,19 @@ export class AddEditComponent extends BaseAddEditComponent implements OnInit, On ); } - async generateSshKey() { + async generateSshKey(showNotification: boolean = true) { const sshKey = await ipc.platform.sshAgent.generateKey("ed25519"); this.cipher.sshKey.privateKey = sshKey.privateKey; this.cipher.sshKey.publicKey = sshKey.publicKey; this.cipher.sshKey.keyFingerprint = sshKey.keyFingerprint; - this.toastService.showToast({ - variant: "success", - title: "", - message: this.i18nService.t("sshKeyGenerated"), - }); + + if (showNotification) { + this.toastService.showToast({ + variant: "success", + title: "", + message: this.i18nService.t("sshKeyGenerated"), + }); + } } async importSshKeyFromClipboard() { diff --git a/libs/common/src/vault/models/view/ssh-key.view.ts b/libs/common/src/vault/models/view/ssh-key.view.ts index 4fedb1f8a36..9f0cc8abb88 100644 --- a/libs/common/src/vault/models/view/ssh-key.view.ts +++ b/libs/common/src/vault/models/view/ssh-key.view.ts @@ -17,6 +17,10 @@ export class SshKeyView extends ItemView { } get maskedPrivateKey(): string { + if (!this.privateKey || this.privateKey.length === 0) { + return ""; + } + let lines = this.privateKey.split("\n").filter((l) => l.trim() !== ""); lines = lines.map((l, i) => { if (i === 0 || i === lines.length - 1) {