From 4a4f311cf83015170738db4a2a504027bab45cb0 Mon Sep 17 00:00:00 2001
From: shortcutme <tamas@zeronet.io>
Date: Fri, 29 Mar 2019 02:29:55 +0100
Subject: [PATCH] Better logging of cert generation

---
 src/Crypt/CryptConnection.py | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/Crypt/CryptConnection.py b/src/Crypt/CryptConnection.py
index 25ebc52e..faa46c8b 100644
--- a/src/Crypt/CryptConnection.py
+++ b/src/Crypt/CryptConnection.py
@@ -106,13 +106,14 @@ class CryptConnectionManager:
             self.cacert_pem
         )
         cmd = "%s req -new -newkey rsa:2048 -days 3650 -nodes -x509 -config %s -subj %s -keyout %s -out %s -batch" % cmd_params
+        logging.debug("Generating RSA CAcert and CAkey PEM files...")
         proc = subprocess.Popen(
             cmd, shell=True, stderr=subprocess.STDOUT,
             stdout=subprocess.PIPE, env=self.openssl_env
         )
-        back = proc.stdout.read().strip()
+        back = proc.stdout.read().strip().decode().replace("\r", "")
         proc.wait()
-        logging.debug("Generating RSA CAcert and CAkey PEM files... %s: %s" % (cmd, back.decode()))
+        logging.debug("%s\n%s" % (cmd, back))
 
         if not (os.path.isfile(self.cacert_pem) and os.path.isfile(self.cakey_pem)):
             logging.error("RSA ECC SSL CAcert generation failed, CAcert or CAkey files not exist.")
@@ -127,13 +128,14 @@ class CryptConnectionManager:
             self.openssl_env["OPENSSL_CONF"],
         )
         cmd = "%s req -new -newkey rsa:2048 -keyout %s -out %s -subj %s -sha256 -nodes -batch -config %s" % cmd_params
+        logging.debug("Generating certificate key and signing request...")
         proc = subprocess.Popen(
             cmd, shell=True, stderr=subprocess.STDOUT,
             stdout=subprocess.PIPE, env=self.openssl_env
         )
-        back = proc.stdout.read().strip()
+        back = proc.stdout.read().strip().decode().replace("\r", "")
         proc.wait()
-        logging.debug("Generating certificate key and signing request...%s" % back.decode())
+        logging.debug("%s\n%s" % (cmd, back))
 
         # Sign request and generate certificate
         cmd_params = helper.shellquote(
@@ -145,13 +147,14 @@ class CryptConnectionManager:
             self.openssl_env["OPENSSL_CONF"]
         )
         cmd = "%s x509 -req -in %s -CA %s -CAkey %s -CAcreateserial -out %s -days 730 -sha256 -extensions x509_ext -extfile %s" % cmd_params
+        logging.debug("Generating RSA cert...")
         proc = subprocess.Popen(
             cmd, shell=True, stderr=subprocess.STDOUT,
             stdout=subprocess.PIPE, env=self.openssl_env
         )
-        back = proc.stdout.read().strip()
+        back = proc.stdout.read().strip().decode().replace("\r", "")
         proc.wait()
-        logging.debug("Generating RSA cert...%s" % back.decode())
+        logging.debug("%s\n%s" % (cmd, back))
 
         if os.path.isfile(self.cert_pem) and os.path.isfile(self.key_pem):
             return True