From 5b7b2a03ddbecbc93adc54a5c69e8141c00c192f Mon Sep 17 00:00:00 2001 From: Oscar Hinton Date: Thu, 24 Mar 2022 10:42:11 +0100 Subject: [PATCH] Remove Internet Explorer logic (#723) --- angular/src/components/register.component.ts | 7 ++-- .../src/components/set-password.component.ts | 7 ++-- angular/src/services/jslib-services.module.ts | 2 +- .../src/abstractions/platformUtils.service.ts | 1 - common/src/enums/kdfType.ts | 4 +++ common/src/services/export.service.ts | 4 +-- common/src/services/send.service.ts | 3 +- .../src/services/webCryptoFunction.service.ts | 35 ++----------------- .../services/electronPlatformUtils.service.ts | 4 --- .../cli/services/cliPlatformUtils.service.ts | 4 --- .../webCryptoFunction.service.spec.ts | 9 +---- 11 files changed, 18 insertions(+), 62 deletions(-) diff --git a/angular/src/components/register.component.ts b/angular/src/components/register.component.ts index f66800c9d0..d4b99e17a2 100644 --- a/angular/src/components/register.component.ts +++ b/angular/src/components/register.component.ts @@ -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, diff --git a/angular/src/components/set-password.component.ts b/angular/src/components/set-password.component.ts index d87dffee03..4b996b5667 100644 --- a/angular/src/components/set-password.component.ts +++ b/angular/src/components/set-password.component.ts @@ -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; } diff --git a/angular/src/services/jslib-services.module.ts b/angular/src/services/jslib-services.module.ts index f389b86069..068b0ee3f9 100644 --- a/angular/src/services/jslib-services.module.ts +++ b/angular/src/services/jslib-services.module.ts @@ -413,7 +413,7 @@ import { ValidationService } from "./validation.service"; { provide: CryptoFunctionServiceAbstraction, useClass: WebCryptoFunctionService, - deps: ["WINDOW", PlatformUtilsServiceAbstraction], + deps: ["WINDOW"], }, { provide: EventServiceAbstraction, diff --git a/common/src/abstractions/platformUtils.service.ts b/common/src/abstractions/platformUtils.service.ts index dded8171e7..4a014868d5 100644 --- a/common/src/abstractions/platformUtils.service.ts +++ b/common/src/abstractions/platformUtils.service.ts @@ -16,7 +16,6 @@ export abstract class PlatformUtilsService { isOpera: () => boolean; isVivaldi: () => boolean; isSafari: () => boolean; - isIE: () => boolean; isMacAppStore: () => boolean; isViewOpen: () => Promise; launchUri: (uri: string, options?: any) => void; diff --git a/common/src/enums/kdfType.ts b/common/src/enums/kdfType.ts index bf331faef3..cc7fa7e0dc 100644 --- a/common/src/enums/kdfType.ts +++ b/common/src/enums/kdfType.ts @@ -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; diff --git a/common/src/services/export.service.ts b/common/src/services/export.service.ts index ddece8eb34..55f9206f6b 100644 --- a/common/src/services/export.service.ts +++ b/common/src/services/export.service.ts @@ -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, diff --git a/common/src/services/send.service.ts b/common/src/services/send.service.ts index 2baf45d927..75530db34b 100644 --- a/common/src/services/send.service.ts +++ b/common/src/services/send.service.ts @@ -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); } diff --git a/common/src/services/webCryptoFunction.service.ts b/common/src/services/webCryptoFunction.service.ts index 356a6317c3..b863f2267c 100644 --- a/common/src/services/webCryptoFunction.service.ts +++ b/common/src/services/webCryptoFunction.service.ts @@ -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 { - 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 { - 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 { - 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) }, diff --git a/electron/src/services/electronPlatformUtils.service.ts b/electron/src/services/electronPlatformUtils.service.ts index 7e089d89b0..c80218d2a0 100644 --- a/electron/src/services/electronPlatformUtils.service.ts +++ b/electron/src/services/electronPlatformUtils.service.ts @@ -75,10 +75,6 @@ export class ElectronPlatformUtilsService implements PlatformUtilsService { return false; } - isIE(): boolean { - return false; - } - isMacAppStore(): boolean { return isMacAppStore(); } diff --git a/node/src/cli/services/cliPlatformUtils.service.ts b/node/src/cli/services/cliPlatformUtils.service.ts index 6d40f07e6c..520170c2cc 100644 --- a/node/src/cli/services/cliPlatformUtils.service.ts +++ b/node/src/cli/services/cliPlatformUtils.service.ts @@ -69,10 +69,6 @@ export class CliPlatformUtilsService implements PlatformUtilsService { return false; } - isIE() { - return false; - } - isMacAppStore() { return false; } diff --git a/spec/web/services/webCryptoFunction.service.spec.ts b/spec/web/services/webCryptoFunction.service.spec.ts index 986919932a..5bb2547aee 100644 --- a/spec/web/services/webCryptoFunction.service.spec.ts +++ b/spec/web/services/webCryptoFunction.service.spec.ts @@ -545,15 +545,8 @@ function testRsaGenerateKeyPair(length: 1024 | 2048 | 4096) { function getWebCryptoFunctionService() { const platformUtilsMock = Substitute.for(); 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) {