1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-06 00:13:28 +00:00

[PM-10413] ssh keygen on web and browser (#12176)

* Move desktop to sdk ssh-key generation

* Add ssh keygen support on web and browser

* Move ssh keygen on all clients behind feature flag

* Update package lock

* Fix linting

* Fix build

* Fix build

* Remove rand_chacha

* Move libc to linux-only target

* Remove async-streams dep

* Make generateSshKey private

* Remove async from generate ssh key

* Update cargo lock

* Fix sdk init for ssh key generation

* Update index.d.ts

* Fix build on browser

* Fix build

* Fix build by updating libc dependency
This commit is contained in:
Bernd Schoolmann
2025-01-08 16:01:23 +01:00
committed by GitHub
parent 3949aae8e3
commit bb2961f4ca
21 changed files with 142 additions and 162 deletions

View File

@@ -2,11 +2,15 @@
// @ts-strict-ignore
import { CommonModule } from "@angular/common";
import { Component, Input, OnInit } from "@angular/core";
import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
import { FormBuilder, ReactiveFormsModule } from "@angular/forms";
import { firstValueFrom } from "rxjs";
import { JslibModule } from "@bitwarden/angular/jslib.module";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { SdkService } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
import { CipherView } from "@bitwarden/common/vault/models/view/cipher.view";
import { SshKeyView } from "@bitwarden/common/vault/models/view/ssh-key.view";
import {
CardComponent,
FormFieldModule,
@@ -16,6 +20,7 @@ import {
SelectModule,
TypographyModule,
} from "@bitwarden/components";
import { generate_ssh_key } from "@bitwarden/sdk-internal";
import { CipherFormContainer } from "../../cipher-form-container";
@@ -50,20 +55,35 @@ export class SshKeySectionComponent implements OnInit {
* leaving as just null gets inferred as `unknown`
*/
sshKeyForm = this.formBuilder.group({
privateKey: null as string | null,
publicKey: null as string | null,
keyFingerprint: null as string | null,
privateKey: [""],
publicKey: [""],
keyFingerprint: [""],
});
constructor(
private cipherFormContainer: CipherFormContainer,
private formBuilder: FormBuilder,
private i18nService: I18nService,
) {}
private sdkService: SdkService,
) {
this.cipherFormContainer.registerChildForm("sshKeyDetails", this.sshKeyForm);
this.sshKeyForm.valueChanges.pipe(takeUntilDestroyed()).subscribe((value) => {
const data = new SshKeyView();
data.privateKey = value.privateKey;
data.publicKey = value.publicKey;
data.keyFingerprint = value.keyFingerprint;
this.cipherFormContainer.patchCipher((cipher) => {
cipher.sshKey = data;
return cipher;
});
});
}
ngOnInit() {
if (this.originalCipherView?.card) {
async ngOnInit() {
if (this.originalCipherView?.sshKey) {
this.setInitialValues();
} else {
await this.generateSshKey();
}
this.sshKeyForm.disable();
@@ -79,4 +99,14 @@ export class SshKeySectionComponent implements OnInit {
keyFingerprint,
});
}
private async generateSshKey() {
await firstValueFrom(this.sdkService.client$);
const sshKey = generate_ssh_key("Ed25519");
this.sshKeyForm.setValue({
privateKey: sshKey.private_key,
publicKey: sshKey.public_key,
keyFingerprint: sshKey.key_fingerprint,
});
}
}