Module: check_mk
Branch: master
Commit: ef8b38f4d7bef95aa77c88899d44986768767465
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=ef8b38f4d7bef9…
Author: Lars Michelsen <lm(a)mathias-kettner.de>
Date: Fri Oct 28 08:57:40 2016 +0200
SSHKeyPair: Cleaned up hacky creation of SSH keys
---
web/htdocs/valuespec.py | 27 ++++-----------------------
1 file changed, 4 insertions(+), 23 deletions(-)
diff --git a/web/htdocs/valuespec.py b/web/htdocs/valuespec.py
index e0b8fd7..a4e5630 100644
--- a/web/htdocs/valuespec.py
+++ b/web/htdocs/valuespec.py
@@ -37,6 +37,7 @@ import hashlib
import socket
from lib import *
import cmk.defines as defines
+from Crypto.PublicKey import RSA
try:
import simplejson as json
@@ -4137,22 +4138,9 @@ class SSHKeyPair(ValueSpec):
@classmethod
def _generate_ssh_key(cls, varprefix):
- tmp_file_name_base = cls._tmp_file_name()
- private_key_file = tmp_file_name_base + ".key"
- public_key_file = private_key_file + ".pub"
- f = os.popen("echo | ssh-keygen -t rsa -b 4096 -f %s 2>&1" %
- quote_shell_string(private_key_file))
- output = f.read()
- status = f.close()
- os.remove(tmp_file_name_base)
- if status:
- os.remove(private_key_file)
- os.remove(public_key_file)
- raise MKUserError(varprefix, _("Failed to create SSH key pair: %s")
% output)
- private_key = file(private_key_file).read()
- public_key = file(public_key_file).read()
- os.remove(private_key_file)
- os.remove(public_key_file)
+ key = RSA.generate(4096)
+ private_key = key.exportKey('PEM')
+ public_key = pubkey.exportKey('OpenSSH')
return (private_key, public_key)
@@ -4164,13 +4152,6 @@ class SSHKeyPair(ValueSpec):
return ':'.join(a+b for a,b in zip(fp_plain[::2], fp_plain[1::2]))
- @staticmethod
- def _tmp_file_name():
- fd, path = tempfile.mkstemp(dir=cmk.paths.tmp_dir)
- os.close(fd)
- return path
-
-
class SchedulePeriod(CascadingDropdown):
def __init__(self, from_end=True, **kwargs):