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-10938] Import ssh-keys from 1password 1pux #10787

Draft
wants to merge 3 commits into
base: feature/ssh-keys
Choose a base branch
from
Draft
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
21 changes: 21 additions & 0 deletions libs/importer/spec/onepassword-1pux-importer.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { SanitizedExport } from "./test-data/onepassword-1pux/sanitized-export";
import { SecureNoteData } from "./test-data/onepassword-1pux/secure-note";
import { ServerData } from "./test-data/onepassword-1pux/server";
import { SoftwareLicenseData } from "./test-data/onepassword-1pux/software-license";
import { SSH_KeyData } from "./test-data/onepassword-1pux/ssh-key";
import { SSNData } from "./test-data/onepassword-1pux/ssn";
import { WirelessRouterData } from "./test-data/onepassword-1pux/wireless-router";

Expand Down Expand Up @@ -658,6 +659,26 @@ describe("1Password 1Pux Importer", () => {
validateCustomField(cipher.fields, "medication notes", "multiple times a day");
});

it("should parse category 114 - SSH Key", async () => {
const importer = new OnePassword1PuxImporter();
const jsonString = JSON.stringify(SSH_KeyData);
const result = await importer.parse(jsonString);
expect(result != null).toBe(true);
const cipher = result.ciphers.shift();
expect(cipher.type).toEqual(CipherType.SSHKey);
expect(cipher.name).toEqual("Some SSH Key");
expect(cipher.notes).toEqual("SSH Key Note");
expect(cipher.sshKey.privateKey).toEqual(
"-----BEGIN PRIVATE KEY-----\nMFECAQEwBQYDK2VwBCIEIDn1BgTbZ/5UUeGLIfVV+qLBOvEsS3XMK6Twzw2Dkukq\ngSEAlrKdxRVVQrBndt4bHEZAz3xsymfM9Vf2QfZ823QxUbM=\n-----END PRIVATE KEY-----\n",
);
expect(cipher.sshKey.publicKey).toEqual(
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJayncUVVUKwZ3beGxxGQM98bMpnzPVX9kH2fNt0MVGz",
);
expect(cipher.sshKey.keyFingerprint).toEqual(
"SHA256:/9qSxXuic8kaVBhwv3c8PuetiEpaOgIp7xHNCbcSuN8",
);
});

it("should create folders", async () => {
const importer = new OnePassword1PuxImporter();
const result = await importer.parse(SanitizedExportJson);
Expand Down
83 changes: 83 additions & 0 deletions libs/importer/spec/test-data/onepassword-1pux/ssh-key.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { ExportData } from "../../../src/importers/onepassword/types/onepassword-1pux-importer-types";

export const SSH_KeyData: ExportData = {
accounts: [
{
attrs: {
accountName: "1Password Customer",
name: "1Password Customer",
avatar: "",
email: "[email protected]",
uuid: "TRIZ3XV4JJFRXJ3BARILLTUA6E",
domain: "https://my.1password.com/",
},
vaults: [
{
attrs: {
uuid: "pqcgbqjxr4tng2hsqt5ffrgwju",
desc: "Just test entries",
avatar: "ke7i5rxnjrh3tj6uesstcosspu.png",
name: "T's Test Vault",
type: "U",
},
items: [
{
uuid: "kf7wevmfiqmbgyao42plvgrasy",
favIndex: 0,
createdAt: 1724868152,
updatedAt: 1724868152,
state: "active",
categoryUuid: "114",
details: {
loginFields: [],
notesPlain: "SSH Key Note",
sections: [
{
title: "SSH Key Section",
fields: [
{
title: "private key",
id: "private_key",
value: {
sshKey: {
privateKey:
"-----BEGIN PRIVATE KEY-----\nMFECAQEwBQYDK2VwBCIEIDn1BgTbZ/5UUeGLIfVV+qLBOvEsS3XMK6Twzw2Dkukq\ngSEAlrKdxRVVQrBndt4bHEZAz3xsymfM9Vf2QfZ823QxUbM=\n-----END PRIVATE KEY-----\n",
metadata: {
privateKey:
"-----BEGIN PRIVATE KEY-----\nMFECAQEwBQYDK2VwBCIEIDn1BgTbZ/5UUeGLIfVV+qLBOvEsS3XMK6Twzw2Dkukq\ngSEAlrKdxRVVQrBndt4bHEZAz3xsymfM9Vf2QfZ823QxUbM=\n-----END PRIVATE KEY-----\n",
publicKey:
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJayncUVVUKwZ3beGxxGQM98bMpnzPVX9kH2fNt0MVGz",
fingerprint: "SHA256:/9qSxXuic8kaVBhwv3c8PuetiEpaOgIp7xHNCbcSuN8",
keyType: "ed25519",
},
},
},
guarded: true,
multiline: false,
dontGenerate: false,
inputTraits: {
keyboard: "default",
correction: "default",
capitalization: "default",
},
},
],
hideAddAnotherField: true,
},
],
passwordHistory: [],
},
overview: {
subtitle: "SHA256:/9qSxXuic8kaVBhwv3c8PuetiEpaOgIp7xHNCbcSuN8",
icons: null,
title: "Some SSH Key",
url: "",
watchtowerExclusions: null,
},
},
],
},
],
},
],
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { IdentityView } from "@bitwarden/common/vault/models/view/identity.view"
import { LoginView } from "@bitwarden/common/vault/models/view/login.view";
import { PasswordHistoryView } from "@bitwarden/common/vault/models/view/password-history.view";
import { SecureNoteView } from "@bitwarden/common/vault/models/view/secure-note.view";
import { SSHKeyView } from "@bitwarden/common/vault/models/view/ssh-key.view";

import { ImportResult } from "../../models/import-result";
import { BaseImporter } from "../base-importer";
Expand Down Expand Up @@ -78,6 +79,10 @@ export class OnePassword1PuxImporter extends BaseImporter implements Importer {
cipher.type = CipherType.Identity;
cipher.identity = new IdentityView();
break;
case CategoryEnum.SSH_Key:
cipher.type = CipherType.SSHKey;
cipher.sshKey = new SSHKeyView();
break;
default:
break;
}
Expand Down Expand Up @@ -314,6 +319,14 @@ export class OnePassword1PuxImporter extends BaseImporter implements Importer {
default:
break;
}
} else if (cipher.type === CipherType.SSHKey) {
if (valueKey === "sshKey") {
const { privateKey, metadata } = field.value.sshKey;
cipher.sshKey.privateKey = privateKey;
cipher.sshKey.publicKey = metadata.publicKey;
cipher.sshKey.keyFingerprint = metadata.fingerprint;
return;
}
}

if (valueKey === "email") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export enum CategoryEnum {
EmailAccount = "111",
API_Credential = "112",
MedicalRecord = "113",
SSH_Key = "114",
}

export interface Item {
Expand Down Expand Up @@ -116,6 +117,7 @@ export interface Value {
creditCardType?: string | null;
creditCardNumber?: string | null;
reference?: string | null;
sshKey?: SSHKey | null;
}

export interface Email {
Expand All @@ -130,6 +132,19 @@ export interface Address {
zip: string;
state: string;
}

export interface SSHKey {
privateKey: string;
metadata: SSHKeyMetadata;
}

export interface SSHKeyMetadata {
privateKey: string;
publicKey: string;
fingerprint: string;
keyType: string;
}

export interface InputTraits {
keyboard: string;
correction: string;
Expand Down
Loading