483b06
From 391fe8e9d0587ad44a92c320a8d1c9de2c9b980a Mon Sep 17 00:00:00 2001
483b06
From: Tomas Krizek <tkrizek@redhat.com>
483b06
Date: Wed, 3 May 2017 10:16:13 +0200
483b06
Subject: [PATCH] ca, kra install: validate DM password
483b06
483b06
Before proceeding with installation, validate DM password. If the
483b06
provided DM password is invalid, abort the installation.
483b06
483b06
Fixes https://pagure.io/freeipa/issue/6892
483b06
483b06
Signed-off-by: Tomas Krizek <tkrizek@redhat.com>
483b06
Reviewed-By: Martin Basti <mbasti@redhat.com>
483b06
Reviewed-By: Christian Heimes <cheimes@redhat.com>
483b06
Reviewed-By: Stanislav Laznicka <slaznick@redhat.com>
483b06
---
483b06
 install/tools/ipa-ca-install         | 18 ++++++++++--------
483b06
 ipaserver/install/ipa_kra_install.py |  8 ++++++++
483b06
 2 files changed, 18 insertions(+), 8 deletions(-)
483b06
483b06
diff --git a/install/tools/ipa-ca-install b/install/tools/ipa-ca-install
483b06
index 4bcb59a29d5a64c118649374104ae8f1cd451ea4..f84b4749a3e2a80aca002a2aa057b200e6187f18 100755
483b06
--- a/install/tools/ipa-ca-install
483b06
+++ b/install/tools/ipa-ca-install
483b06
@@ -117,17 +117,19 @@ def parse_options():
483b06
 
483b06
 
483b06
 def _get_dirman_password(password=None, unattended=False):
483b06
+    # sys.exit() is used on purpose, because otherwise user is advised to
483b06
+    # uninstall the component, even though it is not needed
483b06
     if not password:
483b06
         if unattended:
483b06
             sys.exit('Directory Manager password required')
483b06
-        try:
483b06
-            password = installutils.read_password(
483b06
-                "Directory Manager (existing master)", confirm=False,
483b06
-                validate=False)
483b06
-        except KeyboardInterrupt:
483b06
-            sys.exit(0)
483b06
-        if password is None:
483b06
-            sys.exit("Directory Manager password required")
483b06
+        password = installutils.read_password(
483b06
+            "Directory Manager (existing master)", confirm=False,
483b06
+            validate=False)
483b06
+    try:
483b06
+        installutils.validate_dm_password_ldap(password)
483b06
+    except ValueError:
483b06
+        sys.exit("Directory Manager password is invalid")
483b06
+
483b06
     return password
483b06
 
483b06
 
483b06
diff --git a/ipaserver/install/ipa_kra_install.py b/ipaserver/install/ipa_kra_install.py
483b06
index b06d49c834d0ffa4f2e35c3241a83e42c4c9c337..8369d2f4082d35b453487ee0f17c9ce050188daf 100644
483b06
--- a/ipaserver/install/ipa_kra_install.py
483b06
+++ b/ipaserver/install/ipa_kra_install.py
483b06
@@ -137,6 +137,14 @@ class KRAInstaller(KRAInstall):
483b06
     def run(self):
483b06
         super(KRAInstaller, self).run()
483b06
 
483b06
+        # Verify DM password. This has to be called after ask_for_options(),
483b06
+        # so it can't be placed in validate_options().
483b06
+        try:
483b06
+            installutils.validate_dm_password_ldap(self.options.password)
483b06
+        except ValueError:
483b06
+            raise admintool.ScriptError(
483b06
+                "Directory Manager password is invalid")
483b06
+
483b06
         if not cainstance.is_ca_installed_locally():
483b06
             raise RuntimeError("Dogtag CA is not installed. "
483b06
                                "Please install the CA first")
483b06
-- 
483b06
2.9.4
483b06