simple_ssl_context() is now a helper exposed in module sfa.util.ssl
[sfa.git] / sfa / trust / certificate.py
index e05d3a1..a0e3a70 100644 (file)
@@ -57,8 +57,6 @@ import OpenSSL
 # M2Crypto is imported on the fly to minimize crashes
 # import M2Crypto
 
-from sfa.util.py23 import PY3
-
 from sfa.util.faults import (CertExpired, CertMissingParent,
                              CertNotSignedByParent)
 from sfa.util.sfalogging import logger
@@ -117,7 +115,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
@@ -191,7 +189,6 @@ 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)
@@ -276,8 +273,7 @@ class Keypair:
     def get_m2_pubkey(self):
         import M2Crypto
         if not self.m2key:
-            self.m2key = M2Crypto.EVP.load_key_string(
-                self.as_pem().encode(encoding="utf-8"))
+            self.m2key = M2Crypto.EVP.load_key_string(self.as_pem())
         return self.m2key
 
     ##
@@ -361,8 +357,8 @@ class Certificate:
     # @param create If create==True, then also create a blank X509 certificate.
     # @param subject If subject!=None, then create a blank certificate and set
     #     it's subject name.
-    # @param string If string!=None, load the certficate from the string.
-    # @param filename If filename!=None, load the certficiate from the file.
+    # @param string If string!=None, load the certificate from the string.
+    # @param filename If filename!=None, load the certificate from the file.
     # @param isCA If !=None, set whether this cert is for a CA
 
     def __init__(self, lifeDays=1825, create=False, subject=None, string=None,
@@ -475,7 +471,7 @@ class Certificate:
             return ""
         string = OpenSSL.crypto.dump_certificate(
             OpenSSL.crypto.FILETYPE_PEM, self.x509)
-        if PY3 and isinstance(string, bytes):
+        if isinstance(string, bytes):
             string = string.decode()
         if save_parents and self.parent:
             string = string + self.parent.save_to_string(save_parents)
@@ -492,7 +488,7 @@ class Certificate:
             f = filep
         else:
             f = open(filename, 'w')
-        if PY3 and isinstance(string, bytes):
+        if isinstance(string, bytes):
             string = string.decode()
         f.write(string)
         f.close()
@@ -807,7 +803,7 @@ class Certificate:
         return result
 
     ##
-    # Set the parent certficiate.
+    # Set the parent certificate.
     #
     # @param p certificate object.