Esempio n. 1
0
def convert_public_key(key):
    keyconvert_path = "/usr/bin/keyconvert.py"
    if not os.path.isfile(keyconvert_path):
        raise IOError, "Could not find keyconvert in %s" % keyconvert_path

    # we can only convert rsa keys
    if "ssh-dss" in key:
        raise Exception, "keyconvert: dss keys are not supported"

    (ssh_f, ssh_fn) = tempfile.mkstemp()
    ssl_fn = tempfile.mktemp()
    os.write(ssh_f, key)
    os.close(ssh_f)

    cmd = keyconvert_path + " " + ssh_fn + " " + ssl_fn
    os.system(cmd)

    # this check leaves the temporary file containing the public key so
    # that it can be expected to see why it failed.
    # TODO: for production, cleanup the temporary files
    if not os.path.exists(ssl_fn):
        raise Exception, "keyconvert: generated certificate not found. keyconvert may have failed."

    k = Keypair()
    try:
        k.load_pubkey_from_file(ssl_fn)
        return k
    except:
        logger.log_exc("convert_public_key caught exception")
        raise
    finally:
        # remove the temporary files
        if os.path.exists(ssh_fn):
            os.remove(ssh_fn)
        if os.path.exists(ssl_fn):
            os.remove(ssl_fn)
Esempio n. 2
0
def convert_public_key(key):
    keyconvert_path = "/usr/bin/keyconvert.py"
    if not os.path.isfile(keyconvert_path):
        raise IOError, "Could not find keyconvert in %s" % keyconvert_path

    # we can only convert rsa keys
    if "ssh-dss" in key:
        raise Exception, "keyconvert: dss keys are not supported"

    (ssh_f, ssh_fn) = tempfile.mkstemp()
    ssl_fn = tempfile.mktemp()
    os.write(ssh_f, key)
    os.close(ssh_f)

    cmd = keyconvert_path + " " + ssh_fn + " " + ssl_fn
    os.system(cmd)

    # this check leaves the temporary file containing the public key so
    # that it can be expected to see why it failed.
    # TODO: for production, cleanup the temporary files
    if not os.path.exists(ssl_fn):
        raise Exception, "keyconvert: generated certificate not found. keyconvert may have failed."

    k = Keypair()
    try:
        k.load_pubkey_from_file(ssl_fn)
        return k
    except:
        logger.log_exc("convert_public_key caught exception")
        raise
    finally:
        # remove the temporary files
        if os.path.exists(ssh_fn):
            os.remove(ssh_fn)
        if os.path.exists(ssl_fn):
            os.remove(ssl_fn)
Esempio n. 3
0
 def decode(self):
     try:
         doc = parseString(self.xml)
     except ExpatError,e:
         logger.log_exc ("Failed to parse credential, %s"%self.xml)
         raise
Esempio n. 4
0
 def decode(self):
     try:
         doc = parseString(self.xml)
     except ExpatError, e:
         logger.log_exc("Failed to parse credential, %s" % self.xml)
         raise