import os
import tempfile
import base64
+import traceback
from OpenSSL import crypto
import M2Crypto
from M2Crypto import X509
from sfa.util.faults import *
def convert_public_key(key):
- keyconvert_path = "/usr/share/keyconvert/keyconvert"
+ keyconvert_path = "/usr/bin/keyconvert"
if not os.path.isfile(keyconvert_path):
raise IOError, "Could not find keyconvert in %s" % keyconvert_path
try:
k.load_pubkey_from_file(ssl_fn)
except:
- print "XXX: Error while converting key: ", key_str
+ print "XXX: Error while converting key: ", key
+ traceback.print_exc()
k = None
# remove the temporary files
def as_pem(self):
return crypto.dump_privatekey(crypto.FILETYPE_PEM, self.key)
+ ##
+ # Return an M2Crypto key object
+
def get_m2_pkey(self):
if not self.m2key:
self.m2key = M2Crypto.EVP.load_key_string(self.as_pem())
return self.m2key
+ ##
+ # Returns a string containing the public key represented by this object.
+
+ def get_pubkey_string(self):
+ m2pkey = self.get_m2_pkey()
+ return base64.b64encode(m2pkey.as_der())
+
##
# Return an OpenSSL pkey object