diff options
author | Jesse Luehrs <doy@tozt.net> | 2014-09-15 02:12:23 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2014-09-15 02:12:23 -0400 |
commit | 06485aea1e9a77b7f9ed09c6e5de093c2c89d76c (patch) | |
tree | 2e636b5d0f5a90d9bbe2caed92f7c9c1cf15e27b /ssh.py | |
parent | 4cde2aef1f9f77f559a19d35b796fb3a19184eae (diff) | |
download | python-termcast-server-06485aea1e9a77b7f9ed09c6e5de093c2c89d76c.tar.gz python-termcast-server-06485aea1e9a77b7f9ed09c6e5de093c2c89d76c.zip |
allow rsa or dsa keys
Diffstat (limited to 'ssh.py')
-rw-r--r-- | ssh.py | 15 |
1 files changed, 13 insertions, 2 deletions
@@ -2,9 +2,20 @@ import paramiko import time class Connection(object): - def __init__(self, client, connection_id, publisher, rsa_keyfile): + def __init__(self, client, connection_id, publisher, keyfile): self.transport = paramiko.Transport(client) - self.transport.add_server_key(paramiko.RSAKey(filename=rsa_keyfile)) + + key = None + with open(keyfile) as f: + header = f.readline() + if header == "-----BEGIN DSA PRIVATE KEY-----\n": + key = paramiko.DSSKey(filename=keyfile) + elif header == "-----BEGIN RSA PRIVATE KEY-----\n": + key = paramiko.RSAKey(filename=keyfile) + if key is None: + raise Exception("%s doesn't appear to be an SSH keyfile" % keyfile) + self.transport.add_server_key(key) + self.connection_id = connection_id self.publisher = publisher self.initialized = False |