mirror of
https://github.com/bitwarden/browser
synced 2025-12-16 08:13:42 +00:00
static ContainerService for edge case dependencies
This commit is contained in:
@@ -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;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user