summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-05-27 11:04:54 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2014-05-27 20:24:39 +0900
commit25e19df6144a454dd4a8f44b22d55155048c0c75 (patch)
tree4ea2de226e1ac62ba9e74884d0536fc7c61e5998
parent5c78159a36cab2d005920cf610dd35f35fd586cb (diff)
bgp: use host's ssh host key if not specified
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/services/protocols/bgp/operator/ssh.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/ryu/services/protocols/bgp/operator/ssh.py b/ryu/services/protocols/bgp/operator/ssh.py
index ac937910..86b233f6 100644
--- a/ryu/services/protocols/bgp/operator/ssh.py
+++ b/ryu/services/protocols/bgp/operator/ssh.py
@@ -21,6 +21,7 @@ import paramiko
import sys
from copy import copy
from oslo.config import cfg
+import os.path
from ryu.lib import hub
from ryu import version
@@ -79,11 +80,25 @@ Hello, this is Ryu BGP speaker (version %s).
transport = paramiko.Transport(sock)
transport.load_server_moduli()
- host_key = paramiko.RSAKey.from_private_key_file(CONF.cli_ssh_hostkey)
+ host_key = self._find_ssh_server_key()
transport.add_server_key(host_key)
self.transport = transport
transport.start_server(server=self)
+ def _find_ssh_server_key(self):
+ if CONF.cli_ssh_hostkey:
+ return paramiko.RSAKey.from_private_key_file(CONF.cli_ssh_hostkey)
+ elif os.path.exists("/etc/ssh_host_rsa_key"):
+ # OSX
+ return paramiko.RSAKey.from_private_key_file(
+ "/etc/ssh_host_rsa_key")
+ elif os.path.exists("/etc/ssh/ssh_host_rsa_key"):
+ # Linux
+ return paramiko.RSAKey.from_private_key_file(
+ "/etc/ssh/ssh_host_rsa_key")
+ else:
+ return paramiko.RSAKey.generate(1024)
+
def check_auth_none(self, username):
return paramiko.AUTH_SUCCESSFUL