pgreco / rpms / ipa

Forked from forks/areguera/rpms/ipa 4 years ago
Clone
483b06
From ea2fc433d3f72364340919345805c667ce0d7524 Mon Sep 17 00:00:00 2001
483b06
From: Pavel Vomacka <pvomacka@redhat.com>
483b06
Date: Thu, 1 Jun 2017 09:56:16 +0200
483b06
Subject: [PATCH] Turn off OCSP check
483b06
483b06
The OCSP check was previously turned on but it introduced several
483b06
issues. Therefore the check will be turned off by default.
483b06
483b06
For turning on should be used ipa advise command with correct recipe.
483b06
The solution is tracked here: https://pagure.io/freeipa/issue/6982
483b06
483b06
Fixes: https://pagure.io/freeipa/issue/6981
483b06
Reviewed-By: Martin Babinsky <mbabinsk@redhat.com>
483b06
---
483b06
 install/restart_scripts/restart_httpd | 15 +-----------
483b06
 ipaserver/install/httpinstance.py     | 43 +++++++++++++++++++----------------
483b06
 ipaserver/install/server/upgrade.py   | 25 +++-----------------
483b06
 3 files changed, 28 insertions(+), 55 deletions(-)
483b06
483b06
diff --git a/install/restart_scripts/restart_httpd b/install/restart_scripts/restart_httpd
483b06
index cd7f12024ea3cab16e9c664687cd854e666c9570..d1684812904a9d32842a0ca548ec6b9df5a5a0b7 100644
483b06
--- a/install/restart_scripts/restart_httpd
483b06
+++ b/install/restart_scripts/restart_httpd
483b06
@@ -21,24 +21,11 @@
483b06
 
483b06
 import syslog
483b06
 import traceback
483b06
-from ipalib import api
483b06
 from ipaplatform import services
483b06
-from ipaplatform.paths import paths
483b06
-from ipapython.certdb import TRUSTED_PEER_TRUST_FLAGS
483b06
-from ipaserver.install import certs, installutils
483b06
+from ipaserver.install import certs
483b06
 
483b06
 
483b06
 def _main():
483b06
-
483b06
-    api.bootstrap(in_server=True, context='restart', confdir=paths.ETC_IPA)
483b06
-    api.finalize()
483b06
-
483b06
-    db = certs.CertDB(api.env.realm, nssdir=paths.HTTPD_ALIAS_DIR)
483b06
-    nickname = installutils.get_directive(paths.HTTPD_NSS_CONF, "NSSNickname")
483b06
-
483b06
-    # Add trust flag which set certificate trusted for SSL connections.
483b06
-    db.trust_root_cert(nickname, TRUSTED_PEER_TRUST_FLAGS)
483b06
-
483b06
     syslog.syslog(syslog.LOG_NOTICE, 'certmonger restarted httpd')
483b06
 
483b06
     try:
483b06
diff --git a/ipaserver/install/httpinstance.py b/ipaserver/install/httpinstance.py
483b06
index 12fdddccc26b0c1132bcdca7fe2249a85997892e..f637b97db8f21ddbc00c4f70e18e836d300b2f33 100644
483b06
--- a/ipaserver/install/httpinstance.py
483b06
+++ b/ipaserver/install/httpinstance.py
483b06
@@ -34,8 +34,7 @@ from augeas import Augeas
483b06
 from ipalib.install import certmonger
483b06
 from ipapython import ipaldap
483b06
 from ipapython.certdb import (IPA_CA_TRUST_FLAGS,
483b06
-                              EXTERNAL_CA_TRUST_FLAGS,
483b06
-                              TRUSTED_PEER_TRUST_FLAGS)
483b06
+                              EXTERNAL_CA_TRUST_FLAGS)
483b06
 from ipaserver.install import replication
483b06
 from ipaserver.install import service
483b06
 from ipaserver.install import certs
483b06
@@ -74,6 +73,10 @@ NSS_CIPHER_SUITE = [
483b06
 ]
483b06
 NSS_CIPHER_REVISION = '20160129'
483b06
 
483b06
+OCSP_DIRECTIVE = 'NSSOCSP'
483b06
+
483b06
+NSS_OCSP_ENABLED = 'nss_ocsp_enabled'
483b06
+
483b06
 
483b06
 def httpd_443_configured():
483b06
     """
483b06
@@ -163,7 +166,7 @@ class HTTPInstance(service.Service):
483b06
                   self.set_mod_nss_protocol)
483b06
         self.step("setting mod_nss password file", self.__set_mod_nss_passwordfile)
483b06
         self.step("enabling mod_nss renegotiate", self.enable_mod_nss_renegotiate)
483b06
-        self.step("enabling mod_nss OCSP", self.enable_mod_nss_ocsp)
483b06
+        self.step("disabling mod_nss OCSP", self.disable_mod_nss_ocsp)
483b06
         self.step("adding URL rewriting rules", self.__add_include)
483b06
         self.step("configuring httpd", self.__configure_http)
483b06
         self.step("setting up httpd keytab", self.request_service_keytab)
483b06
@@ -270,7 +273,12 @@ class HTTPInstance(service.Service):
483b06
         installutils.set_directive(paths.HTTPD_NSS_CONF, 'NSSRenegotiation', 'on', False)
483b06
         installutils.set_directive(paths.HTTPD_NSS_CONF, 'NSSRequireSafeNegotiation', 'on', False)
483b06
 
483b06
-    def enable_mod_nss_ocsp(self):
483b06
+    def disable_mod_nss_ocsp(self):
483b06
+        if sysupgrade.get_upgrade_state('http', NSS_OCSP_ENABLED) is None:
483b06
+            self.__disable_mod_nss_ocsp()
483b06
+            sysupgrade.set_upgrade_state('http', NSS_OCSP_ENABLED, False)
483b06
+
483b06
+    def __disable_mod_nss_ocsp(self):
483b06
         aug = Augeas(flags=Augeas.NO_LOAD | Augeas.NO_MODL_AUTOLOAD)
483b06
 
483b06
         aug.set('/augeas/load/Httpd/lens', 'Httpd.lns')
483b06
@@ -278,22 +286,21 @@ class HTTPInstance(service.Service):
483b06
         aug.load()
483b06
 
483b06
         path = '/files{}/VirtualHost'.format(paths.HTTPD_NSS_CONF)
483b06
+        ocsp_path = '{}/directive[.="{}"]'.format(path, OCSP_DIRECTIVE)
483b06
+        ocsp_arg = '{}/arg'.format(ocsp_path)
483b06
+        ocsp_comment = '{}/#comment[.="{}"]'.format(path, OCSP_DIRECTIVE)
483b06
 
483b06
-        ocsp_comment = aug.get(
483b06
-                        '{}/#comment[.=~regexp("NSSOCSP .*")]'.format(path))
483b06
-        ocsp_dir = aug.get('{}/directive[.="NSSOCSP"]'.format(path))
483b06
+        ocsp_dir = aug.get(ocsp_path)
483b06
 
483b06
-        if ocsp_dir is None and ocsp_comment is not None:
483b06
-            # Directive is missing, comment is present
483b06
-            aug.set('{}/#comment[.=~regexp("NSSOCSP .*")]'.format(path),
483b06
-                    'NSSOCSP')
483b06
-            aug.rename('{}/#comment[.="NSSOCSP"]'.format(path), 'directive')
483b06
-        elif ocsp_dir is None:
483b06
-            # Directive is missing and comment is missing
483b06
-            aug.set('{}/directive[last()+1]'.format(path), "NSSOCSP")
483b06
+        # there is NSSOCSP directive in nss.conf file, comment it
483b06
+        # otherwise just do nothing
483b06
+        if ocsp_dir is not None:
483b06
+            ocsp_state = aug.get(ocsp_arg)
483b06
+            aug.remove(ocsp_arg)
483b06
+            aug.rename(ocsp_path, '#comment')
483b06
+            aug.set(ocsp_comment, '{} {}'.format(OCSP_DIRECTIVE, ocsp_state))
483b06
+            aug.save()
483b06
 
483b06
-        aug.set('{}/directive[. = "NSSOCSP"]/arg'.format(path), 'on')
483b06
-        aug.save()
483b06
 
483b06
     def set_mod_nss_cipher_suite(self):
483b06
         ciphers = ','.join(NSS_CIPHER_SUITE)
483b06
@@ -412,8 +419,6 @@ class HTTPInstance(service.Service):
483b06
             self.__set_mod_nss_nickname(nickname)
483b06
             self.add_cert_to_service()
483b06
 
483b06
-            db.trust_root_cert(nickname, TRUSTED_PEER_TRUST_FLAGS)
483b06
-
483b06
         else:
483b06
             if not self.promote:
483b06
                 ca_args = [
483b06
diff --git a/ipaserver/install/server/upgrade.py b/ipaserver/install/server/upgrade.py
483b06
index b1f59d3e29d69bffc11935ec22d4b5f510293355..732776f2cf513a4bb11d8f3f0dfaac78217e460f 100644
483b06
--- a/ipaserver/install/server/upgrade.py
483b06
+++ b/ipaserver/install/server/upgrade.py
483b06
@@ -1395,24 +1395,6 @@ def fix_trust_flags():
483b06
     sysupgrade.set_upgrade_state('http', 'fix_trust_flags', True)
483b06
 
483b06
 
483b06
-def fix_server_cert_trust_flags():
483b06
-    root_logger.info(
483b06
-        '[Fixing server certificate trust flags in %s]' %
483b06
-        paths.HTTPD_ALIAS_DIR)
483b06
-
483b06
-    if sysupgrade.get_upgrade_state('http', 'fix_serv_cert_trust_flags'):
483b06
-        root_logger.info("Trust flags already processed")
483b06
-        return
483b06
-
483b06
-    db = certs.CertDB(api.env.realm, nssdir=paths.HTTPD_ALIAS_DIR)
483b06
-    sc_nickname = installutils.get_directive(paths.HTTPD_NSS_CONF,
483b06
-                                             "NSSNickname")
483b06
-    # Add trust flag which set certificate trusted for SSL connections.
483b06
-    db.trust_root_cert(sc_nickname, certdb.TRUSTED_PEER_TRUST_FLAGS)
483b06
-
483b06
-    sysupgrade.set_upgrade_state('http', 'fix_serv_cert_trust_flags', True)
483b06
-
483b06
-
483b06
 def update_mod_nss_protocol(http):
483b06
     root_logger.info('[Updating mod_nss protocol versions]')
483b06
 
483b06
@@ -1425,9 +1407,9 @@ def update_mod_nss_protocol(http):
483b06
     sysupgrade.set_upgrade_state('nss.conf', 'protocol_updated_tls12', True)
483b06
 
483b06
 
483b06
-def enable_mod_nss_ocsp(http):
483b06
+def disable_mod_nss_ocsp(http):
483b06
     root_logger.info('[Updating mod_nss enabling OCSP]')
483b06
-    http.enable_mod_nss_ocsp()
483b06
+    http.disable_mod_nss_ocsp()
483b06
 
483b06
 
483b06
 def update_mod_nss_cipher_suite(http):
483b06
@@ -1721,9 +1703,8 @@ def upgrade_configuration():
483b06
     update_ipa_httpd_service_conf(http)
483b06
     update_mod_nss_protocol(http)
483b06
     update_mod_nss_cipher_suite(http)
483b06
-    enable_mod_nss_ocsp(http)
483b06
+    disable_mod_nss_ocsp(http)
483b06
     fix_trust_flags()
483b06
-    fix_server_cert_trust_flags()
483b06
     update_http_keytab(http)
483b06
     http.configure_gssproxy()
483b06
     http.start()
483b06
-- 
483b06
2.9.4
483b06