From 8dade6ece01d6d20161e7a138c4091cfebe85012 Mon Sep 17 00:00:00 2001 From: Hans-Christoph Steiner Date: Wed, 29 Aug 2018 14:42:57 +0200 Subject: [PATCH] gitlab-ci: check if Application ID will cause keyalias collision fdroid/fdroidserver#553 --- .gitlab-ci.yml | 1 + tools/check-keyalias-collision.py | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100755 tools/check-keyalias-collision.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 0f53fc1889..579c6e6ef7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -37,4 +37,5 @@ lint: - echo "these images have EXIF that must be stripped:" - git --no-pager diff --stat - git --no-pager diff --name-only --exit-code || export EXITVALUE=1 + - ./tools/check-keyalias-collision.py || export EXITVALUE=1 - exit $EXITVALUE diff --git a/tools/check-keyalias-collision.py b/tools/check-keyalias-collision.py new file mode 100755 index 0000000000..7c93e37083 --- /dev/null +++ b/tools/check-keyalias-collision.py @@ -0,0 +1,30 @@ +#!/usr/bin/env python3 + +import glob +import hashlib +import inspect +import os +import sys + +def generate_keyalias(s): + m = hashlib.md5() + m.update(s.encode()) + return m.hexdigest()[:8] + +base = os.path.realpath( + os.path.join(os.path.dirname(inspect.getfile(inspect.currentframe())), '..')) +metadatafiles = sorted(glob.glob(base + '/metadata/*.txt') + + glob.glob(base + '/metadata/*.yml')) + +if not metadatafiles: + print('No metadata files found!') + sys.exit(1) + +keyaliases = dict() +for f in metadatafiles: + appid = os.path.basename(f)[:-4] + keyalias = generate_keyalias(appid) + if keyalias in keyaliases: + print(appid, "keyalias conflicts with", keyaliases[keyalias]) + sys.exit(1) + keyaliases[keyalias] = appid