1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-18 01:03:35 +00:00

is old safari check on pbkdf2

This commit is contained in:
Kyle Spearrin
2018-09-10 16:28:35 -04:00
parent 46f9e17056
commit ffa7b35494

View File

@@ -5,25 +5,31 @@ import { PlatformUtilsService } from '../abstractions/platformUtils.service';
import { Utils } from '../misc/utils'; import { Utils } from '../misc/utils';
import { SymmetricCryptoKey } from '../models/domain';
import { DecryptParameters } from '../models/domain/decryptParameters'; import { DecryptParameters } from '../models/domain/decryptParameters';
import { SymmetricCryptoKey } from '../models/domain/symmetricCryptoKey';
import { DeviceType } from '../enums/deviceType';
export class WebCryptoFunctionService implements CryptoFunctionService { export class WebCryptoFunctionService implements CryptoFunctionService {
private crypto: Crypto; private crypto: Crypto;
private subtle: SubtleCrypto; private subtle: SubtleCrypto;
private isEdge: boolean; private isEdge: boolean;
private isIE: boolean; private isIE: boolean;
private isOldSafari: boolean;
constructor(private win: Window, private platformUtilsService: PlatformUtilsService) { constructor(private win: Window, private platformUtilsService: PlatformUtilsService) {
this.crypto = typeof win.crypto !== 'undefined' ? win.crypto : null; this.crypto = typeof win.crypto !== 'undefined' ? win.crypto : null;
this.subtle = (!!this.crypto && typeof win.crypto.subtle !== 'undefined') ? win.crypto.subtle : null; this.subtle = (!!this.crypto && typeof win.crypto.subtle !== 'undefined') ? win.crypto.subtle : null;
this.isEdge = platformUtilsService.isEdge(); this.isEdge = platformUtilsService.isEdge();
this.isIE = platformUtilsService.isIE(); this.isIE = platformUtilsService.isIE();
const ua = win.navigator.userAgent;
this.isOldSafari = platformUtilsService.getDevice() === DeviceType.SafariBrowser &&
(ua.indexOf(' Version/10.') > -1 || ua.indexOf(' Version/9.') > -1);
} }
async pbkdf2(password: string | ArrayBuffer, salt: string | ArrayBuffer, algorithm: 'sha256' | 'sha512', async pbkdf2(password: string | ArrayBuffer, salt: string | ArrayBuffer, algorithm: 'sha256' | 'sha512',
iterations: number): Promise<ArrayBuffer> { iterations: number): Promise<ArrayBuffer> {
if (this.isEdge || this.isIE) { if (this.isEdge || this.isIE || this.isOldSafari) {
const forgeLen = algorithm === 'sha256' ? 32 : 64; const forgeLen = algorithm === 'sha256' ? 32 : 64;
const passwordBytes = this.toByteString(password); const passwordBytes = this.toByteString(password);
const saltBytes = this.toByteString(salt); const saltBytes = this.toByteString(salt);