mirror of
https://github.com/bitwarden/browser
synced 2025-12-17 16:53:34 +00:00
copy common ts code over from browser repo
This commit is contained in:
20
src/models/data/attachmentData.ts
Normal file
20
src/models/data/attachmentData.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { AttachmentResponse } from '../response/attachmentResponse';
|
||||
|
||||
class AttachmentData {
|
||||
id: string;
|
||||
url: string;
|
||||
fileName: string;
|
||||
size: number;
|
||||
sizeName: string;
|
||||
|
||||
constructor(response: AttachmentResponse) {
|
||||
this.id = response.id;
|
||||
this.url = response.url;
|
||||
this.fileName = response.fileName;
|
||||
this.size = response.size;
|
||||
this.sizeName = response.sizeName;
|
||||
}
|
||||
}
|
||||
|
||||
export { AttachmentData };
|
||||
(window as any).AttachmentData = AttachmentData;
|
||||
20
src/models/data/cardData.ts
Normal file
20
src/models/data/cardData.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
class CardData {
|
||||
cardholderName: string;
|
||||
brand: string;
|
||||
number: string;
|
||||
expMonth: string;
|
||||
expYear: string;
|
||||
code: string;
|
||||
|
||||
constructor(data: any) {
|
||||
this.cardholderName = data.CardholderName;
|
||||
this.brand = data.Brand;
|
||||
this.number = data.Number;
|
||||
this.expMonth = data.ExpMonth;
|
||||
this.expYear = data.ExpYear;
|
||||
this.code = data.Code;
|
||||
}
|
||||
}
|
||||
|
||||
export { CardData };
|
||||
(window as any).CardData = CardData;
|
||||
87
src/models/data/cipherData.ts
Normal file
87
src/models/data/cipherData.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import { CipherType } from '../../enums/cipherType.enum';
|
||||
|
||||
import { AttachmentData } from './attachmentData';
|
||||
import { CardData } from './cardData';
|
||||
import { FieldData } from './fieldData';
|
||||
import { IdentityData } from './identityData';
|
||||
import { LoginData } from './loginData';
|
||||
import { SecureNoteData } from './secureNoteData';
|
||||
|
||||
import { CipherResponse } from '../response/cipherResponse';
|
||||
|
||||
class CipherData {
|
||||
id: string;
|
||||
organizationId: string;
|
||||
folderId: string;
|
||||
userId: string;
|
||||
edit: boolean;
|
||||
organizationUseTotp: boolean;
|
||||
favorite: boolean;
|
||||
revisionDate: string;
|
||||
type: CipherType;
|
||||
sizeName: string;
|
||||
name: string;
|
||||
notes: string;
|
||||
login?: LoginData;
|
||||
secureNote?: SecureNoteData;
|
||||
card?: CardData;
|
||||
identity?: IdentityData;
|
||||
fields?: FieldData[];
|
||||
attachments?: AttachmentData[];
|
||||
collectionIds?: string[];
|
||||
|
||||
constructor(response: CipherResponse, userId: string, collectionIds?: string[]) {
|
||||
this.id = response.id;
|
||||
this.organizationId = response.organizationId;
|
||||
this.folderId = response.folderId;
|
||||
this.userId = userId;
|
||||
this.edit = response.edit;
|
||||
this.organizationUseTotp = response.organizationUseTotp;
|
||||
this.favorite = response.favorite;
|
||||
this.revisionDate = response.revisionDate;
|
||||
this.type = response.type;
|
||||
|
||||
if (collectionIds != null) {
|
||||
this.collectionIds = collectionIds;
|
||||
} else {
|
||||
this.collectionIds = response.collectionIds;
|
||||
}
|
||||
|
||||
this.name = response.data.Name;
|
||||
this.notes = response.data.Notes;
|
||||
|
||||
switch (this.type) {
|
||||
case CipherType.Login:
|
||||
this.login = new LoginData(response.data);
|
||||
break;
|
||||
case CipherType.SecureNote:
|
||||
this.secureNote = new SecureNoteData(response.data);
|
||||
break;
|
||||
case CipherType.Card:
|
||||
this.card = new CardData(response.data);
|
||||
break;
|
||||
case CipherType.Identity:
|
||||
this.identity = new IdentityData(response.data);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (response.data.Fields != null) {
|
||||
this.fields = [];
|
||||
response.data.Fields.forEach((field: any) => {
|
||||
this.fields.push(new FieldData(field));
|
||||
});
|
||||
}
|
||||
|
||||
if (response.attachments != null) {
|
||||
this.attachments = [];
|
||||
response.attachments.forEach((attachment) => {
|
||||
this.attachments.push(new AttachmentData(attachment));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { CipherData };
|
||||
(window as any).CipherData = CipherData;
|
||||
16
src/models/data/collectionData.ts
Normal file
16
src/models/data/collectionData.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { CollectionResponse } from '../response/collectionResponse';
|
||||
|
||||
class CollectionData {
|
||||
id: string;
|
||||
organizationId: string;
|
||||
name: string;
|
||||
|
||||
constructor(response: CollectionResponse) {
|
||||
this.id = response.id;
|
||||
this.organizationId = response.organizationId;
|
||||
this.name = response.name;
|
||||
}
|
||||
}
|
||||
|
||||
export { CollectionData };
|
||||
(window as any).CollectionData = CollectionData;
|
||||
16
src/models/data/fieldData.ts
Normal file
16
src/models/data/fieldData.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { FieldType } from '../../enums/fieldType.enum';
|
||||
|
||||
class FieldData {
|
||||
type: FieldType;
|
||||
name: string;
|
||||
value: string;
|
||||
|
||||
constructor(response: any) {
|
||||
this.type = response.Type;
|
||||
this.name = response.Name;
|
||||
this.value = response.Value;
|
||||
}
|
||||
}
|
||||
|
||||
export { FieldData };
|
||||
(window as any).FieldData = FieldData;
|
||||
18
src/models/data/folderData.ts
Normal file
18
src/models/data/folderData.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import { FolderResponse } from '../response/folderResponse';
|
||||
|
||||
class FolderData {
|
||||
id: string;
|
||||
userId: string;
|
||||
name: string;
|
||||
revisionDate: string;
|
||||
|
||||
constructor(response: FolderResponse, userId: string) {
|
||||
this.userId = userId;
|
||||
this.name = response.name;
|
||||
this.id = response.id;
|
||||
this.revisionDate = response.revisionDate;
|
||||
}
|
||||
}
|
||||
|
||||
export { FolderData };
|
||||
(window as any).FolderData = FolderData;
|
||||
44
src/models/data/identityData.ts
Normal file
44
src/models/data/identityData.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
class IdentityData {
|
||||
title: string;
|
||||
firstName: string;
|
||||
middleName: string;
|
||||
lastName: string;
|
||||
address1: string;
|
||||
address2: string;
|
||||
address3: string;
|
||||
city: string;
|
||||
state: string;
|
||||
postalCode: string;
|
||||
country: string;
|
||||
company: string;
|
||||
email: string;
|
||||
phone: string;
|
||||
ssn: string;
|
||||
username: string;
|
||||
passportNumber: string;
|
||||
licenseNumber: string;
|
||||
|
||||
constructor(data: any) {
|
||||
this.title = data.Title;
|
||||
this.firstName = data.FirstName;
|
||||
this.middleName = data.MiddleName;
|
||||
this.lastName = data.LastName;
|
||||
this.address1 = data.Address1;
|
||||
this.address2 = data.Address2;
|
||||
this.address3 = data.Address3;
|
||||
this.city = data.City;
|
||||
this.state = data.State;
|
||||
this.postalCode = data.PostalCode;
|
||||
this.country = data.Country;
|
||||
this.company = data.Company;
|
||||
this.email = data.Email;
|
||||
this.phone = data.Phone;
|
||||
this.ssn = data.SSN;
|
||||
this.username = data.Username;
|
||||
this.passportNumber = data.PassportNumber;
|
||||
this.licenseNumber = data.LicenseNumber;
|
||||
}
|
||||
}
|
||||
|
||||
export { IdentityData };
|
||||
(window as any).IdentityData = IdentityData;
|
||||
16
src/models/data/loginData.ts
Normal file
16
src/models/data/loginData.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
class LoginData {
|
||||
uri: string;
|
||||
username: string;
|
||||
password: string;
|
||||
totp: string;
|
||||
|
||||
constructor(data: any) {
|
||||
this.uri = data.Uri;
|
||||
this.username = data.Username;
|
||||
this.password = data.Password;
|
||||
this.totp = data.Totp;
|
||||
}
|
||||
}
|
||||
|
||||
export { LoginData };
|
||||
(window as any).LoginData = LoginData;
|
||||
12
src/models/data/secureNoteData.ts
Normal file
12
src/models/data/secureNoteData.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { SecureNoteType } from '../../enums/secureNoteType.enum';
|
||||
|
||||
class SecureNoteData {
|
||||
type: SecureNoteType;
|
||||
|
||||
constructor(data: any) {
|
||||
this.type = data.Type;
|
||||
}
|
||||
}
|
||||
|
||||
export { SecureNoteData };
|
||||
(window as any).SecureNoteData = SecureNoteData;
|
||||
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;
|
||||
}
|
||||
}
|
||||
89
src/models/request/cipherRequest.ts
Normal file
89
src/models/request/cipherRequest.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import { CipherType } from '../../enums/cipherType.enum';
|
||||
|
||||
class CipherRequest {
|
||||
type: CipherType;
|
||||
folderId: string;
|
||||
organizationId: string;
|
||||
name: string;
|
||||
notes: string;
|
||||
favorite: boolean;
|
||||
login: any;
|
||||
secureNote: any;
|
||||
card: any;
|
||||
identity: any;
|
||||
fields: any[];
|
||||
|
||||
constructor(cipher: any) {
|
||||
this.type = cipher.type;
|
||||
this.folderId = cipher.folderId;
|
||||
this.organizationId = cipher.organizationId;
|
||||
this.name = cipher.name ? cipher.name.encryptedString : null;
|
||||
this.notes = cipher.notes ? cipher.notes.encryptedString : null;
|
||||
this.favorite = cipher.favorite;
|
||||
|
||||
switch (this.type) {
|
||||
case CipherType.Login:
|
||||
this.login = {
|
||||
uri: cipher.login.uri ? cipher.login.uri.encryptedString : null,
|
||||
username: cipher.login.username ? cipher.login.username.encryptedString : null,
|
||||
password: cipher.login.password ? cipher.login.password.encryptedString : null,
|
||||
totp: cipher.login.totp ? cipher.login.totp.encryptedString : null,
|
||||
};
|
||||
break;
|
||||
case CipherType.SecureNote:
|
||||
this.secureNote = {
|
||||
type: cipher.secureNote.type,
|
||||
};
|
||||
break;
|
||||
case CipherType.Card:
|
||||
this.card = {
|
||||
cardholderName: cipher.card.cardholderName ? cipher.card.cardholderName.encryptedString : null,
|
||||
brand: cipher.card.brand ? cipher.card.brand.encryptedString : null,
|
||||
number: cipher.card.number ? cipher.card.number.encryptedString : null,
|
||||
expMonth: cipher.card.expMonth ? cipher.card.expMonth.encryptedString : null,
|
||||
expYear: cipher.card.expYear ? cipher.card.expYear.encryptedString : null,
|
||||
code: cipher.card.code ? cipher.card.code.encryptedString : null,
|
||||
};
|
||||
break;
|
||||
case CipherType.Identity:
|
||||
this.identity = {
|
||||
title: cipher.identity.title ? cipher.identity.title.encryptedString : null,
|
||||
firstName: cipher.identity.firstName ? cipher.identity.firstName.encryptedString : null,
|
||||
middleName: cipher.identity.middleName ? cipher.identity.middleName.encryptedString : null,
|
||||
lastName: cipher.identity.lastName ? cipher.identity.lastName.encryptedString : null,
|
||||
address1: cipher.identity.address1 ? cipher.identity.address1.encryptedString : null,
|
||||
address2: cipher.identity.address2 ? cipher.identity.address2.encryptedString : null,
|
||||
address3: cipher.identity.address3 ? cipher.identity.address3.encryptedString : null,
|
||||
city: cipher.identity.city ? cipher.identity.city.encryptedString : null,
|
||||
state: cipher.identity.state ? cipher.identity.state.encryptedString : null,
|
||||
postalCode: cipher.identity.postalCode ? cipher.identity.postalCode.encryptedString : null,
|
||||
country: cipher.identity.country ? cipher.identity.country.encryptedString : null,
|
||||
company: cipher.identity.company ? cipher.identity.company.encryptedString : null,
|
||||
email: cipher.identity.email ? cipher.identity.email.encryptedString : null,
|
||||
phone: cipher.identity.phone ? cipher.identity.phone.encryptedString : null,
|
||||
ssn: cipher.identity.ssn ? cipher.identity.ssn.encryptedString : null,
|
||||
username: cipher.identity.username ? cipher.identity.username.encryptedString : null,
|
||||
passportNumber: cipher.identity.passportNumber ?
|
||||
cipher.identity.passportNumber.encryptedString : null,
|
||||
licenseNumber: cipher.identity.licenseNumber ? cipher.identity.licenseNumber.encryptedString : null,
|
||||
};
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (cipher.fields) {
|
||||
this.fields = [];
|
||||
cipher.fields.forEach((field: any) => {
|
||||
this.fields.push({
|
||||
type: field.type,
|
||||
name: field.name ? field.name.encryptedString : null,
|
||||
value: field.value ? field.value.encryptedString : null,
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { CipherRequest };
|
||||
(window as any).CipherRequest = CipherRequest;
|
||||
19
src/models/request/deviceRequest.ts
Normal file
19
src/models/request/deviceRequest.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { BrowserType } from '../../enums/browserType.enum';
|
||||
import { UtilsService } from '../../services/abstractions/utils.service';
|
||||
|
||||
class DeviceRequest {
|
||||
type: BrowserType;
|
||||
name: string;
|
||||
identifier: string;
|
||||
pushToken?: string;
|
||||
|
||||
constructor(appId: string, utilsService: UtilsService) {
|
||||
this.type = utilsService.getBrowser();
|
||||
this.name = utilsService.getBrowserString();
|
||||
this.identifier = appId;
|
||||
this.pushToken = null;
|
||||
}
|
||||
}
|
||||
|
||||
export { DeviceRequest };
|
||||
(window as any).DeviceRequest = DeviceRequest;
|
||||
10
src/models/request/deviceTokenRequest.ts
Normal file
10
src/models/request/deviceTokenRequest.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
class DeviceTokenRequest {
|
||||
pushToken: string;
|
||||
|
||||
constructor() {
|
||||
this.pushToken = null;
|
||||
}
|
||||
}
|
||||
|
||||
export { DeviceTokenRequest };
|
||||
(window as any).DeviceTokenRequest = DeviceTokenRequest;
|
||||
12
src/models/request/folderRequest.ts
Normal file
12
src/models/request/folderRequest.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { Folder } from '../domain/folder';
|
||||
|
||||
class FolderRequest {
|
||||
name: string;
|
||||
|
||||
constructor(folder: Folder) {
|
||||
this.name = folder.name ? folder.name.encryptedString : null;
|
||||
}
|
||||
}
|
||||
|
||||
export { FolderRequest };
|
||||
(window as any).FolderRequest = FolderRequest;
|
||||
10
src/models/request/passwordHintRequest.ts
Normal file
10
src/models/request/passwordHintRequest.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
class PasswordHintRequest {
|
||||
email: string;
|
||||
|
||||
constructor(email: string) {
|
||||
this.email = email;
|
||||
}
|
||||
}
|
||||
|
||||
export { PasswordHintRequest };
|
||||
(window as any).PasswordHintRequest = PasswordHintRequest;
|
||||
18
src/models/request/registerRequest.ts
Normal file
18
src/models/request/registerRequest.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
class RegisterRequest {
|
||||
name: string;
|
||||
email: string;
|
||||
masterPasswordHash: string;
|
||||
masterPasswordHint: string;
|
||||
key: string;
|
||||
|
||||
constructor(email: string, masterPasswordHash: string, masterPasswordHint: string, key: string) {
|
||||
this.name = null;
|
||||
this.email = email;
|
||||
this.masterPasswordHash = masterPasswordHash;
|
||||
this.masterPasswordHint = masterPasswordHint ? masterPasswordHint : null;
|
||||
this.key = key;
|
||||
}
|
||||
}
|
||||
|
||||
export { RegisterRequest };
|
||||
(window as any).RegisterRequest = RegisterRequest;
|
||||
49
src/models/request/tokenRequest.ts
Normal file
49
src/models/request/tokenRequest.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { DeviceRequest } from './deviceRequest';
|
||||
|
||||
class TokenRequest {
|
||||
email: string;
|
||||
masterPasswordHash: string;
|
||||
token: string;
|
||||
provider: number;
|
||||
remember: boolean;
|
||||
device?: DeviceRequest;
|
||||
|
||||
constructor(email: string, masterPasswordHash: string, provider: number,
|
||||
token: string, remember: boolean, device?: DeviceRequest) {
|
||||
this.email = email;
|
||||
this.masterPasswordHash = masterPasswordHash;
|
||||
this.token = token;
|
||||
this.provider = provider;
|
||||
this.remember = remember;
|
||||
this.device = device != null ? device : null;
|
||||
}
|
||||
|
||||
toIdentityToken() {
|
||||
const obj: any = {
|
||||
grant_type: 'password',
|
||||
username: this.email,
|
||||
password: this.masterPasswordHash,
|
||||
scope: 'api offline_access',
|
||||
client_id: 'browser',
|
||||
};
|
||||
|
||||
if (this.device) {
|
||||
obj.deviceType = this.device.type;
|
||||
obj.deviceIdentifier = this.device.identifier;
|
||||
obj.deviceName = this.device.name;
|
||||
// no push tokens for browser apps yet
|
||||
// obj.devicePushToken = this.device.pushToken;
|
||||
}
|
||||
|
||||
if (this.token && this.provider !== null && (typeof this.provider !== 'undefined')) {
|
||||
obj.twoFactorToken = this.token;
|
||||
obj.twoFactorProvider = this.provider;
|
||||
obj.twoFactorRemember = this.remember ? '1' : '0';
|
||||
}
|
||||
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
export { TokenRequest };
|
||||
(window as any).TokenRequest = TokenRequest;
|
||||
12
src/models/request/twoFactorEmailRequest.ts
Normal file
12
src/models/request/twoFactorEmailRequest.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
class TwoFactorEmailRequest {
|
||||
email: string;
|
||||
masterPasswordHash: string;
|
||||
|
||||
constructor(email: string, masterPasswordHash: string) {
|
||||
this.email = email;
|
||||
this.masterPasswordHash = masterPasswordHash;
|
||||
}
|
||||
}
|
||||
|
||||
export { TwoFactorEmailRequest };
|
||||
(window as any).TwoFactorEmailRequest = TwoFactorEmailRequest;
|
||||
18
src/models/response/attachmentResponse.ts
Normal file
18
src/models/response/attachmentResponse.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
class AttachmentResponse {
|
||||
id: string;
|
||||
url: string;
|
||||
fileName: string;
|
||||
size: number;
|
||||
sizeName: string;
|
||||
|
||||
constructor(response: any) {
|
||||
this.id = response.Id;
|
||||
this.url = response.Url;
|
||||
this.fileName = response.FileName;
|
||||
this.size = response.Size;
|
||||
this.sizeName = response.SizeName;
|
||||
}
|
||||
}
|
||||
|
||||
export { AttachmentResponse };
|
||||
(window as any).AttachmentResponse = AttachmentResponse;
|
||||
44
src/models/response/cipherResponse.ts
Normal file
44
src/models/response/cipherResponse.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { AttachmentResponse } from './attachmentResponse';
|
||||
|
||||
class CipherResponse {
|
||||
id: string;
|
||||
organizationId: string;
|
||||
folderId: string;
|
||||
type: number;
|
||||
favorite: boolean;
|
||||
edit: boolean;
|
||||
organizationUseTotp: boolean;
|
||||
data: any;
|
||||
revisionDate: string;
|
||||
attachments: AttachmentResponse[];
|
||||
collectionIds: string[];
|
||||
|
||||
constructor(response: any) {
|
||||
this.id = response.Id;
|
||||
this.organizationId = response.OrganizationId;
|
||||
this.folderId = response.FolderId;
|
||||
this.type = response.Type;
|
||||
this.favorite = response.Favorite;
|
||||
this.edit = response.Edit;
|
||||
this.organizationUseTotp = response.OrganizationUseTotp;
|
||||
this.data = response.Data;
|
||||
this.revisionDate = response.RevisionDate;
|
||||
|
||||
if (response.Attachments != null) {
|
||||
this.attachments = [];
|
||||
response.Attachments.forEach((attachment: any) => {
|
||||
this.attachments.push(new AttachmentResponse(attachment));
|
||||
});
|
||||
}
|
||||
|
||||
if (response.CollectionIds) {
|
||||
this.collectionIds = [];
|
||||
response.CollectionIds.forEach((id: string) => {
|
||||
this.collectionIds.push(id);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { CipherResponse };
|
||||
(window as any).CipherResponse = CipherResponse;
|
||||
14
src/models/response/collectionResponse.ts
Normal file
14
src/models/response/collectionResponse.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
class CollectionResponse {
|
||||
id: string;
|
||||
organizationId: string;
|
||||
name: string;
|
||||
|
||||
constructor(response: any) {
|
||||
this.id = response.Id;
|
||||
this.organizationId = response.OrganizationId;
|
||||
this.name = response.Name;
|
||||
}
|
||||
}
|
||||
|
||||
export { CollectionResponse };
|
||||
(window as any).CollectionResponse = CollectionResponse;
|
||||
20
src/models/response/deviceResponse.ts
Normal file
20
src/models/response/deviceResponse.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { BrowserType } from '../../enums/browserType.enum';
|
||||
|
||||
class DeviceResponse {
|
||||
id: string;
|
||||
name: number;
|
||||
identifier: string;
|
||||
type: BrowserType;
|
||||
creationDate: string;
|
||||
|
||||
constructor(response: any) {
|
||||
this.id = response.Id;
|
||||
this.name = response.Name;
|
||||
this.identifier = response.Identifier;
|
||||
this.type = response.Type;
|
||||
this.creationDate = response.CreationDate;
|
||||
}
|
||||
}
|
||||
|
||||
export { DeviceResponse };
|
||||
(window as any).DeviceResponse = DeviceResponse;
|
||||
20
src/models/response/domainsResponse.ts
Normal file
20
src/models/response/domainsResponse.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { GlobalDomainResponse } from './globalDomainResponse';
|
||||
|
||||
class DomainsResponse {
|
||||
equivalentDomains: string[][];
|
||||
globalEquivalentDomains: GlobalDomainResponse[] = [];
|
||||
|
||||
constructor(response: any) {
|
||||
this.equivalentDomains = response.EquivalentDomains;
|
||||
|
||||
this.globalEquivalentDomains = [];
|
||||
if (response.GlobalEquivalentDomains) {
|
||||
response.GlobalEquivalentDomains.forEach((domain: any) => {
|
||||
this.globalEquivalentDomains.push(new GlobalDomainResponse(domain));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { DomainsResponse };
|
||||
(window as any).DomainsResponse = DomainsResponse;
|
||||
37
src/models/response/errorResponse.ts
Normal file
37
src/models/response/errorResponse.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
class ErrorResponse {
|
||||
message: string;
|
||||
validationErrors: { [key: string]: string[]; };
|
||||
statusCode: number;
|
||||
|
||||
constructor(response: any, status: number, identityResponse?: boolean) {
|
||||
let errorModel = null;
|
||||
if (identityResponse && response && response.ErrorModel) {
|
||||
errorModel = response.ErrorModel;
|
||||
} else if (response) {
|
||||
errorModel = response;
|
||||
}
|
||||
|
||||
if (errorModel) {
|
||||
this.message = errorModel.Message;
|
||||
this.validationErrors = errorModel.ValidationErrors;
|
||||
}
|
||||
this.statusCode = status;
|
||||
}
|
||||
|
||||
getSingleMessage(): string {
|
||||
if (this.validationErrors) {
|
||||
for (const key in this.validationErrors) {
|
||||
if (!this.validationErrors.hasOwnProperty(key)) {
|
||||
continue;
|
||||
}
|
||||
if (this.validationErrors[key].length) {
|
||||
return this.validationErrors[key][0];
|
||||
}
|
||||
}
|
||||
}
|
||||
return this.message;
|
||||
}
|
||||
}
|
||||
|
||||
export { ErrorResponse };
|
||||
(window as any).ErrorResponse = ErrorResponse;
|
||||
14
src/models/response/folderResponse.ts
Normal file
14
src/models/response/folderResponse.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
class FolderResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
revisionDate: string;
|
||||
|
||||
constructor(response: any) {
|
||||
this.id = response.Id;
|
||||
this.name = response.Name;
|
||||
this.revisionDate = response.RevisionDate;
|
||||
}
|
||||
}
|
||||
|
||||
export { FolderResponse };
|
||||
(window as any).FolderResponse = FolderResponse;
|
||||
14
src/models/response/globalDomainResponse.ts
Normal file
14
src/models/response/globalDomainResponse.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
class GlobalDomainResponse {
|
||||
type: number;
|
||||
domains: string[];
|
||||
excluded: number[];
|
||||
|
||||
constructor(response: any) {
|
||||
this.type = response.Type;
|
||||
this.domains = response.Domains;
|
||||
this.excluded = response.Excluded;
|
||||
}
|
||||
}
|
||||
|
||||
export { GlobalDomainResponse };
|
||||
(window as any).GlobalDomainResponse = GlobalDomainResponse;
|
||||
24
src/models/response/identityTokenResponse.ts
Normal file
24
src/models/response/identityTokenResponse.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
class IdentityTokenResponse {
|
||||
accessToken: string;
|
||||
expiresIn: number;
|
||||
refreshToken: string;
|
||||
tokenType: string;
|
||||
|
||||
privateKey: string;
|
||||
key: string;
|
||||
twoFactorToken: string;
|
||||
|
||||
constructor(response: any) {
|
||||
this.accessToken = response.access_token;
|
||||
this.expiresIn = response.expires_in;
|
||||
this.refreshToken = response.refresh_token;
|
||||
this.tokenType = response.token_type;
|
||||
|
||||
this.privateKey = response.PrivateKey;
|
||||
this.key = response.Key;
|
||||
this.twoFactorToken = response.TwoFactorToken;
|
||||
}
|
||||
}
|
||||
|
||||
export { IdentityTokenResponse };
|
||||
(window as any).IdentityTokenResponse = IdentityTokenResponse;
|
||||
12
src/models/response/keysResponse.ts
Normal file
12
src/models/response/keysResponse.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
class KeysResponse {
|
||||
privateKey: string;
|
||||
publicKey: string;
|
||||
|
||||
constructor(response: any) {
|
||||
this.privateKey = response.PrivateKey;
|
||||
this.publicKey = response.PublicKey;
|
||||
}
|
||||
}
|
||||
|
||||
export { KeysResponse };
|
||||
(window as any).KeysResponse = KeysResponse;
|
||||
10
src/models/response/listResponse.ts
Normal file
10
src/models/response/listResponse.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
class ListResponse {
|
||||
data: any;
|
||||
|
||||
constructor(data: any) {
|
||||
this.data = data;
|
||||
}
|
||||
}
|
||||
|
||||
export { ListResponse };
|
||||
(window as any).ListResponse = ListResponse;
|
||||
30
src/models/response/profileOrganizationResponse.ts
Normal file
30
src/models/response/profileOrganizationResponse.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
class ProfileOrganizationResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
useGroups: boolean;
|
||||
useDirectory: boolean;
|
||||
useTotp: boolean;
|
||||
seats: number;
|
||||
maxCollections: number;
|
||||
maxStorageGb?: number;
|
||||
key: string;
|
||||
status: number; // TODO: map to enum
|
||||
type: number; // TODO: map to enum
|
||||
|
||||
constructor(response: any) {
|
||||
this.id = response.Id;
|
||||
this.name = response.Name;
|
||||
this.useGroups = response.UseGroups;
|
||||
this.useDirectory = response.UseDirectory;
|
||||
this.useTotp = response.UseTotp;
|
||||
this.seats = response.Seats;
|
||||
this.maxCollections = response.MaxCollections;
|
||||
this.maxStorageGb = response.MaxStorageGb;
|
||||
this.key = response.Key;
|
||||
this.status = response.Status;
|
||||
this.type = response.Type;
|
||||
}
|
||||
}
|
||||
|
||||
export { ProfileOrganizationResponse };
|
||||
(window as any).ProfileOrganizationResponse = ProfileOrganizationResponse;
|
||||
39
src/models/response/profileResponse.ts
Normal file
39
src/models/response/profileResponse.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import { ProfileOrganizationResponse } from './profileOrganizationResponse';
|
||||
|
||||
class ProfileResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
email: string;
|
||||
emailVerified: boolean;
|
||||
masterPasswordHint: string;
|
||||
premium: boolean;
|
||||
culture: string;
|
||||
twoFactorEnabled: boolean;
|
||||
key: string;
|
||||
privateKey: string;
|
||||
securityStamp: string;
|
||||
organizations: ProfileOrganizationResponse[] = [];
|
||||
|
||||
constructor(response: any) {
|
||||
this.id = response.Id;
|
||||
this.name = response.Name;
|
||||
this.email = response.Email;
|
||||
this.emailVerified = response.EmailVerified;
|
||||
this.masterPasswordHint = response.MasterPasswordHint;
|
||||
this.premium = response.Premium;
|
||||
this.culture = response.Culture;
|
||||
this.twoFactorEnabled = response.TwoFactorEnabled;
|
||||
this.key = response.Key;
|
||||
this.privateKey = response.PrivateKey;
|
||||
this.securityStamp = response.SecurityStamp;
|
||||
|
||||
if (response.Organizations) {
|
||||
response.Organizations.forEach((org: any) => {
|
||||
this.organizations.push(new ProfileOrganizationResponse(org));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { ProfileResponse };
|
||||
(window as any).ProfileResponse = ProfileResponse;
|
||||
44
src/models/response/syncResponse.ts
Normal file
44
src/models/response/syncResponse.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { CipherResponse } from './cipherResponse';
|
||||
import { CollectionResponse } from './collectionResponse';
|
||||
import { DomainsResponse } from './domainsResponse';
|
||||
import { FolderResponse } from './folderResponse';
|
||||
import { ProfileResponse } from './profileResponse';
|
||||
|
||||
class SyncResponse {
|
||||
profile?: ProfileResponse;
|
||||
folders: FolderResponse[] = [];
|
||||
collections: CollectionResponse[] = [];
|
||||
ciphers: CipherResponse[] = [];
|
||||
domains?: DomainsResponse;
|
||||
|
||||
constructor(response: any) {
|
||||
if (response.Profile) {
|
||||
this.profile = new ProfileResponse(response.Profile);
|
||||
}
|
||||
|
||||
if (response.Folders) {
|
||||
response.Folders.forEach((folder: any) => {
|
||||
this.folders.push(new FolderResponse(folder));
|
||||
});
|
||||
}
|
||||
|
||||
if (response.Collections) {
|
||||
response.Collections.forEach((collection: any) => {
|
||||
this.collections.push(new CollectionResponse(collection));
|
||||
});
|
||||
}
|
||||
|
||||
if (response.Ciphers) {
|
||||
response.Ciphers.forEach((cipher: any) => {
|
||||
this.ciphers.push(new CipherResponse(cipher));
|
||||
});
|
||||
}
|
||||
|
||||
if (response.Domains) {
|
||||
this.domains = new DomainsResponse(response.Domains);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export { SyncResponse };
|
||||
(window as any).SyncResponse = SyncResponse;
|
||||
Reference in New Issue
Block a user