[java-identity-provider] 02/02: IDP-1253 test for unsafe password saving.

Rod Widdowson rdw at steadingsoftware.com
Fri Jun 8 09:29:02 EDT 2018


This is an automated email from the git hooks/post-receive script.

rdw pushed a commit to branch master
in repository java-identity-provider.

View the commit online:
http://git.shibboleth.net/view/?p=java-identity-provider.git;a=commit;h=837332c480c7bd577407ea02cabb8140ced0de41

commit 837332c480c7bd577407ea02cabb8140ced0de41
Author: Rod Widdowson <rdw at steadingsoftware.com>
AuthorDate: Fri Jun 8 14:27:18 2018 +0100

    IDP-1253 test for unsafe password saving.
    
    https://issues.shibboleth.net/jira/browse/IDP-1253
    
    Bounce the putative password through our manipulation prior to accepting
    it as valid.
---
 .../idp/installer/ant/impl/PasswordHandler.java    | 48 ++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/idp-installer/src/main/java/net/shibboleth/idp/installer/ant/impl/PasswordHandler.java b/idp-installer/src/main/java/net/shibboleth/idp/installer/ant/impl/PasswordHandler.java
index 6ff291f..74c39fa 100644
--- a/idp-installer/src/main/java/net/shibboleth/idp/installer/ant/impl/PasswordHandler.java
+++ b/idp-installer/src/main/java/net/shibboleth/idp/installer/ant/impl/PasswordHandler.java
@@ -17,12 +17,56 @@
 
 package net.shibboleth.idp.installer.ant.impl;
 
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+import javax.annotation.Nonnull;
+
 import org.apache.tools.ant.input.InputRequest;
 import org.apache.tools.ant.input.SecureInputHandler;
 
+import net.shibboleth.idp.installer.impl.PropertiesWithComments;
+import net.shibboleth.utilities.java.support.annotation.constraint.NotEmpty;
+
 /** Ant helper class to ask for passwords, rejecting zero length passwords and asking for confirmation. */
 public class PasswordHandler extends SecureInputHandler {
 
+    /** Spool the file to a {@link PropertiesWithComments}, read it in again as a {@link Properties} and check
+     * for equivalence.
+     * @param password what to look at
+     * @return if the password can go to a property file OK
+     */
+    private boolean passwordSavesOK(final @Nonnull @NotEmpty String password) {
+        final String propertyName="pass";
+        try {
+            final PropertiesWithComments saveProps = new PropertiesWithComments();
+            // init
+            saveProps.load(new ByteArrayInputStream(new byte[0]));
+
+            // set up
+            saveProps.replaceProperty(propertyName, password);
+
+            // save
+            final ByteArrayOutputStream saveStream = new ByteArrayOutputStream();
+            saveProps.store(saveStream);
+
+            // reload
+            final Properties loadProps = new Properties();
+            final ByteArrayInputStream loadStream = new ByteArrayInputStream(saveStream.toByteArray());
+            saveStream.close();
+            loadProps.load(loadStream);
+            loadStream.close();
+
+            // test
+            return password.equals(loadProps.getProperty(propertyName));
+        } catch (final IOException e) {
+            System.console().printf("Internal error :\n" + e.getStackTrace() + "\n");
+            return false;
+        }
+    }
+
     /** {@inheritDoc} */
     @Override
     public void handleInput(final InputRequest arg0) {
@@ -35,6 +79,10 @@ public class PasswordHandler extends SecureInputHandler {
                 continue;
             }
             final String firstPass = String.copyValueOf(result);
+            if (!passwordSavesOK(firstPass)) {
+                System.console().printf("Password contains unsafe characters\n");
+                continue;
+            }
             System.console().printf("Re-enter password: ");
             System.console().flush();
             result  = System.console().readPassword();

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the commits mailing list