X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sfa%2Ftrust%2Fcertificate.py;h=817422624dd737246695a2fd8ed9290329e71697;hb=061c47a7b94d746ef379591230f8e96e31c5b5bf;hp=cdad52ab80ffe2de234e09b2a3308138766875f9;hpb=4a9e6751f9f396f463932133b9d62fc925a99ef6;p=sfa.git diff --git a/sfa/trust/certificate.py b/sfa/trust/certificate.py index cdad52ab..81742262 100644 --- a/sfa/trust/certificate.py +++ b/sfa/trust/certificate.py @@ -117,7 +117,7 @@ def convert_public_key(key): (ssh_f, ssh_fn) = tempfile.mkstemp() ssl_fn = tempfile.mktemp() - os.write(ssh_f, key) + os.write(ssh_f, key.encode()) os.close(ssh_f) cmd = keyconvert_path + " " + ssh_fn + " " + ssl_fn @@ -182,7 +182,7 @@ class Keypair: # @param filename name of file to store the keypair in def save_to_file(self, filename): - with open(filename, 'w') as output: + with open(filename, 'wb') as output: output.write(self.as_pem()) self.filename = filename @@ -191,6 +191,7 @@ class Keypair: # public key. def load_from_file(self, filename): + logger.info(f"opening {filename} from certficate.load_from_file") self.filename = filename buffer = open(filename, 'r').read() self.load_from_string(buffer) @@ -206,12 +207,13 @@ class Keypair: OpenSSL.crypto.FILETYPE_PEM, string, functools.partial(glo_passphrase_callback, self, string)) self.m2key = M2Crypto.EVP.load_key_string( - string, functools.partial(glo_passphrase_callback, - self, string)) + string.encode(encoding="utf-8"), + functools.partial(glo_passphrase_callback, self, string)) else: self.key = OpenSSL.crypto.load_privatekey( OpenSSL.crypto.FILETYPE_PEM, string) - self.m2key = M2Crypto.EVP.load_key_string(string) + self.m2key = M2Crypto.EVP.load_key_string( + string.encode(encoding="utf-8")) ## # Load the public key from a string. No private key is loaded. @@ -274,7 +276,8 @@ class Keypair: def get_m2_pubkey(self): import M2Crypto if not self.m2key: - self.m2key = M2Crypto.EVP.load_key_string(self.as_pem()) + self.m2key = M2Crypto.EVP.load_key_string( + self.as_pem().encode(encoding="utf-8")) return self.m2key ## @@ -676,6 +679,11 @@ class Certificate: # raise "Cannot add extension {} which had val {} with new val {}"\ # .format(name, oldExtVal, value) + if isinstance(name, str): + name = name.encode() + if isinstance(value, str): + value = value.encode() + ext = OpenSSL.crypto.X509Extension(name, critical, value) self.x509.add_extensions([ext])