Added missing awaits for cache functions

This commit is contained in:
Jonathan Barrow
2022-09-25 18:20:00 -04:00
parent 7b9534f2a8
commit 9f77a0054c
5 changed files with 14 additions and 14 deletions

View File

@@ -91,13 +91,13 @@ router.post('/', async (request, response) => {
});
}
let publicKey = cache.getServicePublicKey('account');
let publicKey= await cache.getServicePublicKey('account');
if (publicKey === null) {
publicKey = await fs.readFile(`${cryptoPath}/public.pem`);
await cache.setServicePublicKey('account', publicKey);
}
let secretKey = cache.getServiceSecretKey('account');
let secretKey= await cache.getServiceSecretKey('account');
if (secretKey === null) {
secretKey = await fs.readFile(`${cryptoPath}/secret.key`);
await cache.setServiceSecretKey('account', secretKey);

View File

@@ -311,13 +311,13 @@ router.post('/', async (request, response) => {
});
}
let publicKey = cache.getServicePublicKey('account');
let publicKey= await cache.getServicePublicKey('account');
if (publicKey === null) {
publicKey = await fs.readFile(`${cryptoPath}/public.pem`);
await cache.setServicePublicKey('account', publicKey);
}
let secretKey = cache.getServiceSecretKey('account');
let secretKey= await cache.getServiceSecretKey('account');
if (secretKey === null) {
secretKey = await fs.readFile(`${cryptoPath}/secret.key`);
await cache.setServiceSecretKey('account', secretKey);

View File

@@ -55,13 +55,13 @@ async function processLoginRequest(request) {
const cryptoPath = `${__dirname}/../../../../certs/nex/${service_name}`;
let publicKey = cache.getNEXPublicKey(service_name);
let publicKey= await 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);
let secretKey= await cache.getNEXSecretKey(service_name);
if (secretKey === null) {
secretKey = await fs.readFile(`${cryptoPath}/secret.key`);
await cache.setNEXSecretKey(service_name, secretKey);

View File

@@ -44,13 +44,13 @@ router.get('/service_token/@me', async (request, response) => {
}).end());
}
let publicKey = cache.getServicePublicKey(service_name);
let publicKey= await cache.getServicePublicKey(service_name);
if (publicKey === null) {
publicKey = await fs.readFile(`${cryptoPath}/public.pem`);
await cache.setServicePublicKey(service_name, publicKey);
}
let secretKey = cache.getServiceSecretKey(service_name);
let secretKey= await cache.getServiceSecretKey(service_name);
if (secretKey === null) {
secretKey = await fs.readFile(`${cryptoPath}/secret.key`);
await cache.setServiceSecretKey(service_name, secretKey);
@@ -134,13 +134,13 @@ router.get('/nex_token/@me', async (request, response) => {
}).end());
}
let publicKey = cache.getNEXPublicKey(service_name);
let publicKey= await 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);
let secretKey= await cache.getNEXSecretKey(service_name);
if (secretKey === null) {
secretKey = await fs.readFile(`${cryptoPath}/secret.key`);
await cache.setNEXSecretKey(service_name, secretKey);

View File

@@ -41,7 +41,7 @@ async function generateToken(cryptoOptions, tokenOptions) {
// Access and refresh tokens use a different format since they must be much smaller
// They take no extra crypto options
if (!cryptoOptions) {
let aesKey = cache.getServiceAESKey('account', 'hex');
let aesKey = await cache.getServiceAESKey('account', 'hex');
if (aesKey === null) {
const fileBuffer = await fs.readFile(`${__dirname}/../certs/access/aes.key`, { encoding: 'utf8' });
@@ -135,7 +135,7 @@ async function decryptToken(token) {
// Access and refresh tokens use a different format since they must be much smaller
// Assume a small length means access or refresh token
if (token.length <= 32) {
let aesKey = cache.getServiceAESKey('account', 'hex');
let aesKey = await cache.getServiceAESKey('account', 'hex');
if (aesKey === null) {
const fileBuffer = await fs.readFile(`${cryptoPath}/aes.key`, { encoding: 'utf8' });
@@ -153,13 +153,13 @@ async function decryptToken(token) {
return decryptedBody;
}
let privateKeyBytes = cache.getServicePrivateKey('account');
let privateKeyBytes = await cache.getServicePrivateKey('account');
if (privateKeyBytes === null) {
privateKeyBytes = await fs.readFile(`${cryptoPath}/private.pem`);
await cache.setServicePrivateKey('account', privateKeyBytes);
}
let secretKey = cache.getServiceSecretKey('account');
let secretKey = await cache.getServiceSecretKey('account');
if (secretKey === null) {
secretKey = await fs.readFile(`${cryptoPath}/secret.key`);
await cache.setServiceSecretKey('account', secretKey);