From a9f9fff19b62e4ee4195a2a13008cd6b59341ad1 Mon Sep 17 00:00:00 2001 From: John Date: Sat, 22 Feb 2020 03:19:58 -0500 Subject: [PATCH] Updated Pycryptodome signer to work --- adb/sign_pycryptodome.py | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/adb/sign_pycryptodome.py b/adb/sign_pycryptodome.py index 6a61ce9..eac9a2b 100644 --- a/adb/sign_pycryptodome.py +++ b/adb/sign_pycryptodome.py @@ -1,14 +1,27 @@ from adb import adb_protocol -from Crypto.Hash import SHA256 from Crypto.PublicKey import RSA -from Crypto.Signature import pkcs1_15 +from Crypto.Signature import PKCS1_v1_5 +class FakeSHA1: + oid = "1.3.14.3.2.26" # SHA-1 OID -class PycryptodomeAuthSigner(adb_protocol.AuthSigner): + def __init__(self, data: (bytes, bytearray)) -> None: + self.reset() + self._data = data + def reset(self) -> None: + self._data = b"" + + def update(self, data: (bytes, bytearray)) -> None: + self._data += data + + def digest(self) -> (bytes, bytearray): + return self._data + +class PycryptodomeSigner(adb_protocol.AuthSigner): def __init__(self, rsa_key_path=None): - super(PycryptodomeAuthSigner, self).__init__() + super(PycryptodomeSigner, self).__init__() if rsa_key_path: with open(rsa_key_path + '.pub', 'rb') as rsa_pub_file: @@ -18,8 +31,8 @@ def __init__(self, rsa_key_path=None): self.rsa_key = RSA.import_key(rsa_priv_file.read()) def Sign(self, data): - h = SHA256.new(data) - return pkcs1_15.new(self.rsa_key).sign(h) + h = FakeSHA1(data) + return PKCS1_v1_5.new(self.rsa_key).sign(h) def GetPublicKey(self): - return self.public_key + return self.public_key \ No newline at end of file