Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apkutils: Add certificate tests, different checksum algorithms
This patch adds support for multiple checksum algorithms rather than just returning md5. APK.get_certs() behaves the same way, but it can now take an optional 'digestalgo' parameter. Digest algorithms are cached per algorithm. In the process of testing this, I also found that the library can't handle some apps that add data files to META-INF (i.e. any kotlin app will do this) because they try to interpret said data files as certificates. The patch instead uses the AOSP guessing logic to get the certificate name (must be in META-INF and be named *.RSA or *.DSA). There's also a sample kotlin app and test case.
- Loading branch information
Showing
4 changed files
with
51 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import os | ||
import unittest | ||
|
||
from apkutils import APK | ||
|
||
|
||
class TestCerts(unittest.TestCase): | ||
|
||
def test_youtube(self): | ||
file_path = os.path.abspath(os.path.join( | ||
os.path.dirname(__file__), "..", 'data', 'youtube.zip')) | ||
apk = APK(file_path) | ||
|
||
# Check that the default (md5) is correct | ||
self.assertEqual([('C=US, ST=CA, L=Mountain View, O=Google, Inc, OU=Google, Inc, CN=Unknown', | ||
'D046FC5D1FC3CD0E57C5444097CD5449')], apk.get_certs()) | ||
|
||
# Check that sha1 is correct | ||
self.assertEqual([('C=US, ST=CA, L=Mountain View, O=Google, Inc, OU=Google, Inc, CN=Unknown', | ||
'24BB24C05E47E0AEFA68A58A766179D9B613A600')], apk.get_certs('sha1')) | ||
|
||
# Check that sha256 is correct | ||
self.assertEqual([('C=US, ST=CA, L=Mountain View, O=Google, Inc, OU=Google, Inc, CN=Unknown', | ||
'3D7A1223019AA39D9EA0E3436AB7C0896BFB4FB679F4DE5FE7C23F326C8F994A')], apk.get_certs('sha256')) | ||
|
||
|
||
# Kotlin apps add data mime-typed files to META-INF which might | ||
# confuse the certifiacte guesser, check that we can handle those | ||
def test_kotlin_app(self): | ||
file_path = os.path.abspath(os.path.join( | ||
os.path.dirname(__file__), "..", 'data', 'kotlin-app.zip')) | ||
apk = APK(file_path) | ||
self.assertEqual([('CN=Android Debug, O=Android, C=US', | ||
'299D8DE477962C781714EAAB76A90C287BB67123CD2909DE0F743838CAD264E4')], apk.get_certs('sha256')) | ||
|
||
if __name__ == "__main__": | ||
unittest.main() |