TTOPM commited on
Commit
350e53e
·
verified ·
1 Parent(s): 92ca311

Create tools/hash_blocklist.py

Browse files
belel-shield/sentinel/scanner/tools/hash_blocklist.py ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ import hashlib, json, sys, pathlib, datetime
3
+
4
+ ROOT = pathlib.Path(__file__).resolve().parents[2]
5
+ BL = ROOT / "blocklists" / "belel-blocklist.json"
6
+ CS = ROOT / "blocklists" / "belel-blocklist.checksums.json"
7
+
8
+ def sha256(fp: pathlib.Path) -> str:
9
+ h = hashlib.sha256()
10
+ with open(fp, "rb") as f:
11
+ for chunk in iter(lambda: f.read(8192), b""):
12
+ h.update(chunk)
13
+ return h.hexdigest()
14
+
15
+ if __name__ == "__main__":
16
+ if not BL.exists():
17
+ print(f"[!] Not found: {BL}")
18
+ sys.exit(1)
19
+ digest = sha256(BL)
20
+ print(f"[+] sha256({BL.name}) = {digest}")
21
+
22
+ # Optional: auto-write checksum file (uncomment to overwrite)
23
+ # cs_doc = {
24
+ # "artifact": "belel-blocklist.json",
25
+ # "algo": "sha256",
26
+ # "hash": digest,
27
+ # "version": "1.0.0",
28
+ # "last_updated": datetime.datetime.utcnow().isoformat() + "Z",
29
+ # "notes": "Auto-generated by tools/hash_blocklist.py"
30
+ # }
31
+ # CS.write_text(json.dumps(cs_doc, indent=2))
32
+ # print(f"[+] Wrote {CS}")