Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a13f3c34 authored by Abhishek Aggarwal's avatar Abhishek Aggarwal Committed by Mohammed Althaf T
Browse files
parent 88a970fb
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -226,6 +226,7 @@ ifdef LOCAL_DEX_PREOPT
	mv -f $@ $@.tmp
	$(PRIVATE_STRIP_SCRIPT) $@.tmp $@
endif  # LOCAL_DEX_PREOPT
	$(patch-trichrome)
	$(sign-package)
	# No need for align-package because sign-package takes care of alignment
else  # LOCAL_CERTIFICATE == PRESIGNED
+2 −0
Original line number Diff line number Diff line
@@ -619,6 +619,8 @@ JETIFIER := prebuilts/sdk/tools/jetifier/jetifier-standalone/bin/jetifier-standa

EXTRACT_KERNEL := build/make/tools/extract_kernel.py

PATCH_TRICHROME := build/make/tools/chromium_trichrome_patcher.py

USE_OPENJDK9 := true

ifeq ($(EXPERIMENTAL_USE_OPENJDK9),)
+5 −0
Original line number Diff line number Diff line
@@ -3444,3 +3444,8 @@ $(hide) CLANG_BIN="$(LLVM_PREBUILTS_PATH)" \
	XZ="$(XZ)" \
	$(LIBRARY_IDENTITY_CHECK_SCRIPT) $(SOONG_STRIP_PATH) $(1) $(2)
endef

# Patch Trichrome to add cert digest at buildtime
define patch-trichrome
$(hide) $(PATCH_TRICHROME) $@ $(PRIVATE_CERTIFICATE)
endef
+36 −0
Original line number Diff line number Diff line
#!/usr/bin/env python3

import os
import subprocess
import sys
import zipfile

infilename, sign_key = sys.argv[1:]

def ExtractFingerprint(cert):
    cmd = ['openssl', 'x509', '-sha256', '-fingerprint', '-noout', '-in', cert]
    proc = subprocess.run(cmd, stdout=subprocess.PIPE)
    return proc.stdout.decode('utf-8').split('=')[1].replace(':', '')

def patch_trichrome(infilename, sign_key):
    orig_certdigest = "32a2fc74d731105859e5a85df16d95f102d85b22099b8064c5d8915c61dad1e0"
    new_certdigest = ExtractFingerprint(sign_key).lower().rstrip()

    with zipfile.ZipFile(infilename, 'r') as zin, zipfile.ZipFile(infilename + ".patched", 'w') as zout:
        for info in zin.infolist():
            data = zin.read(info.filename)
            if info.filename == 'AndroidManifest.xml':
                # Make sure we can find the certdigest
                data.rindex(orig_certdigest.encode('utf-16-le'))
                # Replace it
                data = data.replace(orig_certdigest.encode('utf-16-le'), new_certdigest.encode('utf-16-le'))
            zout.writestr(info, data)

    # Delete the original file
    os.remove(infilename)

    # Rename the output file to the original file name
    os.rename(infilename + ".patched", infilename)

if "Browser_" in infilename or "BrowserWebView_" in infilename:
    patch_trichrome(infilename, sign_key)