update: purge system clock check, APKs no longer have dates in them

A long time ago, APKs' ZIP headers usually included the dates that the
files where actually created.  That was a source of current date/time info
for fully offline signing servers, e.g. if the system clock was set to a
time older than included in the APK, then it was probably wrong.

For reproducibility, those dates have been zeroed out since long ago. So
now this is no longer useful since the dates are always 1980-01-01.
This commit is contained in:
Hans-Christoph Steiner
2026-02-27 08:00:34 +01:00
committed by Michael Pöhn
parent 8ab474ad3b
commit 9609cbb082
2 changed files with 2 additions and 33 deletions

View File

@@ -79,7 +79,7 @@ import zipfile
from argparse import BooleanOptionalAction
from base64 import urlsafe_b64encode
from binascii import hexlify
from datetime import datetime, timedelta, timezone
from datetime import datetime, timezone
from pathlib import Path
from queue import Queue
from typing import List
@@ -2894,23 +2894,6 @@ def natural_key(s):
return [int(sp) if sp.isdigit() else sp for sp in re.split(r'(\d+)', s)]
def check_system_clock(dt_obj, path):
"""Check if system clock is updated based on provided date.
If an APK has files newer than the system time, suggest updating
the system clock. This is useful for offline systems, used for
signing, which do not have another source of clock sync info. It
has to be more than 24 hours newer because ZIP/APK files do not
store timezone info
"""
checkdt = dt_obj - timedelta(1)
if datetime.today() < checkdt:
logging.warning(_('System clock is older than date in {path}!').format(path=path)
+ '\n' + _('Set clock to that time using:') + '\n'
+ 'sudo date -s "' + str(dt_obj) + '"')
def get_file_extension(filename):
"""Get the normalized file extension, can be blank string but never None."""
if isinstance(filename, bytes):

View File

@@ -36,7 +36,6 @@ import time
import warnings
import zipfile
from argparse import ArgumentParser
from datetime import datetime
from pathlib import Path
import asn1crypto.cms
@@ -2207,23 +2206,10 @@ def process_apk(apkcache, apkfilename, repodir, package_added_cache, use_date_fr
.format(apkfilename=apkfilename))
return True, None, False
apkzip = zipfile.ZipFile(apkfile, 'r')
manifest = apkzip.getinfo('AndroidManifest.xml')
# 1980-0-0 means zeroed out, any other invalid date should trigger a warning
if (1980, 0, 0) != manifest.date_time[0:3]:
try:
common.check_system_clock(datetime(*manifest.date_time), apkfilename)
except ValueError as e:
logging.warning(_("{apkfilename}'s AndroidManifest.xml has a bad date: ")
.format(apkfilename=apkfile) + str(e))
# extract icons from APK zip file
iconfilename = get_old_icon_filename(apk['packageName'], apk['versionCode'])
try:
with zipfile.ZipFile(apkfile, 'r') as apkzip:
empty_densities = extract_apk_icons(iconfilename, apk, apkzip, repodir)
finally:
apkzip.close() # ensure that APK zip file gets closed
# resize existing icons for densities missing in the APK
fill_missing_icon_densities(empty_densities, iconfilename, apk, repodir)