commit 185887281c611dfb4156e7127e03ee9056464772
Author: Stanislav Král <stanislav.kral3@gmail.com>
Date:   Tue Mar 30 20:52:41 2021 +0200

    Re #8472 - Small changes in the documentation

diff --git a/proj/services/cryptography.py b/proj/services/cryptography.py
index b044eb2..a13146e 100644
--- a/proj/services/cryptography.py
+++ b/proj/services/cryptography.py
@@ -72,7 +72,7 @@ class CryptographyService:
         Creates a private key with the option to encrypt it using a passphrase.
         :param passphrase: A passphrase to be used when encrypting the key (if none is passed then the key is not
         encrypted at all). Empty passphrase ("") also results in a key that is not encrypted.
-        :return: A text representation of the generated private key.
+        :return: string containing the generated private key in PEM format
         """
         if passphrase is None or len(passphrase) == 0:
             return self._run_for_output(["genrsa", "2048"]).decode()
@@ -80,7 +80,7 @@ class CryptographyService:
             return self._run_for_output(
                 ["genrsa", PRIVATE_KEY_ENCRYPTION_METHOD, "-passout", f"pass:{passphrase}", "2048"]).decode()
 
-    def create_sscrt(self, key, subject, config="", extensions="", key_passphrase=None):
+    def create_sscrt(self, key, subject, config="", extensions="", key_pass=None):
         """
         Creates a root CA
 
@@ -88,9 +88,9 @@ class CryptographyService:
         :param subject: an instance of <Subject> representing the subject to be added to the certificate
         :param config: string containing the configuration to be used
         :param extensions: name of the section in the configuration representing extensions
-        :param key_passphrase: passphrase of the private key
+        :param key_pass: passphrase of the private key
 
-        :return: byte array containing the generated certificate
+        :return: string containing the generated certificate in PEM format
         """
         assert key is not None
         assert subject is not None
@@ -111,7 +111,7 @@ class CryptographyService:
 
             #  add the passphrase even when None is passed. Otherwise when running tests with pytest some tests freeze
             # waiting for the passphrase to be typed in
-            args.extend(["-passin", f"pass:{key_passphrase}"])
+            args.extend(["-passin", f"pass:{key_pass}"])
 
             return self._run_for_output(args, proc_input=bytes(key, encoding="utf-8")).decode()
 
@@ -122,7 +122,7 @@ class CryptographyService:
         :param subject: an instance of <Subject> representing the subject to be added to the CSR
         :param subject_key: the private key of the subject to be used to generate the CSR
         :param subject_key_pass: passphrase of the subject's private key
-        :return: byte array containing the generated certificate signing request
+        :return: string containing the generated certificate signing request in PEM format
         """
 
         subj_param = self.subject_to_param_format(subject)
@@ -167,24 +167,25 @@ class CryptographyService:
 
             return self._run_for_output(params, proc_input=(bytes(proc_input, encoding="utf-8"))).decode()
 
-    def create_crt(self, subject, key, issuer_pem, issuer_key, key_pass=None, issuer_key_pass=None, config="",
+    def create_crt(self, subject, subject_key, issuer_pem, issuer_key, subject_key_pass=None, issuer_key_pass=None,
+                   config="",
                    extensions=""):
         """
         Signs the given CSR by the given issuer CA
         :param subject: subject to be added to the created certificate
-        :param key: string containing the private key to be used when creating the certificate in PEM format
+        :param subject_key: string containing the private key to be used when creating the certificate in PEM format
         :param issuer_key: string containing the private key of the issuer's certificate in PEM format
         :param issuer_pem: string containing the certificate of the issuer that will sign this CSR in PEM format
         :param issuer_key: string containing the private key of the issuer's certificate in PEM format
-        :param key_pass: string containing the passphrase of the private key used when creating the certificate in PEM
+        :param subject_key_pass: string containing the passphrase of the private key used when creating the certificate in PEM
         format
         :param issuer_key_pass: string containing the passphrase of the private key of the issuer's certificate in PEM
         format
         :param config: TODO NOT USED
         :param extensions: extensions to be applied when creating the certificate
-        :return: string containing the generated in PEM format
+        :return: string containing the generated certificate in PEM format
         """
-        csr = self.make_csr(subject, key, subject_key_pass=key_pass)
+        csr = self.make_csr(subject, subject_key, subject_key_pass=subject_key_pass)
         return self.sign_csr(csr, issuer_pem, issuer_key, issuer_key_pass=issuer_key_pass, extensions=extensions)
 
 
diff --git a/proj/tests/services/cryptography/create_crt_test.py b/proj/tests/services/cryptography/create_crt_test.py
index b3a3121..40bb786 100644
--- a/proj/tests/services/cryptography/create_crt_test.py
+++ b/proj/tests/services/cryptography/create_crt_test.py
@@ -33,7 +33,7 @@ def test_sign_crt_passphrase(service):
     # create root CA and encrypt the private key of the root CA
     root_key_passphrase = "barbaz"
     root_key = service.create_private_key(passphrase=root_key_passphrase)
-    root_ca = service.create_sscrt(root_key, Subject(common_name="foo"), key_passphrase=root_key_passphrase)
+    root_ca = service.create_sscrt(root_key, Subject(common_name="foo"), key_pass=root_key_passphrase)
 
     # create a private key to be used to make a CSR for the intermediate CA
     inter_key_passphrase = "foobazbar"
@@ -41,7 +41,7 @@ def test_sign_crt_passphrase(service):
 
     # create a CA using the root CA
     inter_ca = service.create_crt(Subject(common_name="bar", country="CZ"), inter_key, root_ca, root_key,
-                                  key_pass=inter_key_passphrase, issuer_key_pass=root_key_passphrase)
+                                  subject_key_pass=inter_key_passphrase, issuer_key_pass=root_key_passphrase)
 
     inter_ca_printed = export_crt(inter_ca)
 
@@ -63,7 +63,7 @@ def test_sign_crt_passphrase(service):
         # try to create it using a wrong issuer passphrase
         with pytest.raises(CryptographyException) as e:
             inter_ca = service.create_crt(Subject(common_name="bar", country="CZ"), inter_key, root_ca, root_key,
-                                          key_pass=key_pass, issuer_key_pass=issuer_key_pass)
+                                          subject_key_pass=key_pass, issuer_key_pass=issuer_key_pass)
         assert "bad decrypt" in e.value.message
 
 
@@ -71,7 +71,7 @@ def test_sign_crt_extensions(service):
     # create root CA and encrypt the private key of the root CA
     root_key_passphrase = "barbaz"
     root_key = service.create_private_key(passphrase=root_key_passphrase)
-    root_ca = service.create_sscrt(root_key, Subject(common_name="foo"), key_passphrase=root_key_passphrase)
+    root_ca = service.create_sscrt(root_key, Subject(common_name="foo"), key_pass=root_key_passphrase)
 
     # create a private key to be used to make a CSR for the intermediate CA
     inter_key_passphrase = "foofoo"
@@ -79,7 +79,7 @@ def test_sign_crt_extensions(service):
 
     # create a CA using the root CA
     inter_ca = service.create_crt(Subject(common_name="bar", country="CZ"), inter_key, root_ca, root_key,
-                                  key_pass=inter_key_passphrase, issuer_key_pass=root_key_passphrase,
+                                  subject_key_pass=inter_key_passphrase, issuer_key_pass=root_key_passphrase,
                                   extensions="authorityInfoAccess = caIssuers;URI:bar.cz/baz/cert\nbasicConstraints=critical,CA:TRUE")
 
     inter_ca_printed = export_crt(inter_ca)
diff --git a/proj/tests/services/cryptography/private_keys_test.py b/proj/tests/services/cryptography/private_keys_test.py
index 7419a61..b1f53bb 100644
--- a/proj/tests/services/cryptography/private_keys_test.py
+++ b/proj/tests/services/cryptography/private_keys_test.py
@@ -1,6 +1,7 @@
-import pytest
 import subprocess
 
+import pytest
+
 
 def test_private_key(service):
     private_key = service.create_private_key()
@@ -24,4 +25,4 @@ def test_encrypted_private_key_incorrect_pass(service):
     # incorrect passphrase provided
     with pytest.raises(subprocess.CalledProcessError):
         subprocess.check_output(["openssl", "rsa", "-in", "-", "-passin", "pass:bazbaz", "-check"],
-                                input=bytes(private_key, encoding="utf-8"), stderr=subprocess.STDOUT)
\ No newline at end of file
+                                input=bytes(private_key, encoding="utf-8"), stderr=subprocess.STDOUT)
diff --git a/proj/tests/services/cryptography/self_signed_cert_test.py b/proj/tests/services/cryptography/self_signed_cert_test.py
index 9aff643..3e73cb4 100644
--- a/proj/tests/services/cryptography/self_signed_cert_test.py
+++ b/proj/tests/services/cryptography/self_signed_cert_test.py
@@ -1,8 +1,9 @@
-import pytest
 import subprocess
 
+import pytest
+
 from proj.model.subject import Subject
-from proj.services.cryptography import CryptographyService, CryptographyException
+from proj.services.cryptography import CryptographyException
 
 
 def test_create_sscrt(service):
@@ -35,7 +36,7 @@ def test_create_sscrt(service):
                                         email_address="mysterious@box.cz"),
                                 config=config,
                                 extensions="root_ca_ext",
-                                key_passphrase="foobar")
+                                key_pass="foobar")
 
     cert_printed = subprocess.check_output(["openssl", "x509", "-noout", "-text", "-in", "-"],
                                            input=bytes(cert, encoding="utf-8"), stderr=subprocess.STDOUT).decode()
@@ -89,7 +90,7 @@ def test_create_sscrt_passphrase(service):
     # create a self signed certificate with a PK that is protected by a passphrase
     private_key = service.create_private_key(passphrase="foobar")
 
-    cert = service.create_sscrt(private_key, Subject(common_name="Topnax", country="CZ"), key_passphrase="foobar")
+    cert = service.create_sscrt(private_key, Subject(common_name="Topnax", country="CZ"), key_pass="foobar")
 
     cert_printed = subprocess.check_output(["openssl", "x509", "-noout", "-text", "-in", "-"],
                                            input=bytes(cert, encoding="utf-8"), stderr=subprocess.STDOUT).decode()
@@ -105,11 +106,10 @@ def test_create_sscrt_incorrect_passphrase(service):
 
     # incorrect passphrase provided when using a protected private key
     with pytest.raises(CryptographyException) as e:
-        service.create_sscrt(private_key, Subject(common_name="Topnax", country="CZ"), key_passphrase="bazfoo")
+        service.create_sscrt(private_key, Subject(common_name="Topnax", country="CZ"), key_pass="bazfoo")
     assert "bad decrypt" in e.value.message
 
     # no passphrase provided when using a protected private key
     with pytest.raises(CryptographyException) as e:
         service.create_sscrt(private_key, Subject(common_name="Topnax", country="CZ"))
     assert "bad decrypt" in e.value.message
-
diff --git a/proj/tests/services/cryptography/sign_csr_test.py b/proj/tests/services/cryptography/sign_csr_test.py
index ad04075..91a5cb0 100644
--- a/proj/tests/services/cryptography/sign_csr_test.py
+++ b/proj/tests/services/cryptography/sign_csr_test.py
@@ -6,7 +6,7 @@ from proj.model.subject import Subject
 from proj.services.cryptography import CryptographyException
 
 
-def export_csr(csr):
+def export_crt(csr):
     return subprocess.check_output(["openssl", "x509", "-noout", "-text", "-in", "-"],
                                    input=bytes(csr, encoding="utf-8"), stderr=subprocess.STDOUT).decode()
 
@@ -23,7 +23,7 @@ def test_sign_csr(service):
     # sign the created CSR with root CA
     inter_ca = service.sign_csr(csr, root_ca, root_key)
 
-    inter_ca_printed = export_csr(inter_ca)
+    inter_ca_printed = export_crt(inter_ca)
 
     # assert fields
     assert "Issuer: CN = foo" in inter_ca_printed
@@ -34,7 +34,7 @@ def test_sign_csr_passphrase(service):
     # create root CA and encrypt the private key of the root CA
     root_key_passphrase = "barbaz"
     root_key = service.create_private_key(passphrase=root_key_passphrase)
-    root_ca = service.create_sscrt(root_key, Subject(common_name="foo"), key_passphrase=root_key_passphrase)
+    root_ca = service.create_sscrt(root_key, Subject(common_name="foo"), key_pass=root_key_passphrase)
 
     # create a private key to be used to make a CSR for the intermediate CA
     inter_key = service.create_private_key()
@@ -43,7 +43,7 @@ def test_sign_csr_passphrase(service):
     # sign the created CSR with root CA and specify root key passphrase
     inter_ca = service.sign_csr(csr, root_ca, root_key, issuer_key_pass=root_key_passphrase)
 
-    inter_ca_printed = export_csr(inter_ca)
+    inter_ca_printed = export_crt(inter_ca)
 
     # assert fields
     assert "Issuer: CN = foo" in inter_ca_printed
@@ -66,7 +66,7 @@ def test_sign_csr_extensions(service):
     # create root CA and encrypt the private key of the root CA
     root_key_passphrase = "barbaz"
     root_key = service.create_private_key(passphrase=root_key_passphrase)
-    root_ca = service.create_sscrt(root_key, Subject(common_name="foo"), key_passphrase=root_key_passphrase)
+    root_ca = service.create_sscrt(root_key, Subject(common_name="foo"), key_pass=root_key_passphrase)
 
     # create a private key to be used to make a CSR for the intermediate CA
     inter_key = service.create_private_key()
@@ -77,7 +77,7 @@ def test_sign_csr_extensions(service):
                                 extensions="authorityInfoAccess = caIssuers;URI:bar.cz/baz/cert\nbasicConstraints=critical,CA:TRUE",
                                 issuer_key_pass=root_key_passphrase)
 
-    inter_ca_printed = export_csr(inter_ca)
+    inter_ca_printed = export_crt(inter_ca)
 
     # assert fields
     assert "Issuer: CN = foo" in inter_ca_printed
