chiark / gitweb /
update: warn if APK has a date that is newer than the system clock
authorHans-Christoph Steiner <hans@eds.org>
Mon, 20 Jul 2015 23:42:40 +0000 (16:42 -0700)
committerHans-Christoph Steiner <hans@eds.org>
Thu, 23 Jul 2015 17:39:30 +0000 (10:39 -0700)
If the date in an APK is in the future, that could cause confusion.  If the
system clock is wrong, then the APK will also have a date in the future.
This is most likely on offline signing machines, since they do not have a
time source to sync to.

fdroidserver/update.py

index 5afa87585145a59611ac1089d0508c2024d0366f..17694f0d51e19cdccab5c3932ae0dd5480daf3d0 100644 (file)
@@ -27,6 +27,7 @@ import socket
 import zipfile
 import hashlib
 import pickle
+from datetime import datetime, timedelta
 from xml.dom.minidom import Document
 from optparse import OptionParser
 import time
@@ -542,6 +543,19 @@ def scan_apks(apps, apkcache, repodir, knownapks):
 
             apk = zipfile.ZipFile(apkfile, 'r')
 
+            # 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
+            info = apk.getinfo('AndroidManifest.xml')
+            dt_obj = datetime(*info.date_time)
+            checkdt = dt_obj - timedelta(1)
+            if datetime.today() < checkdt:
+                logging.warn('System clock is older than manifest in: '
+                             + apkfilename + '\nSet clock to that time using:\n'
+                             + 'sudo date -s "' + str(dt_obj) + '"')
+
             iconfilename = "%s.%s.png" % (
                 thisinfo['id'],
                 thisinfo['versioncode'])