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 a3a9c92915..015a7c6b21 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 4fedb1f8a3..9f0cc8abb8 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) {