From c1f04e8e3e073da5d20dc756c3053f02679c6dc0 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Tue, 17 Dec 2024 13:25:55 +0100 Subject: [PATCH] Fixed cert generation on Android. Fixes #65. --- sbapp/buildozer.spec | 2 +- sbapp/sideband/certgen.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/sbapp/buildozer.spec b/sbapp/buildozer.spec index 09f9530..04ab47f 100644 --- a/sbapp/buildozer.spec +++ b/sbapp/buildozer.spec @@ -10,7 +10,7 @@ source.exclude_patterns = app_storage/*,venv/*,Makefile,./Makefil*,requirements, version.regex = __version__ = ['"](.*)['"] version.filename = %(source.dir)s/main.py -android.numeric_version = 20241213 +android.numeric_version = 20241217 requirements = kivy==2.3.0,libbz2,pillow==10.2.0,qrcode==7.3.1,usb4a,usbserial4a,able_recipe,libwebp,libogg,libopus,opusfile,numpy,cryptography,ffpyplayer,codec2,pycodec2,sh,pynacl,typing-extensions diff --git a/sbapp/sideband/certgen.py b/sbapp/sideband/certgen.py index 70e4802..631a8b4 100644 --- a/sbapp/sideband/certgen.py +++ b/sbapp/sideband/certgen.py @@ -47,7 +47,11 @@ def get_key(key_path, force_reload=False): return LOADED_KEY elif os.path.isfile(KEY_PATH): with open(KEY_PATH, "rb") as f: - key = load_pem_private_key(f.read(), KEY_PASSPHRASE) + if cryptography_major_version > 3: + key = load_pem_private_key(f.read(), KEY_PASSPHRASE) + else: + from cryptography.hazmat.backends import default_backend + key = load_pem_private_key(f.read(), KEY_PASSPHRASE, backend=default_backend()) else: if cryptography_major_version > 3: key = ec.generate_private_key(curve=ec.SECP256R1()) @@ -87,6 +91,7 @@ def gen_cert(cert_path, key): cb = cb.not_valid_before(datetime.datetime.now(datetime.timezone.utc)+datetime.timedelta(days=-14)) cb = cb.not_valid_after(datetime.datetime.now(datetime.timezone.utc)+datetime.timedelta(days=3652)) cb = cb.add_extension(x509.SubjectAlternativeName([x509.DNSName("localhost")]), critical=False) + if cryptography_major_version > 3: cert = cb.sign(key, hashes.SHA256()) else: