Skip to content

Commit

Permalink
Force ssh key creation when creating new ssh item while filtering to …
Browse files Browse the repository at this point in the history
…ssh keys in desktop
  • Loading branch information
quexten committed Nov 13, 2024
1 parent e341a66 commit 73d5bc5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
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 @@ 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();

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

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 @@ export class SshKeyView extends ItemView {
}

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

0 comments on commit 73d5bc5

Please sign in to comment.