Skip to content

Commit fc26f55

Browse files
committed
additional changes needed for py3 branch
1 parent 532bfd9 commit fc26f55

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

hubblestack/utils/signing.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ def split_certs(fh):
114114
else:
115115
ret += line
116116
if line.startswith('----'):
117+
ret = ret.encode()
117118
try:
118119
yield ossl.load_certificate(ossl.FILETYPE_PEM, ret)
119120
except Exception as e:
@@ -186,7 +187,7 @@ def __init__(self, public_crt, ca_crt):
186187
if d in already:
187188
continue
188189
already.add(d)
189-
d += " " + stringify_ossl_cert(c)
190+
d = d.decode() + " " + stringify_ossl_cert(c)
190191
log.debug('adding %s as a trusted certificate approver', d)
191192
self.store.add_cert(c)
192193
self.trusted.append(d)
@@ -196,7 +197,7 @@ def __init__(self, public_crt, ca_crt):
196197
if d in already:
197198
continue
198199
already.add(d)
199-
d += " " + stringify_ossl_cert(c)
200+
d = d.decode() + " " + stringify_ossl_cert(c)
200201
log.debug('checking to see if %s is trustworthy', d)
201202
try:
202203
ossl.X509StoreContext(self.store, c).verify_certificate()
@@ -213,7 +214,7 @@ def __init__(self, public_crt, ca_crt):
213214
if d in already:
214215
continue
215216
already.add(d)
216-
d += " " + stringify_ossl_cert(c)
217+
d = d.decode() + " " + stringify_ossl_cert(c)
217218
log.debug('checking to see if %s is a valid leaf cert', d)
218219
try:
219220
ossl.X509StoreContext(self.store, c).verify_certificate()
@@ -245,7 +246,7 @@ def __init__(self, public_crt, ca_crt):
245246
def stringify_ossl_cert(c):
246247
if isinstance(c, (list,tuple)):
247248
return ', '.join([ stringify_ossl_cert(x) for x in c ])
248-
return '/'.join([ '='.join(x) for x in c.get_subject().get_components() ])
249+
return '/'.join([ '='.join([ x_.decode() for x_ in x ]) for x in c.get_subject().get_components() ])
249250

250251
def jsonify(obj, indent=2):
251252
return json.dumps(obj, indent=indent)
@@ -285,7 +286,7 @@ def hash_target(fname, obj_mode=False, chosen_hash=None):
285286
if obj_mode:
286287
return hasher, chosen_hash
287288
digest = hasher.finalize()
288-
hd = ''.join([ '{:02x}'.format(ord(x)) for x in digest ])
289+
hd = ''.join([ '{:02x}'.format(x) for x in digest ])
289290
log.debug('hashed %s: %s', fname, hd)
290291
return hd
291292

@@ -453,7 +454,7 @@ def verify_files(targets, mfname='MANIFEST', sfname='SIGNATURE', public_crt='pub
453454
# without a matching SIGNATURE
454455
ret[vfname] = STATUS.FAIL
455456
# fix any normalized names so the caller gets back their specified targets
456-
for k,v in xlate.iteritems():
457+
for k,v in xlate.items():
457458
ret[v] = ret.pop(k)
458459
return ret
459460

0 commit comments

Comments
 (0)