mirror of
https://github.com/bitwarden/browser
synced 2025-12-18 09:13:33 +00:00
copy common ts code over from browser repo
This commit is contained in:
43
src/models/domain/attachment.ts
Normal file
43
src/models/domain/attachment.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { AttachmentData } from '../data/attachmentData';
|
||||
|
||||
import { CipherString } from './cipherString';
|
||||
import Domain from './domain';
|
||||
|
||||
class Attachment extends Domain {
|
||||
id: string;
|
||||
url: string;
|
||||
size: number;
|
||||
sizeName: string;
|
||||
fileName: CipherString;
|
||||
|
||||
constructor(obj?: AttachmentData, alreadyEncrypted: boolean = false) {
|
||||
super();
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.size = obj.size;
|
||||
this.buildDomainModel(this, obj, {
|
||||
id: null,
|
||||
url: null,
|
||||
sizeName: null,
|
||||
fileName: null,
|
||||
}, alreadyEncrypted, ['id', 'url', 'sizeName']);
|
||||
}
|
||||
|
||||
decrypt(orgId: string): Promise<any> {
|
||||
const model = {
|
||||
id: this.id,
|
||||
size: this.size,
|
||||
sizeName: this.sizeName,
|
||||
url: this.url,
|
||||
};
|
||||
|
||||
return this.decryptObj(model, {
|
||||
fileName: null,
|
||||
}, orgId);
|
||||
}
|
||||
}
|
||||
|
||||
export { Attachment };
|
||||
(window as any).Attachment = Attachment;
|
||||
22
src/models/domain/autofillField.ts
Normal file
22
src/models/domain/autofillField.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
export default class AutofillField {
|
||||
opid: string;
|
||||
elementNumber: number;
|
||||
visible: boolean;
|
||||
viewable: boolean;
|
||||
htmlID: string;
|
||||
htmlName: string;
|
||||
htmlClass: string;
|
||||
'label-left': string;
|
||||
'label-right': string;
|
||||
'label-top': string;
|
||||
'label-tag': string;
|
||||
placeholder: string;
|
||||
type: string;
|
||||
value: string;
|
||||
disabled: boolean;
|
||||
readonly: boolean;
|
||||
onePasswordFieldType: string;
|
||||
form: string;
|
||||
autoCompleteType: string;
|
||||
selectInfo: any;
|
||||
}
|
||||
7
src/models/domain/autofillForm.ts
Normal file
7
src/models/domain/autofillForm.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
export default class AutofillForm {
|
||||
opid: string;
|
||||
htmlName: string;
|
||||
htmlID: string;
|
||||
htmlAction: string;
|
||||
htmlMethod: string;
|
||||
}
|
||||
13
src/models/domain/autofillPageDetails.ts
Normal file
13
src/models/domain/autofillPageDetails.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import AutofillField from './autofillField';
|
||||
import AutofillForm from './autofillForm';
|
||||
|
||||
export default class AutofillPageDetails {
|
||||
documentUUID: string;
|
||||
title: string;
|
||||
url: string;
|
||||
documentUrl: string;
|
||||
tabUrl: string;
|
||||
forms: { [id: string]: AutofillForm; };
|
||||
fields: AutofillField[];
|
||||
collectedTimestamp: number;
|
||||
}
|
||||
12
src/models/domain/autofillScript.ts
Normal file
12
src/models/domain/autofillScript.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
export default class AutofillScript {
|
||||
script: string[][] = [];
|
||||
documentUUID: any = {};
|
||||
properties: any = {};
|
||||
options: any = {};
|
||||
metadata: any = {};
|
||||
autosubmit: any = null;
|
||||
|
||||
constructor(documentUUID: string) {
|
||||
this.documentUUID = documentUUID;
|
||||
}
|
||||
}
|
||||
43
src/models/domain/card.ts
Normal file
43
src/models/domain/card.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { CardData } from '../data/cardData';
|
||||
|
||||
import { CipherString } from './cipherString';
|
||||
import Domain from './domain';
|
||||
|
||||
class Card extends Domain {
|
||||
cardholderName: CipherString;
|
||||
brand: CipherString;
|
||||
number: CipherString;
|
||||
expMonth: CipherString;
|
||||
expYear: CipherString;
|
||||
code: CipherString;
|
||||
|
||||
constructor(obj?: CardData, alreadyEncrypted: boolean = false) {
|
||||
super();
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.buildDomainModel(this, obj, {
|
||||
cardholderName: null,
|
||||
brand: null,
|
||||
number: null,
|
||||
expMonth: null,
|
||||
expYear: null,
|
||||
code: null,
|
||||
}, alreadyEncrypted, []);
|
||||
}
|
||||
|
||||
decrypt(orgId: string): Promise<any> {
|
||||
return this.decryptObj({}, {
|
||||
cardholderName: null,
|
||||
brand: null,
|
||||
number: null,
|
||||
expMonth: null,
|
||||
expYear: null,
|
||||
code: null,
|
||||
}, orgId);
|
||||
}
|
||||
}
|
||||
|
||||
export { Card };
|
||||
(window as any).Card = Card;
|
||||
192
src/models/domain/cipher.ts
Normal file
192
src/models/domain/cipher.ts
Normal file
@@ -0,0 +1,192 @@
|
||||
import { CipherType } from '../../enums/cipherType.enum';
|
||||
|
||||
import { CipherData } from '../data/cipherData';
|
||||
|
||||
import { Attachment } from './attachment';
|
||||
import { Card } from './card';
|
||||
import { CipherString } from './cipherString';
|
||||
import Domain from './domain';
|
||||
import { Field } from './field';
|
||||
import { Identity } from './identity';
|
||||
import { Login } from './login';
|
||||
import { SecureNote } from './secureNote';
|
||||
|
||||
import { UtilsService } from '../../services/abstractions/utils.service';
|
||||
|
||||
class Cipher extends Domain {
|
||||
id: string;
|
||||
organizationId: string;
|
||||
folderId: string;
|
||||
name: CipherString;
|
||||
notes: CipherString;
|
||||
type: CipherType;
|
||||
favorite: boolean;
|
||||
organizationUseTotp: boolean;
|
||||
edit: boolean;
|
||||
localData: any;
|
||||
login: Login;
|
||||
identity: Identity;
|
||||
card: Card;
|
||||
secureNote: SecureNote;
|
||||
attachments: Attachment[];
|
||||
fields: Field[];
|
||||
collectionIds: string[];
|
||||
|
||||
private utilsService: UtilsService;
|
||||
|
||||
constructor(obj?: CipherData, alreadyEncrypted: boolean = false, localData: any = null) {
|
||||
super();
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.buildDomainModel(this, obj, {
|
||||
id: null,
|
||||
organizationId: null,
|
||||
folderId: null,
|
||||
name: null,
|
||||
notes: null,
|
||||
}, alreadyEncrypted, ['id', 'organizationId', 'folderId']);
|
||||
|
||||
this.type = obj.type;
|
||||
this.favorite = obj.favorite;
|
||||
this.organizationUseTotp = obj.organizationUseTotp;
|
||||
this.edit = obj.edit;
|
||||
this.collectionIds = obj.collectionIds;
|
||||
this.localData = localData;
|
||||
|
||||
switch (this.type) {
|
||||
case CipherType.Login:
|
||||
this.login = new Login(obj.login, alreadyEncrypted);
|
||||
break;
|
||||
case CipherType.SecureNote:
|
||||
this.secureNote = new SecureNote(obj.secureNote, alreadyEncrypted);
|
||||
break;
|
||||
case CipherType.Card:
|
||||
this.card = new Card(obj.card, alreadyEncrypted);
|
||||
break;
|
||||
case CipherType.Identity:
|
||||
this.identity = new Identity(obj.identity, alreadyEncrypted);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (obj.attachments != null) {
|
||||
this.attachments = [];
|
||||
obj.attachments.forEach((attachment) => {
|
||||
this.attachments.push(new Attachment(attachment, alreadyEncrypted));
|
||||
});
|
||||
} else {
|
||||
this.attachments = null;
|
||||
}
|
||||
|
||||
if (obj.fields != null) {
|
||||
this.fields = [];
|
||||
obj.fields.forEach((field) => {
|
||||
this.fields.push(new Field(field, alreadyEncrypted));
|
||||
});
|
||||
} else {
|
||||
this.fields = null;
|
||||
}
|
||||
}
|
||||
|
||||
async decrypt(): Promise<any> {
|
||||
const model = {
|
||||
id: this.id,
|
||||
organizationId: this.organizationId,
|
||||
folderId: this.folderId,
|
||||
favorite: this.favorite,
|
||||
type: this.type,
|
||||
localData: this.localData,
|
||||
login: null as any,
|
||||
card: null as any,
|
||||
identity: null as any,
|
||||
secureNote: null as any,
|
||||
subTitle: null as string,
|
||||
attachments: null as any[],
|
||||
fields: null as any[],
|
||||
collectionIds: this.collectionIds,
|
||||
};
|
||||
|
||||
await this.decryptObj(model, {
|
||||
name: null,
|
||||
notes: null,
|
||||
}, this.organizationId);
|
||||
|
||||
switch (this.type) {
|
||||
case CipherType.Login:
|
||||
model.login = await this.login.decrypt(this.organizationId);
|
||||
model.subTitle = model.login.username;
|
||||
if (model.login.uri) {
|
||||
if (this.utilsService == null) {
|
||||
this.utilsService = chrome.extension.getBackgroundPage()
|
||||
.bitwardenMain.utilsService as UtilsService;
|
||||
}
|
||||
|
||||
model.login.domain = this.utilsService.getDomain(model.login.uri);
|
||||
}
|
||||
break;
|
||||
case CipherType.SecureNote:
|
||||
model.secureNote = await this.secureNote.decrypt(this.organizationId);
|
||||
model.subTitle = null;
|
||||
break;
|
||||
case CipherType.Card:
|
||||
model.card = await this.card.decrypt(this.organizationId);
|
||||
model.subTitle = model.card.brand;
|
||||
if (model.card.number && model.card.number.length >= 4) {
|
||||
if (model.subTitle !== '') {
|
||||
model.subTitle += ', ';
|
||||
}
|
||||
model.subTitle += ('*' + model.card.number.substr(model.card.number.length - 4));
|
||||
}
|
||||
break;
|
||||
case CipherType.Identity:
|
||||
model.identity = await this.identity.decrypt(this.organizationId);
|
||||
model.subTitle = '';
|
||||
if (model.identity.firstName) {
|
||||
model.subTitle = model.identity.firstName;
|
||||
}
|
||||
if (model.identity.lastName) {
|
||||
if (model.subTitle !== '') {
|
||||
model.subTitle += ' ';
|
||||
}
|
||||
model.subTitle += model.identity.lastName;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
const orgId = this.organizationId;
|
||||
|
||||
if (this.attachments != null && this.attachments.length > 0) {
|
||||
const attachments: any[] = [];
|
||||
await this.attachments.reduce((promise, attachment) => {
|
||||
return promise.then(() => {
|
||||
return attachment.decrypt(orgId);
|
||||
}).then((decAttachment) => {
|
||||
attachments.push(decAttachment);
|
||||
});
|
||||
}, Promise.resolve());
|
||||
model.attachments = attachments;
|
||||
}
|
||||
|
||||
if (this.fields != null && this.fields.length > 0) {
|
||||
const fields: any[] = [];
|
||||
await this.fields.reduce((promise, field) => {
|
||||
return promise.then(() => {
|
||||
return field.decrypt(orgId);
|
||||
}).then((decField) => {
|
||||
fields.push(decField);
|
||||
});
|
||||
}, Promise.resolve());
|
||||
model.fields = fields;
|
||||
}
|
||||
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
export { Cipher };
|
||||
(window as any).Cipher = Cipher;
|
||||
115
src/models/domain/cipherString.ts
Normal file
115
src/models/domain/cipherString.ts
Normal file
@@ -0,0 +1,115 @@
|
||||
import { EncryptionType } from '../../enums/encryptionType.enum';
|
||||
import { CryptoService } from '../../services/abstractions/crypto.service';
|
||||
|
||||
class CipherString {
|
||||
encryptedString?: string;
|
||||
encryptionType?: EncryptionType;
|
||||
decryptedValue?: string;
|
||||
cipherText?: string;
|
||||
initializationVector?: string;
|
||||
mac?: string;
|
||||
|
||||
private cryptoService: CryptoService;
|
||||
|
||||
constructor(encryptedStringOrType: string | EncryptionType, ct?: string, iv?: string, mac?: string) {
|
||||
if (ct != null) {
|
||||
// ct and header
|
||||
const encType = encryptedStringOrType as EncryptionType;
|
||||
this.encryptedString = encType + '.' + ct;
|
||||
|
||||
// iv
|
||||
if (iv != null) {
|
||||
this.encryptedString += ('|' + iv);
|
||||
}
|
||||
|
||||
// mac
|
||||
if (mac != null) {
|
||||
this.encryptedString += ('|' + mac);
|
||||
}
|
||||
|
||||
this.encryptionType = encType;
|
||||
this.cipherText = ct;
|
||||
this.initializationVector = iv;
|
||||
this.mac = mac;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
this.encryptedString = encryptedStringOrType as string;
|
||||
if (!this.encryptedString) {
|
||||
return;
|
||||
}
|
||||
|
||||
const headerPieces = this.encryptedString.split('.');
|
||||
let encPieces: string[] = null;
|
||||
|
||||
if (headerPieces.length === 2) {
|
||||
try {
|
||||
this.encryptionType = parseInt(headerPieces[0], null);
|
||||
encPieces = headerPieces[1].split('|');
|
||||
} catch (e) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
encPieces = this.encryptedString.split('|');
|
||||
this.encryptionType = encPieces.length === 3 ? EncryptionType.AesCbc128_HmacSha256_B64 :
|
||||
EncryptionType.AesCbc256_B64;
|
||||
}
|
||||
|
||||
switch (this.encryptionType) {
|
||||
case EncryptionType.AesCbc128_HmacSha256_B64:
|
||||
case EncryptionType.AesCbc256_HmacSha256_B64:
|
||||
if (encPieces.length !== 3) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.initializationVector = encPieces[0];
|
||||
this.cipherText = encPieces[1];
|
||||
this.mac = encPieces[2];
|
||||
break;
|
||||
case EncryptionType.AesCbc256_B64:
|
||||
if (encPieces.length !== 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.initializationVector = encPieces[0];
|
||||
this.cipherText = encPieces[1];
|
||||
break;
|
||||
case EncryptionType.Rsa2048_OaepSha256_B64:
|
||||
case EncryptionType.Rsa2048_OaepSha1_B64:
|
||||
if (encPieces.length !== 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.cipherText = encPieces[0];
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
decrypt(orgId: string) {
|
||||
if (this.decryptedValue) {
|
||||
return Promise.resolve(this.decryptedValue);
|
||||
}
|
||||
|
||||
const self = this;
|
||||
if (this.cryptoService == null) {
|
||||
this.cryptoService = chrome.extension.getBackgroundPage()
|
||||
.bitwardenMain.cryptoService as CryptoService;
|
||||
}
|
||||
|
||||
return this.cryptoService.getOrgKey(orgId).then((orgKey: any) => {
|
||||
return self.cryptoService.decrypt(self, orgKey);
|
||||
}).then((decValue: any) => {
|
||||
self.decryptedValue = decValue;
|
||||
return self.decryptedValue;
|
||||
}).catch(() => {
|
||||
self.decryptedValue = '[error: cannot decrypt]';
|
||||
return self.decryptedValue;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export { CipherString };
|
||||
(window as any).CipherString = CipherString;
|
||||
37
src/models/domain/collection.ts
Normal file
37
src/models/domain/collection.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { CollectionData } from '../data/collectionData';
|
||||
|
||||
import { CipherString } from './cipherString';
|
||||
import Domain from './domain';
|
||||
|
||||
class Collection extends Domain {
|
||||
id: string;
|
||||
organizationId: string;
|
||||
name: CipherString;
|
||||
|
||||
constructor(obj?: CollectionData, alreadyEncrypted: boolean = false) {
|
||||
super();
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.buildDomainModel(this, obj, {
|
||||
id: null,
|
||||
organizationId: null,
|
||||
name: null,
|
||||
}, alreadyEncrypted, ['id', 'organizationId']);
|
||||
}
|
||||
|
||||
decrypt(): Promise<any> {
|
||||
const model = {
|
||||
id: this.id,
|
||||
organizationId: this.organizationId,
|
||||
};
|
||||
|
||||
return this.decryptObj(model, {
|
||||
name: null,
|
||||
}, this.organizationId);
|
||||
}
|
||||
}
|
||||
|
||||
export { Collection };
|
||||
(window as any).Collection = Collection;
|
||||
46
src/models/domain/domain.ts
Normal file
46
src/models/domain/domain.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { CipherString } from '../domain/cipherString';
|
||||
|
||||
export default abstract class Domain {
|
||||
protected buildDomainModel(model: any, obj: any, map: any, alreadyEncrypted: boolean, notEncList: any[] = []) {
|
||||
for (const prop in map) {
|
||||
if (!map.hasOwnProperty(prop)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const objProp = obj[(map[prop] || prop)];
|
||||
if (alreadyEncrypted === true || notEncList.indexOf(prop) > -1) {
|
||||
model[prop] = objProp ? objProp : null;
|
||||
} else {
|
||||
model[prop] = objProp ? new CipherString(objProp) : null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected async decryptObj(model: any, map: any, orgId: string) {
|
||||
const promises = [];
|
||||
const self: any = this;
|
||||
|
||||
for (const prop in map) {
|
||||
if (!map.hasOwnProperty(prop)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// tslint:disable-next-line
|
||||
(function (theProp) {
|
||||
const p = Promise.resolve().then(() => {
|
||||
const mapProp = map[theProp] || theProp;
|
||||
if (self[mapProp]) {
|
||||
return self[mapProp].decrypt(orgId);
|
||||
}
|
||||
return null;
|
||||
}).then((val: any) => {
|
||||
model[theProp] = val;
|
||||
});
|
||||
promises.push(p);
|
||||
})(prop);
|
||||
}
|
||||
|
||||
await Promise.all(promises);
|
||||
return model;
|
||||
}
|
||||
}
|
||||
8
src/models/domain/encryptedObject.ts
Normal file
8
src/models/domain/encryptedObject.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import SymmetricCryptoKey from './symmetricCryptoKey';
|
||||
|
||||
export default class EncryptedObject {
|
||||
iv: Uint8Array;
|
||||
ct: Uint8Array;
|
||||
mac: Uint8Array;
|
||||
key: SymmetricCryptoKey;
|
||||
}
|
||||
5
src/models/domain/environmentUrls.ts
Normal file
5
src/models/domain/environmentUrls.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export default class EnvironmentUrls {
|
||||
base: string;
|
||||
api: string;
|
||||
identity: string;
|
||||
}
|
||||
39
src/models/domain/field.ts
Normal file
39
src/models/domain/field.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { FieldType } from '../../enums/fieldType.enum';
|
||||
|
||||
import { FieldData } from '../data/fieldData';
|
||||
|
||||
import { CipherString } from './cipherString';
|
||||
import Domain from './domain';
|
||||
|
||||
class Field extends Domain {
|
||||
name: CipherString;
|
||||
vault: CipherString;
|
||||
type: FieldType;
|
||||
|
||||
constructor(obj?: FieldData, alreadyEncrypted: boolean = false) {
|
||||
super();
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.type = obj.type;
|
||||
this.buildDomainModel(this, obj, {
|
||||
name: null,
|
||||
value: null,
|
||||
}, alreadyEncrypted, []);
|
||||
}
|
||||
|
||||
decrypt(orgId: string): Promise<any> {
|
||||
const model = {
|
||||
type: this.type,
|
||||
};
|
||||
|
||||
return this.decryptObj(model, {
|
||||
name: null,
|
||||
value: null,
|
||||
}, orgId);
|
||||
}
|
||||
}
|
||||
|
||||
export { Field };
|
||||
(window as any).Field = Field;
|
||||
34
src/models/domain/folder.ts
Normal file
34
src/models/domain/folder.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { FolderData } from '../data/folderData';
|
||||
|
||||
import { CipherString } from './cipherString';
|
||||
import Domain from './domain';
|
||||
|
||||
class Folder extends Domain {
|
||||
id: string;
|
||||
name: CipherString;
|
||||
|
||||
constructor(obj?: FolderData, alreadyEncrypted: boolean = false) {
|
||||
super();
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.buildDomainModel(this, obj, {
|
||||
id: null,
|
||||
name: null,
|
||||
}, alreadyEncrypted, ['id']);
|
||||
}
|
||||
|
||||
decrypt(): Promise<any> {
|
||||
const model = {
|
||||
id: this.id,
|
||||
};
|
||||
|
||||
return this.decryptObj(model, {
|
||||
name: null,
|
||||
}, null);
|
||||
}
|
||||
}
|
||||
|
||||
export { Folder };
|
||||
(window as any).Folder = Folder;
|
||||
79
src/models/domain/identity.ts
Normal file
79
src/models/domain/identity.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
import { IdentityData } from '../data/identityData';
|
||||
|
||||
import { CipherString } from './cipherString';
|
||||
import Domain from './domain';
|
||||
|
||||
class Identity extends Domain {
|
||||
title: CipherString;
|
||||
firstName: CipherString;
|
||||
middleName: CipherString;
|
||||
lastName: CipherString;
|
||||
address1: CipherString;
|
||||
address2: CipherString;
|
||||
address3: CipherString;
|
||||
city: CipherString;
|
||||
state: CipherString;
|
||||
postalCode: CipherString;
|
||||
country: CipherString;
|
||||
company: CipherString;
|
||||
email: CipherString;
|
||||
phone: CipherString;
|
||||
ssn: CipherString;
|
||||
username: CipherString;
|
||||
passportNumber: CipherString;
|
||||
licenseNumber: CipherString;
|
||||
|
||||
constructor(obj?: IdentityData, alreadyEncrypted: boolean = false) {
|
||||
super();
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.buildDomainModel(this, obj, {
|
||||
title: null,
|
||||
firstName: null,
|
||||
middleName: null,
|
||||
lastName: null,
|
||||
address1: null,
|
||||
address2: null,
|
||||
address3: null,
|
||||
city: null,
|
||||
state: null,
|
||||
postalCode: null,
|
||||
country: null,
|
||||
company: null,
|
||||
email: null,
|
||||
phone: null,
|
||||
ssn: null,
|
||||
username: null,
|
||||
passportNumber: null,
|
||||
licenseNumber: null,
|
||||
}, alreadyEncrypted, []);
|
||||
}
|
||||
|
||||
decrypt(orgId: string): Promise<any> {
|
||||
return this.decryptObj({}, {
|
||||
title: null,
|
||||
firstName: null,
|
||||
middleName: null,
|
||||
lastName: null,
|
||||
address1: null,
|
||||
address2: null,
|
||||
address3: null,
|
||||
city: null,
|
||||
state: null,
|
||||
postalCode: null,
|
||||
country: null,
|
||||
company: null,
|
||||
email: null,
|
||||
phone: null,
|
||||
ssn: null,
|
||||
username: null,
|
||||
passportNumber: null,
|
||||
licenseNumber: null,
|
||||
}, orgId);
|
||||
}
|
||||
}
|
||||
|
||||
export { Identity };
|
||||
(window as any).Identity = Identity;
|
||||
37
src/models/domain/login.ts
Normal file
37
src/models/domain/login.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { LoginData } from '../data/loginData';
|
||||
|
||||
import { CipherString } from './cipherString';
|
||||
import Domain from './domain';
|
||||
|
||||
class Login extends Domain {
|
||||
uri: CipherString;
|
||||
username: CipherString;
|
||||
password: CipherString;
|
||||
totp: CipherString;
|
||||
|
||||
constructor(obj?: LoginData, alreadyEncrypted: boolean = false) {
|
||||
super();
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.buildDomainModel(this, obj, {
|
||||
uri: null,
|
||||
username: null,
|
||||
password: null,
|
||||
totp: null,
|
||||
}, alreadyEncrypted, []);
|
||||
}
|
||||
|
||||
decrypt(orgId: string): Promise<any> {
|
||||
return this.decryptObj({}, {
|
||||
uri: null,
|
||||
username: null,
|
||||
password: null,
|
||||
totp: null,
|
||||
}, orgId);
|
||||
}
|
||||
}
|
||||
|
||||
export { Login };
|
||||
(window as any).Login = Login;
|
||||
9
src/models/domain/passwordHistory.ts
Normal file
9
src/models/domain/passwordHistory.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export default class PasswordHistory {
|
||||
password: string;
|
||||
date: number;
|
||||
|
||||
constructor(password: string, date: number) {
|
||||
this.password = password;
|
||||
this.date = date;
|
||||
}
|
||||
}
|
||||
27
src/models/domain/secureNote.ts
Normal file
27
src/models/domain/secureNote.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { SecureNoteType } from '../../enums/secureNoteType.enum';
|
||||
|
||||
import { SecureNoteData } from '../data/secureNoteData';
|
||||
|
||||
import Domain from './domain';
|
||||
|
||||
class SecureNote extends Domain {
|
||||
type: SecureNoteType;
|
||||
|
||||
constructor(obj?: SecureNoteData, alreadyEncrypted: boolean = false) {
|
||||
super();
|
||||
if (obj == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.type = obj.type;
|
||||
}
|
||||
|
||||
decrypt(orgId: string): any {
|
||||
return {
|
||||
type: this.type,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export { SecureNote };
|
||||
(window as any).SecureNote = SecureNote;
|
||||
80
src/models/domain/symmetricCryptoKey.ts
Normal file
80
src/models/domain/symmetricCryptoKey.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import * as forge from 'node-forge';
|
||||
|
||||
import { EncryptionType } from '../../enums/encryptionType.enum';
|
||||
|
||||
import SymmetricCryptoKeyBuffers from './symmetricCryptoKeyBuffers';
|
||||
|
||||
import UtilsService from '../../services/utils.service';
|
||||
|
||||
export default class SymmetricCryptoKey {
|
||||
key: string;
|
||||
keyB64: string;
|
||||
encKey: string;
|
||||
macKey: string;
|
||||
encType: EncryptionType;
|
||||
keyBuf: SymmetricCryptoKeyBuffers;
|
||||
|
||||
constructor(keyBytes: string, b64KeyBytes?: boolean, encType?: EncryptionType) {
|
||||
if (b64KeyBytes) {
|
||||
keyBytes = forge.util.decode64(keyBytes);
|
||||
}
|
||||
|
||||
if (!keyBytes) {
|
||||
throw new Error('Must provide keyBytes');
|
||||
}
|
||||
|
||||
const buffer = (forge as any).util.createBuffer(keyBytes);
|
||||
if (!buffer || buffer.length() === 0) {
|
||||
throw new Error('Couldn\'t make buffer');
|
||||
}
|
||||
|
||||
const bufferLength: number = buffer.length();
|
||||
|
||||
if (encType == null) {
|
||||
if (bufferLength === 32) {
|
||||
encType = EncryptionType.AesCbc256_B64;
|
||||
} else if (bufferLength === 64) {
|
||||
encType = EncryptionType.AesCbc256_HmacSha256_B64;
|
||||
} else {
|
||||
throw new Error('Unable to determine encType.');
|
||||
}
|
||||
}
|
||||
|
||||
this.key = keyBytes;
|
||||
this.keyB64 = forge.util.encode64(keyBytes);
|
||||
this.encType = encType;
|
||||
|
||||
if (encType === EncryptionType.AesCbc256_B64 && bufferLength === 32) {
|
||||
this.encKey = keyBytes;
|
||||
this.macKey = null;
|
||||
} else if (encType === EncryptionType.AesCbc128_HmacSha256_B64 && bufferLength === 32) {
|
||||
this.encKey = buffer.getBytes(16); // first half
|
||||
this.macKey = buffer.getBytes(16); // second half
|
||||
} else if (encType === EncryptionType.AesCbc256_HmacSha256_B64 && bufferLength === 64) {
|
||||
this.encKey = buffer.getBytes(32); // first half
|
||||
this.macKey = buffer.getBytes(32); // second half
|
||||
} else {
|
||||
throw new Error('Unsupported encType/key length.');
|
||||
}
|
||||
}
|
||||
|
||||
getBuffers() {
|
||||
if (this.keyBuf) {
|
||||
return this.keyBuf;
|
||||
}
|
||||
|
||||
const key = UtilsService.fromB64ToArray(this.keyB64);
|
||||
const keys = new SymmetricCryptoKeyBuffers(key.buffer);
|
||||
|
||||
if (this.macKey) {
|
||||
keys.encKey = key.slice(0, key.length / 2).buffer;
|
||||
keys.macKey = key.slice(key.length / 2).buffer;
|
||||
} else {
|
||||
keys.encKey = key.buffer;
|
||||
keys.macKey = null;
|
||||
}
|
||||
|
||||
this.keyBuf = keys;
|
||||
return this.keyBuf;
|
||||
}
|
||||
}
|
||||
9
src/models/domain/symmetricCryptoKeyBuffers.ts
Normal file
9
src/models/domain/symmetricCryptoKeyBuffers.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export default class SymmetricCryptoKeyBuffers {
|
||||
key: ArrayBuffer;
|
||||
encKey?: ArrayBuffer;
|
||||
macKey?: ArrayBuffer;
|
||||
|
||||
constructor(key: ArrayBuffer) {
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user