fix: use newBootloaderQuery

This commit is contained in:
Derrick Hammer 2023-09-11 06:42:32 -04:00
parent 85615350f0
commit 25d2f6b1c0
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 11 additions and 20 deletions

View File

@ -5,6 +5,7 @@ import {
kernelLoadedDefer, kernelLoadedDefer,
loginDefer, loginDefer,
logoutDefer, logoutDefer,
newBootloaderQuery,
newKernelQuery, newKernelQuery,
} from "./queries.js"; } from "./queries.js";
import { Err } from "#types.js"; import { Err } from "#types.js";
@ -85,35 +86,25 @@ async function login(key: Uint8Array) {
return; return;
} }
let pubKeyRet = await newKernelQuery( let pubKeyRet = await newBootloaderQuery("exchangeCommunicationKeys", {
"exchangeCommunicationKeys", data: bytesToHex(x25519.getPublicKey(privKey)),
{ });
data: bytesToHex(x25519.getPublicKey(privKey)),
},
false,
);
let pubKeyT = await pubKeyRet[1]; if (pubKeyRet.err) {
alert(`Failed to login: could not get communication key: ${pubKeyRet.err}`);
if (pubKeyT[1]) {
alert(`Failed to login: could not get communication key: ${pubKeyT}`);
return; return;
} }
let pubKey = hexToBytes(pubKeyT[1]?.[0] as string); let pubKey = hexToBytes(pubKeyRet.data);
const secret = x25519.getSharedSecret(privKey, pubKey); const secret = x25519.getSharedSecret(privKey, pubKey);
const nonce = randomBytes(24); const nonce = randomBytes(24);
const box = secretbox(secret, nonce); const box = secretbox(secret, nonce);
const ciphertext = box.seal(key); const ciphertext = box.seal(key);
await newKernelQuery( await newBootloaderQuery("setLoginKey", {
"setLoginKey", data: bytesToHex(ciphertext),
{ nonce: bytesToHex(nonce),
data: bytesToHex(ciphertext), });
nonce: bytesToHex(nonce),
},
false,
);
} }
export { loginComplete, kernelLoaded, logoutComplete, openAuthWindow, login }; export { loginComplete, kernelLoaded, logoutComplete, openAuthWindow, login };