From 3687f8966ad46d0cb0e5fbd5c22459f7131b137c Mon Sep 17 00:00:00 2001 From: Mateusz779 Date: Tue, 25 Apr 2023 10:24:30 +0200 Subject: [PATCH] - --- utils.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/utils.py b/utils.py index 53dfabb..06ee379 100644 --- a/utils.py +++ b/utils.py @@ -10,6 +10,8 @@ from time import sleep import db import config import ipaddress +from os import chmod +from Crypto.PublicKey import RSA DELETE_TIMEOUT = 30 RESTART_DELETE_THREAD = 10 @@ -44,11 +46,18 @@ def ssh_thread_function(): except: pass if os.path.exists(os.path.join(os.getcwd(), 'keys', "sshkey")) is False: - process = subprocess.run(['ssh-keygen', '-t rsa', '-P ""', '-f ' + - os.path.join(os.getcwd(), 'keys', "sshkey")]) - print(process.args) - while os.path.exists(os.path.join(os.getcwd(), 'keys', "sshkey")) is False: - pass + # process = subprocess.run(['ssh-keygen', '-t rsa', '-P ""', '-f ' + + # os.path.join(os.getcwd(), 'keys', "sshkey")]) + # print(process.args) + key = RSA.generate(3072) + with open(os.path.join(os.getcwd(), 'keys', "sshkey"), 'wb') as content_file: + chmod(os.path.join(os.getcwd(), 'keys', "sshkey"), 0600) + content_file.write(key.exportKey('PEM')) + pubkey = key.publickey() + with open(os.path.join(os.getcwd(), 'keys', "sshkey.pub"), 'wb') as content_file: + content_file.write(pubkey.exportKey('OpenSSH')) + # while os.path.exists(os.path.join(os.getcwd(), 'keys', "sshkey")) is False: + # pass subprocess.run(['wssh', '--fbidhttp=False', '--port='+config.webssh_port, '--hostfile='+os.path.join(os.getcwd(), 'keys', "sshkey")])