syncope-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cohei...@apache.org
Subject syncope git commit: Fixing the installer to work with SSHA256
Date Wed, 19 Jul 2017 10:41:46 GMT
Repository: syncope
Updated Branches:
  refs/heads/master 0367ace84 -> 39d1e6179


Fixing the installer to work with SSHA256


Project: http://git-wip-us.apache.org/repos/asf/syncope/repo
Commit: http://git-wip-us.apache.org/repos/asf/syncope/commit/39d1e617
Tree: http://git-wip-us.apache.org/repos/asf/syncope/tree/39d1e617
Diff: http://git-wip-us.apache.org/repos/asf/syncope/diff/39d1e617

Branch: refs/heads/master
Commit: 39d1e61798e8eda628ed1f36b4af25a313911083
Parents: 0367ace
Author: Colm O hEigeartaigh <coheigea@apache.org>
Authored: Wed Jul 19 11:41:37 2017 +0100
Committer: Colm O hEigeartaigh <coheigea@apache.org>
Committed: Wed Jul 19 11:41:37 2017 +0100

----------------------------------------------------------------------
 installer/pom.xml                               |  5 +++
 .../syncope/installer/utilities/MavenUtils.java | 42 +++++++++++++-------
 installer/src/main/resources/izpack/install.xml |  1 +
 3 files changed, 33 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/syncope/blob/39d1e617/installer/pom.xml
----------------------------------------------------------------------
diff --git a/installer/pom.xml b/installer/pom.xml
index 227bd89..7db2240 100644
--- a/installer/pom.xml
+++ b/installer/pom.xml
@@ -87,6 +87,11 @@ under the License.
       <groupId>commons-logging</groupId>
       <artifactId>commons-logging</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.jasypt</groupId>
+      <artifactId>jasypt</artifactId>
+    </dependency>
+
   </dependencies>
 
   <build>

http://git-wip-us.apache.org/repos/asf/syncope/blob/39d1e617/installer/src/main/java/org/apache/syncope/installer/utilities/MavenUtils.java
----------------------------------------------------------------------
diff --git a/installer/src/main/java/org/apache/syncope/installer/utilities/MavenUtils.java
b/installer/src/main/java/org/apache/syncope/installer/utilities/MavenUtils.java
index 59ee898..27f0c2a 100644
--- a/installer/src/main/java/org/apache/syncope/installer/utilities/MavenUtils.java
+++ b/installer/src/main/java/org/apache/syncope/installer/utilities/MavenUtils.java
@@ -23,23 +23,17 @@ import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.PrintStream;
-import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 import java.util.Properties;
-import java.util.logging.Level;
-import java.util.logging.Logger;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.TransformerException;
 
-import org.apache.commons.codec.binary.Hex;
 import org.apache.commons.io.FileUtils;
 import org.apache.maven.shared.invoker.DefaultInvocationRequest;
 import org.apache.maven.shared.invoker.DefaultInvoker;
@@ -49,6 +43,8 @@ import org.apache.maven.shared.invoker.Invoker;
 import org.apache.maven.shared.invoker.MavenInvocationException;
 import org.apache.maven.shared.invoker.PrintStreamHandler;
 import org.apache.maven.shared.invoker.PrintStreamLogger;
+import org.jasypt.commons.CommonUtils;
+import org.jasypt.digest.StandardStringDigester;
 import org.w3c.dom.Document;
 import org.w3c.dom.Element;
 import org.xml.sax.SAXException;
@@ -119,15 +115,9 @@ public class MavenUtils {
         properties.setProperty("jwsKey", jwsKey);
 
         if (adminPassword != null) {
-            try {
-                final MessageDigest cript = MessageDigest.getInstance("SHA-1");
-                String encodedPassword =
-                    new String(Hex.encodeHex(cript.digest(adminPassword.getBytes(StandardCharsets.UTF_8))));
-                properties.setProperty("adminPassword", encodedPassword);
-            } catch (final NoSuchAlgorithmException ex) {
-                Logger.getLogger(MavenUtils.class.getName()).log(Level.SEVERE, "NoSuchAlgorithmException",
ex);
-
-            }
+            StandardStringDigester digester = getDigester("S-SHA-256");
+            String encodedPassword = digester.digest(adminPassword);
+            properties.setProperty("adminPassword", encodedPassword);
         }
         properties.setProperty("version", "1.0-SNAPSHOT");
         return properties;
@@ -245,4 +235,26 @@ public class MavenUtils {
         }
         return tempSettingsXML;
     }
+
+    private static StandardStringDigester getDigester(final String cipherAlgorithm) {
+        StandardStringDigester digester = new StandardStringDigester();
+
+        if (cipherAlgorithm.startsWith("S-")) {
+            // Salted ...
+            digester.setAlgorithm(cipherAlgorithm.replaceFirst("S\\-", ""));
+            digester.setIterations(1);
+            digester.setSaltSizeBytes(8);
+            digester.setInvertPositionOfPlainSaltInEncryptionResults(true);
+            digester.setInvertPositionOfSaltInMessageBeforeDigesting(true);
+            digester.setUseLenientSaltSizeCheck(true);
+        } else {
+            // Not salted ...
+            digester.setAlgorithm(cipherAlgorithm);
+            digester.setIterations(1);
+            digester.setSaltSizeBytes(0);
+        }
+
+        digester.setStringOutputType(CommonUtils.STRING_OUTPUT_TYPE_HEXADECIMAL);
+        return digester;
+    }
 }

http://git-wip-us.apache.org/repos/asf/syncope/blob/39d1e617/installer/src/main/resources/izpack/install.xml
----------------------------------------------------------------------
diff --git a/installer/src/main/resources/izpack/install.xml b/installer/src/main/resources/izpack/install.xml
index 023cea3..3a65898 100644
--- a/installer/src/main/resources/izpack/install.xml
+++ b/installer/src/main/resources/izpack/install.xml
@@ -140,6 +140,7 @@ under the License.
   <jar src="lib/jackson-databind-@{jackson.version}.jar"/>
   <jar src="lib/jackson-core-@{jackson.version}.jar"/>
   <jar src="lib/jackson-annotations-@{jackson.version}.jar"/>
+  <jar src="lib/jasypt-@{jasypt.version}.jar"/>
   
   <jar src="lib/maven-invoker-@{maven-invoker.version}.jar"/>
   <jar src="lib/plexus-utils-3.0.24.jar"/>


Mime
View raw message