From 950ef83d4c345d467d6ca647dfea8f8a73578c49 Mon Sep 17 00:00:00 2001 From: Daniel James Smith Date: Thu, 29 Aug 2024 10:36:58 +0200 Subject: [PATCH 1/3] Create new types for SSH_Key within 1pux --- .../types/onepassword-1pux-importer-types.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libs/importer/src/importers/onepassword/types/onepassword-1pux-importer-types.ts b/libs/importer/src/importers/onepassword/types/onepassword-1pux-importer-types.ts index ebb523865457..697ce779790a 100644 --- a/libs/importer/src/importers/onepassword/types/onepassword-1pux-importer-types.ts +++ b/libs/importer/src/importers/onepassword/types/onepassword-1pux-importer-types.ts @@ -46,6 +46,7 @@ export enum CategoryEnum { EmailAccount = "111", API_Credential = "112", MedicalRecord = "113", + SSH_Key = "114", } export interface Item { @@ -116,6 +117,7 @@ export interface Value { creditCardType?: string | null; creditCardNumber?: string | null; reference?: string | null; + sshKey?: SSHKey | null; } export interface Email { @@ -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; From 09aa9628195fce2d85f509b41c924cc35d2f47b0 Mon Sep 17 00:00:00 2001 From: Daniel James Smith Date: Thu, 29 Aug 2024 10:39:01 +0200 Subject: [PATCH 2/3] Add unit test to verify ssh key mapping/import --- .../spec/onepassword-1pux-importer.spec.ts | 21 +++++ .../test-data/onepassword-1pux/ssh-key.ts | 83 +++++++++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 libs/importer/spec/test-data/onepassword-1pux/ssh-key.ts diff --git a/libs/importer/spec/onepassword-1pux-importer.spec.ts b/libs/importer/spec/onepassword-1pux-importer.spec.ts index fe1b2801bdff..3816ac5d214b 100644 --- a/libs/importer/spec/onepassword-1pux-importer.spec.ts +++ b/libs/importer/spec/onepassword-1pux-importer.spec.ts @@ -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"; @@ -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); diff --git a/libs/importer/spec/test-data/onepassword-1pux/ssh-key.ts b/libs/importer/spec/test-data/onepassword-1pux/ssh-key.ts new file mode 100644 index 000000000000..ec10431e932c --- /dev/null +++ b/libs/importer/spec/test-data/onepassword-1pux/ssh-key.ts @@ -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: "username123123123@gmail.com", + 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, + }, + }, + ], + }, + ], + }, + ], +}; From 5bda3d1d14d76d1f3939024c26c00be2c6f47706 Mon Sep 17 00:00:00 2001 From: Daniel James Smith Date: Thu, 29 Aug 2024 10:39:35 +0200 Subject: [PATCH 3/3] Add mapping code to support importing SSH keys from 1password 1pux --- .../onepassword/onepassword-1pux-importer.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libs/importer/src/importers/onepassword/onepassword-1pux-importer.ts b/libs/importer/src/importers/onepassword/onepassword-1pux-importer.ts index 34af24fe228d..334da0cd4735 100644 --- a/libs/importer/src/importers/onepassword/onepassword-1pux-importer.ts +++ b/libs/importer/src/importers/onepassword/onepassword-1pux-importer.ts @@ -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"; @@ -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; } @@ -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") {