From 25e19df6144a454dd4a8f44b22d55155048c0c75 Mon Sep 17 00:00:00 2001 From: FUJITA Tomonori Date: Tue, 27 May 2014 11:04:54 +0900 Subject: [PATCH] bgp: use host's ssh host key if not specified Signed-off-by: FUJITA Tomonori --- ryu/services/protocols/bgp/operator/ssh.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) 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