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-10413] ssh keygen on web and browser #12176

Merged
merged 37 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
347bfcd
Move desktop to sdk ssh-key generation
quexten Nov 28, 2024
7c95f06
Add ssh keygen support on web and browser
quexten Nov 28, 2024
e0c0d1f
Move ssh keygen on all clients behind feature flag
quexten Nov 28, 2024
74f69b6
Update package lock
quexten Nov 28, 2024
dde9433
Fix linting
quexten Nov 28, 2024
bf1198f
Merge branch 'main' into km/pm-10413/ssh-keygen-web-client
quexten Dec 2, 2024
1b5c3e9
Merge branch 'main' into km/pm-10413/ssh-keygen-web-client
quexten Dec 3, 2024
f024026
Merge branch 'main' into km/pm-10413/ssh-keygen-web-client
quexten Dec 10, 2024
86e46b8
Merge branch 'main' into km/pm-10413/ssh-keygen-web-client
quexten Dec 10, 2024
c417c6e
Fix build
quexten Dec 10, 2024
057be27
Merge branch 'km/pm-10413/ssh-keygen-web-client' of github.com:bitwarโ€ฆ
quexten Dec 10, 2024
d9091c0
Fix build
quexten Dec 10, 2024
d4bdff8
Remove rand_chacha
quexten Dec 16, 2024
78ada71
Merge branch 'main' into km/pm-10413/ssh-keygen-web-client
quexten Dec 16, 2024
5626afc
Move libc to linux-only target
quexten Dec 16, 2024
d892002
Remove async-streams dep
quexten Dec 16, 2024
9f2fb6a
Merge branch 'main' into km/pm-10413/ssh-keygen-web-client
quexten Dec 18, 2024
1333155
Merge branch 'km/pm-10413/ssh-keygen-web-client' of github.com:bitwarโ€ฆ
quexten Dec 18, 2024
c7146ef
Merge branch 'main' into km/pm-10413/ssh-keygen-web-client
quexten Dec 23, 2024
51314df
Merge branch 'main' into km/pm-10413/ssh-keygen-web-client
quexten Dec 24, 2024
11da15e
Merge branch 'main' into km/pm-10413/ssh-keygen-web-client
quexten Jan 3, 2025
9ed9572
Make generateSshKey private
quexten Jan 6, 2025
753f76f
Remove async from generate ssh key
quexten Jan 6, 2025
3c5ca0c
Merge branch 'km/pm-10413/ssh-keygen-web-client' of github.com:bitwarโ€ฆ
quexten Jan 6, 2025
ff18a84
Merge branch 'main' into km/pm-10413/ssh-keygen-web-client
quexten Jan 6, 2025
4794ee6
Update cargo lock
quexten Jan 6, 2025
0d4f29d
Fix sdk init for ssh key generation
quexten Jan 6, 2025
1b3b2e8
Update index.d.ts
quexten Jan 6, 2025
6cd2a4e
Merge branch 'km/pm-10413/ssh-keygen-web-client' of github.com:bitwarโ€ฆ
quexten Jan 6, 2025
3a56b90
Fix build on browser
quexten Jan 6, 2025
3314387
Fix build
quexten Jan 6, 2025
15dd184
Merge branch 'main' into km/pm-10413/ssh-keygen-web-client
quexten Jan 7, 2025
5f53a6f
Merge branch 'main' into km/pm-10413/ssh-keygen-web-client
quexten Jan 8, 2025
b55b671
Merge branch 'main' into km/pm-10413/ssh-keygen-web-client
quexten Jan 8, 2025
c909147
Fix build by updating libc dependency
quexten Jan 8, 2025
51bb018
Merge branch 'km/pm-10413/ssh-keygen-web-client' of github.com:bitwarโ€ฆ
quexten Jan 8, 2025
4497fee
Merge branch 'main' into km/pm-10413/ssh-keygen-web-client
quexten Jan 8, 2025
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
2 changes: 1 addition & 1 deletion apps/browser/src/popup/services/services.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,7 @@ const safeProviders: SafeProvider[] = [
}),
safeProvider({
provide: SdkClientFactory,
useFactory: (logService) =>
useFactory: (logService: LogService) =>
flagEnabled("sdk") ? new BrowserSdkClientFactory(logService) : new NoopSdkClientFactory(),
deps: [LogService],
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
<i class="bwi bwi-sticky-note" slot="start" aria-hidden="true"></i>
{{ "note" | i18n }}
</a>
<a bitMenuItem (click)="newItemNavigate(cipherType.SshKey)" *ngIf="sshKeysEnabled">
<i class="bwi bwi-key" slot="start" aria-hidden="true"></i>
{{ "typeSshKey" | i18n }}
</a>
<bit-menu-divider></bit-menu-divider>
<button type="button" bitMenuItem (click)="openFolderDialog()">
<i class="bwi bwi-folder" slot="start" aria-hidden="true"></i>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ComponentFixture, TestBed } from "@angular/core/testing";
import { Router } from "@angular/router";

import { JslibModule } from "@bitwarden/angular/jslib.module";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { CipherType } from "@bitwarden/common/vault/enums";
import { ButtonModule, DialogService, MenuModule } from "@bitwarden/components";
Expand Down Expand Up @@ -33,6 +34,7 @@ describe("NewItemDropdownV2Component", () => {
providers: [
{ provide: I18nService, useValue: { t: (key: string) => key } },
{ provide: Router, useValue: { navigate } },
{ provide: ConfigService, useValue: { getFeatureFlag: () => Promise.resolve(false) } },
],
})
.overrideProvider(DialogService, { useValue: { open } })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { CommonModule } from "@angular/common";
import { Component, Input } from "@angular/core";
import { Component, Input, OnInit } from "@angular/core";
import { Router, RouterLink } from "@angular/router";

import { JslibModule } from "@bitwarden/angular/jslib.module";
import { FeatureFlag } from "@bitwarden/common/enums/feature-flag.enum";
import { ConfigService } from "@bitwarden/common/platform/abstractions/config/config.service";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { CollectionId, OrganizationId } from "@bitwarden/common/types/guid";
import { CipherType } from "@bitwarden/common/vault/enums";
Expand All @@ -25,20 +27,26 @@ export interface NewItemInitialValues {
standalone: true,
imports: [NoItemsModule, JslibModule, CommonModule, ButtonModule, RouterLink, MenuModule],
})
export class NewItemDropdownV2Component {
export class NewItemDropdownV2Component implements OnInit {
cipherType = CipherType;

/**
* Optional initial values to pass to the add cipher form
*/
@Input()
initialValues: NewItemInitialValues;

constructor(
private router: Router,
private dialogService: DialogService,
private configService: ConfigService,
) {}

sshKeysEnabled = false;

async ngOnInit() {
this.sshKeysEnabled = await this.configService.getFeatureFlag(FeatureFlag.SSHKeyVaultItem);
}

private async buildQueryParams(type: CipherType): Promise<AddEditQueryParams> {
const tab = await BrowserApi.getTabFromCurrentWindow();
const poppedOut = BrowserPopupUtils.inPopout(window);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import { CipherType } from "@bitwarden/common/vault/enums";
import { LoginUriView } from "@bitwarden/common/vault/models/view/login-uri.view";
import { CipherAuthorizationService } from "@bitwarden/common/vault/services/cipher-authorization.service";
import { DialogService } from "@bitwarden/components";
import { DialogService, ToastService } from "@bitwarden/components";

Check warning on line 28 in apps/browser/src/vault/popup/components/vault/add-edit.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/browser/src/vault/popup/components/vault/add-edit.component.ts#L28

Added line #L28 was not covered by tests
import { PasswordRepromptService } from "@bitwarden/vault";

import { BrowserFido2UserInterfaceSession } from "../../../../autofill/fido2/services/browser-fido2-user-interface.service";
Expand Down Expand Up @@ -74,6 +74,7 @@
configService: ConfigService,
private fido2UserVerificationService: Fido2UserVerificationService,
cipherAuthorizationService: CipherAuthorizationService,
toastService: ToastService,
) {
super(
cipherService,
Expand All @@ -95,6 +96,7 @@
datePipe,
configService,
cipherAuthorizationService,
toastService,
);
}

Expand Down
45 changes: 0 additions & 45 deletions apps/desktop/desktop_native/core/src/ssh_agent/generator.rs

This file was deleted.

1 change: 0 additions & 1 deletion apps/desktop/desktop_native/core/src/ssh_agent/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ use bitwarden_russh::ssh_agent::{self, Key};
#[cfg_attr(target_os = "linux", path = "unix.rs")]
mod platform_ssh_agent;

pub mod generator;
pub mod importer;

#[derive(Clone)]
Expand Down
8 changes: 0 additions & 8 deletions apps/desktop/desktop_native/napi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,14 +350,6 @@ pub mod sshagent {
let bitwarden_agent_state = &mut agent_state.state;
bitwarden_agent_state.clear_keys().map_err(|e| napi::Error::from_reason(e.to_string()))
}

#[napi]
pub async fn generate_keypair(key_algorithm: String) -> napi::Result<SshKey> {
desktop_core::ssh_agent::generator::generate_keypair(key_algorithm)
.await
.map_err(|e| napi::Error::from_reason(e.to_string()))
.map(|k| k.into())
}
}

#[napi]
Expand Down
6 changes: 0 additions & 6 deletions apps/desktop/src/platform/main/main-ssh-agent.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,6 @@ export class MainSshAgentService {
this.requestResponses.push({ requestId, accepted, timestamp: new Date() });
},
);
ipcMain.handle(
"sshagent.generatekey",
async (event: any, { keyAlgorithm }: { keyAlgorithm: string }): Promise<sshagent.SshKey> => {
return await sshagent.generateKeypair(keyAlgorithm);
},
);
ipcMain.handle(
"sshagent.importkey",
async (
Expand Down
3 changes: 0 additions & 3 deletions apps/desktop/src/platform/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ const sshAgent = {
signRequestResponse: async (requestId: number, accepted: boolean) => {
await ipcRenderer.invoke("sshagent.signrequestresponse", { requestId, accepted });
},
generateKey: async (keyAlgorithm: string): Promise<ssh.SshKey> => {
return await ipcRenderer.invoke("sshagent.generatekey", { keyAlgorithm });
},
lock: async () => {
return await ipcRenderer.invoke("sshagent.lock");
},
Expand Down
36 changes: 2 additions & 34 deletions apps/desktop/src/vault/app/vault/add-edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/pl
import { SendApiService } from "@bitwarden/common/tools/send/services/send-api.service.abstraction";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
import { CipherType } from "@bitwarden/common/vault/enums";
import { CipherAuthorizationService } from "@bitwarden/common/vault/services/cipher-authorization.service";
import { DialogService, ToastService } from "@bitwarden/components";
import { SshKeyPasswordPromptComponent } from "@bitwarden/importer/ui";
Expand Down Expand Up @@ -56,7 +55,7 @@ export class AddEditComponent extends BaseAddEditComponent implements OnInit, On
dialogService: DialogService,
datePipe: DatePipe,
configService: ConfigService,
private toastService: ToastService,
toastService: ToastService,
cipherAuthorizationService: CipherAuthorizationService,
) {
super(
Expand All @@ -79,6 +78,7 @@ export class AddEditComponent extends BaseAddEditComponent implements OnInit, On
datePipe,
configService,
cipherAuthorizationService,
toastService,
);
}

Expand Down Expand Up @@ -115,17 +115,6 @@ export class AddEditComponent extends BaseAddEditComponent implements OnInit, On
}

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() {
Expand Down Expand Up @@ -157,21 +146,6 @@ export class AddEditComponent extends BaseAddEditComponent implements OnInit, On
);
}

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;

if (showNotification) {
this.toastService.showToast({
variant: "success",
title: "",
message: this.i18nService.t("sshKeyGenerated"),
});
}
}

async importSshKeyFromClipboard(password: string = "") {
const key = await this.platformUtilsService.readFromClipboard();
const parsedKey = await ipc.platform.sshAgent.importKey(key, password);
Expand Down Expand Up @@ -232,12 +206,6 @@ export class AddEditComponent extends BaseAddEditComponent implements OnInit, On
return await lastValueFrom(dialog.closed);
}

async typeChange() {
if (this.cipher.type === CipherType.SshKey) {
await this.generateSshKey();
}
}

truncateString(value: string, length: number) {
return value.length > length ? value.substring(0, length) + "..." : value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folde
import { TotpService } from "@bitwarden/common/vault/abstractions/totp.service";
import { Cipher } from "@bitwarden/common/vault/models/domain/cipher";
import { CipherAuthorizationService } from "@bitwarden/common/vault/services/cipher-authorization.service";
import { DialogService } from "@bitwarden/components";
import { DialogService, ToastService } from "@bitwarden/components";
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
import { PasswordRepromptService } from "@bitwarden/vault";

Expand Down Expand Up @@ -56,6 +56,7 @@ export class EmergencyAddEditCipherComponent extends BaseAddEditComponent {
configService: ConfigService,
billingAccountProfileStateService: BillingAccountProfileStateService,
cipherAuthorizationService: CipherAuthorizationService,
toastService: ToastService,
) {
super(
cipherService,
Expand All @@ -79,6 +80,7 @@ export class EmergencyAddEditCipherComponent extends BaseAddEditComponent {
configService,
billingAccountProfileStateService,
cipherAuthorizationService,
toastService,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@
case CipherType.SecureNote:
this.title = this.i18nService.t(partOne, this.i18nService.t("note").toLowerCase());
break;
case CipherType.SshKey:
this.title = this.i18nService.t(partOne, this.i18nService.t("typeSshKey").toLowerCase());
break;

Check warning on line 431 in apps/web/src/app/vault/components/vault-item-dialog/vault-item-dialog.component.ts

View check run for this annotation

Codecov / codecov/patch

apps/web/src/app/vault/components/vault-item-dialog/vault-item-dialog.component.ts#L430-L431

Added lines #L430 - L431 were not covered by tests
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ <h1 class="modal-title" id="cipherAddEditTitle">{{ title }}</h1>
[(ngModel)]="cipher.type"
class="form-control"
[disabled]="cipher.isDeleted"
(change)="typeChange()"
appAutofocus
>
<option *ngFor="let o of typeOptions" [ngValue]="o.value">{{ o.name }}</option>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { TotpService } from "@bitwarden/common/vault/abstractions/totp.service";
import { CipherType } from "@bitwarden/common/vault/enums";
import { Launchable } from "@bitwarden/common/vault/interfaces/launchable";
import { CipherAuthorizationService } from "@bitwarden/common/vault/services/cipher-authorization.service";
import { DialogService } from "@bitwarden/components";
import { DialogService, ToastService } from "@bitwarden/components";
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
import { PasswordRepromptService } from "@bitwarden/vault";

Expand Down Expand Up @@ -73,6 +73,7 @@ export class AddEditComponent extends BaseAddEditComponent implements OnInit, On
configService: ConfigService,
private billingAccountProfileStateService: BillingAccountProfileStateService,
cipherAuthorizationService: CipherAuthorizationService,
toastService: ToastService,
) {
super(
cipherService,
Expand All @@ -94,6 +95,7 @@ export class AddEditComponent extends BaseAddEditComponent implements OnInit, On
datePipe,
configService,
cipherAuthorizationService,
toastService,
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@
<i class="bwi bwi-sticky-note" slot="start" aria-hidden="true"></i>
{{ "note" | i18n }}
</button>
<button type="button" bitMenuItem (click)="addCipher(CipherType.SshKey)">
<i class="bwi bwi-key" slot="start" aria-hidden="true"></i>
{{ "typeSshKey" | i18n }}
</button>
<bit-menu-divider />
<button type="button" bitMenuItem (click)="addFolder()">
<i class="bwi bwi-fw bwi-folder" aria-hidden="true"></i>
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/app/vault/org-vault/add-edit.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { TotpService } from "@bitwarden/common/vault/abstractions/totp.service";
import { CipherData } from "@bitwarden/common/vault/models/data/cipher.data";
import { Cipher } from "@bitwarden/common/vault/models/domain/cipher";
import { CipherAuthorizationService } from "@bitwarden/common/vault/services/cipher-authorization.service";
import { DialogService } from "@bitwarden/components";
import { DialogService, ToastService } from "@bitwarden/components";
import { PasswordGenerationServiceAbstraction } from "@bitwarden/generator-legacy";
import { PasswordRepromptService } from "@bitwarden/vault";

Expand Down Expand Up @@ -59,6 +59,7 @@ export class AddEditComponent extends BaseAddEditComponent {
configService: ConfigService,
billingAccountProfileStateService: BillingAccountProfileStateService,
cipherAuthorizationService: CipherAuthorizationService,
toastService: ToastService,
) {
super(
cipherService,
Expand All @@ -82,6 +83,7 @@ export class AddEditComponent extends BaseAddEditComponent {
configService,
billingAccountProfileStateService,
cipherAuthorizationService,
toastService,
);
}

Expand Down
Loading