Add boss schedule retrieval & parsing

This commit is contained in:
kittentm 2026-02-19 06:08:41 +01:00
commit 8f7e705092
6 changed files with 218 additions and 3 deletions

View file

@ -0,0 +1,60 @@
import subprocess
import requests
import oead
import os
from config import settings
def process_boss_file():
temp_boss = "bosstemp.bin"
output_yaml = "boss.yaml"
decrypt_script = os.path.join("services", "decrypt.js")
if not os.path.exists(decrypt_script):
print(f"{decrypt_script} is missing!")
return False
try:
boss_url = settings.boss_url
res = requests.get(boss_url, timeout=10)
res.raise_for_status()
with open(temp_boss, "wb") as f:
f.write(res.content)
node_env = os.environ.copy()
node_env["BOSS_AES_KEY"] = settings.boss_aes_key
node_env["BOSS_HMAC_KEY"] = settings.boss_hmac_key
result = subprocess.run(
['node', decrypt_script, temp_boss],
capture_output=True,
text=False,
env=node_env
)
if result.returncode != 0:
print(f"decrypt fail! {result.stderr.decode()}")
return False
byml_obj = oead.byml.from_binary(result.stdout)
yaml_content = oead.byml.to_text(byml_obj)
with open(output_yaml, "w", encoding="utf-8") as f:
f.write(yaml_content)
print(f"yay! success: {output_yaml}")
return True
except Exception as e:
print(f"exception {e}")
return False
finally:
print("garbage pickup is running (boss)")
if os.path.exists(temp_boss):
os.remove(temp_boss)
print(f"Removed {temp_boss}")
if os.path.exists("boss.byml"):
os.remove("boss.byml")
print("Removed boss.byml")

44
services/decrypt.js Normal file
View file

@ -0,0 +1,44 @@
const fs = require('node:fs');
const path = require('node:path');
const crypto = require('node:crypto');
const BOSS_AES_KEY = process.env.BOSS_AES_KEY;
const BOSS_HMAC_KEY = process.env.BOSS_HMAC_KEY;
async function run() {
try {
if (!BOSS_AES_KEY || !BOSS_HMAC_KEY) {
process.stderr.write("decrypt: missing environment keys\n");
process.exit(1);
}
const data = fs.readFileSync(process.argv[2]);
const IV = Buffer.concat([
data.subarray(0x0C, 0x18),
Buffer.from([0x00, 0x00, 0x00, 0x01])
]);
const decipher = crypto.createDecipheriv('aes-128-ctr', Buffer.from(BOSS_AES_KEY, 'hex'), IV);
const decrypted = Buffer.concat([decipher.update(data.subarray(0x20)), decipher.final()]);
const hmac = decrypted.subarray(0, 0x20);
const content = decrypted.subarray(0x20);
const calculatedHmac = crypto.createHmac('sha256', Buffer.from(BOSS_HMAC_KEY, 'hex'))
.update(content)
.digest();
if (!calculatedHmac.equals(hmac)) {
process.stderr.write("Console HMAC check failed. Is the key correct?\n");
process.exit(1);
}
process.stdout.write(content);
} catch (err) {
process.stderr.write(`decrypt.js: ${err.message}\n`);
process.exit(1);
}
}
run();