mdkcontroller 1.3.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dk_modules/authorization.js +6 -40
- package/dk_modules/dkEncrypC.js +33 -0
- package/dk_modules/users.js +6 -4
- package/package.json +1 -4
- package/dk_modules/EncryptC/DKEncryptCMD.deps.json +0 -23
- package/dk_modules/EncryptC/DKEncryptCMD.dll +0 -0
- package/dk_modules/EncryptC/DKEncryptCMD.exe +0 -0
- package/dk_modules/EncryptC/DKEncryptCMD.runtimeconfig.json +0 -9
|
@@ -1,20 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
function isCalledFromNodeModules() {
|
|
4
|
-
const error = new Error();
|
|
5
|
-
const stackLines = error.stack.split('\n');
|
|
6
|
-
// Bỏ qua dòng đầu tiên vì đó là thông tin của Error
|
|
7
|
-
for (let i = 1; i < stackLines.length; i++) {
|
|
8
|
-
if (stackLines[i].includes('node_modules')) {
|
|
9
|
-
return true;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
1
|
+
import { decrypt, encrypt } from "./dkEncrypC.js";
|
|
14
2
|
|
|
15
3
|
export default function () {
|
|
16
4
|
|
|
17
|
-
const isModule = isCalledFromNodeModules();
|
|
18
5
|
const validateBase = function name(req, res) {
|
|
19
6
|
const db = global.db;
|
|
20
7
|
db.data.loginTokens = db.data.loginTokens || [];
|
|
@@ -43,16 +30,15 @@ export default function () {
|
|
|
43
30
|
}
|
|
44
31
|
}
|
|
45
32
|
console.log(
|
|
46
|
-
"Module dk_modules/authorization.js: ()=>{ validate:fn, validateBool:fn }"
|
|
33
|
+
"Module dk_modules/authorization.js: ()=>{ validate:fn, validateBool:fn, encrypt:fn, decrypt:fn }"
|
|
47
34
|
);
|
|
48
35
|
return {
|
|
49
36
|
validate: (req, res, next) => {
|
|
50
37
|
const resultValidate = validateBase(req, res);
|
|
51
38
|
switch (resultValidate) {
|
|
52
39
|
case 0:
|
|
53
|
-
return res.status(401).json({ message: '
|
|
40
|
+
return res.status(401).json({ message: 'Bạn cần đăng nhập trước khi thực hiện các yêu cầu đến endpoint này.' });
|
|
54
41
|
case 1:
|
|
55
|
-
|
|
56
42
|
next();
|
|
57
43
|
break;
|
|
58
44
|
case -1:
|
|
@@ -62,31 +48,11 @@ export default function () {
|
|
|
62
48
|
validateBool: (req, res) => {
|
|
63
49
|
return validateBase(req, res);
|
|
64
50
|
},
|
|
65
|
-
encrypt:
|
|
66
|
-
|
|
67
|
-
const cmd = data + " " + pw;
|
|
68
|
-
return new Promise((resolve, reject) => {
|
|
69
|
-
child_process.exec(`${cdtoCmd}dk_modules\\EncryptC\\DKEncryptCMD e ${cmd}`, (error, stdout, stderr) => {
|
|
70
|
-
if (error) {
|
|
71
|
-
reject(error);
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
resolve(stdout.trimEnd());
|
|
75
|
-
});
|
|
76
|
-
});
|
|
51
|
+
encrypt: function (data = "", pw = "mdkpaswoEcrHidDefat") {
|
|
52
|
+
return encrypt(data, pw);
|
|
77
53
|
},
|
|
78
54
|
decrypt: function (data = "", pw = "mdkpaswoEcrHidDefat") {
|
|
79
|
-
|
|
80
|
-
const cmd = data + " " + pw;
|
|
81
|
-
return new Promise((resolve, reject) => {
|
|
82
|
-
child_process.exec(`${cdtoCmd}dk_modules\\EncryptC\\DKEncryptCMD d ${cmd}`, (error, stdout, stderr) => {
|
|
83
|
-
if (error) {
|
|
84
|
-
reject(error);
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
resolve(stdout);
|
|
88
|
-
});
|
|
89
|
-
});
|
|
55
|
+
return decrypt(data, pw);
|
|
90
56
|
}
|
|
91
57
|
}
|
|
92
58
|
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import crypto from 'crypto';
|
|
2
|
+
|
|
3
|
+
function normalizeKey32(inputKey) {
|
|
4
|
+
const length = 32;
|
|
5
|
+
if (inputKey.length > length) {
|
|
6
|
+
return inputKey.slice(0, length); // Cắt bớt nếu quá dài
|
|
7
|
+
}
|
|
8
|
+
return inputKey.padEnd(length, '0'); // Thêm '0' vào cuối nếu quá ngắn
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const encrypt = (text, keyTextMAX32) => {
|
|
12
|
+
const key = Buffer.from(normalizeKey32(keyTextMAX32), 'utf8');
|
|
13
|
+
const iv = crypto.randomBytes(16); // Vector khởi tạo
|
|
14
|
+
const cipher = crypto.createCipheriv('aes-256-cbc', Buffer.from(key, 'hex'), iv);
|
|
15
|
+
let encrypted = cipher.update(text, 'utf8', 'hex');
|
|
16
|
+
encrypted += cipher.final('hex');
|
|
17
|
+
return iv.toString('hex') + encrypted;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const decrypt = (encryptedText, keyTextMAX32) => {
|
|
21
|
+
const key = Buffer.from(normalizeKey32(keyTextMAX32), 'utf8');
|
|
22
|
+
const iv = Buffer.from(encryptedText.slice(0, 32), 'hex');
|
|
23
|
+
const encryptedData = encryptedText.slice(32);
|
|
24
|
+
const decipher = crypto.createDecipheriv('aes-256-cbc', Buffer.from(key, 'hex'), iv);
|
|
25
|
+
let decrypted = decipher.update(encryptedData, 'hex', 'utf8');
|
|
26
|
+
decrypted += decipher.final('utf8');
|
|
27
|
+
return decrypted;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
console.log(
|
|
32
|
+
"Module dk_modules/authorization.js: { encrypt:fn, decrypt:fn }"
|
|
33
|
+
);
|
package/dk_modules/users.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { console } from "inspector";
|
|
1
2
|
import authInstant from "./authorization.js";
|
|
2
3
|
import { getNumber } from "./autoSequence.js";
|
|
3
4
|
|
|
@@ -35,10 +36,11 @@ export default (router, db) => {
|
|
|
35
36
|
router.post("/users/login", async (req, res) => {
|
|
36
37
|
const bodyParser = req.body;
|
|
37
38
|
if (bodyParser.userName && bodyParser.password) {
|
|
38
|
-
|
|
39
|
+
|
|
40
|
+
let userLoging = tbUser.find(f => f.userName == bodyParser.userName.toLowerCase().trim() && auth.decrypt(f.password) == bodyParser.password);
|
|
39
41
|
if (userLoging) {
|
|
40
|
-
const userIdCode =
|
|
41
|
-
const accessToken = userIdCode + global.
|
|
42
|
+
const userIdCode = auth.encrypt(userLoging.userName);
|
|
43
|
+
const accessToken = userIdCode + global.generateRandomString(100);
|
|
42
44
|
|
|
43
45
|
const expiredValue = new Date();
|
|
44
46
|
expiredValue.setMonth(expiredValue.getMonth() + 1);
|
|
@@ -89,7 +91,7 @@ export default (router, db) => {
|
|
|
89
91
|
id: getNumber('users'),
|
|
90
92
|
userName: bodyParser.userName.toLowerCase(),
|
|
91
93
|
email: bodyParser.email.toLowerCase(),
|
|
92
|
-
password: bodyParser.password,
|
|
94
|
+
password: auth.encrypt(bodyParser.password),
|
|
93
95
|
active: true,
|
|
94
96
|
amount: 0
|
|
95
97
|
});
|
package/package.json
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"dependencies": {
|
|
3
|
-
"child_process": "^1.0.2",
|
|
4
3
|
"cookie-parser": "^1.4.6",
|
|
5
4
|
"express": "^4.18.2",
|
|
6
|
-
"fluent-ffmpeg": "^2.1.2",
|
|
7
|
-
"handlebars": "^4.7.8",
|
|
8
5
|
"lowdb": "^7.0.1",
|
|
9
6
|
"socket.io": "^4.7.2"
|
|
10
7
|
},
|
|
11
8
|
"name": "mdkcontroller",
|
|
12
|
-
"version": "1.3.
|
|
9
|
+
"version": "1.3.1",
|
|
13
10
|
"keywords": [],
|
|
14
11
|
"author": "KHANHNBD <khanh272421@gmail.com>",
|
|
15
12
|
"license": "ISC",
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"runtimeTarget": {
|
|
3
|
-
"name": ".NETCoreApp,Version=v7.0",
|
|
4
|
-
"signature": ""
|
|
5
|
-
},
|
|
6
|
-
"compilationOptions": {},
|
|
7
|
-
"targets": {
|
|
8
|
-
".NETCoreApp,Version=v7.0": {
|
|
9
|
-
"DKEncryptCMD/1.0.0": {
|
|
10
|
-
"runtime": {
|
|
11
|
-
"DKEncryptCMD.dll": {}
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
},
|
|
16
|
-
"libraries": {
|
|
17
|
-
"DKEncryptCMD/1.0.0": {
|
|
18
|
-
"type": "project",
|
|
19
|
-
"serviceable": false,
|
|
20
|
-
"sha512": ""
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
Binary file
|
|
Binary file
|