You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@turbine.apache.org by gk...@apache.org on 2021/04/13 14:52:46 UTC

svn commit: r1888735 - in /turbine/fulcrum/trunk: pbe/pom.xml pbe/src/java/org/apache/fulcrum/pbe/PBEServiceImpl.java pbe/src/test/TestComponentConfig.xml pbe/src/test/org/apache/fulcrum/pbe/PBEServiceTest.java resourcemanager/pom.xml

Author: gk
Date: Tue Apr 13 14:52:45 2021
New Revision: 1888735

URL: http://svn.apache.org/viewvc?rev=1888735&view=rev
Log:
- Fulcrum module pbe, update to current yaafi - crypto 2.0.1 version.
- update parent in resourcemanager/pom.xml

Modified:
    turbine/fulcrum/trunk/pbe/pom.xml
    turbine/fulcrum/trunk/pbe/src/java/org/apache/fulcrum/pbe/PBEServiceImpl.java
    turbine/fulcrum/trunk/pbe/src/test/TestComponentConfig.xml
    turbine/fulcrum/trunk/pbe/src/test/org/apache/fulcrum/pbe/PBEServiceTest.java
    turbine/fulcrum/trunk/resourcemanager/pom.xml

Modified: turbine/fulcrum/trunk/pbe/pom.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/pbe/pom.xml?rev=1888735&r1=1888734&r2=1888735&view=diff
==============================================================================
--- turbine/fulcrum/trunk/pbe/pom.xml (original)
+++ turbine/fulcrum/trunk/pbe/pom.xml Tue Apr 13 14:52:45 2021
@@ -16,11 +16,11 @@
    limitations under the License.
 -->
 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-  <parent>
-    <artifactId>turbine-parent</artifactId>
-       <groupId>org.apache.turbine</groupId>
-       <version>5</version>
-  </parent>
+    <parent>
+        <artifactId>turbine-parent</artifactId>
+        <groupId>org.apache.turbine</groupId>
+        <version>7</version>
+    </parent>
 
   <modelVersion>4.0.0</modelVersion>
   <groupId>org.apache.fulcrum</groupId>
@@ -67,13 +67,13 @@
     <dependency>
       <groupId>org.apache.fulcrum</groupId>
       <artifactId>fulcrum-yaafi-crypto</artifactId>
-      <version>1.0.7</version>
+      <version>2.0.1</version>
     </dependency>
     <!-- testing dependencies -->
     <dependency>
       <groupId>org.apache.fulcrum</groupId>
       <artifactId>fulcrum-testcontainer</artifactId>
-      <version>1.0.8</version>
+      <version>1.0.9</version>
       <scope>test</scope>
     </dependency>
     <dependency>

Modified: turbine/fulcrum/trunk/pbe/src/java/org/apache/fulcrum/pbe/PBEServiceImpl.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/pbe/src/java/org/apache/fulcrum/pbe/PBEServiceImpl.java?rev=1888735&r1=1888734&r2=1888735&view=diff
==============================================================================
--- turbine/fulcrum/trunk/pbe/src/java/org/apache/fulcrum/pbe/PBEServiceImpl.java (original)
+++ turbine/fulcrum/trunk/pbe/src/java/org/apache/fulcrum/pbe/PBEServiceImpl.java Tue Apr 13 14:52:45 2021
@@ -1,5 +1,7 @@
 package org.apache.fulcrum.pbe;
 
+import java.io.ByteArrayOutputStream;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -35,6 +37,7 @@ import org.apache.fulcrum.jce.crypto.Cry
 import org.apache.fulcrum.jce.crypto.HexConverter;
 import org.apache.fulcrum.jce.crypto.PasswordFactory;
 import org.apache.fulcrum.jce.crypto.PasswordParameters;
+import org.apache.fulcrum.jce.crypto.StreamUtil;
 
 /**
  * Encapsulates an PBE (Password Based Encryption) functionality
@@ -58,6 +61,8 @@ public class PBEServiceImpl
 
     /** the default password */
     private char[] defaultPassword;
+    
+    private String algorithm = "";
 
     /**
      * Constructor
@@ -79,9 +84,11 @@ public class PBEServiceImpl
     {
         // read the parameters for CryptoStreamFactory
 
-        byte[] cryptoSalt = CryptoParameters.SALT;
+        byte[] cryptoSalt = CryptoParameters.Salt();
         int cryptoCount = configuration.getChild("cyrptoCount").getValueAsInteger(CryptoParameters.COUNT);
         String tempCryptoSalt = configuration.getChild("cryptoSalt").getValue("");
+        
+        this.algorithm = configuration.getChild("algo").getValue("SHA1");
 
         if( tempCryptoSalt.length() > 0 )
         {
@@ -97,9 +104,9 @@ public class PBEServiceImpl
 
         // read the parameters for PasswordFactory
 
-        this.passwordSalt = PasswordParameters.SALT;
+        this.passwordSalt = PasswordParameters.Salt();
         this.passwordCount = configuration.getChild("passwordCount").getValueAsInteger(PasswordParameters.COUNT);
-        this.defaultPassword = PasswordParameters.DEFAULTPASSWORD;
+        this.defaultPassword = PasswordParameters.DefaultPassword();
     }
 
 
@@ -112,7 +119,8 @@ public class PBEServiceImpl
      */
     public char[] createPassword() throws Exception
     {
-        return PasswordFactory.create(
+        //"SHA-256", default "SHA1"
+        return PasswordFactory.getInstance(algorithm).create(
             this.defaultPassword,
             this.passwordSalt,
             this.passwordCount
@@ -124,7 +132,7 @@ public class PBEServiceImpl
      */
     public char [] createPassword(char [] seed) throws Exception
     {
-        return PasswordFactory.create(
+        return PasswordFactory.getInstance(algorithm).create(
             seed,
             this.passwordSalt,
             this.passwordCount
@@ -137,7 +145,7 @@ public class PBEServiceImpl
     public String decryptString(String cipherText, char [] password)
         throws GeneralSecurityException, IOException
     {
-        return CryptoUtil.decryptString(
+        return CryptoUtil.getInstance().decryptString(
             this.getCryptoStreamFactory(),
             cipherText,
             password
@@ -150,10 +158,11 @@ public class PBEServiceImpl
     public String encryptString(String plainText, char [] password)
         throws GeneralSecurityException, IOException
     {
-        return CryptoUtil.encryptString(
+        return CryptoUtil.getInstance().encryptString(
             this.getCryptoStreamFactory(),
             plainText,
-            password
+            password,
+            false
             );
     }
 
@@ -199,12 +208,17 @@ public class PBEServiceImpl
     public void decrypt(Object source, Object target, char [] password)
         throws GeneralSecurityException, IOException
     {
-        CryptoUtil.decrypt(
-            this.getCryptoStreamFactory(),
-            source,
-            target,
-            password
-            );
+        InputStream is = StreamUtil.createInputStream(source);
+        OutputStream os = StreamUtil.createOutputStream(target);
+        InputStream dis = this.getCryptoStreamFactory().getInputStream(is, password);
+        StreamUtil.copy(dis, os);               
+        // protected
+//        CryptoUtil.getInstance().decrypt(
+//            this.getCryptoStreamFactory(),
+//            source,
+//            target,
+//            password
+//            );
     }
 
     /**
@@ -213,7 +227,7 @@ public class PBEServiceImpl
     public void encrypt(Object source, Object target, char [] password)
         throws GeneralSecurityException, IOException
     {
-        CryptoUtil.encrypt(
+        CryptoUtil.getInstance().encrypt(
             this.getCryptoStreamFactory(),
             source,
             target,

Modified: turbine/fulcrum/trunk/pbe/src/test/TestComponentConfig.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/pbe/src/test/TestComponentConfig.xml?rev=1888735&r1=1888734&r2=1888735&view=diff
==============================================================================
--- turbine/fulcrum/trunk/pbe/src/test/TestComponentConfig.xml (original)
+++ turbine/fulcrum/trunk/pbe/src/test/TestComponentConfig.xml Tue Apr 13 14:52:45 2021
@@ -32,5 +32,7 @@
     <cryptoSalt>4463657541544141</cryptoSalt>
     <cyrptoCount>20</cyrptoCount>
     <passwordCount>20</passwordCount>
+    <!-- optional algo, default SHA1 -->
+    <!-- algo>SHA-256</algo-->
   </PBEService>
 </componentConfig>

Modified: turbine/fulcrum/trunk/pbe/src/test/org/apache/fulcrum/pbe/PBEServiceTest.java
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/pbe/src/test/org/apache/fulcrum/pbe/PBEServiceTest.java?rev=1888735&r1=1888734&r2=1888735&view=diff
==============================================================================
--- turbine/fulcrum/trunk/pbe/src/test/org/apache/fulcrum/pbe/PBEServiceTest.java (original)
+++ turbine/fulcrum/trunk/pbe/src/test/org/apache/fulcrum/pbe/PBEServiceTest.java Tue Apr 13 14:52:45 2021
@@ -1,5 +1,10 @@
 package org.apache.fulcrum.pbe;
 
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.fail;
+
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -18,37 +23,32 @@ package org.apache.fulcrum.pbe;
  * specific language governing permissions and limitations
  * under the License.
  */
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.io.OutputStream;
 
-import java.io.*;
-
-import org.apache.fulcrum.testcontainer.BaseUnitTest;
 import org.apache.fulcrum.jce.crypto.StreamUtil;
+import org.apache.fulcrum.testcontainer.BaseUnit5Test;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 /**
  * PBEServiceTest
  *
  * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
  */
-public class PBEServiceTest extends BaseUnitTest
+public class PBEServiceTest extends BaseUnit5Test
 {
     private PBEService service;
 
     /**
-     * Defines the testcase name for JUnit.
-     *
-     * @param name the testcase's name.
-     */
-    public PBEServiceTest(String name)
-    {
-        super(name);
-    }
-
-    /**
      * Test setup
      */
+    @BeforeEach
     protected void setUp() throws Exception
     {
-        super.setUp();
 
         try
         {
@@ -80,6 +80,7 @@ public class PBEServiceTest extends Base
      * Create the default password do be used.
      * @throws Exception generic exception
      */
+    @Test
     public void testCreateDefaultPassword() throws Exception
     {
         char[] result = this.getService().createPassword();
@@ -92,6 +93,7 @@ public class PBEServiceTest extends Base
      * Create a password with a user-supplied seed value.
      * @throws Exception generic exception
      */
+    @Test
     public void testCreatePassword() throws Exception
     {
         char[] seed = "mysecret".toCharArray();
@@ -105,6 +107,7 @@ public class PBEServiceTest extends Base
      * Test encryption and decryption of Strings
      * @throws Exception generic exception
      */
+    @Test
     public void testEncryptDecryptStringUsingDefaultPassword() throws Exception
     {
         String source = "Nobody knows the troubles I have seen ...";
@@ -118,6 +121,7 @@ public class PBEServiceTest extends Base
      * a caller-supplied password
      * @throws Exception generic exception
      */
+    @Test
     public void testEncryptDecryptStringUsingCustomPassword() throws Exception
     {
         char[] myPassword = this.getService().createPassword("mysecret".toCharArray());
@@ -131,6 +135,7 @@ public class PBEServiceTest extends Base
      * Test encryption and decryption of binary data using the default password.
      * @throws Exception generic exception
      */
+    @Test
     public void testBinaryEncryptDecrypt() throws Exception
     {
         byte[] result;
@@ -163,6 +168,7 @@ public class PBEServiceTest extends Base
      * Test encryption/decryption based on streams.
      * @throws Exception generic exception
      */
+    @Test
     public void testStreamCiphers() throws Exception
     {
         byte[] cipherText;
@@ -192,6 +198,7 @@ public class PBEServiceTest extends Base
      * Test a few of the convinience methods.
      * @throws Exception generic exception
      */
+    @Test
     public void testConvinienceEncryption() throws Exception
     {
         String plainText = "Nobody knows the troubles I have seen ...";

Modified: turbine/fulcrum/trunk/resourcemanager/pom.xml
URL: http://svn.apache.org/viewvc/turbine/fulcrum/trunk/resourcemanager/pom.xml?rev=1888735&r1=1888734&r2=1888735&view=diff
==============================================================================
--- turbine/fulcrum/trunk/resourcemanager/pom.xml (original)
+++ turbine/fulcrum/trunk/resourcemanager/pom.xml Tue Apr 13 14:52:45 2021
@@ -15,7 +15,7 @@
 	<parent>
 		<artifactId>turbine-parent</artifactId>
 		<groupId>org.apache.turbine</groupId>
-		<version>6</version>
+		<version>8-SNAPSHOT</version>
 	</parent>
 
 	<modelVersion>4.0.0</modelVersion>