mirror of
https://github.com/bitwarden/browser.git
synced 2024-09-19 02:51:14 +02:00
Refactor for barrels. Utils service to jslib
This commit is contained in:
parent
c018f096b4
commit
03258e50f7
@ -3,7 +3,8 @@ import BrowserApi from '../browser/browserApi';
|
||||
import MainBackground from './main.background';
|
||||
|
||||
import PasswordGenerationService from '../services/passwordGeneration.service';
|
||||
import UtilsService from '../services/utils.service';
|
||||
|
||||
import { Services } from '@bitwarden/jslib';
|
||||
|
||||
export default class CommandsBackground {
|
||||
private commands: any;
|
||||
@ -34,7 +35,7 @@ export default class CommandsBackground {
|
||||
private async generatePasswordToClipboard() {
|
||||
const options = await this.passwordGenerationService.getOptions();
|
||||
const password = PasswordGenerationService.generatePassword(options);
|
||||
UtilsService.copyToClipboard(password);
|
||||
Services.UtilsService.copyToClipboard(password);
|
||||
this.passwordGenerationService.addHistory(password);
|
||||
|
||||
(window as any).ga('send', {
|
||||
|
@ -4,7 +4,8 @@ import MainBackground from './main.background';
|
||||
|
||||
import CipherService from '../services/cipher.service';
|
||||
import PasswordGenerationService from '../services/passwordGeneration.service';
|
||||
import UtilsService from '../services/utils.service';
|
||||
|
||||
import { Services } from '@bitwarden/jslib';
|
||||
|
||||
export default class ContextMenusBackground {
|
||||
private contextMenus: any;
|
||||
@ -32,7 +33,7 @@ export default class ContextMenusBackground {
|
||||
private async generatePasswordToClipboard() {
|
||||
const options = await this.passwordGenerationService.getOptions();
|
||||
const password = PasswordGenerationService.generatePassword(options);
|
||||
UtilsService.copyToClipboard(password);
|
||||
Services.UtilsService.copyToClipboard(password);
|
||||
this.passwordGenerationService.addHistory(password);
|
||||
|
||||
(window as any).ga('send', {
|
||||
@ -68,13 +69,13 @@ export default class ContextMenusBackground {
|
||||
hitType: 'event',
|
||||
eventAction: 'Copied Username From Context Menu',
|
||||
});
|
||||
UtilsService.copyToClipboard(cipher.login.username);
|
||||
Services.UtilsService.copyToClipboard(cipher.login.username);
|
||||
} else if (info.parentMenuItemId === 'copy-password') {
|
||||
(window as any).ga('send', {
|
||||
hitType: 'event',
|
||||
eventAction: 'Copied Password From Context Menu',
|
||||
});
|
||||
UtilsService.copyToClipboard(cipher.login.password);
|
||||
Services.UtilsService.copyToClipboard(cipher.login.password);
|
||||
}
|
||||
|
||||
break;
|
||||
|
@ -2,13 +2,13 @@ import ConstantsService from '../services/constants.service';
|
||||
import LockService from '../services/lock.service';
|
||||
import MainBackground from './main.background';
|
||||
|
||||
import { StorageService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
export default class IdleBackground {
|
||||
private idle: any;
|
||||
|
||||
constructor(private main: MainBackground, private lockService: LockService,
|
||||
private storageService: StorageService) {
|
||||
private storageService: Abstractions.StorageService) {
|
||||
this.idle = chrome.idle;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { CipherType } from '@bitwarden/jslib';
|
||||
import { Abstractions, Enums, Services } from '@bitwarden/jslib';
|
||||
|
||||
import { Cipher } from '../models/domain/cipher';
|
||||
|
||||
@ -33,16 +33,13 @@ import SyncService from '../services/sync.service';
|
||||
import TokenService from '../services/token.service';
|
||||
import TotpService from '../services/totp.service';
|
||||
import UserService from '../services/user.service';
|
||||
import UtilsService from '../services/utils.service';
|
||||
|
||||
import { MessagingService, PlatformUtilsService, StorageService } from '@bitwarden/jslib';
|
||||
|
||||
export default class MainBackground {
|
||||
messagingService: MessagingService;
|
||||
storageService: StorageService;
|
||||
messagingService: Abstractions.MessagingService;
|
||||
storageService: Abstractions.StorageService;
|
||||
i18nService: any;
|
||||
platformUtilsService: PlatformUtilsService;
|
||||
utilsService: UtilsService;
|
||||
platformUtilsService: Abstractions.PlatformUtilsService;
|
||||
utilsService: Abstractions.UtilsService;
|
||||
constantsService: ConstantsService;
|
||||
cryptoService: CryptoService;
|
||||
tokenService: TokenService;
|
||||
@ -80,7 +77,7 @@ export default class MainBackground {
|
||||
|
||||
constructor() {
|
||||
// Services
|
||||
this.utilsService = new UtilsService();
|
||||
this.utilsService = new Services.UtilsService();
|
||||
this.platformUtilsService = new BrowserPlatformUtilsService();
|
||||
this.messagingService = new BrowserMessagingService(this.platformUtilsService);
|
||||
this.storageService = new BrowserStorageService(this.platformUtilsService);
|
||||
@ -348,7 +345,7 @@ export default class MainBackground {
|
||||
}
|
||||
|
||||
private async loadLoginContextMenuOptions(cipher: any) {
|
||||
if (cipher == null || cipher.type !== CipherType.Login) {
|
||||
if (cipher == null || cipher.type !== Enums.CipherType.Login) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -365,7 +362,7 @@ export default class MainBackground {
|
||||
|
||||
private async loadContextMenuOptions(title: string, idSuffix: string, cipher: any) {
|
||||
if (!chrome.contextMenus || this.menuOptionsLoaded.indexOf(idSuffix) > -1 ||
|
||||
(cipher != null && cipher.type !== CipherType.Login)) {
|
||||
(cipher != null && cipher.type !== Enums.CipherType.Login)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { CipherType } from '@bitwarden/jslib';
|
||||
import { Abstractions, Enums, Services } from '@bitwarden/jslib';
|
||||
|
||||
import BrowserApi from '../browser/browserApi';
|
||||
|
||||
@ -6,9 +6,6 @@ import MainBackground from './main.background';
|
||||
|
||||
import AutofillService from '../services/autofill.service';
|
||||
import CipherService from '../services/cipher.service';
|
||||
import UtilsService from '../services/utils.service';
|
||||
|
||||
import { PlatformUtilsService } from '@bitwarden/jslib';
|
||||
|
||||
export default class RuntimeBackground {
|
||||
private runtime: any;
|
||||
@ -16,7 +13,7 @@ export default class RuntimeBackground {
|
||||
private pageDetailsToAutoFill: any[] = [];
|
||||
|
||||
constructor(private main: MainBackground, private autofillService: AutofillService,
|
||||
private cipherService: CipherService, private platformUtilsService: PlatformUtilsService) {
|
||||
private cipherService: CipherService, private platformUtilsService: Abstractions.PlatformUtilsService) {
|
||||
this.runtime = chrome.runtime;
|
||||
}
|
||||
|
||||
@ -149,7 +146,7 @@ export default class RuntimeBackground {
|
||||
favorite: false,
|
||||
name: loginInfo.name,
|
||||
notes: null,
|
||||
type: CipherType.Login,
|
||||
type: Enums.CipherType.Login,
|
||||
login: {
|
||||
uri: loginInfo.uri,
|
||||
username: loginInfo.username,
|
||||
@ -180,7 +177,7 @@ export default class RuntimeBackground {
|
||||
}
|
||||
|
||||
this.main.loginsToAdd.splice(i, 1);
|
||||
const hostname = UtilsService.getHostname(tab.url);
|
||||
const hostname = Services.UtilsService.getHostname(tab.url);
|
||||
await this.cipherService.saveNeverDomain(hostname);
|
||||
BrowserApi.tabSendMessage(tab, 'closeNotificationBar');
|
||||
}
|
||||
|
@ -1,13 +1,14 @@
|
||||
import CipherService from '../services/cipher.service';
|
||||
|
||||
import { PlatformUtilsService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
export default class WebRequestBackground {
|
||||
private pendingAuthRequests: any[] = [];
|
||||
private webRequest: any;
|
||||
private isFirefox: boolean;
|
||||
|
||||
constructor(private platformUtilsService: PlatformUtilsService, private cipherService: CipherService) {
|
||||
constructor(private platformUtilsService: Abstractions.PlatformUtilsService,
|
||||
private cipherService: CipherService) {
|
||||
this.webRequest = (window as any).chrome.webRequest;
|
||||
this.isFirefox = platformUtilsService.isFirefox();
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { CipherType } from '@bitwarden/jslib';
|
||||
import { Enums } from '@bitwarden/jslib';
|
||||
|
||||
import { AttachmentData } from './attachmentData';
|
||||
import { CardData } from './cardData';
|
||||
@ -18,7 +18,7 @@ class CipherData {
|
||||
organizationUseTotp: boolean;
|
||||
favorite: boolean;
|
||||
revisionDate: string;
|
||||
type: CipherType;
|
||||
type: Enums.CipherType;
|
||||
sizeName: string;
|
||||
name: string;
|
||||
notes: string;
|
||||
@ -51,16 +51,16 @@ class CipherData {
|
||||
this.notes = response.data.Notes;
|
||||
|
||||
switch (this.type) {
|
||||
case CipherType.Login:
|
||||
case Enums.CipherType.Login:
|
||||
this.login = new LoginData(response.data);
|
||||
break;
|
||||
case CipherType.SecureNote:
|
||||
case Enums.CipherType.SecureNote:
|
||||
this.secureNote = new SecureNoteData(response.data);
|
||||
break;
|
||||
case CipherType.Card:
|
||||
case Enums.CipherType.Card:
|
||||
this.card = new CardData(response.data);
|
||||
break;
|
||||
case CipherType.Identity:
|
||||
case Enums.CipherType.Identity:
|
||||
this.identity = new IdentityData(response.data);
|
||||
break;
|
||||
default:
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { FieldType } from '@bitwarden/jslib';
|
||||
import { Enums } from '@bitwarden/jslib';
|
||||
|
||||
class FieldData {
|
||||
type: FieldType;
|
||||
type: Enums.FieldType;
|
||||
name: string;
|
||||
value: string;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { SecureNoteType } from '@bitwarden/jslib';
|
||||
import { Enums } from '@bitwarden/jslib';
|
||||
|
||||
class SecureNoteData {
|
||||
type: SecureNoteType;
|
||||
type: Enums.SecureNoteType;
|
||||
|
||||
constructor(data: any) {
|
||||
this.type = data.Type;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { CipherType } from '@bitwarden/jslib';
|
||||
import { Enums } from '@bitwarden/jslib';
|
||||
|
||||
import { CipherData } from '../data/cipherData';
|
||||
|
||||
@ -19,7 +19,7 @@ class Cipher extends Domain {
|
||||
folderId: string;
|
||||
name: CipherString;
|
||||
notes: CipherString;
|
||||
type: CipherType;
|
||||
type: Enums.CipherType;
|
||||
favorite: boolean;
|
||||
organizationUseTotp: boolean;
|
||||
edit: boolean;
|
||||
@ -54,16 +54,16 @@ class Cipher extends Domain {
|
||||
this.localData = localData;
|
||||
|
||||
switch (this.type) {
|
||||
case CipherType.Login:
|
||||
case Enums.CipherType.Login:
|
||||
this.login = new Login(obj.login, alreadyEncrypted);
|
||||
break;
|
||||
case CipherType.SecureNote:
|
||||
case Enums.CipherType.SecureNote:
|
||||
this.secureNote = new SecureNote(obj.secureNote, alreadyEncrypted);
|
||||
break;
|
||||
case CipherType.Card:
|
||||
case Enums.CipherType.Card:
|
||||
this.card = new Card(obj.card, alreadyEncrypted);
|
||||
break;
|
||||
case CipherType.Identity:
|
||||
case Enums.CipherType.Identity:
|
||||
this.identity = new Identity(obj.identity, alreadyEncrypted);
|
||||
break;
|
||||
default:
|
||||
@ -113,18 +113,18 @@ class Cipher extends Domain {
|
||||
}, this.organizationId);
|
||||
|
||||
switch (this.type) {
|
||||
case CipherType.Login:
|
||||
case Enums.CipherType.Login:
|
||||
model.login = await this.login.decrypt(this.organizationId);
|
||||
model.subTitle = model.login.username;
|
||||
if (model.login.uri) {
|
||||
model.login.domain = BrowserPlatformUtilsService.getDomain(model.login.uri);
|
||||
}
|
||||
break;
|
||||
case CipherType.SecureNote:
|
||||
case Enums.CipherType.SecureNote:
|
||||
model.secureNote = await this.secureNote.decrypt(this.organizationId);
|
||||
model.subTitle = null;
|
||||
break;
|
||||
case CipherType.Card:
|
||||
case Enums.CipherType.Card:
|
||||
model.card = await this.card.decrypt(this.organizationId);
|
||||
model.subTitle = model.card.brand;
|
||||
if (model.card.number && model.card.number.length >= 4) {
|
||||
@ -134,7 +134,7 @@ class Cipher extends Domain {
|
||||
model.subTitle += ('*' + model.card.number.substr(model.card.number.length - 4));
|
||||
}
|
||||
break;
|
||||
case CipherType.Identity:
|
||||
case Enums.CipherType.Identity:
|
||||
model.identity = await this.identity.decrypt(this.organizationId);
|
||||
model.subTitle = '';
|
||||
if (model.identity.firstName) {
|
||||
|
@ -1,19 +1,19 @@
|
||||
import { EncryptionType } from '@bitwarden/jslib';
|
||||
import { Enums } from '@bitwarden/jslib';
|
||||
|
||||
import ContainerService from '../../services/container.service';
|
||||
|
||||
class CipherString {
|
||||
encryptedString?: string;
|
||||
encryptionType?: EncryptionType;
|
||||
encryptionType?: Enums.EncryptionType;
|
||||
decryptedValue?: string;
|
||||
cipherText?: string;
|
||||
initializationVector?: string;
|
||||
mac?: string;
|
||||
|
||||
constructor(encryptedStringOrType: string | EncryptionType, ct?: string, iv?: string, mac?: string) {
|
||||
constructor(encryptedStringOrType: string | Enums.EncryptionType, ct?: string, iv?: string, mac?: string) {
|
||||
if (ct != null) {
|
||||
// ct and header
|
||||
const encType = encryptedStringOrType as EncryptionType;
|
||||
const encType = encryptedStringOrType as Enums.EncryptionType;
|
||||
this.encryptedString = encType + '.' + ct;
|
||||
|
||||
// iv
|
||||
@ -51,13 +51,13 @@ class CipherString {
|
||||
}
|
||||
} else {
|
||||
encPieces = this.encryptedString.split('|');
|
||||
this.encryptionType = encPieces.length === 3 ? EncryptionType.AesCbc128_HmacSha256_B64 :
|
||||
EncryptionType.AesCbc256_B64;
|
||||
this.encryptionType = encPieces.length === 3 ? Enums.EncryptionType.AesCbc128_HmacSha256_B64 :
|
||||
Enums.EncryptionType.AesCbc256_B64;
|
||||
}
|
||||
|
||||
switch (this.encryptionType) {
|
||||
case EncryptionType.AesCbc128_HmacSha256_B64:
|
||||
case EncryptionType.AesCbc256_HmacSha256_B64:
|
||||
case Enums.EncryptionType.AesCbc128_HmacSha256_B64:
|
||||
case Enums.EncryptionType.AesCbc256_HmacSha256_B64:
|
||||
if (encPieces.length !== 3) {
|
||||
return;
|
||||
}
|
||||
@ -66,7 +66,7 @@ class CipherString {
|
||||
this.cipherText = encPieces[1];
|
||||
this.mac = encPieces[2];
|
||||
break;
|
||||
case EncryptionType.AesCbc256_B64:
|
||||
case Enums.EncryptionType.AesCbc256_B64:
|
||||
if (encPieces.length !== 2) {
|
||||
return;
|
||||
}
|
||||
@ -74,8 +74,8 @@ class CipherString {
|
||||
this.initializationVector = encPieces[0];
|
||||
this.cipherText = encPieces[1];
|
||||
break;
|
||||
case EncryptionType.Rsa2048_OaepSha256_B64:
|
||||
case EncryptionType.Rsa2048_OaepSha1_B64:
|
||||
case Enums.EncryptionType.Rsa2048_OaepSha256_B64:
|
||||
case Enums.EncryptionType.Rsa2048_OaepSha1_B64:
|
||||
if (encPieces.length !== 1) {
|
||||
return;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { FieldType } from '@bitwarden/jslib';
|
||||
import { Enums } from '@bitwarden/jslib';
|
||||
|
||||
import { FieldData } from '../data/fieldData';
|
||||
|
||||
@ -8,7 +8,7 @@ import Domain from './domain';
|
||||
class Field extends Domain {
|
||||
name: CipherString;
|
||||
vault: CipherString;
|
||||
type: FieldType;
|
||||
type: Enums.FieldType;
|
||||
|
||||
constructor(obj?: FieldData, alreadyEncrypted: boolean = false) {
|
||||
super();
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { SecureNoteType } from '@bitwarden/jslib';
|
||||
import { Enums } from '@bitwarden/jslib';
|
||||
|
||||
import { SecureNoteData } from '../data/secureNoteData';
|
||||
|
||||
import Domain from './domain';
|
||||
|
||||
class SecureNote extends Domain {
|
||||
type: SecureNoteType;
|
||||
type: Enums.SecureNoteType;
|
||||
|
||||
constructor(obj?: SecureNoteData, alreadyEncrypted: boolean = false) {
|
||||
super();
|
||||
|
@ -1,20 +1,18 @@
|
||||
import * as forge from 'node-forge';
|
||||
|
||||
import { EncryptionType } from '@bitwarden/jslib';
|
||||
import { Enums, Services } from '@bitwarden/jslib';
|
||||
|
||||
import SymmetricCryptoKeyBuffers from './symmetricCryptoKeyBuffers';
|
||||
|
||||
import UtilsService from '../../services/utils.service';
|
||||
|
||||
export default class SymmetricCryptoKey {
|
||||
key: string;
|
||||
keyB64: string;
|
||||
encKey: string;
|
||||
macKey: string;
|
||||
encType: EncryptionType;
|
||||
encType: Enums.EncryptionType;
|
||||
keyBuf: SymmetricCryptoKeyBuffers;
|
||||
|
||||
constructor(keyBytes: string, b64KeyBytes?: boolean, encType?: EncryptionType) {
|
||||
constructor(keyBytes: string, b64KeyBytes?: boolean, encType?: Enums.EncryptionType) {
|
||||
if (b64KeyBytes) {
|
||||
keyBytes = forge.util.decode64(keyBytes);
|
||||
}
|
||||
@ -32,9 +30,9 @@ export default class SymmetricCryptoKey {
|
||||
|
||||
if (encType == null) {
|
||||
if (bufferLength === 32) {
|
||||
encType = EncryptionType.AesCbc256_B64;
|
||||
encType = Enums.EncryptionType.AesCbc256_B64;
|
||||
} else if (bufferLength === 64) {
|
||||
encType = EncryptionType.AesCbc256_HmacSha256_B64;
|
||||
encType = Enums.EncryptionType.AesCbc256_HmacSha256_B64;
|
||||
} else {
|
||||
throw new Error('Unable to determine encType.');
|
||||
}
|
||||
@ -44,13 +42,13 @@ export default class SymmetricCryptoKey {
|
||||
this.keyB64 = forge.util.encode64(keyBytes);
|
||||
this.encType = encType;
|
||||
|
||||
if (encType === EncryptionType.AesCbc256_B64 && bufferLength === 32) {
|
||||
if (encType === Enums.EncryptionType.AesCbc256_B64 && bufferLength === 32) {
|
||||
this.encKey = keyBytes;
|
||||
this.macKey = null;
|
||||
} else if (encType === EncryptionType.AesCbc128_HmacSha256_B64 && bufferLength === 32) {
|
||||
} else if (encType === Enums.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) {
|
||||
} else if (encType === Enums.EncryptionType.AesCbc256_HmacSha256_B64 && bufferLength === 64) {
|
||||
this.encKey = buffer.getBytes(32); // first half
|
||||
this.macKey = buffer.getBytes(32); // second half
|
||||
} else {
|
||||
@ -63,7 +61,7 @@ export default class SymmetricCryptoKey {
|
||||
return this.keyBuf;
|
||||
}
|
||||
|
||||
const key = UtilsService.fromB64ToArray(this.keyB64);
|
||||
const key = Services.UtilsService.fromB64ToArray(this.keyB64);
|
||||
const keys = new SymmetricCryptoKeyBuffers(key.buffer);
|
||||
|
||||
if (this.macKey) {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { CipherType } from '@bitwarden/jslib';
|
||||
import { Enums } from '@bitwarden/jslib';
|
||||
|
||||
class CipherRequest {
|
||||
type: CipherType;
|
||||
type: Enums.CipherType;
|
||||
folderId: string;
|
||||
organizationId: string;
|
||||
name: string;
|
||||
@ -22,7 +22,7 @@ class CipherRequest {
|
||||
this.favorite = cipher.favorite;
|
||||
|
||||
switch (this.type) {
|
||||
case CipherType.Login:
|
||||
case Enums.CipherType.Login:
|
||||
this.login = {
|
||||
uri: cipher.login.uri ? cipher.login.uri.encryptedString : null,
|
||||
username: cipher.login.username ? cipher.login.username.encryptedString : null,
|
||||
@ -30,12 +30,12 @@ class CipherRequest {
|
||||
totp: cipher.login.totp ? cipher.login.totp.encryptedString : null,
|
||||
};
|
||||
break;
|
||||
case CipherType.SecureNote:
|
||||
case Enums.CipherType.SecureNote:
|
||||
this.secureNote = {
|
||||
type: cipher.secureNote.type,
|
||||
};
|
||||
break;
|
||||
case CipherType.Card:
|
||||
case Enums.CipherType.Card:
|
||||
this.card = {
|
||||
cardholderName: cipher.card.cardholderName ? cipher.card.cardholderName.encryptedString : null,
|
||||
brand: cipher.card.brand ? cipher.card.brand.encryptedString : null,
|
||||
@ -45,7 +45,7 @@ class CipherRequest {
|
||||
code: cipher.card.code ? cipher.card.code.encryptedString : null,
|
||||
};
|
||||
break;
|
||||
case CipherType.Identity:
|
||||
case Enums.CipherType.Identity:
|
||||
this.identity = {
|
||||
title: cipher.identity.title ? cipher.identity.title.encryptedString : null,
|
||||
firstName: cipher.identity.firstName ? cipher.identity.firstName.encryptedString : null,
|
||||
|
@ -1,12 +1,12 @@
|
||||
import { DeviceType, PlatformUtilsService } from '@bitwarden/jslib';
|
||||
import { Abstractions, Enums } from '@bitwarden/jslib';
|
||||
|
||||
class DeviceRequest {
|
||||
type: DeviceType;
|
||||
type: Enums.DeviceType;
|
||||
name: string;
|
||||
identifier: string;
|
||||
pushToken?: string;
|
||||
|
||||
constructor(appId: string, platformUtilsService: PlatformUtilsService) {
|
||||
constructor(appId: string, platformUtilsService: Abstractions.PlatformUtilsService) {
|
||||
this.type = platformUtilsService.getDevice();
|
||||
this.name = platformUtilsService.getDeviceString();
|
||||
this.identifier = appId;
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { DeviceType } from '@bitwarden/jslib';
|
||||
import { Enums } from '@bitwarden/jslib';
|
||||
|
||||
class DeviceResponse {
|
||||
id: string;
|
||||
name: number;
|
||||
identifier: string;
|
||||
type: DeviceType;
|
||||
type: Enums.DeviceType;
|
||||
creationDate: string;
|
||||
|
||||
constructor(response: any) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as template from './action-buttons.component.html';
|
||||
|
||||
import { PlatformUtilsService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
export class ActionButtonsController implements ng.IController {
|
||||
onView: Function;
|
||||
@ -11,7 +11,8 @@ export class ActionButtonsController implements ng.IController {
|
||||
constants: any;
|
||||
|
||||
constructor(private i18nService: any, private $analytics: any, private constantsService: any, private toastr: any,
|
||||
private $timeout: any, private $window: any, private platformUtilsService: PlatformUtilsService) {
|
||||
private $timeout: any, private $window: any,
|
||||
private platformUtilsService: Abstractions.PlatformUtilsService) {
|
||||
this.i18n = i18nService;
|
||||
this.constants = constantsService;
|
||||
}
|
||||
|
@ -1,11 +1,12 @@
|
||||
import * as template from './pop-out.component.html';
|
||||
|
||||
import { PlatformUtilsService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
export class PopOutController implements ng.IController {
|
||||
i18n: any;
|
||||
|
||||
constructor(private $analytics: any, private $window: any, private platformUtilsService: PlatformUtilsService,
|
||||
constructor(private $analytics: any, private $window: any,
|
||||
private platformUtilsService: Abstractions.PlatformUtilsService,
|
||||
private i18nService: any) {
|
||||
this.i18n = i18nService;
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { CipherType } from '@bitwarden/jslib';
|
||||
import { Abstractions, Enums } from '@bitwarden/jslib';
|
||||
|
||||
import { PlatformUtilsService, UtilsService } from '@bitwarden/jslib';
|
||||
import * as template from './current.component.html';
|
||||
|
||||
export class CurrentController {
|
||||
@ -17,8 +16,9 @@ export class CurrentController {
|
||||
inSidebar: boolean = false;
|
||||
disableSearch: boolean = false;
|
||||
|
||||
constructor($scope: any, private cipherService: any, private platformUtilsService: PlatformUtilsService,
|
||||
private utilsService: UtilsService, private toastr: any, private $window: any, private $state: any,
|
||||
constructor($scope: any, private cipherService: any,
|
||||
private platformUtilsService: Abstractions.PlatformUtilsService,
|
||||
private utilsService: Abstractions.UtilsService, private toastr: any, private $window: any, private $state: any,
|
||||
private $timeout: any, private autofillService: any, private $analytics: any, private i18nService: any,
|
||||
private $filter: any) {
|
||||
this.i18n = i18nService;
|
||||
@ -117,8 +117,8 @@ export class CurrentController {
|
||||
});
|
||||
|
||||
const otherTypes = [
|
||||
CipherType.Card,
|
||||
CipherType.Identity,
|
||||
Enums.CipherType.Card,
|
||||
Enums.CipherType.Identity,
|
||||
];
|
||||
|
||||
this.cipherService.getAllDecryptedForDomain(this.domain, otherTypes).then((ciphers: any[]) => {
|
||||
@ -131,13 +131,13 @@ export class CurrentController {
|
||||
|
||||
sortedCiphers.forEach((cipher: any) => {
|
||||
switch (cipher.type) {
|
||||
case CipherType.Login:
|
||||
case Enums.CipherType.Login:
|
||||
loginCiphers.push(cipher);
|
||||
break;
|
||||
case CipherType.Card:
|
||||
case Enums.CipherType.Card:
|
||||
cardCiphers.push(cipher);
|
||||
break;
|
||||
case CipherType.Identity:
|
||||
case Enums.CipherType.Identity:
|
||||
identityCiphers.push(cipher);
|
||||
break;
|
||||
default:
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { UtilsService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
export class MainController implements ng.IController {
|
||||
smBody: boolean;
|
||||
@ -6,7 +6,7 @@ export class MainController implements ng.IController {
|
||||
animation: string;
|
||||
|
||||
constructor($scope: any, $transitions: any, $state: any, authService: any, toastr: any,
|
||||
i18nService: any, $analytics: any, utilsService: UtilsService, $window: any) {
|
||||
i18nService: any, $analytics: any, utilsService: Abstractions.UtilsService, $window: any) {
|
||||
this.animation = '';
|
||||
this.xsBody = $window.screen.availHeight < 600;
|
||||
this.smBody = !this.xsBody && $window.screen.availHeight <= 800;
|
||||
|
@ -3,15 +3,16 @@ import * as template from './lock.component.html';
|
||||
|
||||
import { CryptoService } from '../../../services/abstractions/crypto.service';
|
||||
|
||||
import { MessagingService, PlatformUtilsService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
export class LockController {
|
||||
i18n: any;
|
||||
masterPassword: string;
|
||||
|
||||
constructor(public $state: any, public i18nService: any, private $timeout: any,
|
||||
private platformUtilsService: PlatformUtilsService, public cryptoService: CryptoService, public toastr: any,
|
||||
public userService: any, public messagingService: MessagingService, public SweetAlert: any) {
|
||||
private platformUtilsService: Abstractions.PlatformUtilsService,
|
||||
public cryptoService: CryptoService, public toastr: any, public userService: any,
|
||||
public messagingService: Abstractions.MessagingService, public SweetAlert: any) {
|
||||
this.i18n = i18nService;
|
||||
}
|
||||
|
||||
|
@ -3,13 +3,13 @@ import { TokenRequest } from '../../../models/request/tokenRequest';
|
||||
|
||||
import { CryptoService } from '../../../services/abstractions/crypto.service';
|
||||
|
||||
import { MessagingService, PlatformUtilsService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
class AuthService {
|
||||
constructor(public cryptoService: CryptoService, public apiService: any, public userService: any,
|
||||
public tokenService: any, public $rootScope: any, public appIdService: any,
|
||||
public platformUtilsService: PlatformUtilsService, public constantsService: any,
|
||||
public messagingService: MessagingService) {
|
||||
public platformUtilsService: Abstractions.PlatformUtilsService, public constantsService: any,
|
||||
public messagingService: Abstractions.MessagingService) {
|
||||
}
|
||||
|
||||
async logIn(email: string, masterPassword: string, twoFactorProvider?: number,
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { CryptoService } from '../../../services/abstractions/crypto.service';
|
||||
|
||||
import { PlatformUtilsService, StorageService, UtilsService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
function getBackgroundService<T>(service: string) {
|
||||
return (): T => {
|
||||
@ -9,7 +9,7 @@ function getBackgroundService<T>(service: string) {
|
||||
};
|
||||
}
|
||||
|
||||
export const storageService = getBackgroundService<StorageService>('storageService');
|
||||
export const storageService = getBackgroundService<Abstractions.StorageService>('storageService');
|
||||
export const tokenService = getBackgroundService<any>('tokenService');
|
||||
export const cryptoService = getBackgroundService<any>('cryptoService');
|
||||
export const userService = getBackgroundService<any>('userService');
|
||||
@ -19,8 +19,8 @@ export const cipherService = getBackgroundService<CryptoService>('cipherService'
|
||||
export const syncService = getBackgroundService<any>('syncService');
|
||||
export const autofillService = getBackgroundService<any>('autofillService');
|
||||
export const passwordGenerationService = getBackgroundService<any>('passwordGenerationService');
|
||||
export const platformUtilsService = getBackgroundService<PlatformUtilsService>('platformUtilsService');
|
||||
export const utilsService = getBackgroundService<UtilsService>('utilsService');
|
||||
export const platformUtilsService = getBackgroundService<Abstractions.PlatformUtilsService>('platformUtilsService');
|
||||
export const utilsService = getBackgroundService<Abstractions.UtilsService>('utilsService');
|
||||
export const appIdService = getBackgroundService<any>('appIdService');
|
||||
export const i18nService = getBackgroundService<any>('i18nService');
|
||||
export const constantsService = getBackgroundService<any>('constantsService');
|
||||
|
@ -1,9 +1,9 @@
|
||||
import { StorageService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
class StateService {
|
||||
private state: any = {};
|
||||
|
||||
constructor(private storageService: StorageService, private constantsService: any) {
|
||||
constructor(private storageService: Abstractions.StorageService, private constantsService: any) {
|
||||
}
|
||||
|
||||
async init() {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import * as angular from 'angular';
|
||||
import * as template from './environment.component.html';
|
||||
|
||||
import { PlatformUtilsService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
export class EnvironmentController {
|
||||
iconsUrl: string;
|
||||
@ -11,7 +11,8 @@ export class EnvironmentController {
|
||||
baseUrl: string;
|
||||
i18n: any;
|
||||
|
||||
constructor(private i18nService: any, private $analytics: any, platformUtilsService: PlatformUtilsService,
|
||||
constructor(private i18nService: any, private $analytics: any,
|
||||
platformUtilsService: Abstractions.PlatformUtilsService,
|
||||
private environmentService: any, private toastr: any, private $timeout: ng.ITimeoutService) {
|
||||
this.i18n = i18nService;
|
||||
|
||||
|
@ -2,7 +2,7 @@ import * as angular from 'angular';
|
||||
import { Folder } from '../../../../models/domain/folder';
|
||||
import * as template from './add-folder.component.html';
|
||||
|
||||
import { PlatformUtilsService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
export class AddFolderController {
|
||||
savePromise: any;
|
||||
@ -10,7 +10,7 @@ export class AddFolderController {
|
||||
i18n: any;
|
||||
|
||||
constructor(private folderService: any, private $state: any, private toastr: any,
|
||||
platformUtilsService: PlatformUtilsService, private $analytics: any, private i18nService: any,
|
||||
platformUtilsService: Abstractions.PlatformUtilsService, private $analytics: any, private i18nService: any,
|
||||
$timeout: any) {
|
||||
$timeout(() => {
|
||||
platformUtilsService.initListSectionItemListeners(document, angular);
|
||||
|
@ -2,7 +2,7 @@ import * as angular from 'angular';
|
||||
import { Folder } from '../../../../models/domain/folder';
|
||||
import * as template from './edit-folder.component.html';
|
||||
|
||||
import { PlatformUtilsService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
export class EditFolderController {
|
||||
$transition$: any;
|
||||
@ -12,7 +12,7 @@ export class EditFolderController {
|
||||
folder: Folder;
|
||||
|
||||
constructor($scope: any, $stateParams: any, private folderService: any, private toastr: any, private $state: any,
|
||||
private SweetAlert: any, platformUtilsService: PlatformUtilsService, private $analytics: any,
|
||||
private SweetAlert: any, platformUtilsService: Abstractions.PlatformUtilsService, private $analytics: any,
|
||||
private i18nService: any, $timeout: any) {
|
||||
this.i18n = i18nService;
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as angular from 'angular';
|
||||
|
||||
import { MessagingService, PlatformUtilsService, StorageService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
import StateService from '../services/state.service';
|
||||
import * as template from './options.component.html';
|
||||
@ -15,9 +15,9 @@ export class OptionsController {
|
||||
i18n: any;
|
||||
|
||||
constructor(private i18nService: any, private $analytics: any, private constantsService: any,
|
||||
private platformUtilsService: PlatformUtilsService, private totpService: any,
|
||||
private stateService: StateService, private storageService: StorageService,
|
||||
public messagingService: MessagingService, private $timeout: ng.ITimeoutService) {
|
||||
private platformUtilsService: Abstractions.PlatformUtilsService, private totpService: any,
|
||||
private stateService: StateService, private storageService: Abstractions.StorageService,
|
||||
public messagingService: Abstractions.MessagingService, private $timeout: ng.ITimeoutService) {
|
||||
this.i18n = i18nService;
|
||||
|
||||
$timeout(() => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as angular from 'angular';
|
||||
|
||||
import { DeviceType, MessagingService, PlatformUtilsService, StorageService } from '@bitwarden/jslib';
|
||||
import { Abstractions, Enums } from '@bitwarden/jslib';
|
||||
|
||||
import { CryptoService } from '../../../services/abstractions/crypto.service';
|
||||
import ConstantsService from '../../../services/constants.service';
|
||||
@ -8,17 +8,17 @@ import ConstantsService from '../../../services/constants.service';
|
||||
import * as template from './settings.component.html';
|
||||
|
||||
const RateUrls = {
|
||||
[DeviceType.Chrome]:
|
||||
[Enums.DeviceType.Chrome]:
|
||||
'https://chrome.google.com/webstore/detail/bitwarden-free-password-m/nngceckbapebfimnlniiiahkandclblb/reviews',
|
||||
[DeviceType.Firefox]:
|
||||
[Enums.DeviceType.Firefox]:
|
||||
'https://addons.mozilla.org/en-US/firefox/addon/bitwarden-password-manager/#reviews',
|
||||
[DeviceType.Opera]:
|
||||
[Enums.DeviceType.Opera]:
|
||||
'https://addons.opera.com/en/extensions/details/bitwarden-free-password-manager/#feedback-container',
|
||||
[DeviceType.Edge]:
|
||||
[Enums.DeviceType.Edge]:
|
||||
'https://www.microsoft.com/store/p/bitwarden-free-password-manager/9p6kxl0svnnl',
|
||||
[DeviceType.Vivaldi]:
|
||||
[Enums.DeviceType.Vivaldi]:
|
||||
'https://chrome.google.com/webstore/detail/bitwarden-free-password-m/nngceckbapebfimnlniiiahkandclblb/reviews',
|
||||
[DeviceType.Safari]:
|
||||
[Enums.DeviceType.Safari]:
|
||||
'https://itunes.com', // TODO
|
||||
};
|
||||
|
||||
@ -27,10 +27,12 @@ export class SettingsController {
|
||||
i18n: any;
|
||||
showOnLocked: boolean;
|
||||
|
||||
constructor(private $state: any, private SweetAlert: any, private platformUtilsService: PlatformUtilsService,
|
||||
private $analytics: any, private i18nService: any, private constantsService: ConstantsService,
|
||||
private cryptoService: CryptoService, private lockService: any, private storageService: StorageService,
|
||||
public messagingService: MessagingService, private $timeout: ng.ITimeoutService) {
|
||||
constructor(private $state: any, private SweetAlert: any,
|
||||
private platformUtilsService: Abstractions.PlatformUtilsService, private $analytics: any,
|
||||
private i18nService: any, private constantsService: ConstantsService,
|
||||
private cryptoService: CryptoService, private lockService: any,
|
||||
private storageService: Abstractions.StorageService,
|
||||
public messagingService: Abstractions.MessagingService, private $timeout: ng.ITimeoutService) {
|
||||
this.i18n = i18nService;
|
||||
|
||||
$timeout(() => {
|
||||
|
@ -2,7 +2,7 @@ import * as angular from 'angular';
|
||||
import * as papa from 'papaparse';
|
||||
import * as template from './export.component.html';
|
||||
|
||||
import { CipherType, UtilsService } from '@bitwarden/jslib';
|
||||
import { Abstractions, Enums } from '@bitwarden/jslib';
|
||||
|
||||
import { CryptoService } from '../../../services/abstractions/crypto.service';
|
||||
|
||||
@ -11,7 +11,7 @@ export class ExportController {
|
||||
masterPassword: string;
|
||||
|
||||
constructor(private $state: any, private cryptoService: CryptoService,
|
||||
private toastr: any, private utilsService: UtilsService, private $analytics: any,
|
||||
private toastr: any, private utilsService: Abstractions.UtilsService, private $analytics: any,
|
||||
private i18nService: any, private folderService: any, private cipherService: any,
|
||||
private $window: any, private userService: any) {
|
||||
this.i18n = i18nService;
|
||||
@ -74,7 +74,7 @@ export class ExportController {
|
||||
const exportCiphers = [];
|
||||
for (const c of decCiphers) {
|
||||
// only export logins and secure notes
|
||||
if (c.type !== CipherType.Login && c.type !== CipherType.SecureNote) {
|
||||
if (c.type !== Enums.CipherType.Login && c.type !== Enums.CipherType.SecureNote) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -105,14 +105,14 @@ export class ExportController {
|
||||
}
|
||||
|
||||
switch (c.type) {
|
||||
case CipherType.Login:
|
||||
case Enums.CipherType.Login:
|
||||
cipher.type = 'login';
|
||||
cipher.login_uri = c.login.uri;
|
||||
cipher.login_username = c.login.username;
|
||||
cipher.login_password = c.login.password;
|
||||
cipher.login_totp = c.login.totp;
|
||||
break;
|
||||
case CipherType.SecureNote:
|
||||
case Enums.CipherType.SecureNote:
|
||||
cipher.type = 'note';
|
||||
break;
|
||||
default:
|
||||
|
@ -1,7 +1,7 @@
|
||||
import * as angular from 'angular';
|
||||
import * as template from './password-generator.component.html';
|
||||
|
||||
import { PlatformUtilsService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
export class PasswordGeneratorController {
|
||||
$transition$: any;
|
||||
@ -13,8 +13,8 @@ export class PasswordGeneratorController {
|
||||
i18n: any;
|
||||
|
||||
constructor(private $state: any, private passwordGenerationService: any,
|
||||
private toastr: any, private platformUtilsService: PlatformUtilsService, private $analytics: any,
|
||||
private i18nService: any, private $timeout: any) {
|
||||
private toastr: any, private platformUtilsService: Abstractions.PlatformUtilsService,
|
||||
private $analytics: any, private i18nService: any, private $timeout: any) {
|
||||
this.i18n = i18nService;
|
||||
|
||||
passwordGenerationService.getOptions().then((options: any) => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as template from './tools.component.html';
|
||||
|
||||
import { PlatformUtilsService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
export class ToolsController {
|
||||
showExport: boolean;
|
||||
@ -8,7 +8,7 @@ export class ToolsController {
|
||||
private webVaultBaseUrl: string = 'https://vault.bitwarden.com';
|
||||
|
||||
constructor(private SweetAlert: any, private i18nService: any,
|
||||
private $analytics: any, private platformUtilsService: PlatformUtilsService,
|
||||
private $analytics: any, private platformUtilsService: Abstractions.PlatformUtilsService,
|
||||
private environmentService: any) {
|
||||
this.i18n = i18nService;
|
||||
this.showExport = !platformUtilsService.isEdge();
|
||||
|
@ -2,7 +2,7 @@ import AppIdService from './appId.service';
|
||||
import ConstantsService from './constants.service';
|
||||
import TokenService from './token.service';
|
||||
|
||||
import { PlatformUtilsService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
import EnvironmentUrls from '../models/domain/environmentUrls';
|
||||
|
||||
@ -36,7 +36,7 @@ export default class ApiService {
|
||||
deviceType: string;
|
||||
logoutCallback: Function;
|
||||
|
||||
constructor(private tokenService: TokenService, platformUtilsService: PlatformUtilsService,
|
||||
constructor(private tokenService: TokenService, platformUtilsService: Abstractions.PlatformUtilsService,
|
||||
logoutCallback: Function) {
|
||||
this.logoutCallback = logoutCallback;
|
||||
this.deviceType = platformUtilsService.getDevice().toString();
|
||||
|
@ -1,9 +1,7 @@
|
||||
import UtilsService from './utils.service';
|
||||
|
||||
import { StorageService } from '@bitwarden/jslib';
|
||||
import { Abstractions, Services } from '@bitwarden/jslib';
|
||||
|
||||
export default class AppIdService {
|
||||
constructor(private storageService: StorageService) {
|
||||
constructor(private storageService: Abstractions.StorageService) {
|
||||
}
|
||||
|
||||
getAppId(): Promise<string> {
|
||||
@ -20,7 +18,7 @@ export default class AppIdService {
|
||||
return existingId;
|
||||
}
|
||||
|
||||
const guid = UtilsService.newGuid();
|
||||
const guid = Services.UtilsService.newGuid();
|
||||
await this.storageService.save(key, guid);
|
||||
return guid;
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { CipherType } from '@bitwarden/jslib';
|
||||
import { FieldType } from '@bitwarden/jslib';
|
||||
import { Abstractions, Enums, Services } from '@bitwarden/jslib';
|
||||
|
||||
import AutofillField from '../models/domain/autofillField';
|
||||
import AutofillPageDetails from '../models/domain/autofillPageDetails';
|
||||
@ -8,9 +7,6 @@ import AutofillScript from '../models/domain/autofillScript';
|
||||
import CipherService from './cipher.service';
|
||||
import TokenService from './token.service';
|
||||
import TotpService from './totp.service';
|
||||
import UtilsService from './utils.service';
|
||||
|
||||
import { PlatformUtilsService } from '@bitwarden/jslib';
|
||||
|
||||
const CardAttributes: string[] = ['autoCompleteType', 'data-stripe', 'htmlName', 'htmlID', 'label-tag',
|
||||
'placeholder', 'label-left', 'label-top'];
|
||||
@ -94,8 +90,8 @@ var IsoProvinces: { [id: string]: string; } = {
|
||||
|
||||
export default class AutofillService {
|
||||
constructor(public cipherService: CipherService, public tokenService: TokenService,
|
||||
public totpService: TotpService, public utilsService: UtilsService,
|
||||
public platformUtilsService: PlatformUtilsService) {
|
||||
public totpService: TotpService, public utilsService: Services.UtilsService,
|
||||
public platformUtilsService: Abstractions.PlatformUtilsService) {
|
||||
}
|
||||
|
||||
getFormsWithPasswordFields(pageDetails: AutofillPageDetails): any[] {
|
||||
@ -169,7 +165,7 @@ export default class AutofillService {
|
||||
fillScript: fillScript,
|
||||
}, { frameId: pd.frameId });
|
||||
|
||||
if (options.cipher.type !== CipherType.Login || totpPromise ||
|
||||
if (options.cipher.type !== Enums.CipherType.Login || totpPromise ||
|
||||
(options.fromBackground && this.platformUtilsService.isFirefox()) || options.skipTotp ||
|
||||
!options.cipher.login.totp || !this.tokenService.getPremium()) {
|
||||
return;
|
||||
@ -183,7 +179,7 @@ export default class AutofillService {
|
||||
return null;
|
||||
}).then((code: string) => {
|
||||
if (code) {
|
||||
UtilsService.copyToClipboard(code);
|
||||
Services.UtilsService.copyToClipboard(code);
|
||||
}
|
||||
|
||||
return code;
|
||||
@ -271,7 +267,7 @@ export default class AutofillService {
|
||||
const matchingIndex = this.findMatchingFieldIndex(field, fieldNames);
|
||||
if (matchingIndex > -1) {
|
||||
let val = fields[matchingIndex].value;
|
||||
if (val == null && fields[matchingIndex].type === FieldType.Boolean) {
|
||||
if (val == null && fields[matchingIndex].type === Enums.FieldType.Boolean) {
|
||||
val = 'false';
|
||||
}
|
||||
|
||||
@ -283,13 +279,13 @@ export default class AutofillService {
|
||||
}
|
||||
|
||||
switch (options.cipher.type) {
|
||||
case CipherType.Login:
|
||||
case Enums.CipherType.Login:
|
||||
fillScript = this.generateLoginFillScript(fillScript, pageDetails, filledFields, options);
|
||||
break;
|
||||
case CipherType.Card:
|
||||
case Enums.CipherType.Card:
|
||||
fillScript = this.generateCardFillScript(fillScript, pageDetails, filledFields, options);
|
||||
break;
|
||||
case CipherType.Identity:
|
||||
case Enums.CipherType.Identity:
|
||||
fillScript = this.generateIdentityFillScript(fillScript, pageDetails, filledFields, options);
|
||||
break;
|
||||
default:
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { MessagingService as MessagingServiceInterface, PlatformUtilsService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
export default class BrowserMessagingService implements MessagingServiceInterface {
|
||||
constructor(private platformUtilsService: PlatformUtilsService) {
|
||||
export default class BrowserMessagingService implements Abstractions.MessagingService {
|
||||
constructor(private platformUtilsService: Abstractions.PlatformUtilsService) {
|
||||
}
|
||||
|
||||
send(subscriber: string, arg: any = {}) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import BrowserPlatformUtilsService from './browserPlatformUtils.service';
|
||||
import { DeviceType } from '@bitwarden/jslib';
|
||||
import { Enums } from '@bitwarden/jslib';
|
||||
|
||||
describe('Browser Utils Service', () => {
|
||||
describe('getDomain', () => {
|
||||
@ -48,7 +48,7 @@ describe('Browser Utils Service', () => {
|
||||
});
|
||||
|
||||
const browserPlatformUtilsService = new BrowserPlatformUtilsService();
|
||||
expect(browserPlatformUtilsService.getDevice()).toBe(DeviceType.Chrome);
|
||||
expect(browserPlatformUtilsService.getDevice()).toBe(Enums.DeviceType.Chrome);
|
||||
});
|
||||
|
||||
it('should detect firefox', () => {
|
||||
@ -58,7 +58,7 @@ describe('Browser Utils Service', () => {
|
||||
});
|
||||
|
||||
const browserPlatformUtilsService = new BrowserPlatformUtilsService();
|
||||
expect(browserPlatformUtilsService.getDevice()).toBe(DeviceType.Firefox);
|
||||
expect(browserPlatformUtilsService.getDevice()).toBe(Enums.DeviceType.Firefox);
|
||||
});
|
||||
|
||||
it('should detect opera', () => {
|
||||
@ -68,7 +68,7 @@ describe('Browser Utils Service', () => {
|
||||
});
|
||||
|
||||
const browserPlatformUtilsService = new BrowserPlatformUtilsService();
|
||||
expect(browserPlatformUtilsService.getDevice()).toBe(DeviceType.Opera);
|
||||
expect(browserPlatformUtilsService.getDevice()).toBe(Enums.DeviceType.Opera);
|
||||
});
|
||||
|
||||
it('should detect edge', () => {
|
||||
@ -78,7 +78,7 @@ describe('Browser Utils Service', () => {
|
||||
});
|
||||
|
||||
const browserPlatformUtilsService = new BrowserPlatformUtilsService();
|
||||
expect(browserPlatformUtilsService.getDevice()).toBe(DeviceType.Edge);
|
||||
expect(browserPlatformUtilsService.getDevice()).toBe(Enums.DeviceType.Edge);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,17 +1,17 @@
|
||||
import * as tldjs from 'tldjs';
|
||||
|
||||
import { DeviceType, PlatformUtilsService as PlatformUtilsServiceInterface } from '@bitwarden/jslib';
|
||||
import { Abstractions, Enums } from '@bitwarden/jslib';
|
||||
|
||||
const AnalyticsIds = {
|
||||
[DeviceType.Chrome]: 'UA-81915606-6',
|
||||
[DeviceType.Firefox]: 'UA-81915606-7',
|
||||
[DeviceType.Opera]: 'UA-81915606-8',
|
||||
[DeviceType.Edge]: 'UA-81915606-9',
|
||||
[DeviceType.Vivaldi]: 'UA-81915606-15',
|
||||
[DeviceType.Safari]: 'UA-81915606-16',
|
||||
[Enums.DeviceType.Chrome]: 'UA-81915606-6',
|
||||
[Enums.DeviceType.Firefox]: 'UA-81915606-7',
|
||||
[Enums.DeviceType.Opera]: 'UA-81915606-8',
|
||||
[Enums.DeviceType.Edge]: 'UA-81915606-9',
|
||||
[Enums.DeviceType.Vivaldi]: 'UA-81915606-15',
|
||||
[Enums.DeviceType.Safari]: 'UA-81915606-16',
|
||||
};
|
||||
|
||||
export default class BrowserPlatformUtilsService implements PlatformUtilsServiceInterface {
|
||||
export default class BrowserPlatformUtilsService implements Abstractions.PlatformUtilsService {
|
||||
static getDomain(uriString: string): string {
|
||||
if (uriString == null) {
|
||||
return null;
|
||||
@ -49,56 +49,56 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
|
||||
return ipRegex.test(ipString);
|
||||
}
|
||||
|
||||
private deviceCache: DeviceType = null;
|
||||
private deviceCache: Enums.DeviceType = null;
|
||||
private analyticsIdCache: string = null;
|
||||
|
||||
getDevice(): DeviceType {
|
||||
getDevice(): Enums.DeviceType {
|
||||
if (this.deviceCache) {
|
||||
return this.deviceCache;
|
||||
}
|
||||
|
||||
if (navigator.userAgent.indexOf('Firefox') !== -1 || navigator.userAgent.indexOf('Gecko/') !== -1) {
|
||||
this.deviceCache = DeviceType.Firefox;
|
||||
this.deviceCache = Enums.DeviceType.Firefox;
|
||||
} else if ((!!(window as any).opr && !!opr.addons) || !!(window as any).opera ||
|
||||
navigator.userAgent.indexOf(' OPR/') >= 0) {
|
||||
this.deviceCache = DeviceType.Opera;
|
||||
this.deviceCache = Enums.DeviceType.Opera;
|
||||
} else if (navigator.userAgent.indexOf(' Edge/') !== -1) {
|
||||
this.deviceCache = DeviceType.Edge;
|
||||
this.deviceCache = Enums.DeviceType.Edge;
|
||||
} else if (navigator.userAgent.indexOf(' Vivaldi/') !== -1) {
|
||||
this.deviceCache = DeviceType.Vivaldi;
|
||||
this.deviceCache = Enums.DeviceType.Vivaldi;
|
||||
} else if ((window as any).chrome) {
|
||||
this.deviceCache = DeviceType.Chrome;
|
||||
this.deviceCache = Enums.DeviceType.Chrome;
|
||||
}
|
||||
|
||||
return this.deviceCache;
|
||||
}
|
||||
|
||||
getDeviceString(): string {
|
||||
return DeviceType[this.getDevice()].toLowerCase();
|
||||
return Enums.DeviceType[this.getDevice()].toLowerCase();
|
||||
}
|
||||
|
||||
isFirefox(): boolean {
|
||||
return this.getDevice() === DeviceType.Firefox;
|
||||
return this.getDevice() === Enums.DeviceType.Firefox;
|
||||
}
|
||||
|
||||
isChrome(): boolean {
|
||||
return this.getDevice() === DeviceType.Chrome;
|
||||
return this.getDevice() === Enums.DeviceType.Chrome;
|
||||
}
|
||||
|
||||
isEdge(): boolean {
|
||||
return this.getDevice() === DeviceType.Edge;
|
||||
return this.getDevice() === Enums.DeviceType.Edge;
|
||||
}
|
||||
|
||||
isOpera(): boolean {
|
||||
return this.getDevice() === DeviceType.Opera;
|
||||
return this.getDevice() === Enums.DeviceType.Opera;
|
||||
}
|
||||
|
||||
isVivaldi(): boolean {
|
||||
return this.getDevice() === DeviceType.Vivaldi;
|
||||
return this.getDevice() === Enums.DeviceType.Vivaldi;
|
||||
}
|
||||
|
||||
isSafari(): boolean {
|
||||
return this.getDevice() === DeviceType.Safari;
|
||||
return this.getDevice() === Enums.DeviceType.Safari;
|
||||
}
|
||||
|
||||
analyticsId(): string {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { PlatformUtilsService, StorageService as StorageServiceInterface } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
export default class BrowserStorageService implements StorageServiceInterface {
|
||||
constructor(private platformUtilsService: PlatformUtilsService) {
|
||||
export default class BrowserStorageService implements Abstractions.StorageService {
|
||||
constructor(private platformUtilsService: Abstractions.PlatformUtilsService) {
|
||||
}
|
||||
|
||||
get<T>(key: string): Promise<T> {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { CipherType } from '@bitwarden/jslib';
|
||||
import { Abstractions, Enums } from '@bitwarden/jslib';
|
||||
|
||||
import { Cipher } from '../models/domain/cipher';
|
||||
import { CipherString } from '../models/domain/cipherString';
|
||||
@ -17,8 +17,6 @@ import CryptoService from './crypto.service';
|
||||
import SettingsService from './settings.service';
|
||||
import UserService from './user.service';
|
||||
|
||||
import { StorageService } from '@bitwarden/jslib';
|
||||
|
||||
const Keys = {
|
||||
ciphersPrefix: 'ciphers_',
|
||||
localData: 'sitesLocalData',
|
||||
@ -70,7 +68,7 @@ export default class CipherService {
|
||||
|
||||
constructor(private cryptoService: CryptoService, private userService: UserService,
|
||||
private settingsService: SettingsService, private apiService: ApiService,
|
||||
private storageService: StorageService) {
|
||||
private storageService: Abstractions.StorageService) {
|
||||
}
|
||||
|
||||
clearCache(): void {
|
||||
@ -223,7 +221,7 @@ export default class CipherService {
|
||||
const ciphersToReturn: any[] = [];
|
||||
|
||||
ciphers.forEach((cipher) => {
|
||||
if (domain && cipher.type === CipherType.Login && cipher.login.domain &&
|
||||
if (domain && cipher.type === Enums.CipherType.Login && cipher.login.domain &&
|
||||
matchingDomains.indexOf(cipher.login.domain) > -1) {
|
||||
ciphersToReturn.push(cipher);
|
||||
} else if (includeOtherTypes && includeOtherTypes.indexOf(cipher.type) > -1) {
|
||||
@ -464,7 +462,7 @@ export default class CipherService {
|
||||
|
||||
private encryptCipherData(cipher: Cipher, model: any, key: SymmetricCryptoKey): Promise<any> {
|
||||
switch (cipher.type) {
|
||||
case CipherType.Login:
|
||||
case Enums.CipherType.Login:
|
||||
model.login = {};
|
||||
return this.encryptObjProperty(cipher.login, model.login, {
|
||||
uri: null,
|
||||
@ -472,12 +470,12 @@ export default class CipherService {
|
||||
password: null,
|
||||
totp: null,
|
||||
}, key);
|
||||
case CipherType.SecureNote:
|
||||
case Enums.CipherType.SecureNote:
|
||||
model.secureNote = {
|
||||
type: cipher.secureNote.type,
|
||||
};
|
||||
return Promise.resolve();
|
||||
case CipherType.Card:
|
||||
case Enums.CipherType.Card:
|
||||
model.card = {};
|
||||
return this.encryptObjProperty(cipher.card, model.card, {
|
||||
cardholderName: null,
|
||||
@ -487,7 +485,7 @@ export default class CipherService {
|
||||
expYear: null,
|
||||
code: null,
|
||||
}, key);
|
||||
case CipherType.Identity:
|
||||
case Enums.CipherType.Identity:
|
||||
model.identity = {};
|
||||
return this.encryptObjProperty(cipher.identity, model.identity, {
|
||||
title: null,
|
||||
|
@ -6,7 +6,7 @@ import { CollectionData } from '../models/data/collectionData';
|
||||
import CryptoService from './crypto.service';
|
||||
import UserService from './user.service';
|
||||
|
||||
import { StorageService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
const Keys = {
|
||||
collectionsPrefix: 'collections_',
|
||||
@ -16,7 +16,7 @@ export default class CollectionService {
|
||||
decryptedCollectionCache: any[];
|
||||
|
||||
constructor(private cryptoService: CryptoService, private userService: UserService,
|
||||
private storageService: StorageService) {
|
||||
private storageService: Abstractions.StorageService) {
|
||||
}
|
||||
|
||||
clearCache(): void {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { PlatformUtilsService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
export default class ConstantsService {
|
||||
static readonly environmentUrlsKey: string = 'environmentUrls';
|
||||
@ -57,7 +57,7 @@ export default class ConstantsService {
|
||||
|
||||
twoFactorProviderInfo: any[];
|
||||
|
||||
constructor(i18nService: any, platformUtilsService: PlatformUtilsService) {
|
||||
constructor(i18nService: any, platformUtilsService: Abstractions.PlatformUtilsService) {
|
||||
if (platformUtilsService.isEdge()) {
|
||||
// delay for i18n fetch
|
||||
setTimeout(() => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import * as forge from 'node-forge';
|
||||
|
||||
import { EncryptionType } from '@bitwarden/jslib';
|
||||
import { Abstractions, Enums, Services } from '@bitwarden/jslib';
|
||||
|
||||
import { CipherString } from '../models/domain/cipherString';
|
||||
import EncryptedObject from '../models/domain/encryptedObject';
|
||||
@ -8,12 +8,9 @@ import SymmetricCryptoKey from '../models/domain/symmetricCryptoKey';
|
||||
import { ProfileOrganizationResponse } from '../models/response/profileOrganizationResponse';
|
||||
|
||||
import ConstantsService from './constants.service';
|
||||
import UtilsService from './utils.service';
|
||||
|
||||
import { CryptoService as CryptoServiceInterface } from './abstractions/crypto.service';
|
||||
|
||||
import { StorageService } from '@bitwarden/jslib';
|
||||
|
||||
const Keys = {
|
||||
key: 'key',
|
||||
encOrgKeys: 'encOrgKeys',
|
||||
@ -42,7 +39,8 @@ export default class CryptoService implements CryptoServiceInterface {
|
||||
private privateKey: ArrayBuffer;
|
||||
private orgKeys: Map<string, SymmetricCryptoKey>;
|
||||
|
||||
constructor(private storageService: StorageService, private secureStorageService: StorageService) {
|
||||
constructor(private storageService: Abstractions.StorageService,
|
||||
private secureStorageService: Abstractions.StorageService) {
|
||||
}
|
||||
|
||||
async setKey(key: SymmetricCryptoKey): Promise<any> {
|
||||
@ -150,7 +148,7 @@ export default class CryptoService implements CryptoServiceInterface {
|
||||
|
||||
const privateKey = await this.decrypt(new CipherString(encPrivateKey), null, 'raw');
|
||||
const privateKeyB64 = forge.util.encode64(privateKey);
|
||||
this.privateKey = UtilsService.fromB64ToArray(privateKeyB64).buffer;
|
||||
this.privateKey = Services.UtilsService.fromB64ToArray(privateKeyB64).buffer;
|
||||
return this.privateKey;
|
||||
}
|
||||
|
||||
@ -286,15 +284,15 @@ export default class CryptoService implements CryptoServiceInterface {
|
||||
|
||||
let plainValueArr: Uint8Array;
|
||||
if (plainValueEncoding === 'utf8') {
|
||||
plainValueArr = UtilsService.fromUtf8ToArray(plainValue as string);
|
||||
plainValueArr = Services.UtilsService.fromUtf8ToArray(plainValue as string);
|
||||
} else {
|
||||
plainValueArr = plainValue as Uint8Array;
|
||||
}
|
||||
|
||||
const encValue = await this.aesEncrypt(plainValueArr.buffer, key);
|
||||
const iv = UtilsService.fromBufferToB64(encValue.iv.buffer);
|
||||
const ct = UtilsService.fromBufferToB64(encValue.ct.buffer);
|
||||
const mac = encValue.mac ? UtilsService.fromBufferToB64(encValue.mac.buffer) : null;
|
||||
const iv = Services.UtilsService.fromBufferToB64(encValue.iv.buffer);
|
||||
const ct = Services.UtilsService.fromBufferToB64(encValue.ct.buffer);
|
||||
const mac = encValue.mac ? Services.UtilsService.fromBufferToB64(encValue.mac.buffer) : null;
|
||||
return new CipherString(encValue.key.encType, iv, ct, mac);
|
||||
}
|
||||
|
||||
@ -345,8 +343,8 @@ export default class CryptoService implements CryptoServiceInterface {
|
||||
let macBytes: Uint8Array = null;
|
||||
|
||||
switch (encType) {
|
||||
case EncryptionType.AesCbc128_HmacSha256_B64:
|
||||
case EncryptionType.AesCbc256_HmacSha256_B64:
|
||||
case Enums.EncryptionType.AesCbc128_HmacSha256_B64:
|
||||
case Enums.EncryptionType.AesCbc256_HmacSha256_B64:
|
||||
if (encBytes.length <= 49) { // 1 + 16 + 32 + ctLength
|
||||
return null;
|
||||
}
|
||||
@ -355,7 +353,7 @@ export default class CryptoService implements CryptoServiceInterface {
|
||||
macBytes = encBytes.slice(17, 49);
|
||||
ctBytes = encBytes.slice(49);
|
||||
break;
|
||||
case EncryptionType.AesCbc256_B64:
|
||||
case Enums.EncryptionType.AesCbc256_B64:
|
||||
if (encBytes.length <= 17) { // 1 + 16 + ctLength
|
||||
return null;
|
||||
}
|
||||
@ -372,11 +370,11 @@ export default class CryptoService implements CryptoServiceInterface {
|
||||
|
||||
async rsaDecrypt(encValue: string): Promise<string> {
|
||||
const headerPieces = encValue.split('.');
|
||||
let encType: EncryptionType = null;
|
||||
let encType: Enums.EncryptionType = null;
|
||||
let encPieces: string[];
|
||||
|
||||
if (headerPieces.length === 1) {
|
||||
encType = EncryptionType.Rsa2048_OaepSha256_B64;
|
||||
encType = Enums.EncryptionType.Rsa2048_OaepSha256_B64;
|
||||
encPieces = [headerPieces[0]];
|
||||
} else if (headerPieces.length === 2) {
|
||||
try {
|
||||
@ -386,14 +384,14 @@ export default class CryptoService implements CryptoServiceInterface {
|
||||
}
|
||||
|
||||
switch (encType) {
|
||||
case EncryptionType.Rsa2048_OaepSha256_B64:
|
||||
case EncryptionType.Rsa2048_OaepSha1_B64:
|
||||
case Enums.EncryptionType.Rsa2048_OaepSha256_B64:
|
||||
case Enums.EncryptionType.Rsa2048_OaepSha1_B64:
|
||||
if (encPieces.length !== 1) {
|
||||
throw new Error('Invalid cipher format.');
|
||||
}
|
||||
break;
|
||||
case EncryptionType.Rsa2048_OaepSha256_HmacSha256_B64:
|
||||
case EncryptionType.Rsa2048_OaepSha1_HmacSha256_B64:
|
||||
case Enums.EncryptionType.Rsa2048_OaepSha256_HmacSha256_B64:
|
||||
case Enums.EncryptionType.Rsa2048_OaepSha1_HmacSha256_B64:
|
||||
if (encPieces.length !== 2) {
|
||||
throw new Error('Invalid cipher format.');
|
||||
}
|
||||
@ -424,15 +422,15 @@ export default class CryptoService implements CryptoServiceInterface {
|
||||
|
||||
let rsaAlgorithm: any = null;
|
||||
switch (encType) {
|
||||
case EncryptionType.Rsa2048_OaepSha256_B64:
|
||||
case EncryptionType.Rsa2048_OaepSha256_HmacSha256_B64:
|
||||
case Enums.EncryptionType.Rsa2048_OaepSha256_B64:
|
||||
case Enums.EncryptionType.Rsa2048_OaepSha256_HmacSha256_B64:
|
||||
rsaAlgorithm = {
|
||||
name: 'RSA-OAEP',
|
||||
hash: { name: 'SHA-256' },
|
||||
};
|
||||
break;
|
||||
case EncryptionType.Rsa2048_OaepSha1_B64:
|
||||
case EncryptionType.Rsa2048_OaepSha1_HmacSha256_B64:
|
||||
case Enums.EncryptionType.Rsa2048_OaepSha1_B64:
|
||||
case Enums.EncryptionType.Rsa2048_OaepSha1_HmacSha256_B64:
|
||||
rsaAlgorithm = {
|
||||
name: 'RSA-OAEP',
|
||||
hash: { name: 'SHA-1' },
|
||||
@ -443,9 +441,9 @@ export default class CryptoService implements CryptoServiceInterface {
|
||||
}
|
||||
|
||||
const privateKey = await Subtle.importKey('pkcs8', privateKeyBytes, rsaAlgorithm, false, ['decrypt']);
|
||||
const ctArr = UtilsService.fromB64ToArray(encPieces[0]);
|
||||
const ctArr = Services.UtilsService.fromB64ToArray(encPieces[0]);
|
||||
const decBytes = await Subtle.decrypt(rsaAlgorithm, privateKey, ctArr.buffer);
|
||||
const b64DecValue = UtilsService.fromBufferToB64(decBytes);
|
||||
const b64DecValue = Services.UtilsService.fromBufferToB64(decBytes);
|
||||
return b64DecValue;
|
||||
}
|
||||
|
||||
@ -474,7 +472,7 @@ export default class CryptoService implements CryptoServiceInterface {
|
||||
return obj;
|
||||
}
|
||||
|
||||
private async aesDecrypt(encType: EncryptionType, ctBytes: string, ivBytes: string, macBytes: string,
|
||||
private async aesDecrypt(encType: Enums.EncryptionType, ctBytes: string, ivBytes: string, macBytes: string,
|
||||
key: SymmetricCryptoKey): Promise<any> {
|
||||
const keyForEnc = await this.getKeyForEncryption(key);
|
||||
const theKey = this.resolveLegacyKey(encType, keyForEnc);
|
||||
@ -503,7 +501,7 @@ export default class CryptoService implements CryptoServiceInterface {
|
||||
return decipher;
|
||||
}
|
||||
|
||||
private async aesDecryptWC(encType: EncryptionType, ctBuf: ArrayBuffer, ivBuf: ArrayBuffer,
|
||||
private async aesDecryptWC(encType: Enums.EncryptionType, ctBuf: ArrayBuffer, ivBuf: ArrayBuffer,
|
||||
macBuf: ArrayBuffer, key: SymmetricCryptoKey): Promise<ArrayBuffer> {
|
||||
const theKey = await this.getKeyForEncryption(key);
|
||||
const keyBuf = theKey.getBuffers();
|
||||
@ -589,11 +587,12 @@ export default class CryptoService implements CryptoServiceInterface {
|
||||
return encKey || (await this.getKey());
|
||||
}
|
||||
|
||||
private resolveLegacyKey(encType: EncryptionType, key: SymmetricCryptoKey): SymmetricCryptoKey {
|
||||
if (encType === EncryptionType.AesCbc128_HmacSha256_B64 && key.encType === EncryptionType.AesCbc256_B64) {
|
||||
private resolveLegacyKey(encType: Enums.EncryptionType, key: SymmetricCryptoKey): SymmetricCryptoKey {
|
||||
if (encType === Enums.EncryptionType.AesCbc128_HmacSha256_B64 &&
|
||||
key.encType === Enums.EncryptionType.AesCbc256_B64) {
|
||||
// Old encrypt-then-mac scheme, make a new key
|
||||
this.legacyEtmKey = this.legacyEtmKey ||
|
||||
new SymmetricCryptoKey(key.key, false, EncryptionType.AesCbc128_HmacSha256_B64);
|
||||
new SymmetricCryptoKey(key.key, false, Enums.EncryptionType.AesCbc128_HmacSha256_B64);
|
||||
return this.legacyEtmKey;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import ApiService from './api.service';
|
||||
import ConstantsService from './constants.service';
|
||||
|
||||
import { StorageService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
import EnvironmentUrls from '../models/domain/environmentUrls';
|
||||
|
||||
@ -12,7 +12,7 @@ export default class EnvironmentService {
|
||||
identityUrl: string;
|
||||
iconsUrl: string;
|
||||
|
||||
constructor(private apiService: ApiService, private storageService: StorageService) {
|
||||
constructor(private apiService: ApiService, private storageService: Abstractions.StorageService) {
|
||||
}
|
||||
|
||||
async setUrlsFromStorage(): Promise<void> {
|
||||
|
@ -10,7 +10,7 @@ import ApiService from './api.service';
|
||||
import CryptoService from './crypto.service';
|
||||
import UserService from './user.service';
|
||||
|
||||
import { StorageService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
const Keys = {
|
||||
foldersPrefix: 'folders_',
|
||||
@ -20,7 +20,8 @@ export default class FolderService {
|
||||
decryptedFolderCache: any[];
|
||||
|
||||
constructor(private cryptoService: CryptoService, private userService: UserService,
|
||||
private i18nService: any, private apiService: ApiService, private storageService: StorageService) {
|
||||
private i18nService: any, private apiService: ApiService,
|
||||
private storageService: Abstractions.StorageService) {
|
||||
}
|
||||
|
||||
clearCache(): void {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { PlatformUtilsService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
export default function i18nService(platformUtilsService: PlatformUtilsService) {
|
||||
export default function i18nService(platformUtilsService: Abstractions.PlatformUtilsService) {
|
||||
const edgeMessages: any = {};
|
||||
|
||||
if (platformUtilsService.isEdge()) {
|
||||
|
@ -4,12 +4,13 @@ import ConstantsService from './constants.service';
|
||||
import CryptoService from './crypto.service';
|
||||
import FolderService from './folder.service';
|
||||
|
||||
import { PlatformUtilsService, StorageService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
export default class LockService {
|
||||
constructor(private cipherService: CipherService, private folderService: FolderService,
|
||||
private collectionService: CollectionService, private cryptoService: CryptoService,
|
||||
private platformUtilsService: PlatformUtilsService, private storageService: StorageService,
|
||||
private platformUtilsService: Abstractions.PlatformUtilsService,
|
||||
private storageService: Abstractions.StorageService,
|
||||
private setIcon: Function, private refreshBadgeAndMenu: Function) {
|
||||
this.checkLock();
|
||||
setInterval(() => this.checkLock(), 10 * 1000); // check every 10 seconds
|
||||
|
@ -2,9 +2,8 @@ import { CipherString } from '../models/domain/cipherString';
|
||||
import PasswordHistory from '../models/domain/passwordHistory';
|
||||
|
||||
import CryptoService from './crypto.service';
|
||||
import UtilsService from './utils.service';
|
||||
|
||||
import { StorageService } from '@bitwarden/jslib';
|
||||
import { Abstractions, Services } from '@bitwarden/jslib';
|
||||
|
||||
const DefaultOptions = {
|
||||
length: 14,
|
||||
@ -81,7 +80,7 @@ export default class PasswordGenerationService {
|
||||
|
||||
// shuffle
|
||||
positions.sort(() => {
|
||||
return UtilsService.secureRandomNumber(0, 1) * 2 - 1;
|
||||
return Services.UtilsService.secureRandomNumber(0, 1) * 2 - 1;
|
||||
});
|
||||
|
||||
// build out the char sets
|
||||
@ -137,7 +136,7 @@ export default class PasswordGenerationService {
|
||||
break;
|
||||
}
|
||||
|
||||
const randomCharIndex = UtilsService.secureRandomNumber(0, positionChars.length - 1);
|
||||
const randomCharIndex = Services.UtilsService.secureRandomNumber(0, positionChars.length - 1);
|
||||
password += positionChars.charAt(randomCharIndex);
|
||||
}
|
||||
|
||||
@ -147,7 +146,7 @@ export default class PasswordGenerationService {
|
||||
optionsCache: any;
|
||||
history: PasswordHistory[] = [];
|
||||
|
||||
constructor(private cryptoService: CryptoService, private storageService: StorageService) {
|
||||
constructor(private cryptoService: CryptoService, private storageService: Abstractions.StorageService) {
|
||||
storageService.get<PasswordHistory[]>(Keys.history).then((encrypted) => {
|
||||
return this.decryptHistory(encrypted);
|
||||
}).then((history) => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import UserService from './user.service';
|
||||
|
||||
import { StorageService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
const Keys = {
|
||||
settingsPrefix: 'settings_',
|
||||
@ -10,7 +10,7 @@ const Keys = {
|
||||
export default class SettingsService {
|
||||
private settingsCache: any;
|
||||
|
||||
constructor(private userService: UserService, private storageService: StorageService) {
|
||||
constructor(private userService: UserService, private storageService: Abstractions.StorageService) {
|
||||
}
|
||||
|
||||
clearCache(): void {
|
||||
|
@ -17,7 +17,7 @@ import FolderService from './folder.service';
|
||||
import SettingsService from './settings.service';
|
||||
import UserService from './user.service';
|
||||
|
||||
import { MessagingService, StorageService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
const Keys = {
|
||||
lastSyncPrefix: 'lastSync_',
|
||||
@ -29,8 +29,8 @@ export default class SyncService {
|
||||
constructor(private userService: UserService, private apiService: ApiService,
|
||||
private settingsService: SettingsService, private folderService: FolderService,
|
||||
private cipherService: CipherService, private cryptoService: CryptoService,
|
||||
private collectionService: CollectionService, private storageService: StorageService,
|
||||
private messagingService: MessagingService, private logoutCallback: Function) {
|
||||
private collectionService: CollectionService, private storageService: Abstractions.StorageService,
|
||||
private messagingService: Abstractions.MessagingService, private logoutCallback: Function) {
|
||||
}
|
||||
|
||||
async getLastSync() {
|
||||
|
@ -1,7 +1,6 @@
|
||||
import ConstantsService from './constants.service';
|
||||
import UtilsService from './utils.service';
|
||||
|
||||
import { StorageService } from '@bitwarden/jslib';
|
||||
import { Abstractions, Services } from '@bitwarden/jslib';
|
||||
|
||||
const Keys = {
|
||||
accessToken: 'accessToken',
|
||||
@ -14,7 +13,7 @@ export default class TokenService {
|
||||
decodedToken: any;
|
||||
refreshToken: string;
|
||||
|
||||
constructor(private storageService: StorageService) {
|
||||
constructor(private storageService: Abstractions.StorageService) {
|
||||
}
|
||||
|
||||
setTokens(accessToken: string, refreshToken: string): Promise<any> {
|
||||
@ -93,7 +92,7 @@ export default class TokenService {
|
||||
throw new Error('JWT must have 3 parts');
|
||||
}
|
||||
|
||||
const decoded = UtilsService.urlBase64Decode(parts[1]);
|
||||
const decoded = Services.UtilsService.urlBase64Decode(parts[1]);
|
||||
if (decoded == null) {
|
||||
throw new Error('Cannot decode the token');
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import ConstantsService from './constants.service';
|
||||
|
||||
import { StorageService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
const b32Chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
|
||||
|
||||
@ -10,7 +10,7 @@ const TotpAlgorithm = {
|
||||
};
|
||||
|
||||
export default class TotpService {
|
||||
constructor(private storageService: StorageService) {
|
||||
constructor(private storageService: Abstractions.StorageService) {
|
||||
}
|
||||
|
||||
async getCode(keyb32: string): Promise<string> {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import TokenService from './token.service';
|
||||
|
||||
import { StorageService } from '@bitwarden/jslib';
|
||||
import { Abstractions } from '@bitwarden/jslib';
|
||||
|
||||
const Keys = {
|
||||
userId: 'userId',
|
||||
@ -13,7 +13,7 @@ export default class UserService {
|
||||
email: string;
|
||||
stamp: string;
|
||||
|
||||
constructor(private tokenService: TokenService, private storageService: StorageService) {
|
||||
constructor(private tokenService: TokenService, private storageService: Abstractions.StorageService) {
|
||||
}
|
||||
|
||||
setUserIdAndEmail(userId: string, email: string): Promise<any> {
|
||||
|
@ -1,32 +1,32 @@
|
||||
import UtilsService from './utils.service';
|
||||
import { Services } from '@bitwarden/jslib';
|
||||
|
||||
describe('Utils Service', () => {
|
||||
describe('getHostname', () => {
|
||||
it('should fail for invalid urls', () => {
|
||||
expect(UtilsService.getHostname(null)).toBeNull();
|
||||
expect(UtilsService.getHostname(undefined)).toBeNull();
|
||||
expect(UtilsService.getHostname(' ')).toBeNull();
|
||||
expect(UtilsService.getHostname('https://bit!:"_&ward.com')).toBeNull();
|
||||
expect(UtilsService.getHostname('bitwarden')).toBeNull();
|
||||
expect(Services.UtilsService.getHostname(null)).toBeNull();
|
||||
expect(Services.UtilsService.getHostname(undefined)).toBeNull();
|
||||
expect(Services.UtilsService.getHostname(' ')).toBeNull();
|
||||
expect(Services.UtilsService.getHostname('https://bit!:"_&ward.com')).toBeNull();
|
||||
expect(Services.UtilsService.getHostname('bitwarden')).toBeNull();
|
||||
});
|
||||
|
||||
it('should handle valid urls', () => {
|
||||
expect(UtilsService.getHostname('https://bitwarden.com')).toBe('bitwarden.com');
|
||||
expect(UtilsService.getHostname('http://bitwarden.com')).toBe('bitwarden.com');
|
||||
expect(UtilsService.getHostname('http://vault.bitwarden.com')).toBe('vault.bitwarden.com');
|
||||
expect(UtilsService.getHostname('https://user:password@bitwarden.com:8080/password/sites?and&query#hash')).toBe('bitwarden.com');
|
||||
expect(Services.UtilsService.getHostname('https://bitwarden.com')).toBe('bitwarden.com');
|
||||
expect(Services.UtilsService.getHostname('http://bitwarden.com')).toBe('bitwarden.com');
|
||||
expect(Services.UtilsService.getHostname('http://vault.bitwarden.com')).toBe('vault.bitwarden.com');
|
||||
expect(Services.UtilsService.getHostname('https://user:password@bitwarden.com:8080/password/sites?and&query#hash')).toBe('bitwarden.com');
|
||||
});
|
||||
|
||||
it('should support localhost and IP', () => {
|
||||
expect(UtilsService.getHostname('https://localhost')).toBe('localhost');
|
||||
expect(UtilsService.getHostname('https://192.168.1.1')).toBe('192.168.1.1');
|
||||
expect(Services.UtilsService.getHostname('https://localhost')).toBe('localhost');
|
||||
expect(Services.UtilsService.getHostname('https://192.168.1.1')).toBe('192.168.1.1');
|
||||
});
|
||||
});
|
||||
|
||||
describe('newGuid', () => {
|
||||
it('should create a valid guid', () => {
|
||||
const validGuid = /^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;
|
||||
expect(UtilsService.newGuid()).toMatch(validGuid);
|
||||
expect(Services.UtilsService.newGuid()).toMatch(validGuid);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,155 +0,0 @@
|
||||
import { UtilsService as UtilsServiceInterface } from '@bitwarden/jslib';
|
||||
|
||||
export default class UtilsService implements UtilsServiceInterface {
|
||||
static copyToClipboard(text: string, doc?: Document): void {
|
||||
doc = doc || document;
|
||||
if ((window as any).clipboardData && (window as any).clipboardData.setData) {
|
||||
// IE specific code path to prevent textarea being shown while dialog is visible.
|
||||
(window as any).clipboardData.setData('Text', text);
|
||||
} else if (doc.queryCommandSupported && doc.queryCommandSupported('copy')) {
|
||||
const textarea = doc.createElement('textarea');
|
||||
textarea.textContent = text;
|
||||
// Prevent scrolling to bottom of page in MS Edge.
|
||||
textarea.style.position = 'fixed';
|
||||
doc.body.appendChild(textarea);
|
||||
textarea.select();
|
||||
|
||||
try {
|
||||
// Security exception may be thrown by some browsers.
|
||||
doc.execCommand('copy');
|
||||
} catch (e) {
|
||||
// tslint:disable-next-line
|
||||
console.warn('Copy to clipboard failed.', e);
|
||||
} finally {
|
||||
doc.body.removeChild(textarea);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static urlBase64Decode(str: string): string {
|
||||
let output = str.replace(/-/g, '+').replace(/_/g, '/');
|
||||
switch (output.length % 4) {
|
||||
case 0:
|
||||
break;
|
||||
case 2:
|
||||
output += '==';
|
||||
break;
|
||||
case 3:
|
||||
output += '=';
|
||||
break;
|
||||
default:
|
||||
throw new Error('Illegal base64url string!');
|
||||
}
|
||||
|
||||
return decodeURIComponent(escape(window.atob(output)));
|
||||
}
|
||||
|
||||
// ref: http://stackoverflow.com/a/2117523/1090359
|
||||
static newGuid(): string {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, (c) => {
|
||||
// tslint:disable-next-line
|
||||
const r = Math.random() * 16 | 0;
|
||||
// tslint:disable-next-line
|
||||
const v = c === 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
}
|
||||
|
||||
// EFForg/OpenWireless
|
||||
// ref https://github.com/EFForg/OpenWireless/blob/master/app/js/diceware.js
|
||||
static secureRandomNumber(min: number, max: number): number {
|
||||
let rval = 0;
|
||||
const range = max - min + 1;
|
||||
const bitsNeeded = Math.ceil(Math.log2(range));
|
||||
if (bitsNeeded > 53) {
|
||||
throw new Error('We cannot generate numbers larger than 53 bits.');
|
||||
}
|
||||
|
||||
const bytesNeeded = Math.ceil(bitsNeeded / 8);
|
||||
const mask = Math.pow(2, bitsNeeded) - 1;
|
||||
// 7776 -> (2^13 = 8192) -1 == 8191 or 0x00001111 11111111
|
||||
|
||||
// Create byte array and fill with N random numbers
|
||||
const byteArray = new Uint8Array(bytesNeeded);
|
||||
window.crypto.getRandomValues(byteArray);
|
||||
|
||||
let p = (bytesNeeded - 1) * 8;
|
||||
for (let i = 0; i < bytesNeeded; i++) {
|
||||
rval += byteArray[i] * Math.pow(2, p);
|
||||
p -= 8;
|
||||
}
|
||||
|
||||
// Use & to apply the mask and reduce the number of recursive lookups
|
||||
// tslint:disable-next-line
|
||||
rval = rval & mask;
|
||||
|
||||
if (rval >= range) {
|
||||
// Integer out of acceptable range
|
||||
return UtilsService.secureRandomNumber(min, max);
|
||||
}
|
||||
|
||||
// Return an integer that falls within the range
|
||||
return min + rval;
|
||||
}
|
||||
|
||||
static fromB64ToArray(str: string): Uint8Array {
|
||||
const binaryString = window.atob(str);
|
||||
const bytes = new Uint8Array(binaryString.length);
|
||||
for (let i = 0; i < binaryString.length; i++) {
|
||||
bytes[i] = binaryString.charCodeAt(i);
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
static fromUtf8ToArray(str: string): Uint8Array {
|
||||
const strUtf8 = unescape(encodeURIComponent(str));
|
||||
const arr = new Uint8Array(strUtf8.length);
|
||||
for (let i = 0; i < strUtf8.length; i++) {
|
||||
arr[i] = strUtf8.charCodeAt(i);
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
|
||||
static fromBufferToB64(buffer: ArrayBuffer): string {
|
||||
let binary = '';
|
||||
const bytes = new Uint8Array(buffer);
|
||||
for (let i = 0; i < bytes.byteLength; i++) {
|
||||
binary += String.fromCharCode(bytes[i]);
|
||||
}
|
||||
return window.btoa(binary);
|
||||
}
|
||||
|
||||
static fromBufferToUtf8(buffer: ArrayBuffer): string {
|
||||
const bytes = new Uint8Array(buffer);
|
||||
const encodedString = String.fromCharCode.apply(null, bytes);
|
||||
return decodeURIComponent(escape(encodedString));
|
||||
}
|
||||
|
||||
static getHostname(uriString: string): string {
|
||||
if (uriString == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
uriString = uriString.trim();
|
||||
if (uriString === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (uriString.startsWith('http://') || uriString.startsWith('https://')) {
|
||||
try {
|
||||
const url = new URL(uriString);
|
||||
return url.hostname;
|
||||
} catch (e) { }
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
getHostname(uriString: string): string {
|
||||
return UtilsService.getHostname(uriString);
|
||||
}
|
||||
|
||||
copyToClipboard(text: string, doc?: Document) {
|
||||
UtilsService.copyToClipboard(text, doc);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user