Embed trusted certificate in flags.rs

- Extract the signing certificate from keyStore via keytool in
  dump_flags_native() and emit TRUSTED_CERT in flags.rs (or an empty
  slice when keyStore is not configured).
- Replace dynamic certificate extraction from stub.apk in
  preserve_stub_apk() with the static TRUSTED_CERT constant.
- Move get_package_uid() out of MagiskD into a standalone function.

Assisted-by: Gemini 4 Argon
This commit is contained in:
topjohnwu
2026-10-22 14:06:48 -07:00
committed by John Wu
parent b43a08fdde
commit c275a4ea30
2 changed files with 38 additions and 26 deletions
+22
View File
@@ -5,6 +5,7 @@ import glob
import os
import re
import shutil
import ssl
import stat
import subprocess
import sys
@@ -278,8 +279,29 @@ def dump_flags_native():
native_gen_path.mkdir(mode=0o755, parents=True, exist_ok=True)
write_if_diff(native_gen_path / "flags.h", flag_txt)
cert = b""
if "keyStore" in config:
ensure_jdk()
pem = cmd_out(
[
"keytool",
"-exportcert",
"-rfc",
"-keystore",
config["keyStore"],
"-storepass",
config["keyStorePass"],
"-alias",
config["keyAlias"],
]
)
if pem:
cert = ssl.PEM_cert_to_DER_cert(pem)
cert_hex = ", ".join(f"0x{b:02x}" for b in cert)
rust_flag_txt = f'pub const MAGISK_VERSION: &str = "{config["version"]}";\n'
rust_flag_txt += f'pub const MAGISK_VER_CODE: i32 = {config["versionCode"]};\n'
rust_flag_txt += f"pub const TRUSTED_CERT: &[u8] = &[{cert_hex}];\n"
write_if_diff(native_gen_path / "flags.rs", rust_flag_txt)