Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PM-14901] Fix ssh keys being empty when creating while filter is active #11985

Merged
merged 2 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions apps/desktop/src/vault/app/vault/add-edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,19 @@
) {
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();

Check warning on line 115 in apps/desktop/src/vault/app/vault/add-edit.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/vault/app/vault/add-edit.component.ts#L115

Added line #L115 was not covered by tests

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);

Check warning on line 124 in apps/desktop/src/vault/app/vault/add-edit.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/vault/app/vault/add-edit.component.ts#L124

Added line #L124 was not covered by tests
}
}
}

onWindowHidden() {
Expand Down Expand Up @@ -145,16 +155,19 @@
);
}

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({

Check warning on line 165 in apps/desktop/src/vault/app/vault/add-edit.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/desktop/src/vault/app/vault/add-edit.component.ts#L165

Added line #L165 was not covered by tests
variant: "success",
title: "",
message: this.i18nService.t("sshKeyGenerated"),
});
}
}

async importSshKeyFromClipboard() {
Expand Down
4 changes: 4 additions & 0 deletions libs/common/src/vault/models/view/ssh-key.view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
}

get maskedPrivateKey(): string {
if (!this.privateKey || this.privateKey.length === 0) {
return "";

Check warning on line 21 in libs/common/src/vault/models/view/ssh-key.view.ts

View check run for this annotation

Codecov / codecov/patch

libs/common/src/vault/models/view/ssh-key.view.ts#L21

Added line #L21 was not covered by tests
}

let lines = this.privateKey.split("\n").filter((l) => l.trim() !== "");
lines = lines.map((l, i) => {
if (i === 0 || i === lines.length - 1) {
Expand Down
Loading