feat(authz): add email-authorized GHDR dual signing
This commit is contained in:
parent
84f7c4c198
commit
bec7a3d7a0
10 changed files with 771 additions and 5 deletions
|
|
@ -4,15 +4,22 @@ const fs = require("node:fs");
|
|||
const path = require("node:path");
|
||||
|
||||
class MapGate {
|
||||
constructor({ mapsDir = "/etc/guanghu/navigation-maps", stateFile = "" } = {}) {
|
||||
constructor({ mapsDir = "/etc/guanghu/navigation-maps", fallbackMapsDir = "", stateFile = "" } = {}) {
|
||||
this.mapsDir = mapsDir;
|
||||
this.fallbackMapsDir = fallbackMapsDir;
|
||||
this.stateFile = stateFile;
|
||||
this.acks = new Map();
|
||||
this.load();
|
||||
}
|
||||
read(target) {
|
||||
if (!/^[A-Z0-9-]+$/.test(target)) throw new Error("invalid_target");
|
||||
const data = JSON.parse(fs.readFileSync(path.join(this.mapsDir, `${target}.json`), "utf8"));
|
||||
const primary = path.join(this.mapsDir, `${target}.json`);
|
||||
const fallback = this.fallbackMapsDir
|
||||
? path.join(this.fallbackMapsDir, `${target}.json`)
|
||||
: "";
|
||||
const selected = fs.existsSync(primary) ? primary : fallback;
|
||||
if (!selected || !fs.existsSync(selected)) throw new Error("navigation_map_not_found");
|
||||
const data = JSON.parse(fs.readFileSync(selected, "utf8"));
|
||||
const canonical = JSON.stringify(data);
|
||||
return { data, hash: crypto.createHash("sha256").update(canonical).digest("hex") };
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue