Skip to content

Commit ab8b4ac

Browse files
committed
⚙ add contents of protect.js injected from workflows
1 parent c9c9cf7 commit ab8b4ac

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

protect.template.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// generate_hash.js
2+
const crypto = require("crypto");
3+
const fs = require("fs");
4+
const path = require("path");
5+
6+
const password = process.env.SITE_PASSWORD;
7+
if (!password) {
8+
console.error("ERROR: SITE_PASSWORD environment variable is required.");
9+
process.exit(1);
10+
}
11+
12+
const templatePath = path.join(__dirname, "protect.template.js");
13+
const outPath = path.join(__dirname, "protect.js");
14+
15+
const iterations = 200000; // PBKDF2 iterations (tune as desired)
16+
const dkLen = 32; // 32 bytes = 256 bits
17+
const saltBytes = crypto.randomBytes(16);
18+
const saltBase64 = saltBytes.toString("base64");
19+
20+
const derivedKey = crypto.pbkdf2Sync(password, saltBytes, iterations, dkLen, "sha256");
21+
22+
const derivedKeyBase64 = derivedKey.toString("base64");
23+
24+
let template = fs.readFileSync(templatePath, "utf8");
25+
26+
template = template.replace("%%SALT%%", saltBase64).replace("%%ITERATIONS%%", String(iterations)).replace("%%KEY%%", derivedKeyBase64);
27+
28+
fs.writeFileSync(outPath, template, { encoding: "utf8", mode: 0o600 });
29+
30+
console.log("protect.js generated (not committed). Salt and derived key injected for deployment.");

0 commit comments

Comments
 (0)