1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-11-22 11:45:59 +01:00

Remove Internet Explorer logic (#723)

This commit is contained in:
Oscar Hinton 2022-03-24 10:42:11 +01:00 committed by GitHub
parent 554dc8d873
commit 5b7b2a03dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 18 additions and 62 deletions

View File

@ -10,7 +10,7 @@ import { LogService } from "jslib-common/abstractions/log.service";
import { PasswordGenerationService } from "jslib-common/abstractions/passwordGeneration.service";
import { PlatformUtilsService } from "jslib-common/abstractions/platformUtils.service";
import { StateService } from "jslib-common/abstractions/state.service";
import { KdfType } from "jslib-common/enums/kdfType";
import { DEFAULT_KDF_ITERATIONS, DEFAULT_KDF_TYPE } from "jslib-common/enums/kdfType";
import { KeysRequest } from "jslib-common/models/request/keysRequest";
import { ReferenceEventRequest } from "jslib-common/models/request/referenceEventRequest";
import { RegisterRequest } from "jslib-common/models/request/registerRequest";
@ -163,9 +163,8 @@ export class RegisterComponent extends CaptchaProtectedComponent implements OnIn
this.name = this.name === "" ? null : this.name;
this.email = this.email.trim().toLowerCase();
const kdf = KdfType.PBKDF2_SHA256;
const useLowerKdf = this.platformUtilsService.isIE();
const kdfIterations = useLowerKdf ? 10000 : 100000;
const kdf = DEFAULT_KDF_TYPE;
const kdfIterations = DEFAULT_KDF_ITERATIONS;
const key = await this.cryptoService.makeKey(
this.masterPassword,
this.email,

View File

@ -12,7 +12,7 @@ import { PolicyService } from "jslib-common/abstractions/policy.service";
import { StateService } from "jslib-common/abstractions/state.service";
import { SyncService } from "jslib-common/abstractions/sync.service";
import { HashPurpose } from "jslib-common/enums/hashPurpose";
import { KdfType } from "jslib-common/enums/kdfType";
import { DEFAULT_KDF_ITERATIONS, DEFAULT_KDF_TYPE } from "jslib-common/enums/kdfType";
import { Utils } from "jslib-common/misc/utils";
import { EncString } from "jslib-common/models/domain/encString";
import { SymmetricCryptoKey } from "jslib-common/models/domain/symmetricCryptoKey";
@ -85,9 +85,8 @@ export class SetPasswordComponent extends BaseChangePasswordComponent {
}
async setupSubmitActions() {
this.kdf = KdfType.PBKDF2_SHA256;
const useLowerKdf = this.platformUtilsService.isIE();
this.kdfIterations = useLowerKdf ? 10000 : 100000;
this.kdf = DEFAULT_KDF_TYPE;
this.kdfIterations = DEFAULT_KDF_ITERATIONS;
return true;
}

View File

@ -413,7 +413,7 @@ import { ValidationService } from "./validation.service";
{
provide: CryptoFunctionServiceAbstraction,
useClass: WebCryptoFunctionService,
deps: ["WINDOW", PlatformUtilsServiceAbstraction],
deps: ["WINDOW"],
},
{
provide: EventServiceAbstraction,

View File

@ -16,7 +16,6 @@ export abstract class PlatformUtilsService {
isOpera: () => boolean;
isVivaldi: () => boolean;
isSafari: () => boolean;
isIE: () => boolean;
isMacAppStore: () => boolean;
isViewOpen: () => Promise<boolean>;
launchUri: (uri: string, options?: any) => void;

View File

@ -1,3 +1,7 @@
export enum KdfType {
PBKDF2_SHA256 = 0,
}
export const DEFAULT_KDF_TYPE = KdfType.PBKDF2_SHA256;
export const DEFAULT_KDF_ITERATIONS = 100000;
export const SEND_KDF_ITERATIONS = 100000;

View File

@ -10,7 +10,7 @@ import {
} from "../abstractions/export.service";
import { FolderService } from "../abstractions/folder.service";
import { CipherType } from "../enums/cipherType";
import { KdfType } from "../enums/kdfType";
import { DEFAULT_KDF_ITERATIONS, KdfType } from "../enums/kdfType";
import { Utils } from "../misc/utils";
import { CipherData } from "../models/data/cipherData";
import { CollectionData } from "../models/data/collectionData";
@ -54,7 +54,7 @@ export class ExportService implements ExportServiceAbstraction {
: await this.getExport("json");
const salt = Utils.fromBufferToB64(await this.cryptoFunctionService.randomBytes(16));
const kdfIterations = 100000;
const kdfIterations = DEFAULT_KDF_ITERATIONS;
const key = await this.cryptoService.makePinKey(
password,
salt,

View File

@ -5,6 +5,7 @@ import { FileUploadService } from "../abstractions/fileUpload.service";
import { I18nService } from "../abstractions/i18n.service";
import { SendService as SendServiceAbstraction } from "../abstractions/send.service";
import { StateService } from "../abstractions/state.service";
import { SEND_KDF_ITERATIONS } from "../enums/kdfType";
import { SendType } from "../enums/sendType";
import { Utils } from "../misc/utils";
import { SendData } from "../models/data/sendData";
@ -55,7 +56,7 @@ export class SendService implements SendServiceAbstraction {
password,
model.key,
"sha256",
100000
SEND_KDF_ITERATIONS
);
send.password = Utils.fromBufferToB64(passwordHash);
}

View File

@ -1,7 +1,6 @@
import * as forge from "node-forge";
import { CryptoFunctionService } from "../abstractions/cryptoFunction.service";
import { PlatformUtilsService } from "../abstractions/platformUtils.service";
import { Utils } from "../misc/utils";
import { DecryptParameters } from "../models/domain/decryptParameters";
import { SymmetricCryptoKey } from "../models/domain/symmetricCryptoKey";
@ -9,18 +8,11 @@ import { SymmetricCryptoKey } from "../models/domain/symmetricCryptoKey";
export class WebCryptoFunctionService implements CryptoFunctionService {
private crypto: Crypto;
private subtle: SubtleCrypto;
private isIE: boolean;
private isOldSafari: boolean;
constructor(private win: Window, private platformUtilsService: PlatformUtilsService) {
constructor(win: Window) {
this.crypto = typeof win.crypto !== "undefined" ? win.crypto : null;
this.subtle =
!!this.crypto && typeof win.crypto.subtle !== "undefined" ? win.crypto.subtle : null;
this.isIE = platformUtilsService.isIE();
const ua = win.navigator.userAgent;
this.isOldSafari =
platformUtilsService.isSafari() &&
(ua.indexOf(" Version/10.") > -1 || ua.indexOf(" Version/9.") > -1);
}
async pbkdf2(
@ -29,20 +21,6 @@ export class WebCryptoFunctionService implements CryptoFunctionService {
algorithm: "sha256" | "sha512",
iterations: number
): Promise<ArrayBuffer> {
if (this.isIE || this.isOldSafari) {
const forgeLen = algorithm === "sha256" ? 32 : 64;
const passwordBytes = this.toByteString(password);
const saltBytes = this.toByteString(salt);
const derivedKeyBytes = (forge as any).pbkdf2(
passwordBytes,
saltBytes,
iterations,
forgeLen,
algorithm
);
return Utils.fromByteStringToArray(derivedKeyBytes).buffer;
}
const wcLen = algorithm === "sha256" ? 256 : 512;
const passwordBuf = this.toBuf(password);
const saltBuf = this.toBuf(salt);
@ -127,7 +105,7 @@ export class WebCryptoFunctionService implements CryptoFunctionService {
value: string | ArrayBuffer,
algorithm: "sha1" | "sha256" | "sha512" | "md5"
): Promise<ArrayBuffer> {
if ((this.isIE && algorithm === "sha1") || algorithm === "md5") {
if (algorithm === "md5") {
const md = algorithm === "md5" ? forge.md.md5.create() : forge.md.sha1.create();
const valueBytes = this.toByteString(value);
md.update(valueBytes, "raw");
@ -143,15 +121,6 @@ export class WebCryptoFunctionService implements CryptoFunctionService {
key: ArrayBuffer,
algorithm: "sha1" | "sha256" | "sha512"
): Promise<ArrayBuffer> {
if (this.isIE && algorithm === "sha512") {
const hmac = (forge as any).hmac.create();
const keyBytes = this.toByteString(key);
const valueBytes = this.toByteString(value);
hmac.start(algorithm, keyBytes);
hmac.update(valueBytes, "raw");
return Utils.fromByteStringToArray(hmac.digest().data).buffer;
}
const signingAlgorithm = {
name: "HMAC",
hash: { name: this.toWebCryptoAlgorithm(algorithm) },

View File

@ -75,10 +75,6 @@ export class ElectronPlatformUtilsService implements PlatformUtilsService {
return false;
}
isIE(): boolean {
return false;
}
isMacAppStore(): boolean {
return isMacAppStore();
}

View File

@ -69,10 +69,6 @@ export class CliPlatformUtilsService implements PlatformUtilsService {
return false;
}
isIE() {
return false;
}
isMacAppStore() {
return false;
}

View File

@ -545,15 +545,8 @@ function testRsaGenerateKeyPair(length: 1024 | 2048 | 4096) {
function getWebCryptoFunctionService() {
const platformUtilsMock = Substitute.for<PlatformUtilsService>();
platformUtilsMock.isEdge().mimicks(() => navigator.userAgent.indexOf(" Edg/") !== -1);
platformUtilsMock
.isIE()
.mimicks(
() =>
navigator.userAgent.indexOf(" Edg/") === -1 &&
navigator.userAgent.indexOf(" Trident/") !== -1
);
return new WebCryptoFunctionService(window, platformUtilsMock);
return new WebCryptoFunctionService(window);
}
function makeStaticByteArray(length: number) {