1
0
mirror of https://gitlab.com/fdroid/fdroidserver.git synced 2024-08-16 03:10:09 +02:00

add require_signature param to scan_apk

This commit is contained in:
linsui 2021-06-24 13:10:11 +08:00 committed by Hans-Christoph Steiner
parent acb123e9f6
commit 03c3e45116

View File

@ -1342,13 +1342,15 @@ def scan_repo_files(apkcache, repodir, knownapks, use_date_from_file=False):
return repo_files, cachechanged
def scan_apk(apk_file):
def scan_apk(apk_file, require_signature=True):
"""
Scans an APK file and returns dictionary with metadata of the APK.
Attention: This does *not* verify that the APK signature is correct.
:param apk_file: The (ideally absolute) path to the APK file
:param require_signature: Raise an exception is there is no valid
signature. Default to Ture.
:raises BuildException
:return A dict containing APK metadata
"""
@ -1375,12 +1377,14 @@ def scan_apk(apk_file):
# Get the signature, or rather the signing key fingerprints
logging.debug('Getting signature of {0}'.format(os.path.basename(apk_file)))
apk['sig'] = getsig(apk_file)
if not apk['sig']:
raise BuildException(_("Failed to get APK signing key fingerprint"))
apk['signer'] = common.apk_signer_fingerprint(os.path.join(os.getcwd(),
apk_file))
if not apk.get('signer'):
raise BuildException(_("Failed to get APK signing key fingerprint"))
if require_signature:
if not apk['sig']:
raise BuildException(_("Failed to get APK signing key fingerprint"))
apk['signer'] = common.apk_signer_fingerprint(
os.path.join(os.getcwd(), apk_file)
)
if not apk.get('signer'):
raise BuildException(_("Failed to get APK signing key fingerprint"))
# Get size of the APK
apk['size'] = os.path.getsize(apk_file)