b38368
From 7bbf7dbc27d1bcde8bf3e4d0bb8fec65de2660c8 Mon Sep 17 00:00:00 2001
b38368
From: Martin Babinsky <mbabinsk@redhat.com>
b38368
Date: Wed, 21 Jun 2017 18:52:57 +0200
b38368
Subject: [PATCH] smart-card advises: add steps to store smart card signing CA
b38368
 cert
b38368
b38368
On master, upload the CA certificate to IPA LDAP and NSS databases. On
b38368
both master and client run ipa-certupdate to update client-side CA
b38368
certificate bundles used as PKINIT anchors.
b38368
b38368
https://pagure.io/freeipa/issue/7036
b38368
b38368
Reviewed-By: Florence Blanc-Renaud <frenaud@redhat.com>
b38368
Reviewed-By: Alexander Bokovoy <abokovoy@redhat.com>
b38368
---
b38368
 ipaserver/advise/plugins/smart_card_auth.py | 46 +++++++++++++++++++++++------
b38368
 1 file changed, 37 insertions(+), 9 deletions(-)
b38368
b38368
diff --git a/ipaserver/advise/plugins/smart_card_auth.py b/ipaserver/advise/plugins/smart_card_auth.py
b38368
index 0ee4808d47aa87a4b1b838d427e9958d98075a4a..0217bd190778f1235981a49e7b0764b8b9cdf582 100644
b38368
--- a/ipaserver/advise/plugins/smart_card_auth.py
b38368
+++ b/ipaserver/advise/plugins/smart_card_auth.py
b38368
@@ -3,6 +3,7 @@
b38368
 #
b38368
 
b38368
 from ipalib.plugable import Registry
b38368
+from ipaplatform import services
b38368
 from ipaplatform.paths import paths
b38368
 from ipaserver.advise.base import Advice
b38368
 from ipaserver.install.httpinstance import NSS_OCSP_ENABLED
b38368
@@ -19,6 +20,16 @@ class common_smart_card_auth_config(Advice):
b38368
     systemwide_nssdb = paths.NSS_DB_DIR
b38368
     smart_card_ca_cert_variable_name = "SC_CA_CERT"
b38368
 
b38368
+    def check_ccache_not_empty(self):
b38368
+        self.log.comment('Check whether the credential cache is not empty')
b38368
+        self.log.exit_on_failed_command(
b38368
+            'klist',
b38368
+            [
b38368
+                "Credential cache is empty",
b38368
+                'Use kinit as privileged user to obtain Kerberos credentials'
b38368
+            ])
b38368
+
b38368
+
b38368
     def check_and_set_ca_cert_path(self):
b38368
         ca_path_variable = self.smart_card_ca_cert_variable_name
b38368
         self.log.command("{}=$1".format(ca_path_variable))
b38368
@@ -40,6 +51,20 @@ class common_smart_card_auth_config(Advice):
b38368
             )
b38368
         )
b38368
 
b38368
+    def install_smart_card_signing_ca_cert(self):
b38368
+        self.log.exit_on_failed_command(
b38368
+            'ipa-cacert-manage install ${} -t CT,C,C'.format(
b38368
+                self.smart_card_ca_cert_variable_name
b38368
+            ),
b38368
+            ['Failed to install external CA certificate to IPA']
b38368
+        )
b38368
+
b38368
+    def update_ipa_ca_certificate_store(self):
b38368
+        self.log.exit_on_failed_command(
b38368
+            'ipa-certupdate',
b38368
+            ['Failed to update IPA CA certificate database']
b38368
+        )
b38368
+
b38368
 
b38368
 @register()
b38368
 class config_server_for_smart_card_auth(common_smart_card_auth_config):
b38368
@@ -56,6 +81,7 @@ class config_server_for_smart_card_auth(common_smart_card_auth_config):
b38368
     nss_conf = paths.HTTPD_NSS_CONF
b38368
     nss_ocsp_directive = 'NSSOCSP'
b38368
     nss_nickname_directive = 'NSSNickname'
b38368
+    kdc_service_name = services.knownservices.krb5kdc.systemd_name
b38368
 
b38368
     def get_info(self):
b38368
         self.log.exit_on_nonroot_euid()
b38368
@@ -70,15 +96,8 @@ class config_server_for_smart_card_auth(common_smart_card_auth_config):
b38368
         self.check_and_enable_pkinit()
b38368
         self.enable_ok_to_auth_as_delegate_on_http_principal()
b38368
         self.upload_smartcard_ca_certificate_to_systemwide_db()
b38368
-
b38368
-    def check_ccache_not_empty(self):
b38368
-        self.log.comment('Check whether the credential cache is not empty')
b38368
-        self.log.exit_on_failed_command(
b38368
-            'klist',
b38368
-            [
b38368
-                "Credential cache is empty",
b38368
-                'Use kinit as privileged user to obtain Kerberos credentials'
b38368
-            ])
b38368
+        self.update_ipa_ca_certificate_store()
b38368
+        self.restart_kdc()
b38368
 
b38368
     def check_hostname_is_in_masters(self):
b38368
         self.log.comment('Check whether the host is IPA master')
b38368
@@ -193,6 +212,12 @@ class config_server_for_smart_card_auth(common_smart_card_auth_config):
b38368
             ["Failed to set OK_AS_AUTH_AS_DELEGATE flag on HTTP principal"]
b38368
         )
b38368
 
b38368
+    def restart_kdc(self):
b38368
+        self.log.exit_on_failed_command(
b38368
+            'systemctl restart {}'.format(self.kdc_service_name),
b38368
+            ['Failed to restart KDC. Please restart the service manually.']
b38368
+        )
b38368
+
b38368
 
b38368
 @register()
b38368
 class config_client_for_smart_card_auth(common_smart_card_auth_config):
b38368
@@ -214,11 +239,14 @@ class config_client_for_smart_card_auth(common_smart_card_auth_config):
b38368
     def get_info(self):
b38368
         self.log.exit_on_nonroot_euid()
b38368
         self.check_and_set_ca_cert_path()
b38368
+        self.check_ccache_not_empty()
b38368
         self.check_and_remove_pam_pkcs11()
b38368
         self.install_opensc_and_dconf_packages()
b38368
         self.start_enable_smartcard_daemon()
b38368
         self.add_pkcs11_module_to_systemwide_db()
b38368
         self.upload_smartcard_ca_certificate_to_systemwide_db()
b38368
+        self.install_smart_card_signing_ca_cert()
b38368
+        self.update_ipa_ca_certificate_store()
b38368
         self.run_authconfig_to_configure_smart_card_auth()
b38368
         self.restart_sssd()
b38368
 
b38368
-- 
b38368
2.9.4
b38368