chore: Fix import of GPG keys when two keys are provided

* chore: Fix import of GPG keys when two keys are provided

We were only retrieving the first output of gpg.list keys because previously we were only running import_gpg_keys once. Now that we run it twice we need to ensure that the key we select from the list matches the one we've imported.
This commit is contained in:
Gonçalo Garcia 2025-10-10 07:58:55 +00:00
parent e1dacbcea8
commit 7987d01a6e
1 changed files with 13 additions and 2 deletions

View File

@ -189,11 +189,22 @@ class PkgCreator:
def import_gpg_keys(self, private_key, public_key): def import_gpg_keys(self, private_key, public_key):
gpg = gnupg.GPG() gpg = gnupg.GPG()
private_key = base64.b64decode(private_key) private_key = base64.b64decode(private_key)
gpg.import_keys(private_key) import_result = gpg.import_keys(private_key)
if not import_result.fingerprints:
raise Exception("Failed to import private key")
public_key = base64.b64decode(public_key) public_key = base64.b64decode(public_key)
gpg.import_keys(public_key) gpg.import_keys(public_key)
imported_fingerprint = import_result.fingerprints[0]
data = gpg.list_keys(secret=True) data = gpg.list_keys(secret=True)
return (data[0]["fingerprint"], data[0]["uids"][0])
# Find the specific key we just imported by comparing fingerprints
for key in data:
if key["fingerprint"] == imported_fingerprint:
return (key["fingerprint"], key["uids"][0])
raise Exception(f"Could not find imported key with fingerprint {imported_fingerprint}")
def import_multiple_gpg_keys(self, primary_private_key, primary_public_key, secondary_private_key=None, secondary_public_key=None): def import_multiple_gpg_keys(self, primary_private_key, primary_public_key, secondary_private_key=None, secondary_public_key=None):
""" """