From f40451ecc5b891139347c51d804ab314502d98e7 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Thu, 7 Jun 2018 23:36:39 -0400 Subject: [PATCH] ie fixes --- src/abstractions/platformUtils.service.ts | 1 + src/angular/components/icon.component.ts | 5 +++-- src/electron/services/electronPlatformUtils.service.ts | 4 ++++ src/misc/utils.ts | 10 +++++++++- src/services/webCryptoFunction.service.ts | 10 ++++++---- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/src/abstractions/platformUtils.service.ts b/src/abstractions/platformUtils.service.ts index d623250bfa..7025010293 100644 --- a/src/abstractions/platformUtils.service.ts +++ b/src/abstractions/platformUtils.service.ts @@ -10,6 +10,7 @@ export abstract class PlatformUtilsService { isOpera: () => boolean; isVivaldi: () => boolean; isSafari: () => boolean; + isIE: () => boolean; isMacAppStore: () => boolean; analyticsId: () => string; getDomain: (uriString: string) => string; diff --git a/src/angular/components/icon.component.ts b/src/angular/components/icon.component.ts index 65b9339e2f..cac8d381a2 100644 --- a/src/angular/components/icon.component.ts +++ b/src/angular/components/icon.component.ts @@ -11,6 +11,8 @@ import { StateService } from '../../abstractions/state.service'; import { ConstantsService } from '../../services/constants.service'; +import { Utils } from '../../misc/utils'; + @Component({ selector: 'app-vault-icon', templateUrl: 'icon.component.html', @@ -77,8 +79,7 @@ export class IconComponent implements OnChanges { if (this.imageEnabled && isWebsite) { try { - const url = new URL(hostnameUri); - this.image = this.iconsUrl + '/' + url.hostname + '/icon.png'; + this.image = this.iconsUrl + '/' + Utils.getHostname(hostnameUri) + '/icon.png'; this.fallbackImage = 'images/fa-globe.png'; } catch (e) { } } diff --git a/src/electron/services/electronPlatformUtils.service.ts b/src/electron/services/electronPlatformUtils.service.ts index 3af58fbb41..057f61da53 100644 --- a/src/electron/services/electronPlatformUtils.service.ts +++ b/src/electron/services/electronPlatformUtils.service.ts @@ -74,6 +74,10 @@ export class ElectronPlatformUtilsService implements PlatformUtilsService { return false; } + isIE(): boolean { + return false; + } + isMacAppStore(): boolean { return isMacAppStore(); } diff --git a/src/misc/utils.ts b/src/misc/utils.ts index bd90f0d1e9..637330ea34 100644 --- a/src/misc/utils.ts +++ b/src/misc/utils.ts @@ -165,7 +165,15 @@ export class Utils { if (uriString.startsWith('http://') || uriString.startsWith('https://')) { try { - return nodeURL != null ? new nodeURL(uriString) : new URL(uriString); + if (nodeURL != null) { + return new nodeURL(uriString); + } else if (typeof URL === 'function') { + return new URL(uriString); + } else if (window != null) { + const anchor = window.document.createElement('a'); + anchor.href = uriString; + return anchor as any; + } } catch (e) { } } diff --git a/src/services/webCryptoFunction.service.ts b/src/services/webCryptoFunction.service.ts index 3938b48b9c..f055df3206 100644 --- a/src/services/webCryptoFunction.service.ts +++ b/src/services/webCryptoFunction.service.ts @@ -12,16 +12,18 @@ export class WebCryptoFunctionService implements CryptoFunctionService { private crypto: Crypto; private subtle: SubtleCrypto; private isEdge: boolean; + private isIE: boolean; constructor(private win: Window, private platformUtilsService: PlatformUtilsService) { - this.crypto = win.crypto; - this.subtle = win.crypto.subtle; + this.crypto = typeof win.crypto !== 'undefined' ? win.crypto : null; + this.subtle = (!!this.crypto && typeof win.crypto.subtle !== 'undefined') ? win.crypto.subtle : null; this.isEdge = platformUtilsService.isEdge(); + this.isIE = platformUtilsService.isIE(); } async pbkdf2(password: string | ArrayBuffer, salt: string | ArrayBuffer, algorithm: 'sha256' | 'sha512', iterations: number): Promise { - if (this.isEdge) { + if (this.isEdge || this.isIE) { const forgeLen = algorithm === 'sha256' ? 32 : 64; const passwordBytes = this.toByteString(password); const saltBytes = this.toByteString(salt); @@ -46,7 +48,7 @@ export class WebCryptoFunctionService implements CryptoFunctionService { } async hash(value: string | ArrayBuffer, algorithm: 'sha1' | 'sha256' | 'sha512'): Promise { - if (this.isEdge && algorithm === 'sha1') { + if ((this.isEdge || this.isIE) && algorithm === 'sha1') { const md = forge.md.sha1.create(); const valueBytes = this.toByteString(value); md.update(valueBytes, 'raw');