mirror of
https://github.com/bitwarden/browser
synced 2025-12-11 13:53:34 +00:00
[PM-3040] [BEEEP] Extend json-export to include passwordhistory and vault item dates (created, updated, deleted) (#5917)
* Add password history to json exports Change callout to not mention missing password history any longer * Added item meta dates to json exports Added vault items creation-/revision-/deleted-dates to json exports * Removed unnecessary promises * Add bitwarden-json-export types Define types Use types in vault-export-service Move existing password-protected type to export-types * Use bitwarden-json-export types in bitwarden-json-importer * Clean up passwordHistory if needed * Define and use bitwarden-csv-export-types
This commit is contained in:
committed by
GitHub
parent
b56bb19c02
commit
15f29c5fb1
23
libs/exporter/src/vault-export/bitwarden-csv-export-type.ts
Normal file
23
libs/exporter/src/vault-export/bitwarden-csv-export-type.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { CipherRepromptType } from "@bitwarden/common/vault/enums/cipher-reprompt-type";
|
||||
|
||||
export type BitwardenCsvExportType = {
|
||||
type: string;
|
||||
name: string;
|
||||
notes: string;
|
||||
fields: string;
|
||||
reprompt: CipherRepromptType;
|
||||
// Login props
|
||||
login_uri: string[];
|
||||
login_username: string;
|
||||
login_password: string;
|
||||
login_totp: string;
|
||||
favorite: number | null;
|
||||
};
|
||||
|
||||
export type BitwardenCsvIndividualExportType = BitwardenCsvExportType & {
|
||||
folder: string | null;
|
||||
};
|
||||
|
||||
export type BitwardenCsvOrgExportType = BitwardenCsvExportType & {
|
||||
collections: string[] | null;
|
||||
};
|
||||
@@ -0,0 +1,51 @@
|
||||
import {
|
||||
CipherWithIdExport,
|
||||
CollectionWithIdExport,
|
||||
FolderWithIdExport,
|
||||
} from "@bitwarden/common/models/export";
|
||||
|
||||
// Base
|
||||
export type BitwardenJsonExport = {
|
||||
encrypted: boolean;
|
||||
items: CipherWithIdExport[];
|
||||
};
|
||||
|
||||
// Decrypted
|
||||
export type BitwardenUnEncryptedJsonExport = BitwardenJsonExport & {
|
||||
encrypted: false;
|
||||
};
|
||||
|
||||
export type BitwardenUnEncryptedIndividualJsonExport = BitwardenUnEncryptedJsonExport & {
|
||||
folders: FolderWithIdExport[];
|
||||
};
|
||||
|
||||
export type BitwardenUnEncryptedOrgJsonExport = BitwardenUnEncryptedJsonExport & {
|
||||
collections: CollectionWithIdExport[];
|
||||
};
|
||||
|
||||
// Account-encrypted
|
||||
export type BitwardenEncryptedJsonExport = BitwardenJsonExport & {
|
||||
encrypted: true;
|
||||
encKeyValidation_DO_NOT_EDIT: string;
|
||||
};
|
||||
|
||||
export type BitwardenEncryptedIndividualJsonExport = BitwardenEncryptedJsonExport & {
|
||||
folders: FolderWithIdExport[];
|
||||
};
|
||||
|
||||
export type BitwardenEncryptedOrgJsonExport = BitwardenEncryptedJsonExport & {
|
||||
collections: CollectionWithIdExport[];
|
||||
};
|
||||
|
||||
// Password-protected
|
||||
export type BitwardenPasswordProtectedFileFormat = {
|
||||
encrypted: boolean;
|
||||
passwordProtected: boolean;
|
||||
salt: string;
|
||||
kdfIterations: number;
|
||||
kdfMemory?: number;
|
||||
kdfParallelism?: number;
|
||||
kdfType: number;
|
||||
encKeyValidation_DO_NOT_EDIT: string;
|
||||
data: string;
|
||||
};
|
||||
@@ -1,11 +0,0 @@
|
||||
export interface BitwardenPasswordProtectedFileFormat {
|
||||
encrypted: boolean;
|
||||
passwordProtected: boolean;
|
||||
salt: string;
|
||||
kdfIterations: number;
|
||||
kdfMemory?: number;
|
||||
kdfParallelism?: number;
|
||||
kdfType: number;
|
||||
encKeyValidation_DO_NOT_EDIT: string;
|
||||
data: string;
|
||||
}
|
||||
@@ -26,7 +26,18 @@ import { CollectionView } from "@bitwarden/common/vault/models/view/collection.v
|
||||
import { FolderView } from "@bitwarden/common/vault/models/view/folder.view";
|
||||
|
||||
import { ExportHelper } from "../../export-helper";
|
||||
import { BitwardenPasswordProtectedFileFormat } from "../bitwarden-password-protected-types";
|
||||
import {
|
||||
BitwardenCsvExportType,
|
||||
BitwardenCsvIndividualExportType,
|
||||
BitwardenCsvOrgExportType,
|
||||
} from "../bitwarden-csv-export-type";
|
||||
import {
|
||||
BitwardenEncryptedIndividualJsonExport,
|
||||
BitwardenEncryptedOrgJsonExport,
|
||||
BitwardenUnEncryptedIndividualJsonExport,
|
||||
BitwardenUnEncryptedOrgJsonExport,
|
||||
BitwardenPasswordProtectedFileFormat,
|
||||
} from "../bitwarden-json-export-types";
|
||||
|
||||
import { ExportFormat, VaultExportServiceAbstraction } from "./vault-export.service.abstraction";
|
||||
|
||||
@@ -123,7 +134,7 @@ export class VaultExportService implements VaultExportServiceAbstraction {
|
||||
}
|
||||
});
|
||||
|
||||
const exportCiphers: any[] = [];
|
||||
const exportCiphers: BitwardenCsvIndividualExportType[] = [];
|
||||
decCiphers.forEach((c) => {
|
||||
// only export logins and secure notes
|
||||
if (c.type !== CipherType.Login && c.type !== CipherType.SecureNote) {
|
||||
@@ -133,7 +144,7 @@ export class VaultExportService implements VaultExportServiceAbstraction {
|
||||
return;
|
||||
}
|
||||
|
||||
const cipher: any = {};
|
||||
const cipher = {} as BitwardenCsvIndividualExportType;
|
||||
cipher.folder =
|
||||
c.folderId != null && foldersMap.has(c.folderId) ? foldersMap.get(c.folderId).name : null;
|
||||
cipher.favorite = c.favorite ? 1 : null;
|
||||
@@ -143,7 +154,7 @@ export class VaultExportService implements VaultExportServiceAbstraction {
|
||||
|
||||
return papa.unparse(exportCiphers);
|
||||
} else {
|
||||
const jsonDoc: any = {
|
||||
const jsonDoc: BitwardenUnEncryptedIndividualJsonExport = {
|
||||
encrypted: false,
|
||||
folders: [],
|
||||
items: [],
|
||||
@@ -193,7 +204,7 @@ export class VaultExportService implements VaultExportServiceAbstraction {
|
||||
|
||||
const encKeyValidation = await this.cryptoService.encrypt(Utils.newGuid());
|
||||
|
||||
const jsonDoc: any = {
|
||||
const jsonDoc: BitwardenEncryptedIndividualJsonExport = {
|
||||
encrypted: true,
|
||||
encKeyValidation_DO_NOT_EDIT: encKeyValidation.encryptedString,
|
||||
folders: [],
|
||||
@@ -269,14 +280,14 @@ export class VaultExportService implements VaultExportServiceAbstraction {
|
||||
collectionsMap.set(c.id, c);
|
||||
});
|
||||
|
||||
const exportCiphers: any[] = [];
|
||||
const exportCiphers: BitwardenCsvOrgExportType[] = [];
|
||||
decCiphers.forEach((c) => {
|
||||
// only export logins and secure notes
|
||||
if (c.type !== CipherType.Login && c.type !== CipherType.SecureNote) {
|
||||
return;
|
||||
}
|
||||
|
||||
const cipher: any = {};
|
||||
const cipher = {} as BitwardenCsvOrgExportType;
|
||||
cipher.collections = [];
|
||||
if (c.collectionIds != null) {
|
||||
cipher.collections = c.collectionIds
|
||||
@@ -289,7 +300,7 @@ export class VaultExportService implements VaultExportServiceAbstraction {
|
||||
|
||||
return papa.unparse(exportCiphers);
|
||||
} else {
|
||||
const jsonDoc: any = {
|
||||
const jsonDoc: BitwardenUnEncryptedOrgJsonExport = {
|
||||
encrypted: false,
|
||||
collections: [],
|
||||
items: [],
|
||||
@@ -317,20 +328,17 @@ export class VaultExportService implements VaultExportServiceAbstraction {
|
||||
|
||||
promises.push(
|
||||
this.apiService.getCollections(organizationId).then((c) => {
|
||||
const collectionPromises: any = [];
|
||||
if (c != null && c.data != null && c.data.length > 0) {
|
||||
c.data.forEach((r) => {
|
||||
const collection = new Collection(new CollectionData(r as CollectionDetailsResponse));
|
||||
collections.push(collection);
|
||||
});
|
||||
}
|
||||
return Promise.all(collectionPromises);
|
||||
})
|
||||
);
|
||||
|
||||
promises.push(
|
||||
this.apiService.getCiphersOrganization(organizationId).then((c) => {
|
||||
const cipherPromises: any = [];
|
||||
if (c != null && c.data != null && c.data.length > 0) {
|
||||
c.data
|
||||
.filter((item) => item.deletedDate === null)
|
||||
@@ -339,7 +347,6 @@ export class VaultExportService implements VaultExportServiceAbstraction {
|
||||
ciphers.push(cipher);
|
||||
});
|
||||
}
|
||||
return Promise.all(cipherPromises);
|
||||
})
|
||||
);
|
||||
|
||||
@@ -348,7 +355,7 @@ export class VaultExportService implements VaultExportServiceAbstraction {
|
||||
const orgKey = await this.cryptoService.getOrgKey(organizationId);
|
||||
const encKeyValidation = await this.cryptoService.encrypt(Utils.newGuid(), orgKey);
|
||||
|
||||
const jsonDoc: any = {
|
||||
const jsonDoc: BitwardenEncryptedOrgJsonExport = {
|
||||
encrypted: true,
|
||||
encKeyValidation_DO_NOT_EDIT: encKeyValidation.encryptedString,
|
||||
collections: [],
|
||||
@@ -369,7 +376,7 @@ export class VaultExportService implements VaultExportServiceAbstraction {
|
||||
return JSON.stringify(jsonDoc, null, " ");
|
||||
}
|
||||
|
||||
private buildCommonCipher(cipher: any, c: CipherView) {
|
||||
private buildCommonCipher(cipher: BitwardenCsvExportType, c: CipherView): BitwardenCsvExportType {
|
||||
cipher.type = null;
|
||||
cipher.name = c.name;
|
||||
cipher.notes = c.notes;
|
||||
@@ -382,7 +389,7 @@ export class VaultExportService implements VaultExportServiceAbstraction {
|
||||
cipher.login_totp = null;
|
||||
|
||||
if (c.fields) {
|
||||
c.fields.forEach((f: any) => {
|
||||
c.fields.forEach((f) => {
|
||||
if (!cipher.fields) {
|
||||
cipher.fields = "";
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user