1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
From: Joel Schneider <joel.schneider@hispeed.ch>
Date: Mon, 21 Dec 2020 18:26:01 +0100
Subject: Fixed deprecated code
Fixed issue: 'asn1crypto.keys.PublicKeyInfo().fingerprint has been removed, please use oscrypto.asymmetric.PublicKey().fingerprint instead'
androguard/cli/main.py | 33 +++++++++++++++++++++++++++++----
requirements.txt | 3 ++-
2 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/androguard/cli/main.py b/androguard/cli/main.py
index 13bc1d0..7b3b1c0 100644
@@ -153,7 +153,7 @@ def plot(cg):
nx.draw_networkx_nodes(cg, pos=pos, node_color='r', nodelist=internal)
nx.draw_networkx_nodes(cg, pos=pos, node_color='b', nodelist=external)
- nx.draw_networkx_edges(cg, pos, arrow=True)
+ nx.draw_networkx_edges(cg, pos, arrows=True)
nx.draw_networkx_labels(cg, pos=pos, labels={x: "{}{}".format(x.class_name, x.name) for x in cg.nodes})
plt.draw()
plt.show()
@@ -334,6 +334,7 @@ def androlyze_main(session, filename):
from androguard.core.bytecodes.apk import APK
from androguard.core.bytecodes.dvm import DalvikVMFormat
from androguard.core.analysis.analysis import Analysis
+ from androguard.misc import AnalyzeAPK
colorama.init()
@@ -422,6 +423,7 @@ def androsign_main(args_apk, args_hash, args_all, show):
import traceback
from colorama import Fore, Style
from asn1crypto import x509, keys
+ from oscrypto import asymmetric
# Keep the list of hash functions in sync with cli/entry_points.py:sign
hashfunctions = dict(md5=hashlib.md5,
@@ -475,12 +477,12 @@ def androsign_main(args_apk, args_hash, args_all, show):
for public_key in pkeys:
if show:
- x509_public_key = keys.PublicKeyInfo.load(public_key)
+ x509_public_key = asymmetric.load_public_key(public_key)
print("PublicKey Algorithm:", x509_public_key.algorithm)
print("Bit Size:", x509_public_key.bit_size)
- print("Fingerprint:", binascii.hexlify(x509_public_key.fingerprint))
+ print("Fingerprint:", binascii.hexlify(x509_public_key.fingerprint).decode())
try:
- print("Hash Algorithm:", x509_public_key.hash_algo)
+ print("Hash Algorithm:", hash_algo(x509_public_key))
except ValueError as ve:
# RSA pkey does not have an hash algorithm
pass
@@ -527,3 +529,26 @@ def androdis_main(offset, size, dex):
idx += i.get_length()
else:
print("Dex could not be loaded!", file=sys.stderr)
+
+def hash_algo(pub_key):
+ """
+ Returns the name of the family of hash algorithms used to generate a
+ DSA key
+ :raises:
+ ValueError - when the key is not a DSA key
+ :return:
+ A unicode string of "sha1" or "sha2"
+ """
+
+ if pub_key.algorithm != 'dsa':
+ raise ValueError(
+ '''
+ Only DSA keys are generated using a hash algorithm, this key is
+ %s
+ ''',
+ pub_key.algorithm.upper()
+ )
+
+ byte_len = math.log(pub_key['private_key_algorithm']['parameters']['q'].native, 2) / 8
+
+ return 'sha1' if byte_len <= 20 else 'sha2'
diff --git a/requirements.txt b/requirements.txt
index 31832c3..65b4b9f 100644
@@ -6,4 +6,5 @@ matplotlib>=3.0.2
asn1crypto>=0.24.0
click>=7.0
pydot>=1.4.1
-ipython>=5.0.0
\ No newline at end of file
+ipython>=5.0.0
+oscrypto
|