commit 02f63b0792592648d4ecc032bfa822f16ace82a8
Author: Stanislav Král <stanislav.kral3@gmail.com>
Date:   Wed Mar 31 11:06:06 2021 +0200

    Re #8472 - Changed order of create_sscrt method parameters

diff --git a/proj/services/cryptography.py b/proj/services/cryptography.py
index 50e93a8..d41e11d 100644
--- a/proj/services/cryptography.py
+++ b/proj/services/cryptography.py
@@ -86,12 +86,12 @@ 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_pass=None):
+    def create_sscrt(self, subject, key, config="", extensions="", key_pass=None):
         """
         Creates a root CA
 
-        :param key: private key of the CA to be used
         :param subject: an instance of <Subject> representing the subject to be added to the certificate
+        :param key: private key of the CA to be used
         :param config: string containing the configuration to be used
         :param extensions: name of the section in the configuration representing extensions
         :param key_pass: passphrase of the private key
diff --git a/proj/tests/services/cryptography/create_crt_test.py b/proj/tests/services/cryptography/create_crt_test.py
index 40bb786..56dd0dc 100644
--- a/proj/tests/services/cryptography/create_crt_test.py
+++ b/proj/tests/services/cryptography/create_crt_test.py
@@ -14,7 +14,7 @@ def export_crt(crt):
 def test_sign_cst(service):
     # create root CA
     root_key = service.create_private_key()
-    root_ca = service.create_sscrt(root_key, Subject(common_name="foo"))
+    root_ca = service.create_sscrt(Subject(common_name="foo"), root_key)
 
     # create a private key to be used to make a CSR for the intermediate CA
     inter_key = service.create_private_key()
@@ -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_pass=root_key_passphrase)
+    root_ca = service.create_sscrt(Subject(common_name="foo"), root_key, key_pass=root_key_passphrase)
 
     # create a private key to be used to make a CSR for the intermediate CA
     inter_key_passphrase = "foobazbar"
@@ -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_pass=root_key_passphrase)
+    root_ca = service.create_sscrt(Subject(common_name="foo"), root_key, key_pass=root_key_passphrase)
 
     # create a private key to be used to make a CSR for the intermediate CA
     inter_key_passphrase = "foofoo"
diff --git a/proj/tests/services/cryptography/self_signed_cert_test.py b/proj/tests/services/cryptography/self_signed_cert_test.py
index 3e73cb4..12549db 100644
--- a/proj/tests/services/cryptography/self_signed_cert_test.py
+++ b/proj/tests/services/cryptography/self_signed_cert_test.py
@@ -26,17 +26,14 @@ def test_create_sscrt(service):
     authorityKeyIdentifier  = keyid:always
     """
 
-    cert = service.create_sscrt(private_key,
-                                Subject(common_name="Topnax",
+    cert = service.create_sscrt(Subject(common_name="Topnax",
                                         country="CZ",
                                         locality="My Locality",
                                         state="My state",
                                         organization="Mysterious Org.",
                                         organization_unit="Department of Mysteries",
-                                        email_address="mysterious@box.cz"),
-                                config=config,
-                                extensions="root_ca_ext",
-                                key_pass="foobar")
+                                        email_address="mysterious@box.cz"), private_key, config=config,
+                                extensions="root_ca_ext", key_pass="foobar")
 
     cert_printed = subprocess.check_output(["openssl", "x509", "-noout", "-text", "-in", "-"],
                                            input=bytes(cert, encoding="utf-8"), stderr=subprocess.STDOUT).decode()
@@ -63,7 +60,7 @@ def test_create_sscrt_config_without_extensions(service):
 
     """
 
-    cert = service.create_sscrt(private_key, Subject(common_name="Topnax", country="CZ"), config=config)
+    cert = service.create_sscrt(Subject(common_name="Topnax", country="CZ"), private_key, config=config)
 
     cert_printed = subprocess.check_output(["openssl", "x509", "-noout", "-text", "-in", "-"],
                                            input=bytes(cert, encoding="utf-8"), stderr=subprocess.STDOUT).decode()
@@ -77,7 +74,7 @@ def test_create_sscrt_plain(service):
     # create a self signed certificate without configuration
     private_key = service.create_private_key()
 
-    cert = service.create_sscrt(private_key, Subject(common_name="Topnax", country="CZ"))
+    cert = service.create_sscrt(Subject(common_name="Topnax", country="CZ"), private_key)
 
     cert_printed = subprocess.check_output(["openssl", "x509", "-noout", "-text", "-in", "-"],
                                            input=bytes(cert, encoding="utf-8"), stderr=subprocess.STDOUT).decode()
@@ -90,7 +87,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_pass="foobar")
+    cert = service.create_sscrt(Subject(common_name="Topnax", country="CZ"), private_key, key_pass="foobar")
 
     cert_printed = subprocess.check_output(["openssl", "x509", "-noout", "-text", "-in", "-"],
                                            input=bytes(cert, encoding="utf-8"), stderr=subprocess.STDOUT).decode()
@@ -106,10 +103,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_pass="bazfoo")
+        service.create_sscrt(Subject(common_name="Topnax", country="CZ"), private_key, 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"))
+        service.create_sscrt(Subject(common_name="Topnax", country="CZ"), private_key)
     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 c448784..1da598c 100644
--- a/proj/tests/services/cryptography/sign_csr_test.py
+++ b/proj/tests/services/cryptography/sign_csr_test.py
@@ -14,7 +14,7 @@ def export_crt(csr):
 def test_sign_csr(service):
     # create root CA
     root_key = service.create_private_key()
-    root_ca = service.create_sscrt(root_key, Subject(common_name="foo"))
+    root_ca = service.create_sscrt(Subject(common_name="foo"), root_key)
 
     # create a private key to be used to make a CSR for the intermediate CA
     inter_key = service.create_private_key()
@@ -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_pass=root_key_passphrase)
+    root_ca = service.create_sscrt(Subject(common_name="foo"), root_key, 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()
@@ -67,7 +67,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_pass=root_key_passphrase)
+    root_ca = service.create_sscrt(Subject(common_name="foo"), root_key, 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()
diff --git a/proj/tests/services/cryptography/verify_ca_test.py b/proj/tests/services/cryptography/verify_ca_test.py
index 587092a..d9ee551 100644
--- a/proj/tests/services/cryptography/verify_ca_test.py
+++ b/proj/tests/services/cryptography/verify_ca_test.py
@@ -7,7 +7,7 @@ from proj.services.cryptography import CryptographyException
 def test_verify_valid_ca(service):
     # verify validation of valid certificates
     private_key = service.create_private_key()
-    root_cert = service.create_sscrt(private_key, Subject(common_name="foo"))
+    root_cert = service.create_sscrt(Subject(common_name="foo"), private_key)
     child_cert = service.create_crt(Subject(common_name="Expired Foo"), private_key, root_cert, private_key, days=1)
 
     assert service.verify_cert(root_cert)
@@ -17,7 +17,7 @@ def test_verify_valid_ca(service):
 def test_verify_invalid_ca(service):
     # test whether expired certificate will fail to get verified
     private_key = service.create_private_key()
-    root_cert = service.create_sscrt(private_key, Subject(common_name="foo"))
+    root_cert = service.create_sscrt(Subject(common_name="foo"), private_key)
 
     expired_cert = service.create_crt(Subject(common_name="Expired Foo"), private_key, root_cert, private_key, days=0)
 
