From: Ondrej Lichtner <olichtne(a)redhat.com>
This adds handling of nonexistent files/directories that we load keys
from.
Signed-off-by: Ondrej Lichtner <olichtne(a)redhat.com>
---
lnst/Controller/CtlSecSocket.py | 18 +++++++++++-------
lnst/Slave/SlaveSecSocket.py | 16 ++++++++++------
2 files changed, 21 insertions(+), 13 deletions(-)
diff --git a/lnst/Controller/CtlSecSocket.py b/lnst/Controller/CtlSecSocket.py
index d92a8c6..fd9ba26 100644
--- a/lnst/Controller/CtlSecSocket.py
+++ b/lnst/Controller/CtlSecSocket.py
@@ -181,19 +181,23 @@ class CtlSecSocket(SecureSocket):
ctl_ssh_key = None
known_hosts = []
ssh_dir_path = os.path.expanduser("~/.ssh")
- with open(ssh_dir_path+"/known_hosts", 'r') as f:
- for line in f.readlines():
- key = line[line.find(' ')+1:]
- try:
- known_hosts.append(load_ssh_public_key(key, backend))
- except:
- continue
+ if os.path.isfile(ssh_dir_path+"/known_hosts"):
+ with open(ssh_dir_path+"/known_hosts", 'r') as f:
+ for line in f.readlines():
+ key = line[line.find(' ')+1:]
+ try:
+ known_hosts.append(load_ssh_public_key(key, backend))
+ except:
+ continue
+ else:
+ logging.error("No known hosts loaded.")
try:
with open(ssh_dir_path+"/id_rsa", 'r') as f:
ctl_ssh_key = load_pem_private_key(f.read(), None, backend)
except:
ctl_ssh_key = None
+ logging.error("No controller ssh key loaded.")
if not ctl_ssh_key:
raise SecSocketException("Handshake failed.")
diff --git a/lnst/Slave/SlaveSecSocket.py b/lnst/Slave/SlaveSecSocket.py
index fa4a59d..24148e1 100644
--- a/lnst/Slave/SlaveSecSocket.py
+++ b/lnst/Slave/SlaveSecSocket.py
@@ -195,12 +195,16 @@ class SlaveSecSocket(SecureSocket):
except:
continue
- with open(ssh_dir_path+"/authorized_keys", 'r') as f:
- for line in f.readlines():
- try:
- authorized_keys.append(load_ssh_public_key(line, backend))
- except:
- continue
+ if os.path.isfile(ssh_dir_path+"/authorized_keys"):
+ with open(ssh_dir_path+"/authorized_keys", 'r') as f:
+ for line in f.readlines():
+ try:
+ authorized_keys.append(load_ssh_public_key(line,
+ backend))
+ except:
+ continue
+ else:
+ logging.error("No authorized keys loaded.")
msg = self.recv_msg()
if msg["type"] != "ssh_client_hello":
--
2.7.2