pgreco / rpms / ipa

Forked from forks/areguera/rpms/ipa 4 years ago
Clone

Blame SOURCES/0089-Fix-RA-cert-import-during-DL0-replication.patch

ac7d03
From 899f9b980afba02cfdf80155905354a7371ad871 Mon Sep 17 00:00:00 2001
ac7d03
From: Stanislav Laznicka <slaznick@redhat.com>
ac7d03
Date: Wed, 19 Apr 2017 11:42:40 +0200
ac7d03
Subject: [PATCH] Fix RA cert import during DL0 replication
ac7d03
ac7d03
Previous versions of FreeIPA add password to the ra.p12 file
ac7d03
contained in the password-protected tarball. This was forgotten
ac7d03
about in the recent changes and fixed now.
ac7d03
ac7d03
https://pagure.io/freeipa/issue/6878
ac7d03
ac7d03
Reviewed-By: Jan Cholasta <jcholast@redhat.com>
ac7d03
---
ac7d03
 ipaserver/install/cainstance.py          | 43 +++++++++++++++++++-------------
ac7d03
 ipaserver/install/ipa_replica_prepare.py | 17 +++++++------
ac7d03
 2 files changed, 35 insertions(+), 25 deletions(-)
ac7d03
ac7d03
diff --git a/ipaserver/install/cainstance.py b/ipaserver/install/cainstance.py
ac7d03
index e2070e39f7e162fcff6e1f8cca41218e440b5f58..640d2884130dd152012e50dde45514f5ca26a523 100644
ac7d03
--- a/ipaserver/install/cainstance.py
ac7d03
+++ b/ipaserver/install/cainstance.py
ac7d03
@@ -338,6 +338,7 @@ class CAInstance(DogtagInstance):
ac7d03
             self.clone = True
ac7d03
         self.master_host = master_host
ac7d03
         self.master_replication_port = master_replication_port
ac7d03
+        self.ra_p12 = ra_p12
ac7d03
 
ac7d03
         self.subject_base = \
ac7d03
             subject_base or installutils.default_subject_base(self.realm)
ac7d03
@@ -400,7 +401,7 @@ class CAInstance(DogtagInstance):
ac7d03
                     self.step("Importing RA key", self.__import_ra_key)
ac7d03
                 else:
ac7d03
                     self.step("importing RA certificate from PKCS #12 file",
ac7d03
-                              lambda: self.import_ra_cert(ra_p12))
ac7d03
+                              self.__import_ra_cert)
ac7d03
 
ac7d03
             if not ra_only:
ac7d03
                 self.step("setting up signing cert profile", self.__setup_sign_profile)
ac7d03
@@ -673,28 +674,36 @@ class CAInstance(DogtagInstance):
ac7d03
                                    'NSS_ENABLE_PKIX_VERIFY', '1',
ac7d03
                                    quotes=False, separator='=')
ac7d03
 
ac7d03
-    def import_ra_cert(self, rafile):
ac7d03
+    def __import_ra_cert(self):
ac7d03
+        """
ac7d03
+        Helper method for IPA domain level 0 replica install
ac7d03
+        """
ac7d03
+        self.import_ra_cert(self.ra_p12, self.dm_password)
ac7d03
+
ac7d03
+    def import_ra_cert(self, rafile, password=''):
ac7d03
         """
ac7d03
         Cloned RAs will use the same RA agent cert as the master so we
ac7d03
         need to import from a PKCS#12 file.
ac7d03
 
ac7d03
         Used when setting up replication
ac7d03
         """
ac7d03
-        # get the private key from the file
ac7d03
-        ipautil.run([paths.OPENSSL,
ac7d03
-                     "pkcs12",
ac7d03
-                     "-in", rafile,
ac7d03
-                     "-nocerts", "-nodes",
ac7d03
-                     "-out", paths.RA_AGENT_KEY,
ac7d03
-                     "-passin", "pass:"])
ac7d03
-
ac7d03
-        # get the certificate from the pkcs12 file
ac7d03
-        ipautil.run([paths.OPENSSL,
ac7d03
-                     "pkcs12",
ac7d03
-                     "-in", rafile,
ac7d03
-                     "-clcerts", "-nokeys",
ac7d03
-                     "-out", paths.RA_AGENT_PEM,
ac7d03
-                     "-passin", "pass:"])
ac7d03
+        with ipautil.write_tmp_file(password) as f:
ac7d03
+            pwdarg = 'file:{file}'.format(file=f.name)
ac7d03
+            # get the private key from the file
ac7d03
+            ipautil.run([paths.OPENSSL,
ac7d03
+                         "pkcs12",
ac7d03
+                         "-in", rafile,
ac7d03
+                         "-nocerts", "-nodes",
ac7d03
+                         "-out", paths.RA_AGENT_KEY,
ac7d03
+                         "-passin", pwdarg])
ac7d03
+
ac7d03
+            # get the certificate from the pkcs12 file
ac7d03
+            ipautil.run([paths.OPENSSL,
ac7d03
+                         "pkcs12",
ac7d03
+                         "-in", rafile,
ac7d03
+                         "-clcerts", "-nokeys",
ac7d03
+                         "-out", paths.RA_AGENT_PEM,
ac7d03
+                         "-passin", pwdarg])
ac7d03
         self.__set_ra_cert_perms()
ac7d03
 
ac7d03
         self.configure_agent_renewal()
ac7d03
diff --git a/ipaserver/install/ipa_replica_prepare.py b/ipaserver/install/ipa_replica_prepare.py
ac7d03
index 95c3818a9fc34c937f8b418e91a1bfc28352b02e..d4456dd796167c3717be013d2378413519a3b366 100644
ac7d03
--- a/ipaserver/install/ipa_replica_prepare.py
ac7d03
+++ b/ipaserver/install/ipa_replica_prepare.py
ac7d03
@@ -571,14 +571,15 @@ class ReplicaPrepare(admintool.AdminTool):
ac7d03
     def export_ra_pkcs12(self):
ac7d03
         if (os.path.exists(paths.RA_AGENT_PEM) and
ac7d03
            os.path.exists(paths.RA_AGENT_KEY)):
ac7d03
-            ipautil.run([
ac7d03
-                paths.OPENSSL,
ac7d03
-                "pkcs12", "-export",
ac7d03
-                "-inkey", paths.RA_AGENT_KEY,
ac7d03
-                "-in", paths.RA_AGENT_PEM,
ac7d03
-                "-out", os.path.join(self.dir, "ra.p12"),
ac7d03
-                "-passout", "pass:"
ac7d03
-            ])
ac7d03
+            with ipautil.write_tmp_file(self.dirman_password) as f:
ac7d03
+                ipautil.run([
ac7d03
+                    paths.OPENSSL,
ac7d03
+                    "pkcs12", "-export",
ac7d03
+                    "-inkey", paths.RA_AGENT_KEY,
ac7d03
+                    "-in", paths.RA_AGENT_PEM,
ac7d03
+                    "-out", os.path.join(self.dir, "ra.p12"),
ac7d03
+                    "-passout", "file:{pwfile}".format(pwfile=f.name)
ac7d03
+                ])
ac7d03
 
ac7d03
     def update_pki_admin_password(self):
ac7d03
         dn = DN('uid=admin', 'ou=people', 'o=ipaca')
ac7d03
-- 
ac7d03
2.12.2
ac7d03