mirror of
https://github.com/bitwarden/browser
synced 2025-12-13 14:53:33 +00:00
Encrypt messages and verify timestamp.
This commit is contained in:
@@ -25,13 +25,16 @@ export class NativeMessagingBackground {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
send(message: object) {
|
async send(message: any) {
|
||||||
// If not connected, try to connect
|
// If not connected, try to connect
|
||||||
if (!this.connected) {
|
if (!this.connected) {
|
||||||
this.connect();
|
this.connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.port.postMessage(message);
|
message.timestamp = Date.now();
|
||||||
|
|
||||||
|
const encrypted = await this.cryptoService.encrypt(JSON.stringify(message));
|
||||||
|
this.port.postMessage(encrypted);
|
||||||
}
|
}
|
||||||
|
|
||||||
await(): Promise<any> {
|
await(): Promise<any> {
|
||||||
@@ -40,14 +43,21 @@ export class NativeMessagingBackground {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private async onMessage(msg: any) {
|
private async onMessage(rawMessage: any) {
|
||||||
switch(msg.command) {
|
const message = JSON.parse(await this.cryptoService.decryptToUtf8(rawMessage));
|
||||||
|
|
||||||
|
if (Math.abs(message.timestamp - Date.now()) > 10*1000) {
|
||||||
|
console.error("MESSAGE IS TO OLD");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch(message.command) {
|
||||||
case 'biometricUnlock': {
|
case 'biometricUnlock': {
|
||||||
await this.storageService.remove(ConstantsService.biometricAwaitingAcceptance);
|
await this.storageService.remove(ConstantsService.biometricAwaitingAcceptance);
|
||||||
|
|
||||||
const enabled = await this.storageService.get(ConstantsService.biometricUnlockKey);
|
const enabled = await this.storageService.get(ConstantsService.biometricUnlockKey);
|
||||||
if (enabled === null || enabled === false) {
|
if (enabled === null || enabled === false) {
|
||||||
if (msg.response === 'unlocked') {
|
if (message.response === 'unlocked') {
|
||||||
await this.storageService.save(ConstantsService.biometricUnlockKey, true);
|
await this.storageService.save(ConstantsService.biometricUnlockKey, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +72,7 @@ export class NativeMessagingBackground {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.resolver) {
|
if (this.resolver) {
|
||||||
this.resolver(msg);
|
this.resolver(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user