pgreco / rpms / ipa

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

Blame SOURCES/0206-smart-card-advises-configure-systemwide-NSS-DB-also-.patch

483b06
From 57c93cb21d542e1d0eab52baa01ac60f30459dc7 Mon Sep 17 00:00:00 2001
483b06
From: Martin Babinsky <mbabinsk@redhat.com>
483b06
Date: Wed, 21 Jun 2017 18:28:50 +0200
483b06
Subject: [PATCH] smart-card advises: configure systemwide NSS DB also on
483b06
 master
483b06
483b06
Previously the Smart card signing CA cert was uploaded to systemwide NSS
483b06
DB only on the client, but it need to be added also to the server.
483b06
Modify the advise plugins to allow for common configuration steps to
483b06
occur in both cases.
483b06
483b06
https://pagure.io/freeipa/issue/7036
483b06
483b06
Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
483b06
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
483b06
---
483b06
 ipaserver/advise/plugins/smart_card_auth.py | 59 +++++++++++++++++------------
483b06
 1 file changed, 35 insertions(+), 24 deletions(-)
483b06
483b06
diff --git a/ipaserver/advise/plugins/smart_card_auth.py b/ipaserver/advise/plugins/smart_card_auth.py
483b06
index 5859e350939fdba0a8b258de5285dd10c7b3bc23..0ee4808d47aa87a4b1b838d427e9958d98075a4a 100644
483b06
--- a/ipaserver/advise/plugins/smart_card_auth.py
483b06
+++ b/ipaserver/advise/plugins/smart_card_auth.py
483b06
@@ -10,8 +10,39 @@ from ipaserver.install.httpinstance import NSS_OCSP_ENABLED
483b06
 register = Registry()
483b06
 
483b06
 
483b06
+class common_smart_card_auth_config(Advice):
483b06
+    """
483b06
+    Common steps required to properly configure both server and client for
483b06
+    smart card auth
483b06
+    """
483b06
+
483b06
+    systemwide_nssdb = paths.NSS_DB_DIR
483b06
+    smart_card_ca_cert_variable_name = "SC_CA_CERT"
483b06
+
483b06
+    def check_and_set_ca_cert_path(self):
483b06
+        ca_path_variable = self.smart_card_ca_cert_variable_name
483b06
+        self.log.command("{}=$1".format(ca_path_variable))
483b06
+        self.log.exit_on_predicate(
483b06
+            '[ -z "${}" ]'.format(ca_path_variable),
483b06
+            ['You need to provide the path to the PEM file containing CA '
483b06
+             'signing the Smart Cards']
483b06
+        )
483b06
+        self.log.exit_on_predicate(
483b06
+            '[ ! -f "${}" ]'.format(ca_path_variable),
483b06
+            ['Invalid CA certificate filename: ${}'.format(ca_path_variable),
483b06
+             'Please check that the path exists and is a valid file']
483b06
+        )
483b06
+
483b06
+    def upload_smartcard_ca_certificate_to_systemwide_db(self):
483b06
+        self.log.command(
483b06
+            'certutil -d {} -A -i ${} -n "Smart Card CA" -t CT,C,C'.format(
483b06
+                self.systemwide_nssdb, self.smart_card_ca_cert_variable_name
483b06
+            )
483b06
+        )
483b06
+
483b06
+
483b06
 @register()
483b06
-class config_server_for_smart_card_auth(Advice):
483b06
+class config_server_for_smart_card_auth(common_smart_card_auth_config):
483b06
     """
483b06
     Configures smart card authentication via Kerberos (PKINIT) and for WebUI
483b06
     """
483b06
@@ -28,6 +59,7 @@ class config_server_for_smart_card_auth(Advice):
483b06
 
483b06
     def get_info(self):
483b06
         self.log.exit_on_nonroot_euid()
483b06
+        self.check_and_set_ca_cert_path()
483b06
         self.check_ccache_not_empty()
483b06
         self.check_hostname_is_in_masters()
483b06
         self.resolve_ipaca_records()
483b06
@@ -37,6 +69,7 @@ class config_server_for_smart_card_auth(Advice):
483b06
         self.record_httpd_ocsp_status()
483b06
         self.check_and_enable_pkinit()
483b06
         self.enable_ok_to_auth_as_delegate_on_http_principal()
483b06
+        self.upload_smartcard_ca_certificate_to_systemwide_db()
483b06
 
483b06
     def check_ccache_not_empty(self):
483b06
         self.log.comment('Check whether the credential cache is not empty')
483b06
@@ -162,11 +195,10 @@ class config_server_for_smart_card_auth(Advice):
483b06
 
483b06
 
483b06
 @register()
483b06
-class config_client_for_smart_card_auth(Advice):
483b06
+class config_client_for_smart_card_auth(common_smart_card_auth_config):
483b06
     """
483b06
     Configures smart card authentication on FreeIPA client
483b06
     """
483b06
-    smart_card_ca_cert_variable_name = "SC_CA_CERT"
483b06
 
483b06
     description = ("Instructions for enabling Smart Card authentication on "
483b06
                    " a single FreeIPA client. Configures Smart Card daemon, "
483b06
@@ -190,20 +222,6 @@ class config_client_for_smart_card_auth(Advice):
483b06
         self.run_authconfig_to_configure_smart_card_auth()
483b06
         self.restart_sssd()
483b06
 
483b06
-    def check_and_set_ca_cert_path(self):
483b06
-        ca_path_variable = self.smart_card_ca_cert_variable_name
483b06
-        self.log.command("{}=$1".format(ca_path_variable))
483b06
-        self.log.exit_on_predicate(
483b06
-            '[ -z "${}" ]'.format(ca_path_variable),
483b06
-            ['You need to provide the path to the PEM file containing CA '
483b06
-             'signing the Smart Cards']
483b06
-        )
483b06
-        self.log.exit_on_predicate(
483b06
-            '[ ! -f "${}" ]'.format(ca_path_variable),
483b06
-            ['Invalid CA certificate filename: ${}'.format(ca_path_variable),
483b06
-             'Please check that the path exists and is a valid file']
483b06
-        )
483b06
-
483b06
     def check_and_remove_pam_pkcs11(self):
483b06
         self.log.command('rpm -qi pam_pkcs11 > /dev/null')
483b06
         self.log.commands_on_predicate(
483b06
@@ -247,13 +265,6 @@ class config_client_for_smart_card_auth(Advice):
483b06
             ]
483b06
         )
483b06
 
483b06
-    def upload_smartcard_ca_certificate_to_systemwide_db(self):
483b06
-        self.log.command(
483b06
-            'certutil -d {} -A -i ${} -n "Smart Card CA" -t CT,C,C'.format(
483b06
-                self.systemwide_nssdb, self.smart_card_ca_cert_variable_name
483b06
-            )
483b06
-        )
483b06
-
483b06
     def run_authconfig_to_configure_smart_card_auth(self):
483b06
         self.log.exit_on_failed_command(
483b06
             'authconfig --enablesmartcard --smartcardmodule=sssd --updateall',
483b06
-- 
483b06
2.9.4
483b06