From fce4269fc9e8b830be7562d128b31ca39a01c50a Mon Sep 17 00:00:00 2001 From: beerpsi Date: Thu, 18 Jul 2024 03:12:57 +0700 Subject: [PATCH] it turns out some of those bits weren't random --- segafs/makesegafs.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/segafs/makesegafs.py b/segafs/makesegafs.py index 404b03e..08c70f4 100644 --- a/segafs/makesegafs.py +++ b/segafs/makesegafs.py @@ -1,11 +1,14 @@ +# pyright: reportMissingTypeStubs=false, reportOperatorIssue=false, reportUnknownArgumentType=false, reportUnknownMemberType=false from math import ceil import os import secrets import struct +import time import zlib -from Crypto.Cipher import AES +from Crypto.Cipher import AES, PKCS1_OAEP from Crypto.Hash import HMAC, SHA1 +from Crypto.PublicKey import RSA from construct import Bytes, Const, Int16ul, Int32ul, Int64ul, Int8ul, Struct # ---- Configuration @@ -65,6 +68,17 @@ BTIV = bytes.fromhex("") # The HMAC key that ensures the app/opt/pack created is authentic. SIGKEY = bytes.fromhex("") + +HEADER_META_PUBKEY = RSA.import_key("""-----BEGIN PUBLIC KEY----- +MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsRMLnJuczNpfoqPpHQ3o +5XNkjKXO6P3ToV/45Az5dNaHVL7uEu9vPI7a2KYFQnNYgD3UUHFahfTcljzLOkcH +1aVrhm8gaB/5mygjUJWcN+kKyB7sASqhL22RC7NlxtDY15ozli/b0MagVoaBAV5D +MytUCa73GPRGY0x9v/wTvtmFclYCWjJ9c2QzrCrQ9eNTVyETwh5q6qKEARHGZgCX +rWmdCsa/+oS+3pLbUGFlHCSZtCvvWCJgmgurlTGAGzoxrieO6XDEg2AGiRprWWL2 +BGNh7gwgnSq6FWnKSf2Qe7xoFcTpV5QhNFBQjrq0KnBDRfz5EXJnMoKxNYL6reqR +uwIDAQAB +-----END PUBLIC KEY----- +""") # ---- # ---- Constants. Don't edit. @@ -123,8 +137,10 @@ print(f"Generated IV: {iv.hex()}") filesize = os.stat(INPUT_FILE).st_size BOOTID["block_count"] = ceil(filesize / BOOTID["block_size"]) + 8 -bullshit = secrets.token_bytes(BOOTID["block_size"]) -bullshit_crc32 = zlib.crc32(bullshit) +header_meta = struct.pack("