Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parsing PGP keys for DNS validation #2019

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions dnf/dnssec.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def _cache_hit(key_union, input_key_string):
if key_union == input_key_string:
logger.debug("Cache hit, valid key")
return Validity.VALID
elif key_union is NoKey:
elif isinstance(key_union, NoKey):
logger.debug("Cache hit, proven non-existence")
return Validity.PROVEN_NONEXISTENCE
else:
Expand Down Expand Up @@ -185,6 +185,10 @@ def _cache_miss(input_key):
if ctx.add_ta_file("/var/lib/unbound/root.key") != 0:
logger.debug("Unbound context: Failed to add trust anchor file")

if input_key.email is None:
logger.debug("A key has no associated e-mail address")
return Validity.ERROR

status, result = ctx.resolve(email2location(input_key.email),
RR_TYPE_OPENPGPKEY, unbound.RR_CLASS_IN)
if status != 0:
Expand Down Expand Up @@ -273,9 +277,27 @@ def _query_db_for_gpg_keys():
return_list = []
for pkg in packages:
packager = dnf.rpm.getheader(pkg, 'packager')
email = re.search('<(.*@.*)>', packager).group(1)
if packager is None:
email = None
else:
email = re.search('<(.*@.*)>', packager).group(1)
if email is None:
logger.debug(any_msg(_(
"Exempting key package {} from a validation "
"because it's not bound to any e-mail address").format(
dnf.rpm.getheader(pkg, 'nevra'))))
continue
description = dnf.rpm.getheader(pkg, 'description')
key_lines = description.split('\n')[3:-3]
# Extract Radix-64-encoded PGP key. Without armor headers and
# a checksum.
key_lines = []
in_headers = True
for line in description.split('\n')[0:-3]:
if in_headers:
if re.match(r'\A\s*\Z', line, re.NOFLAG):
in_headers = False
else:
key_lines.append(line)
key_str = ''.join(key_lines)
return_list += [KeyInfo(email, key_str.encode('ascii'))]

Expand Down
Loading