Skip to content

Commit

Permalink
Update paste icons and throw error on wrong import
Browse files Browse the repository at this point in the history
  • Loading branch information
quexten committed Jan 15, 2025
1 parent e9b6780 commit 79d0827
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 16 deletions.
19 changes: 9 additions & 10 deletions apps/desktop/src/vault/app/vault/add-edit.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,15 @@ <h2 class="box-header">
[ngClass]="{ 'bwi-eye': !showPrivateKey, 'bwi-eye-slash': showPrivateKey }"
></i>
</button>
<button
type="button"
class="row-btn"
appStopClick
appA11yTitle="{{ 'importSshKeyFromClipboard' | i18n }}"
(click)="importSshKeyFromClipboard()"
>
<i class="bwi bwi-lg bwi-paste" aria-hidden="true"></i>
</button>
</div>
</div>
<div class="box-content-row box-content-row-flex" appBoxRow>
Expand Down Expand Up @@ -559,16 +568,6 @@ <h2 class="box-header">
</button>
</div>
</div>
<div class="box-content-row box-content-row-flex" appBoxRow>
<button
type="button"
class="row-btn"
appStopClick
(click)="importSshKeyFromClipboard()"
>
{{ "importSshKeyFromClipboard" | i18n }}
</button>
</div>
</div>
</div>
</div>
Expand Down
3 changes: 3 additions & 0 deletions apps/web/src/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -10194,6 +10194,9 @@
"sshKeyPasted": {
"message": "SSH key imported successfully"
},
"copySSHPrivateKey": {
"message": "Copy private key"
},
"resellerRenewalWarningMsg": {
"message": "Your subscription will renew soon. To ensure uninterrupted service, contact $RESELLER$ to confirm your renewal before $RENEWAL_DATE$.",
"placeholders": {
Expand Down
1 change: 1 addition & 0 deletions libs/angular/src/services/jslib-services.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,7 @@ const safeProviders: SafeProvider[] = [
EncryptService,
PinServiceAbstraction,
AccountServiceAbstraction,
SdkService,
],
}),
safeProvider({
Expand Down
2 changes: 1 addition & 1 deletion libs/common/src/enums/feature-flag.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const DefaultFeatureFlagValue = {
[FeatureFlag.IdpAutoSubmitLogin]: FALSE,
[FeatureFlag.UnauthenticatedExtensionUIRefresh]: FALSE,
[FeatureFlag.AccountDeprovisioning]: FALSE,
[FeatureFlag.SSHKeyVaultItem]: FALSE,
[FeatureFlag.SSHKeyVaultItem]: true,
[FeatureFlag.SSHAgent]: FALSE,
[FeatureFlag.AC2476_DeprecateStripeSourcesAPI]: FALSE,
[FeatureFlag.CipherKeyEncryption]: FALSE,
Expand Down
7 changes: 4 additions & 3 deletions libs/common/src/models/export/ssh-key.export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ export class SshKeyExport {
}

static toView(req: SshKeyExport, view = new SshKeyView()) {
view.privateKey = req.privateKey;
view.publicKey = req.publicKey;
view.keyFingerprint = req.keyFingerprint;
const parsedKey = import_ssh_key(req.privateKey);
view.privateKey = parsedKey.private_key;
view.publicKey = parsedKey.public_key;
view.keyFingerprint = parsedKey.key_fingerprint;
return view;
}

Expand Down
2 changes: 2 additions & 0 deletions libs/importer/src/components/import.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
import { SdkService } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
Expand Down Expand Up @@ -92,6 +93,7 @@ const safeProviders: SafeProvider[] = [
EncryptService,
PinServiceAbstraction,
AccountService,
SdkService,
],
}),
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
} from "@bitwarden/common/models/export";
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { SdkService } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key";
import { OrganizationId } from "@bitwarden/common/types/guid";
Expand Down Expand Up @@ -40,11 +41,15 @@ export class BitwardenJsonImporter extends BaseImporter implements Importer {
protected cipherService: CipherService,
protected pinService: PinServiceAbstraction,
protected accountService: AccountService,
protected sdkService: SdkService,
) {
super();
}

async parse(data: string): Promise<ImportResult> {
// parsing ssh keys needs an sdk initialized
await firstValueFrom(this.sdkService.client$);

this.result = new ImportResult();
const results: BitwardenJsonExport = JSON.parse(data);
if (results == null || results.items == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { PinServiceAbstraction } from "@bitwarden/auth/common";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { SdkService } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
import { EncString } from "@bitwarden/common/platform/models/domain/enc-string";
import { SymmetricCryptoKey } from "@bitwarden/common/platform/models/domain/symmetric-crypto-key";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
Expand Down Expand Up @@ -31,9 +32,18 @@ export class BitwardenPasswordProtectedImporter extends BitwardenJsonImporter im
cipherService: CipherService,
pinService: PinServiceAbstraction,
accountService: AccountService,
sdkService: SdkService,
private promptForPassword_callback: () => Promise<string>,
) {
super(keyService, encryptService, i18nService, cipherService, pinService, accountService);
super(
keyService,
encryptService,
i18nService,
cipherService,
pinService,
accountService,
sdkService,
);
}

async parse(data: string): Promise<ImportResult> {
Expand Down
4 changes: 4 additions & 0 deletions libs/importer/src/services/import.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { PinServiceAbstraction } from "@bitwarden/auth/common";
import { AccountService } from "@bitwarden/common/auth/abstractions/account.service";
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { SdkService } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
Expand All @@ -30,6 +31,7 @@ describe("ImportService", () => {
let encryptService: MockProxy<EncryptService>;
let pinService: MockProxy<PinServiceAbstraction>;
let accountService: MockProxy<AccountService>;
let sdkService: MockProxy<SdkService>;

beforeEach(() => {
cipherService = mock<CipherService>();
Expand All @@ -40,6 +42,7 @@ describe("ImportService", () => {
keyService = mock<KeyService>();
encryptService = mock<EncryptService>();
pinService = mock<PinServiceAbstraction>();
sdkService = mock<SdkService>();

importService = new ImportService(
cipherService,
Expand All @@ -51,6 +54,7 @@ describe("ImportService", () => {
encryptService,
pinService,
accountService,
sdkService,
);
});

Expand Down
3 changes: 3 additions & 0 deletions libs/importer/src/services/import.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { KvpRequest } from "@bitwarden/common/models/request/kvp.request";
import { ErrorResponse } from "@bitwarden/common/models/response/error.response";
import { EncryptService } from "@bitwarden/common/platform/abstractions/encrypt.service";
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
import { SdkService } from "@bitwarden/common/platform/abstractions/sdk/sdk.service";
import { Utils } from "@bitwarden/common/platform/misc/utils";
import { CipherService } from "@bitwarden/common/vault/abstractions/cipher.service";
import { FolderService } from "@bitwarden/common/vault/abstractions/folder/folder.service.abstraction";
Expand Down Expand Up @@ -114,6 +115,7 @@ export class ImportService implements ImportServiceAbstraction {
private encryptService: EncryptService,
private pinService: PinServiceAbstraction,
private accountService: AccountService,
private sdkService: SdkService,
) {}

getImportOptions(): ImportOption[] {
Expand Down Expand Up @@ -220,6 +222,7 @@ export class ImportService implements ImportServiceAbstraction {
this.cipherService,
this.pinService,
this.accountService,
this.sdkService,
promptForPassword_callback,
);
case "lastpasscsv":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h2 bitTypography="h6">
></button>
<button
type="button"
bitIconButton="bwi-clone"
bitIconButton="bwi-paste"
bitSuffix
data-testid="import-privateKey"
(click)="importSshKeyFromClipboard()"
Expand Down

0 comments on commit 79d0827

Please sign in to comment.