gpg: fixup str/bytes issues

This commit is contained in:
Roman Zeyde
2016-05-22 22:17:32 +03:00
parent 4c07b360cd
commit decd3ddf75
4 changed files with 7 additions and 6 deletions

View File

@@ -325,7 +325,7 @@ def verify(pubkey, signature, original_data):
# remove GPG armor # remove GPG armor
lines = stream.readlines()[3:-1] lines = stream.readlines()[3:-1]
data = base64.b64decode(''.join(lines)) data = base64.b64decode(b''.join(lines))
payload, checksum = data[:-3], data[-3:] payload, checksum = data[:-3], data[-3:]
assert util.crc24(payload) == checksum assert util.crc24(payload) == checksum
stream = io.BytesIO(payload) stream = io.BytesIO(payload)

View File

@@ -103,11 +103,12 @@ class Factory(object):
def create_primary(self): def create_primary(self):
"""Export new primary GPG public key, ready for "gpg2 --import".""" """Export new primary GPG public key, ready for "gpg2 --import"."""
pubkey_packet = proto.packet(tag=6, blob=self.pubkey.data()) pubkey_packet = proto.packet(tag=6, blob=self.pubkey.data())
user_id_packet = proto.packet(tag=13, blob=self.user_id) user_id_packet = proto.packet(tag=13,
blob=self.user_id.encode('ascii'))
data_to_sign = (self.pubkey.data_to_hash() + data_to_sign = (self.pubkey.data_to_hash() +
user_id_packet[:1] + user_id_packet[:1] +
util.prefix_len('>L', self.user_id)) util.prefix_len('>L', self.user_id.encode('ascii')))
log.info('signing public key "%s"', self.user_id) log.info('signing public key "%s"', self.user_id)
hashed_subpackets = [ hashed_subpackets = [
proto.subpacket_time(self.pubkey.created), # signature time proto.subpacket_time(self.pubkey.created), # signature time

View File

@@ -150,8 +150,8 @@ def _split_lines(body, size):
def armor(blob, type_str): def armor(blob, type_str):
"""See https://tools.ietf.org/html/rfc4880#section-6 for details.""" """See https://tools.ietf.org/html/rfc4880#section-6 for details."""
head = '-----BEGIN PGP {}-----\nVersion: GnuPG v2\n\n'.format(type_str) head = '-----BEGIN PGP {}-----\nVersion: GnuPG v2\n\n'.format(type_str)
body = base64.b64encode(blob) body = base64.b64encode(blob).decode('ascii')
checksum = base64.b64encode(util.crc24(blob)) checksum = base64.b64encode(util.crc24(blob)).decode('ascii')
tail = '-----END PGP {}-----\n'.format(type_str) tail = '-----END PGP {}-----\n'.format(type_str)
return head + _split_lines(body, 64) + '=' + checksum + '\n' + tail return head + _split_lines(body, 64) + '=' + checksum + '\n' + tail

View File

@@ -42,7 +42,7 @@ def run_sign(args):
data = sys.stdin.read() data = sys.stdin.read()
sig = f.sign_message(data) sig = f.sign_message(data)
sig = proto.armor(sig, 'SIGNATURE') sig = proto.armor(sig, 'SIGNATURE').encode('ascii')
decode.verify(pubkey=pubkey, signature=sig, original_data=data) decode.verify(pubkey=pubkey, signature=sig, original_data=data)
filename = '-' # write to stdout filename = '-' # write to stdout