Skip to content
This repository was archived by the owner on Jan 10, 2023. It is now read-only.

Commit a9f9fff

Browse files
author
John
committed
Updated Pycryptodome signer to work
1 parent f4e597f commit a9f9fff

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

adb/sign_pycryptodome.py

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,27 @@
11
from adb import adb_protocol
22

3-
from Crypto.Hash import SHA256
43
from Crypto.PublicKey import RSA
5-
from Crypto.Signature import pkcs1_15
4+
from Crypto.Signature import PKCS1_v1_5
65

6+
class FakeSHA1:
7+
oid = "1.3.14.3.2.26" # SHA-1 OID
78

8-
class PycryptodomeAuthSigner(adb_protocol.AuthSigner):
9+
def __init__(self, data: (bytes, bytearray)) -> None:
10+
self.reset()
11+
self._data = data
912

13+
def reset(self) -> None:
14+
self._data = b""
15+
16+
def update(self, data: (bytes, bytearray)) -> None:
17+
self._data += data
18+
19+
def digest(self) -> (bytes, bytearray):
20+
return self._data
21+
22+
class PycryptodomeSigner(adb_protocol.AuthSigner):
1023
def __init__(self, rsa_key_path=None):
11-
super(PycryptodomeAuthSigner, self).__init__()
24+
super(PycryptodomeSigner, self).__init__()
1225

1326
if rsa_key_path:
1427
with open(rsa_key_path + '.pub', 'rb') as rsa_pub_file:
@@ -18,8 +31,8 @@ def __init__(self, rsa_key_path=None):
1831
self.rsa_key = RSA.import_key(rsa_priv_file.read())
1932

2033
def Sign(self, data):
21-
h = SHA256.new(data)
22-
return pkcs1_15.new(self.rsa_key).sign(h)
34+
h = FakeSHA1(data)
35+
return PKCS1_v1_5.new(self.rsa_key).sign(h)
2336

2437
def GetPublicKey(self):
25-
return self.public_key
38+
return self.public_key

0 commit comments

Comments
 (0)