mirror of
https://github.com/bitwarden/browser
synced 2025-01-01 20:57:53 +01:00
static ContainerService for edge case dependencies
This commit is contained in:
parent
0dd711471b
commit
0fbbc4a0b9
@ -19,6 +19,7 @@ import ChromeStorageService from '../services/chromeStorage.service';
|
||||
import CipherService from '../services/cipher.service';
|
||||
import CollectionService from '../services/collection.service';
|
||||
import ConstantsService from '../services/constants.service';
|
||||
import ContainerService from '../services/container.service';
|
||||
import CryptoService from '../services/crypto.service';
|
||||
import EnvironmentService from '../services/environment.service';
|
||||
import FolderService from '../services/folder.service';
|
||||
@ -80,7 +81,8 @@ export default class MainBackground {
|
||||
this.browserUtilsService = new BrowserUtilsService();
|
||||
this.i18nService = i18nService(this.browserUtilsService);
|
||||
this.constantsService = new ConstantsService(this.i18nService, this.browserUtilsService);
|
||||
this.cryptoService = new CryptoService(this.storageService, this.storageService);
|
||||
this.cryptoService = ContainerService.cryptoService = new CryptoService(this.storageService,
|
||||
this.storageService);
|
||||
this.tokenService = new TokenService(this.storageService);
|
||||
this.appIdService = new AppIdService(this.storageService);
|
||||
this.apiService = new ApiService(this.tokenService, this.browserUtilsService,
|
||||
|
@ -11,7 +11,7 @@ import { Identity } from './identity';
|
||||
import { Login } from './login';
|
||||
import { SecureNote } from './secureNote';
|
||||
|
||||
import { BrowserUtilsService } from '../../services/abstractions/browserUtils.service';
|
||||
import BrowserUtilsService from '../../services/browserUtils.service';
|
||||
|
||||
class Cipher extends Domain {
|
||||
id: string;
|
||||
@ -32,8 +32,6 @@ class Cipher extends Domain {
|
||||
fields: Field[];
|
||||
collectionIds: string[];
|
||||
|
||||
private browserUtilsService: BrowserUtilsService;
|
||||
|
||||
constructor(obj?: CipherData, alreadyEncrypted: boolean = false, localData: any = null) {
|
||||
super();
|
||||
if (obj == null) {
|
||||
@ -119,12 +117,7 @@ class Cipher extends Domain {
|
||||
model.login = await this.login.decrypt(this.organizationId);
|
||||
model.subTitle = model.login.username;
|
||||
if (model.login.uri) {
|
||||
if (this.browserUtilsService == null) {
|
||||
this.browserUtilsService = chrome.extension.getBackgroundPage()
|
||||
.bitwardenMain.browserUtilsService as BrowserUtilsService;
|
||||
}
|
||||
|
||||
model.login.domain = this.browserUtilsService.getDomain(model.login.uri);
|
||||
model.login.domain = BrowserUtilsService.getDomain(model.login.uri);
|
||||
}
|
||||
break;
|
||||
case CipherType.SecureNote:
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { EncryptionType } from '../../enums/encryptionType.enum';
|
||||
import { CryptoService } from '../../services/abstractions/crypto.service';
|
||||
|
||||
import ContainerService from '../../services/container.service';
|
||||
|
||||
class CipherString {
|
||||
encryptedString?: string;
|
||||
@ -9,8 +10,6 @@ class CipherString {
|
||||
initializationVector?: string;
|
||||
mac?: string;
|
||||
|
||||
private cryptoService: CryptoService;
|
||||
|
||||
constructor(encryptedStringOrType: string | EncryptionType, ct?: string, iv?: string, mac?: string) {
|
||||
if (ct != null) {
|
||||
// ct and header
|
||||
@ -88,25 +87,23 @@ class CipherString {
|
||||
}
|
||||
}
|
||||
|
||||
decrypt(orgId: string) {
|
||||
decrypt(orgId: string): Promise<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;
|
||||
if (ContainerService.cryptoService == null) {
|
||||
throw new Error('ContainerService.cryptoService not initialized');
|
||||
}
|
||||
|
||||
return this.cryptoService.getOrgKey(orgId).then((orgKey: any) => {
|
||||
return self.cryptoService.decrypt(self, orgKey);
|
||||
return ContainerService.cryptoService.getOrgKey(orgId).then((orgKey: any) => {
|
||||
return ContainerService.cryptoService.decrypt(this, orgKey);
|
||||
}).then((decValue: any) => {
|
||||
self.decryptedValue = decValue;
|
||||
return self.decryptedValue;
|
||||
this.decryptedValue = decValue;
|
||||
return this.decryptedValue;
|
||||
}).catch(() => {
|
||||
self.decryptedValue = '[error: cannot decrypt]';
|
||||
return self.decryptedValue;
|
||||
this.decryptedValue = '[error: cannot decrypt]';
|
||||
return this.decryptedValue;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
5
src/services/container.service.ts
Normal file
5
src/services/container.service.ts
Normal file
@ -0,0 +1,5 @@
|
||||
import { CryptoService } from './abstractions/crypto.service';
|
||||
|
||||
export default class ContainerService {
|
||||
static cryptoService: CryptoService = null;
|
||||
}
|
Loading…
Reference in New Issue
Block a user