pgreco / rpms / ipa

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

Blame SOURCES/0062-Update-mod_nss-cipher-list-so-there-is-overlap-with-.patch

9ad913
From 964d13237029e0568f56342917ae386746c0b281 Mon Sep 17 00:00:00 2001
9ad913
From: Rob Crittenden <rcritten@redhat.com>
9ad913
Date: Fri, 1 Feb 2019 10:30:40 -0500
9ad913
Subject: [PATCH] Update mod_nss cipher list so there is overlap with a 4.x
9ad913
 master
9ad913
9ad913
dogtag updated its cipher list, disabling a lot of ciphers, which
9ad913
causes an overlap problem with a RHEL 6.x IPA master.
9ad913
9ad913
This update script adds the two available ciphers to the nss.conf
9ad913
so that creating a CA replica is possible.
9ad913
9ad913
Signed-off-by: Rob Crittenden <rcritten@redhat.com>
9ad913
Reviewed-By: Florence Blanc-Renaud <flo@redhat.com>
9ad913
---
9ad913
 contrib/copy-schema-to-ca-RHEL6.py | 79 ++++++++++++++++++++++++++++++
9ad913
 1 file changed, 79 insertions(+)
9ad913
9ad913
diff --git a/contrib/copy-schema-to-ca-RHEL6.py b/contrib/copy-schema-to-ca-RHEL6.py
9ad913
index 3ed16555e9a63867162b58fe99531db46e867a8b..2b866a52ba99f59db913a127f271c6da63a65b95 100755
9ad913
--- a/contrib/copy-schema-to-ca-RHEL6.py
9ad913
+++ b/contrib/copy-schema-to-ca-RHEL6.py
9ad913
@@ -31,6 +31,12 @@ from ipaserver.install.dsinstance import DS_USER
9ad913
 from ipaserver.install.cainstance import PKI_USER
9ad913
 from ipapython import services
9ad913
 
9ad913
+# for mod_nss
9ad913
+from ipaserver.install.httpinstance import NSS_CONF
9ad913
+from ipaserver.install.httpinstance import HTTPInstance
9ad913
+from ipaserver.install import installutils
9ad913
+from ipapython import sysrestore
9ad913
+
9ad913
 SERVERID = "PKI-IPA"
9ad913
 SCHEMA_FILENAMES = (
9ad913
     "60kerberos.ldif",
9ad913
@@ -100,6 +106,77 @@ def restart_pki_ds():
9ad913
     services.service('dirsrv').restart(SERVERID)
9ad913
 
9ad913
 
9ad913
+# The ipa-3-0 set_directive() has very loose comparision of directive
9ad913
+# which would cause multiple NSSCipherSuite to be added so provide
9ad913
+# a custom function for it.
9ad913
+def set_directive(filename, directive, value, quotes=True, separator=' '):
9ad913
+    """Set a name/value pair directive in a configuration file.
9ad913
+
9ad913
+       A value of None means to drop the directive.
9ad913
+
9ad913
+       This has only been tested with nss.conf
9ad913
+    """
9ad913
+    valueset = False
9ad913
+    st = os.stat(filename)
9ad913
+    fd = open(filename)
9ad913
+    newfile = []
9ad913
+    for line in fd:
9ad913
+        if line.lstrip().startswith(directive):
9ad913
+            valueset = True
9ad913
+            if value is not None:
9ad913
+                if quotes:
9ad913
+                    newfile.append('%s%s"%s"\n' %
9ad913
+                                   (directive, separator, value))
9ad913
+                else:
9ad913
+                    newfile.append('%s%s%s\n' % (directive, separator, value))
9ad913
+        else:
9ad913
+            newfile.append(line)
9ad913
+    fd.close()
9ad913
+    if not valueset:
9ad913
+        if value is not None:
9ad913
+            if quotes:
9ad913
+                newfile.append('%s%s"%s"\n' % (directive, separator, value))
9ad913
+            else:
9ad913
+                newfile.append('%s%s%s\n' % (directive, separator, value))
9ad913
+
9ad913
+    fd = open(filename, "w")
9ad913
+    fd.write("".join(newfile))
9ad913
+    fd.close()
9ad913
+    os.chown(filename, st.st_uid, st.st_gid)  # reset perms
9ad913
+
9ad913
+
9ad913
+def update_mod_nss_cipher_suite():
9ad913
+    add_ciphers = ['ecdhe_rsa_aes_128_sha', 'ecdhe_rsa_aes_256_sha']
9ad913
+    ciphers = installutils.get_directive(NSS_CONF, 'NSSCipherSuite')
9ad913
+
9ad913
+    # Run through once to see if any of the new ciphers are there but
9ad913
+    # disabled. If they are then enable them.
9ad913
+    lciphers = ciphers.split(',')
9ad913
+    new_ciphers = []
9ad913
+    for cipher in lciphers:
9ad913
+        for add in add_ciphers:
9ad913
+            if cipher.endswith(add):
9ad913
+                if cipher.startswith('-'):
9ad913
+                    cipher = '+%s' % add
9ad913
+        new_ciphers.append(cipher)
9ad913
+
9ad913
+    # Run through again and add remaining ciphers as enabled.
9ad913
+    for add in add_ciphers:
9ad913
+        if add not in ciphers:
9ad913
+            new_ciphers.append('+%s' % add)
9ad913
+
9ad913
+    ciphers = ','.join(new_ciphers)
9ad913
+    set_directive(NSS_CONF, 'NSSCipherSuite', ciphers, False)
9ad913
+    root_logger.info('Updated Apache cipher list')
9ad913
+
9ad913
+
9ad913
+def restart_http():
9ad913
+    root_logger.info('Restarting HTTP')
9ad913
+    fstore = sysrestore.FileStore('/var/lib/ipa/sysrestore')
9ad913
+    http = HTTPInstance(fstore)
9ad913
+    http.restart()
9ad913
+
9ad913
+
9ad913
 def main():
9ad913
     if os.getegid() != 0:
9ad913
         sys.exit("Must be root to run this script")
9ad913
@@ -110,6 +187,8 @@ def main():
9ad913
 
9ad913
     add_ca_schema()
9ad913
     restart_pki_ds()
9ad913
+    update_mod_nss_cipher_suite()
9ad913
+    restart_http()
9ad913
 
9ad913
     root_logger.info('Schema updated successfully')
9ad913
 
9ad913
-- 
9ad913
2.20.1
9ad913