aboutsummaryrefslogtreecommitdiffstats
path: root/ssh.py
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-09-15 02:12:23 -0400
committerJesse Luehrs <doy@tozt.net>2014-09-15 02:12:23 -0400
commit06485aea1e9a77b7f9ed09c6e5de093c2c89d76c (patch)
tree2e636b5d0f5a90d9bbe2caed92f7c9c1cf15e27b /ssh.py
parent4cde2aef1f9f77f559a19d35b796fb3a19184eae (diff)
downloadpython-termcast-server-06485aea1e9a77b7f9ed09c6e5de093c2c89d76c.tar.gz
python-termcast-server-06485aea1e9a77b7f9ed09c6e5de093c2c89d76c.zip
allow rsa or dsa keys
Diffstat (limited to 'ssh.py')
-rw-r--r--ssh.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/ssh.py b/ssh.py
index d4664bf..c320aa2 100644
--- a/ssh.py
+++ b/ssh.py
@@ -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