mirror of
https://github.com/bitwarden/browser
synced 2025-12-19 17:53:39 +00:00
support for new attachment keys
This commit is contained in:
@@ -4,6 +4,7 @@ export class AttachmentData {
|
||||
id: string;
|
||||
url: string;
|
||||
fileName: string;
|
||||
key: string;
|
||||
size: number;
|
||||
sizeName: string;
|
||||
|
||||
@@ -14,6 +15,7 @@ export class AttachmentData {
|
||||
this.id = response.id;
|
||||
this.url = response.url;
|
||||
this.fileName = response.fileName;
|
||||
this.key = response.key;
|
||||
this.size = response.size;
|
||||
this.sizeName = response.sizeName;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,21 @@
|
||||
import { AttachmentData } from '../data/attachmentData';
|
||||
|
||||
import { AttachmentView } from '../view/attachmentView';
|
||||
|
||||
import { CipherString } from './cipherString';
|
||||
import Domain from './domainBase';
|
||||
import { SymmetricCryptoKey } from './symmetricCryptoKey';
|
||||
|
||||
import { AttachmentView } from '../view/attachmentView';
|
||||
import { CryptoService } from '../../abstractions/crypto.service';
|
||||
|
||||
import { Utils } from '../../misc/utils';
|
||||
|
||||
export class Attachment extends Domain {
|
||||
id: string;
|
||||
url: string;
|
||||
size: number;
|
||||
sizeName: string;
|
||||
key: CipherString;
|
||||
fileName: CipherString;
|
||||
|
||||
constructor(obj?: AttachmentData, alreadyEncrypted: boolean = false) {
|
||||
@@ -24,13 +30,34 @@ export class Attachment extends Domain {
|
||||
url: null,
|
||||
sizeName: null,
|
||||
fileName: null,
|
||||
key: null,
|
||||
}, alreadyEncrypted, ['id', 'url', 'sizeName']);
|
||||
}
|
||||
|
||||
decrypt(orgId: string): Promise<AttachmentView> {
|
||||
return this.decryptObj(new AttachmentView(this), {
|
||||
async decrypt(orgId: string): Promise<AttachmentView> {
|
||||
const view = await this.decryptObj(new AttachmentView(this), {
|
||||
fileName: null,
|
||||
}, orgId);
|
||||
|
||||
if (this.key != null) {
|
||||
let cryptoService: CryptoService;
|
||||
const containerService = (Utils.global as any).bitwardenContainerService;
|
||||
if (containerService) {
|
||||
cryptoService = containerService.getCryptoService();
|
||||
} else {
|
||||
throw new Error('global bitwardenContainerService not initialized.');
|
||||
}
|
||||
|
||||
try {
|
||||
const orgKey = await cryptoService.getOrgKey(orgId);
|
||||
const decValue = await cryptoService.decryptToBytes(this.key, orgKey);
|
||||
view.key = new SymmetricCryptoKey(decValue);
|
||||
} catch (e) {
|
||||
// TODO: error?
|
||||
}
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
toAttachmentData(): AttachmentData {
|
||||
@@ -40,6 +67,7 @@ export class Attachment extends Domain {
|
||||
url: null,
|
||||
sizeName: null,
|
||||
fileName: null,
|
||||
key: null,
|
||||
}, ['id', 'url', 'sizeName']);
|
||||
return a;
|
||||
}
|
||||
|
||||
4
src/models/request/attachmentRequest.ts
Normal file
4
src/models/request/attachmentRequest.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export class AttachmentRequest {
|
||||
fileName: string;
|
||||
key: string;
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import { IdentityApi } from '../api/identityApi';
|
||||
import { LoginApi } from '../api/loginApi';
|
||||
import { SecureNoteApi } from '../api/secureNoteApi';
|
||||
|
||||
import { AttachmentRequest } from './attachmentRequest';
|
||||
import { PasswordHistoryRequest } from './passwordHistoryRequest';
|
||||
|
||||
export class CipherRequest {
|
||||
@@ -23,7 +24,9 @@ export class CipherRequest {
|
||||
identity: IdentityApi;
|
||||
fields: FieldApi[];
|
||||
passwordHistory: PasswordHistoryRequest[];
|
||||
// Deprecated, remove at some point and rename attachments2 to attachments
|
||||
attachments: { [id: string]: string; };
|
||||
attachments2: { [id: string]: AttachmentRequest; };
|
||||
|
||||
constructor(cipher: Cipher) {
|
||||
this.type = cipher.type;
|
||||
@@ -119,8 +122,16 @@ export class CipherRequest {
|
||||
|
||||
if (cipher.attachments) {
|
||||
this.attachments = {};
|
||||
this.attachments2 = {};
|
||||
cipher.attachments.forEach((attachment) => {
|
||||
this.attachments[attachment.id] = attachment.fileName ? attachment.fileName.encryptedString : null;
|
||||
const fileName = attachment.fileName ? attachment.fileName.encryptedString : null;
|
||||
this.attachments[attachment.id] = fileName;
|
||||
const attachmentRequest = new AttachmentRequest();
|
||||
attachmentRequest.fileName = fileName;
|
||||
if (attachment.key != null) {
|
||||
attachmentRequest.key = attachment.key.encryptedString;
|
||||
}
|
||||
this.attachments2[attachment.id] = attachmentRequest;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ export class AttachmentResponse {
|
||||
id: string;
|
||||
url: string;
|
||||
fileName: string;
|
||||
key: string;
|
||||
size: number;
|
||||
sizeName: string;
|
||||
|
||||
@@ -9,6 +10,7 @@ export class AttachmentResponse {
|
||||
this.id = response.Id;
|
||||
this.url = response.Url;
|
||||
this.fileName = response.FileName;
|
||||
this.key = response.Key;
|
||||
this.size = response.Size;
|
||||
this.sizeName = response.SizeName;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { View } from './view';
|
||||
|
||||
import { Attachment } from '../domain/attachment';
|
||||
import { SymmetricCryptoKey } from '../domain/symmetricCryptoKey';
|
||||
|
||||
export class AttachmentView implements View {
|
||||
id: string;
|
||||
@@ -8,6 +9,7 @@ export class AttachmentView implements View {
|
||||
size: number;
|
||||
sizeName: string;
|
||||
fileName: string;
|
||||
key: SymmetricCryptoKey;
|
||||
|
||||
constructor(a?: Attachment) {
|
||||
if (!a) {
|
||||
|
||||
Reference in New Issue
Block a user