processLoginRequest() now uses cache and async fs

This commit is contained in:
Jonathan Barrow
2022-09-24 19:36:42 -04:00
parent a9bf9cac7c
commit 46e103859d

View File

@@ -1,4 +1,4 @@
const fs = require('fs');
const fs = require('fs-extra');
const express = require('express');
const util = require('../../../util');
const database = require('../../../database');
@@ -55,12 +55,21 @@ async function processLoginRequest(request) {
const cryptoPath = `${__dirname}/../../../../certs/nex/${service_name}`;
const publicKey = fs.readFileSync(`${cryptoPath}/public.pem`);
const hmacSecret = fs.readFileSync(`${cryptoPath}/secret.key`);
let publicKey = cache.getNEXPublicKey(service_name);
if (publicKey === null) {
publicKey = await fs.readFile(`${cryptoPath}/public.pem`);
await cache.setNEXPublicKey(service_name, publicKey);
}
let secretKey = cache.getNEXSecretKey(service_name);
if (secretKey === null) {
secretKey = await fs.readFile(`${cryptoPath}/secret.key`);
await cache.setNEXSecretKey(service_name, secretKey);
}
const cryptoOptions = {
public_key: publicKey,
hmac_secret: hmacSecret
hmac_secret: secretKey
};
const tokenOptions = {