Blame SOURCES/0007-Specify-cert_paths-when-calling-PKIConnection_rhbz#1849155.patch

2ff659
From 9ded9e2573a00c388533f2a09365c499a4e2961e Mon Sep 17 00:00:00 2001
2ff659
From: Alexander Scheel <ascheel@redhat.com>
2ff659
Date: Fri, 19 Jun 2020 08:48:56 -0400
2ff659
Subject: [PATCH] Specify cert_paths when calling PKIConnection
2ff659
2ff659
PKIConnection now defaults to specifying verify=True. We've introduced
2ff659
a new parameter, cert_paths, to specify additional paths (directories or
2ff659
files) to load as certificates. Specify the IPA CA certificate file so
2ff659
we can guarantee connections succeed and validate the peer's certificate.
2ff659
2ff659
Point to IPA CA certificate during pkispawn
2ff659
2ff659
Bump pki_version to 10.9.0-0.4 (aka -b2)
2ff659
2ff659
Fixes: https://pagure.io/freeipa/issue/8379
2ff659
Fixes: https://bugzilla.redhat.com/show_bug.cgi?id=1849155
2ff659
Related: https://github.com/dogtagpki/pki/pull/443
2ff659
Related: https://bugzilla.redhat.com/show_bug.cgi?id=1426572
2ff659
Signed-off-by: Alexander Scheel <ascheel@redhat.com>
2ff659
Signed-off-by: Christian Heimes <cheimes@redhat.com>
2ff659
Reviewed-By: Christian Heimes <cheimes@redhat.com>
2ff659
---
2ff659
 freeipa.spec.in                       |  6 +++---
2ff659
 install/tools/ipa-pki-wait-running.in |  3 ++-
2ff659
 ipaserver/install/cainstance.py       |  7 +++++++
2ff659
 ipaserver/install/dogtaginstance.py   |  3 ++-
2ff659
 ipaserver/plugins/dogtag.py           | 11 +++++------
2ff659
 5 files changed, 19 insertions(+), 11 deletions(-)
2ff659
2ff659
diff --git a/freeipa.spec.in b/freeipa.spec.in
2ff659
index 74e752ea5..d00b9d640 100755
2ff659
--- a/freeipa.spec.in
2ff659
+++ b/freeipa.spec.in
2ff659
@@ -112,9 +112,9 @@
2ff659
 # Fedora
2ff659
 %endif
2ff659
 
2ff659
-# 10.7.3 supports LWCA key replication using AES
2ff659
-# https://pagure.io/freeipa/issue/8020
2ff659
-%global pki_version 10.7.3-1
2ff659
+# PKIConnection has been modified to always validate certs.
2ff659
+# https://pagure.io/freeipa/issue/8379
2ff659
+%global pki_version 10.9.0-0.4
2ff659
 
2ff659
 # https://pagure.io/certmonger/issue/90
2ff659
 %global certmonger_version 0.79.7-1
2ff659
diff --git a/install/tools/ipa-pki-wait-running.in b/install/tools/ipa-pki-wait-running.in
2ff659
index 69f5ec296..4f0f2f34a 100644
2ff659
--- a/install/tools/ipa-pki-wait-running.in
2ff659
+++ b/install/tools/ipa-pki-wait-running.in
2ff659
@@ -59,7 +59,8 @@ def get_conn(hostname, subsystem):
2ff659
     """
2ff659
     conn = PKIConnection(
2ff659
         hostname=hostname,
2ff659
-        subsystem=subsystem
2ff659
+        subsystem=subsystem,
2ff659
+        cert_paths=paths.IPA_CA_CRT
2ff659
     )
2ff659
     logger.info(
2ff659
         "Created connection %s://%s:%s/%s",
2ff659
diff --git a/ipaserver/install/cainstance.py b/ipaserver/install/cainstance.py
2ff659
index 706bc28cc..9294f1dba 100644
2ff659
--- a/ipaserver/install/cainstance.py
2ff659
+++ b/ipaserver/install/cainstance.py
2ff659
@@ -509,6 +509,13 @@ class CAInstance(DogtagInstance):
2ff659
         else:
2ff659
             pki_pin = None
2ff659
 
2ff659
+        # When spawning a CA instance, always point to IPA_CA_CRT if it
2ff659
+        # exists. Later, when we're performing step 2 of an external CA
2ff659
+        # installation, we'll overwrite this key to point to the real
2ff659
+        # external CA.
2ff659
+        if os.path.exists(paths.IPA_CA_CRT):
2ff659
+            cfg['pki_cert_chain_path'] = paths.IPA_CA_CRT
2ff659
+
2ff659
         if self.clone:
2ff659
             if self.no_db_setup:
2ff659
                 cfg.update(
2ff659
diff --git a/ipaserver/install/dogtaginstance.py b/ipaserver/install/dogtaginstance.py
2ff659
index 361d80a8c..7e295665c 100644
2ff659
--- a/ipaserver/install/dogtaginstance.py
2ff659
+++ b/ipaserver/install/dogtaginstance.py
2ff659
@@ -70,7 +70,8 @@ def get_security_domain():
2ff659
     connection = PKIConnection(
2ff659
         protocol='https',
2ff659
         hostname=api.env.ca_host,
2ff659
-        port='8443'
2ff659
+        port='8443',
2ff659
+        cert_paths=paths.IPA_CA_CRT
2ff659
     )
2ff659
     domain_client = pki.system.SecurityDomainClient(connection)
2ff659
     info = domain_client.get_security_domain_info()
2ff659
diff --git a/ipaserver/plugins/dogtag.py b/ipaserver/plugins/dogtag.py
2ff659
index 4de26d76f..b300f6b18 100644
2ff659
--- a/ipaserver/plugins/dogtag.py
2ff659
+++ b/ipaserver/plugins/dogtag.py
2ff659
@@ -2082,13 +2082,12 @@ class kra(Backend):
2ff659
             'https',
2ff659
             self.kra_host,
2ff659
             str(self.kra_port),
2ff659
-            'kra')
2ff659
+            'kra',
2ff659
+            cert_paths=paths.IPA_CA_CRT
2ff659
+        )
2ff659
 
2ff659
-        connection.session.cert = (paths.RA_AGENT_PEM, paths.RA_AGENT_KEY)
2ff659
-        # uncomment the following when this commit makes it to release
2ff659
-        # https://git.fedorahosted.org/cgit/pki.git/commit/?id=71ae20c
2ff659
-        # connection.set_authentication_cert(paths.RA_AGENT_PEM,
2ff659
-        #                                    paths.RA_AGENT_KEY)
2ff659
+        connection.set_authentication_cert(paths.RA_AGENT_PEM,
2ff659
+                                           paths.RA_AGENT_KEY)
2ff659
 
2ff659
         try:
2ff659
             yield KRAClient(connection, crypto)
2ff659
-- 
2ff659
2.26.2
2ff659