mirror of https://github.com/keeweb/keeweb
separated encrypt and decrypt
parent
9701496897
commit
6ef5ae2517
|
@ -200,12 +200,18 @@ if (Launcher) {
|
|||
return this.call('argon2', password, salt, options);
|
||||
},
|
||||
|
||||
hardwareCrypt: async (value, encrypt, touchIdPrompt) => {
|
||||
// let enc = await NativeModules.hardwareCrypt(NativeModules.makeXoredValue('hello'), true);
|
||||
// let dec = await NativeModules.hardwareCrypt(enc, false, 'decrypt');
|
||||
// NativeModules.readXoredValue(dec).toString('utf8');
|
||||
hardwareEncrypt: async (value) => {
|
||||
const { ipcRenderer } = Launcher.electron();
|
||||
return await ipcRenderer.invoke('hardware-crypt', value, encrypt, touchIdPrompt);
|
||||
value = NativeModules.makeXoredValue(value);
|
||||
const encrypted = await ipcRenderer.invoke('hardware-encrypt', value);
|
||||
return NativeModules.readXoredValue(encrypted);
|
||||
},
|
||||
|
||||
hardwareDecrypt: async (value, touchIdPrompt) => {
|
||||
const { ipcRenderer } = Launcher.electron();
|
||||
value = NativeModules.makeXoredValue(value);
|
||||
const decrypted = await ipcRenderer.invoke('hardware-decrypt', value, touchIdPrompt);
|
||||
return NativeModules.readXoredValue(decrypted);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
@ -1,7 +1,20 @@
|
|||
const { readXoredValue, makeXoredValue } = require('../util/byte-utils');
|
||||
const { reqNative } = require('../util/req-native');
|
||||
|
||||
module.exports.hardwareCrypt = async function hardwareCrypt(e, value, encrypt, touchIdPrompt) {
|
||||
module.exports = {
|
||||
hardwareEncrypt,
|
||||
hardwareDecrypt
|
||||
};
|
||||
|
||||
async function hardwareEncrypt(e, value) {
|
||||
return await hardwareCrypto(value, true);
|
||||
}
|
||||
|
||||
async function hardwareDecrypt(e, value, touchIdPrompt) {
|
||||
return await hardwareCrypto(value, false, touchIdPrompt);
|
||||
}
|
||||
|
||||
async function hardwareCrypto(value, encrypt, touchIdPrompt) {
|
||||
if (process.platform !== 'darwin') {
|
||||
throw new Error('Not supported');
|
||||
}
|
||||
|
@ -15,9 +28,9 @@ module.exports.hardwareCrypt = async function hardwareCrypt(e, value, encrypt, t
|
|||
|
||||
const data = readXoredValue(value);
|
||||
|
||||
await checkKey();
|
||||
let res;
|
||||
if (encrypt) {
|
||||
await checkKey();
|
||||
res = await secureEnclave.encrypt({ keyTag, data });
|
||||
} else {
|
||||
res = await secureEnclave.decrypt({ keyTag, data, touchIdPrompt });
|
||||
|
@ -40,4 +53,4 @@ module.exports.hardwareCrypt = async function hardwareCrypt(e, value, encrypt, t
|
|||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
const { ipcMain } = require('electron');
|
||||
const { hardwareCrypt } = require('./ipc-handlers/hardware-crypt');
|
||||
const { hardwareEncrypt, hardwareDecrypt } = require('./ipc-handlers/hardware-crypto');
|
||||
|
||||
module.exports.setupIpcHandlers = () => {
|
||||
ipcMain.handle('hardware-crypt', hardwareCrypt);
|
||||
ipcMain.handle('hardware-encrypt', hardwareEncrypt);
|
||||
ipcMain.handle('hardware-decrypt', hardwareDecrypt);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue