Upgrades
This commit is contained in:
parent
f0feaf508b
commit
b5a4de3e8f
@ -24,6 +24,9 @@ module.exports = async function parseDbResults({ unparsedResults, tableSchema })
|
|||||||
*/
|
*/
|
||||||
let parsedResults = [];
|
let parsedResults = [];
|
||||||
|
|
||||||
|
const encryptionKey = process.env.DSQL_ENCRYPTION_KEY || "";
|
||||||
|
const encryptionSalt = process.env.DSQL_ENCRYPTION_SALT || "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
/**
|
/**
|
||||||
* Declare variables
|
* Declare variables
|
||||||
@ -52,7 +55,7 @@ module.exports = async function parseDbResults({ unparsedResults, tableSchema })
|
|||||||
|
|
||||||
if (resultFieldSchema?.encrypted) {
|
if (resultFieldSchema?.encrypted) {
|
||||||
if (value?.match(/./)) {
|
if (value?.match(/./)) {
|
||||||
result[resultFieldName] = decrypt(value);
|
result[resultFieldName] = decrypt({ encryptedString: value, encryptionKey, encryptionSalt });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,8 @@ const updateDbEntry = require("./updateDbEntry");
|
|||||||
* @param {string} [params.duplicateColumnName] - Duplicate column name
|
* @param {string} [params.duplicateColumnName] - Duplicate column name
|
||||||
* @param {string} [params.duplicateColumnValue] - Duplicate column value
|
* @param {string} [params.duplicateColumnValue] - Duplicate column value
|
||||||
* @param {boolean} [params.update] - Update this row if it exists
|
* @param {boolean} [params.update] - Update this row if it exists
|
||||||
* @param {string} [params.encryptionKey] - Update this row if it exists
|
* @param {string} params.encryptionKey - Update this row if it exists
|
||||||
* @param {string} [params.encryptionSalt] - Update this row if it exists
|
* @param {string} params.encryptionSalt - Update this row if it exists
|
||||||
*
|
*
|
||||||
* @returns {Promise<object|null>}
|
* @returns {Promise<object|null>}
|
||||||
*/
|
*/
|
||||||
@ -63,6 +63,8 @@ async function addDbEntry({ dbContext, paradigm, dbFullName, tableName, data, ta
|
|||||||
tableSchema,
|
tableSchema,
|
||||||
identifierColumnName: duplicateColumnName,
|
identifierColumnName: duplicateColumnName,
|
||||||
identifierValue: duplicateColumnValue || "",
|
identifierValue: duplicateColumnValue || "",
|
||||||
|
encryptionKey,
|
||||||
|
encryptionSalt,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,9 @@ async function runQuery({ dbFullName, query, readOnly, dbSchema, queryValuesArra
|
|||||||
*
|
*
|
||||||
* @description Declare "results" variable
|
* @description Declare "results" variable
|
||||||
*/
|
*/
|
||||||
|
const encryptionKey = process.env.DSQL_ENCRYPTION_KEY || "";
|
||||||
|
const encryptionSalt = process.env.DSQL_ENCRYPTION_SALT || "";
|
||||||
|
|
||||||
let result, error, tableSchema;
|
let result, error, tableSchema;
|
||||||
|
|
||||||
if (dbSchema) {
|
if (dbSchema) {
|
||||||
@ -78,6 +81,8 @@ async function runQuery({ dbFullName, query, readOnly, dbSchema, queryValuesArra
|
|||||||
duplicateColumnName,
|
duplicateColumnName,
|
||||||
duplicateColumnValue,
|
duplicateColumnValue,
|
||||||
tableSchema,
|
tableSchema,
|
||||||
|
encryptionKey,
|
||||||
|
encryptionSalt,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!result?.insertId) {
|
if (!result?.insertId) {
|
||||||
@ -96,6 +101,8 @@ async function runQuery({ dbFullName, query, readOnly, dbSchema, queryValuesArra
|
|||||||
identifierColumnName,
|
identifierColumnName,
|
||||||
identifierValue,
|
identifierValue,
|
||||||
tableSchema,
|
tableSchema,
|
||||||
|
encryptionKey,
|
||||||
|
encryptionSalt,
|
||||||
});
|
});
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -24,10 +24,12 @@ const dbHandler = require("../../engine/utils/dbHandler");
|
|||||||
* @param {import("../../../types/database-schema.td").DSQL_TableSchemaType} [params.tableSchema] - Table schema
|
* @param {import("../../../types/database-schema.td").DSQL_TableSchemaType} [params.tableSchema] - Table schema
|
||||||
* @param {string} params.identifierColumnName - Update row identifier column name
|
* @param {string} params.identifierColumnName - Update row identifier column name
|
||||||
* @param {string | number} params.identifierValue - Update row identifier column value
|
* @param {string | number} params.identifierValue - Update row identifier column value
|
||||||
|
* @param {string} params.encryptionKey - Encryption key
|
||||||
|
* @param {string} params.encryptionSalt - Encryption salt
|
||||||
*
|
*
|
||||||
* @returns {Promise<object|null>}
|
* @returns {Promise<object|null>}
|
||||||
*/
|
*/
|
||||||
async function updateDbEntry({ dbContext, paradigm, dbFullName, tableName, data, tableSchema, identifierColumnName, identifierValue }) {
|
async function updateDbEntry({ dbContext, paradigm, dbFullName, tableName, data, tableSchema, identifierColumnName, identifierValue, encryptionKey, encryptionSalt }) {
|
||||||
/**
|
/**
|
||||||
* Check if data is valid
|
* Check if data is valid
|
||||||
*/
|
*/
|
||||||
@ -47,9 +49,6 @@ async function updateDbEntry({ dbContext, paradigm, dbFullName, tableName, data,
|
|||||||
let updateKeyValueArray = [];
|
let updateKeyValueArray = [];
|
||||||
let updateValues = [];
|
let updateValues = [];
|
||||||
|
|
||||||
const encryptionKey = process.env.DSQL_ENCRYPTION_KEY;
|
|
||||||
const encryptionSalt = process.env.DSQL_ENCRYPTION_SALT;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Declare variables
|
* Declare variables
|
||||||
*
|
*
|
||||||
|
@ -31,6 +31,10 @@ async function localAddUser({ payload, dbSchema }) {
|
|||||||
* Initialize Variables
|
* Initialize Variables
|
||||||
*/
|
*/
|
||||||
const dbFullName = process.env.DSQL_DB_NAME || "";
|
const dbFullName = process.env.DSQL_DB_NAME || "";
|
||||||
|
|
||||||
|
const encryptionKey = process.env.DSQL_ENCRYPTION_KEY || "";
|
||||||
|
const encryptionSalt = process.env.DSQL_ENCRYPTION_SALT || "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hash Password
|
* Hash Password
|
||||||
*
|
*
|
||||||
@ -105,6 +109,8 @@ async function localAddUser({ payload, dbSchema }) {
|
|||||||
image: "/images/user_images/user-preset.png",
|
image: "/images/user_images/user-preset.png",
|
||||||
image_thumbnail: "/images/user_images/user-preset-thumbnail.png",
|
image_thumbnail: "/images/user_images/user-preset-thumbnail.png",
|
||||||
},
|
},
|
||||||
|
encryptionKey,
|
||||||
|
encryptionSalt,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (addUser?.insertId) {
|
if (addUser?.insertId) {
|
||||||
|
@ -5,6 +5,15 @@ const decrypt = ({ encryptedString, encryptionKey, encryptionSalt }) => {
|
|||||||
const algorithm = "aes-192-cbc";
|
const algorithm = "aes-192-cbc";
|
||||||
const password = encryptionKey;
|
const password = encryptionKey;
|
||||||
|
|
||||||
|
if (!encryptionKey?.match(/.{8,}/)) {
|
||||||
|
console.log("Decrption key is invalid");
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
if (!encryptionSalt?.match(/.{8,}/)) {
|
||||||
|
console.log("Decrption salt is invalid");
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
let key = scryptSync(password, encryptionSalt, 24);
|
let key = scryptSync(password, encryptionSalt, 24);
|
||||||
let iv = Buffer.alloc(16, 0);
|
let iv = Buffer.alloc(16, 0);
|
||||||
const decipher = createDecipheriv(algorithm, key, iv);
|
const decipher = createDecipheriv(algorithm, key, iv);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "datasquirel",
|
"name": "datasquirel",
|
||||||
"version": "1.6.1",
|
"version": "1.6.2",
|
||||||
"description": "Cloud-based SQL data management tool",
|
"description": "Cloud-based SQL data management tool",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"bin": {
|
"bin": {
|
||||||
|
Loading…
Reference in New Issue
Block a user