chiark / gitweb /
Merge branch 'ndk' into 'master'
[fdroidserver.git] / fdroidserver / common.py
index 75eac97cafb777403891f45f77b27bd18874223c..c8fdaad529de3f49e1d9bb12b00d649a2da40583 100644 (file)
@@ -74,7 +74,8 @@ default_config = {
         'r11c': None,
         'r12b': "$ANDROID_NDK",
         'r13b': None,
-        'r14': None,
+        'r14b': None,
+        'r15b': None,
     },
     'qt_sdk_path': None,
     'build_tools': "25.0.2",
@@ -85,6 +86,7 @@ default_config = {
     'gradle': 'gradle',
     'accepted_formats': ['txt', 'yml'],
     'sync_from_local_copy_dir': False,
+    'allow_disabled_algorithms': False,
     'per_app_repos': False,
     'make_current_version_link': True,
     'current_version_name_source': 'Name',
@@ -396,8 +398,8 @@ def get_local_metadata_files():
 
 def read_pkg_args(args, allow_vercodes=False):
     """
-    Given the arguments in the form of multiple appid:[vc] strings, this returns
-    a dictionary with the set of vercodes specified for each package.
+    :param args: arguments in the form of multiple appid:[vc] strings
+    :returns: a dictionary with the set of vercodes specified for each package
     """
 
     vercodes = {}
@@ -1582,6 +1584,11 @@ def natural_key(s):
 
 
 class KnownApks:
+    """permanent store of existing APKs with the date they were added
+
+    This is currently the only way to permanently store the "updated"
+    date of APKs.
+    """
 
     def __init__(self):
         self.path = os.path.join('stats', 'known_apks.txt')
@@ -1615,17 +1622,17 @@ class KnownApks:
             for line in sorted(lst, key=natural_key):
                 f.write(line + '\n')
 
-    def recordapk(self, apk, app, default_date=None):
+    def recordapk(self, apkName, app, default_date=None):
         '''
         Record an apk (if it's new, otherwise does nothing)
         Returns the date it was added as a datetime instance
         '''
-        if apk not in self.apks:
+        if apkName not in self.apks:
             if default_date is None:
                 default_date = datetime.utcnow()
-            self.apks[apk] = (app, default_date)
+            self.apks[apkName] = (app, default_date)
             self.changed = True
-        _, added = self.apks[apk]
+        _, added = self.apks[apkName]
         return added
 
     # Look up information - given the 'apkname', returns (app id, date added/None).
@@ -2036,6 +2043,26 @@ def verify_apk_signature(apk, jar=False):
         return subprocess.call([config['jarsigner'], '-strict', '-verify', apk]) == 4
 
 
+def verify_old_apk_signature(apk):
+    """verify the signature on an archived APK, supporting deprecated algorithms
+
+    F-Droid aims to keep every single binary that it ever published.  Therefore,
+    it needs to be able to verify APK signatures that include deprecated/removed
+    algorithms.  For example, jarsigner treats an MD5 signature as unsigned.
+
+    jarsigner passes unsigned APKs as "verified"! So this has to turn
+    on -strict then check for result 4.
+
+    """
+
+    _java_security = os.path.join(os.getcwd(), '.java.security')
+    with open(_java_security, 'w') as fp:
+        fp.write('jdk.jar.disabledAlgorithms=MD2, RSA keySize < 1024')
+
+    return subprocess.call([config['jarsigner'], '-J-Djava.security.properties=' + _java_security,
+                            '-strict', '-verify', apk]) == 4
+
+
 apk_badchars = re.compile('''[/ :;'"]''')