1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-22 11:13:46 +00:00

[TypeScript] Convert background entry script to TypeScript (#419)

* Convert background entry file to typescript. Remove global forge & tldjs variables.

* Minor cleanup.
This commit is contained in:
Oscar Hinton
2017-12-06 19:51:49 +01:00
committed by Kyle Spearrin
parent 97b509e1f6
commit 81fcfb4f6f
10 changed files with 59 additions and 49 deletions

View File

@@ -1,3 +1,5 @@
import * as forge from 'node-forge';
import { EncryptionType } from '../enums/encryptionType.enum';
import { CipherString } from '../models/domain/cipherString';
@@ -249,7 +251,7 @@ export default class CryptoService implements CryptoServiceInterface {
}
makeKey(password: string, salt: string): SymmetricCryptoKey {
const keyBytes: string = forge.pbkdf2(forge.util.encodeUtf8(password), forge.util.encodeUtf8(salt),
const keyBytes: string = (forge as any).pbkdf2(forge.util.encodeUtf8(password), forge.util.encodeUtf8(salt),
5000, 256 / 8, 'sha256');
return new SymmetricCryptoKey(keyBytes);
}
@@ -261,7 +263,7 @@ export default class CryptoService implements CryptoServiceInterface {
throw new Error('Invalid parameters.');
}
const hashBits = forge.pbkdf2(key.key, forge.util.encodeUtf8(password), 1, 256 / 8, 'sha256');
const hashBits = (forge as any).pbkdf2(key.key, forge.util.encodeUtf8(password), 1, 256 / 8, 'sha256');
return forge.util.encode64(hashBits);
}
@@ -487,8 +489,8 @@ export default class CryptoService implements CryptoServiceInterface {
}
}
const ctBuffer = forge.util.createBuffer(ctBytes);
const decipher = forge.cipher.createDecipher('AES-CBC', theKey.encKey);
const ctBuffer = (forge as any).util.createBuffer(ctBytes);
const decipher = (forge as any).cipher.createDecipher('AES-CBC', theKey.encKey);
decipher.start({ iv: ivBytes });
decipher.update(ctBuffer);
decipher.finish();
@@ -524,7 +526,7 @@ export default class CryptoService implements CryptoServiceInterface {
}
private computeMac(dataBytes: string, macKey: string, b64Output: boolean): string {
const hmac = forge.hmac.create();
const hmac = (forge as any).hmac.create();
hmac.start('sha256', macKey);
hmac.update(dataBytes);
const mac = hmac.digest();
@@ -539,7 +541,7 @@ export default class CryptoService implements CryptoServiceInterface {
// Safely compare two MACs in a way that protects against timing attacks (Double HMAC Verification).
// ref: https://www.nccgroup.trust/us/about-us/newsroom-and-events/blog/2011/february/double-hmac-verification/
private macsEqual(macKey: string, mac1: string, mac2: string): boolean {
const hmac = forge.hmac.create();
const hmac = (forge as any).hmac.create();
hmac.start('sha256', macKey);
hmac.update(mac1);

View File

@@ -0,0 +1,30 @@
export default function i18nService() {
const edgeMessages: any = {};
if (navigator.userAgent.indexOf(' Edge/') !== -1) {
fetch('../_locales/en/messages.json')
.then((file) => {
return file.json();
})
.then((locales) => {
for (const prop in locales) {
if (locales.hasOwnProperty(prop)) {
edgeMessages[prop] = chrome.i18n.getMessage(prop);
}
}
});
return edgeMessages;
}
return new Proxy({}, {
get(target, name) {
return chrome.i18n.getMessage(name);
},
set(target, name, value) {
throw new Error('set not allowed for i18n');
// @ts-ignore: Unreachable code error
return false;
},
});
}

View File

@@ -1,26 +0,0 @@
export default function i18nService() {
this.__edgeMessages = {};
if (navigator.userAgent.indexOf(' Edge/') !== -1) {
fetch('../_locales/en/messages.json').then((file) => {
return file.json();
}).then((locales) => {
for (const prop in locales) {
if (locales.hasOwnProperty(prop)) {
this.__edgeMessages[prop] = chrome.i18n.getMessage(prop);
}
}
});
return this.__edgeMessages;
}
return new Proxy({}, {
get: function (target, name) {
return chrome.i18n.getMessage(name);
},
set: function (target, name, value) {
throw 'set not allowed for i18n';
}
});
}