diff --git a/autospec/config.py b/autospec/config.py index e336b96..ddd4fbf 100644 --- a/autospec/config.py +++ b/autospec/config.py @@ -60,6 +60,7 @@ git_uri = None config_file = None old_version = None old_patches = list() +old_keyid = None profile_payload = None signature = None @@ -188,6 +189,7 @@ def setup_patterns(): def parse_existing_spec(path, name): global old_version global old_patches + global old_keyid spec = os.path.join(path, "{}.spec".format(name)) if not os.path.exists(spec): @@ -196,6 +198,9 @@ def parse_existing_spec(path, name): with open(spec, "r", encoding="latin-1") as inp: for line in inp.readlines(): line = line.strip().replace("\r", "").replace("\n", "") + if "Source0 file verified with key" in line: + keyidx = line.find('0x') + 2 + old_keyid = line[keyidx:].split()[0] if keyidx > 2 else old_keyid if ":" not in line: continue spl = line.split(":") diff --git a/autospec/pkg_integrity.py b/autospec/pkg_integrity.py index 55c9e98..8fb29ee 100644 --- a/autospec/pkg_integrity.py +++ b/autospec/pkg_integrity.py @@ -212,6 +212,17 @@ def get_signature_url(package_url): return None +def compare_keys(newkey, oldkey): + if newkey != oldkey: + print_error('Public key has changed:\n' + ' old key: {}\n' + ' new key: {}\n' + 'this is a critical security error, quitting...' + .format(oldkey, newkey)) + exit(1) + + + # GPG Verification class GPGVerifier(Verifier): @@ -279,6 +290,8 @@ class GPGVerifier(Verifier): return None sign_status = verify_cli(pub_key, self.package_path, self.package_sign_path) if sign_status is None: + if config.old_keyid: + compare_keys(KEYID_TRY, config.old_keyid) self.print_result(self.package_path) KEYID = KEYID_TRY config.signature = self.key_url