[GnuPG.confirm_key] Convert email to bytes() before comparison
This commit is contained in:
parent
71afd6ed05
commit
55fa0d0601
|
@ -71,11 +71,19 @@ def public_keys( keyhome ):
|
||||||
email = None
|
email = None
|
||||||
return keys
|
return keys
|
||||||
|
|
||||||
# confirms a key has a given email address
|
def to_bytes(s) -> bytes:
|
||||||
|
if isinstance(s, str):
|
||||||
|
return bytes(s, sys.getdefaultencoding())
|
||||||
|
else:
|
||||||
|
return s
|
||||||
|
|
||||||
|
# Confirms a key has a given email address by importing it into a temporary
|
||||||
|
# keyring. If this operation succeeds and produces a message mentioning the
|
||||||
|
# expected email, a key is confirmed.
|
||||||
def confirm_key( content, email ):
|
def confirm_key( content, email ):
|
||||||
tmpkeyhome = ''
|
tmpkeyhome = ''
|
||||||
if isinstance(content, str):
|
content = to_bytes(content)
|
||||||
content = bytes(content, sys.getdefaultencoding())
|
expected_email = to_bytes(email.lower())
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
tmpkeyhome = '/tmp/' + ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(12))
|
tmpkeyhome = '/tmp/' + ''.join(random.choice(string.ascii_uppercase + string.digits) for x in range(12))
|
||||||
|
@ -92,7 +100,7 @@ def confirm_key( content, email ):
|
||||||
|
|
||||||
for line in result.split(b"\n"):
|
for line in result.split(b"\n"):
|
||||||
if b'imported' in line and b'<' in line and b'>' in line:
|
if b'imported' in line and b'<' in line and b'>' in line:
|
||||||
if line.split(b'<')[1].split(b'>')[0].lower() == email.lower():
|
if line.split(b'<')[1].split(b'>')[0].lower() == expected_email:
|
||||||
confirmed = True
|
confirmed = True
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue