1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-21 02:33:46 +00:00

Initial work of biometric unlock for browser

This commit is contained in:
Hinton
2020-10-09 17:16:15 +02:00
parent 296ccb6829
commit f311101ed9
14 changed files with 133 additions and 28 deletions

View File

@@ -27,7 +27,7 @@ describe('Browser Utils Service', () => {
value: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36',
});
const browserPlatformUtilsService = new BrowserPlatformUtilsService(null, null);
const browserPlatformUtilsService = new BrowserPlatformUtilsService(null, null, null);
expect(browserPlatformUtilsService.getDevice()).toBe(DeviceType.ChromeExtension);
});
@@ -37,7 +37,7 @@ describe('Browser Utils Service', () => {
value: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:58.0) Gecko/20100101 Firefox/58.0',
});
const browserPlatformUtilsService = new BrowserPlatformUtilsService(null, null);
const browserPlatformUtilsService = new BrowserPlatformUtilsService(null, null, null);
expect(browserPlatformUtilsService.getDevice()).toBe(DeviceType.FirefoxExtension);
});
@@ -52,7 +52,7 @@ describe('Browser Utils Service', () => {
value: {},
});
const browserPlatformUtilsService = new BrowserPlatformUtilsService(null, null);
const browserPlatformUtilsService = new BrowserPlatformUtilsService(null, null, null);
expect(browserPlatformUtilsService.getDevice()).toBe(DeviceType.OperaExtension);
});
@@ -62,7 +62,7 @@ describe('Browser Utils Service', () => {
value: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.74 Safari/537.36 Edg/79.0.309.43',
});
const browserPlatformUtilsService = new BrowserPlatformUtilsService(null, null);
const browserPlatformUtilsService = new BrowserPlatformUtilsService(null, null, null);
expect(browserPlatformUtilsService.getDevice()).toBe(DeviceType.EdgeExtension);
});
@@ -77,7 +77,7 @@ describe('Browser Utils Service', () => {
value: true,
});
const browserPlatformUtilsService = new BrowserPlatformUtilsService(null, null);
const browserPlatformUtilsService = new BrowserPlatformUtilsService(null, null, null);
expect(browserPlatformUtilsService.getDevice()).toBe(DeviceType.SafariExtension);
Object.defineProperty(window, 'safariAppExtension', {
@@ -92,7 +92,7 @@ describe('Browser Utils Service', () => {
value: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.97 Safari/537.36 Vivaldi/1.94.1008.40',
});
const browserPlatformUtilsService = new BrowserPlatformUtilsService(null, null);
const browserPlatformUtilsService = new BrowserPlatformUtilsService(null, null, null);
expect(browserPlatformUtilsService.getDevice()).toBe(DeviceType.VivaldiExtension);
});
});

View File

@@ -1,5 +1,6 @@
import { BrowserApi } from '../browser/browserApi';
import { SafariApp } from '../browser/safariApp';
import { NativeMessagingBackground } from '../background/nativeMessaging.background';
import { DeviceType } from 'jslib/enums/deviceType';
@@ -18,7 +19,8 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
private analyticsIdCache: string = null;
constructor(private messagingService: MessagingService,
private clipboardWriteCallback: (clipboardValue: string, clearMs: number) => void) { }
private clipboardWriteCallback: (clipboardValue: string, clearMs: number) => void,
private nativeMessagingBackground: NativeMessagingBackground) { }
getDevice(): DeviceType {
if (this.deviceCache) {
@@ -288,13 +290,18 @@ export default class BrowserPlatformUtilsService implements PlatformUtilsService
}
supportsBiometric() {
return Promise.resolve(false);
return Promise.resolve(true);
}
authenticateBiometric() {
return Promise.resolve(false);
}
async authenticateBiometric() {
const responsePromise = this.nativeMessagingBackground.await();
this.nativeMessagingBackground.send({'command': 'biometricUnlock'});
const response = await responsePromise;
return response.response == 'unlocked';
}
sidebarViewName(): string {
if ((window as any).chrome.sidebarAction && this.isFirefox()) {
return 'sidebar';