@raketa-cloud/admin 0.0.94 → 0.0.95
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/package.json +1 -1
- package/src/setupAuthentication.js +11 -14
- package/src/simpleCipher.js +4 -10
package/package.json
CHANGED
|
@@ -5,31 +5,30 @@ import currentPath from "./currentPath.cjs";
|
|
|
5
5
|
import AuthHelper from "./helpers/AuthHelper";
|
|
6
6
|
// TODO: Maybe change the encryption mechanism?
|
|
7
7
|
import simpleCipher from "./simpleCipher";
|
|
8
|
-
import getConfig from "../../../apps/admin/src/getConfig";
|
|
9
8
|
|
|
10
9
|
// Generate a random signing secret on every server restart
|
|
11
10
|
// const SIGNING_SECRET = randomBytes(64).toString("hex");
|
|
12
11
|
const DELIMITER = ",";
|
|
13
12
|
|
|
14
|
-
function calculateHash(text) {
|
|
15
|
-
return createHmac("sha256",
|
|
13
|
+
function calculateHash(text, config) {
|
|
14
|
+
return createHmac("sha256", config.secrets.signing_secret)
|
|
16
15
|
.update(text)
|
|
17
16
|
.digest("hex");
|
|
18
17
|
}
|
|
19
18
|
|
|
20
|
-
function obfuscateToken(token) {
|
|
19
|
+
function obfuscateToken(token, config) {
|
|
21
20
|
const date = new Date();
|
|
22
21
|
const timestamp = date.getTime() + 2 * 60000;
|
|
23
22
|
const timestamped = [token, timestamp].join(DELIMITER);
|
|
24
|
-
const hash = calculateHash(timestamped);
|
|
23
|
+
const hash = calculateHash(timestamped, config);
|
|
25
24
|
const signed = [hash, timestamped].join(DELIMITER);
|
|
26
25
|
|
|
27
|
-
return Buffer.from(simpleCipher.encrypt(signed)).toString("base64");
|
|
26
|
+
return Buffer.from(simpleCipher.encrypt(signed, config)).toString("base64");
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
function extractToken(text) {
|
|
29
|
+
function extractToken(text, config) {
|
|
31
30
|
const encrypted = Buffer.from(text, "base64").toString("ascii");
|
|
32
|
-
const signed = simpleCipher.decrypt(encrypted);
|
|
31
|
+
const signed = simpleCipher.decrypt(encrypted, config);
|
|
33
32
|
const [hash, token, timestamp] = signed.split(DELIMITER);
|
|
34
33
|
const tDate = new Date(Number.parseInt(timestamp, 10));
|
|
35
34
|
|
|
@@ -37,7 +36,7 @@ function extractToken(text) {
|
|
|
37
36
|
return null;
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
if (hash !== calculateHash([token, timestamp].join(DELIMITER))) {
|
|
39
|
+
if (hash !== calculateHash([token, timestamp].join(DELIMITER), config)) {
|
|
41
40
|
return null;
|
|
42
41
|
}
|
|
43
42
|
|
|
@@ -141,9 +140,7 @@ const setupAuthentication = (app, config) => {
|
|
|
141
140
|
return c.redirect("/login");
|
|
142
141
|
}
|
|
143
142
|
|
|
144
|
-
const ot = obfuscateToken(token);
|
|
145
|
-
|
|
146
|
-
console.log({ ot });
|
|
143
|
+
const ot = obfuscateToken(token, config);
|
|
147
144
|
|
|
148
145
|
return c.redirect(
|
|
149
146
|
[
|
|
@@ -151,7 +148,7 @@ const setupAuthentication = (app, config) => {
|
|
|
151
148
|
"?redirect_to=",
|
|
152
149
|
c.req.query().redirect_to,
|
|
153
150
|
"&snapshot=",
|
|
154
|
-
|
|
151
|
+
ot,
|
|
155
152
|
].join("")
|
|
156
153
|
);
|
|
157
154
|
});
|
|
@@ -159,7 +156,7 @@ const setupAuthentication = (app, config) => {
|
|
|
159
156
|
app.post("/remote/verify", async (c) => {
|
|
160
157
|
const { credentials } = await c.req.json();
|
|
161
158
|
|
|
162
|
-
const token = extractToken(credentials);
|
|
159
|
+
const token = extractToken(credentials, config);
|
|
163
160
|
|
|
164
161
|
if (!token) {
|
|
165
162
|
return unauthorized();
|
package/src/simpleCipher.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import getConfig from "../../../apps/admin/src/getConfig";
|
|
2
|
-
|
|
3
1
|
const ALPHABET =
|
|
4
2
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789,.";
|
|
5
3
|
|
|
@@ -36,10 +34,8 @@ function generateDecryptionLookup(key) {
|
|
|
36
34
|
// const ENCRYPT_LOOKUP = generateEncryptionLookup(CIPHER_KEY);
|
|
37
35
|
// const DECRYPT_LOOKUP = generateDecryptionLookup(CIPHER_KEY);
|
|
38
36
|
|
|
39
|
-
function encrypt(plaintext) {
|
|
40
|
-
const ecryptLookup = generateEncryptionLookup(
|
|
41
|
-
getConfig().secrets.crypto_secret
|
|
42
|
-
);
|
|
37
|
+
function encrypt(plaintext, config) {
|
|
38
|
+
const ecryptLookup = generateEncryptionLookup(config.secrets.crypto_secret);
|
|
43
39
|
|
|
44
40
|
return plaintext
|
|
45
41
|
.split("")
|
|
@@ -47,10 +43,8 @@ function encrypt(plaintext) {
|
|
|
47
43
|
.join("");
|
|
48
44
|
}
|
|
49
45
|
|
|
50
|
-
function decrypt(ciphertext) {
|
|
51
|
-
const decryptLookup = generateDecryptionLookup(
|
|
52
|
-
getConfig().secrets.crypto_secret
|
|
53
|
-
);
|
|
46
|
+
function decrypt(ciphertext, config) {
|
|
47
|
+
const decryptLookup = generateDecryptionLookup(config.secrets.crypto_secret);
|
|
54
48
|
|
|
55
49
|
return ciphertext
|
|
56
50
|
.split("")
|