You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2018/10/30 09:00:33 UTC

svn commit: r1845203 - /tomcat/trunk/java/org/apache/catalina/tribes/group/interceptors/EncryptInterceptor.java

Author: markt
Date: Tue Oct 30 09:00:33 2018
New Revision: 1845203

URL: http://svn.apache.org/viewvc?rev=1845203&view=rev
Log:
Copy code to avoid unwanted dependency.

Modified:
    tomcat/trunk/java/org/apache/catalina/tribes/group/interceptors/EncryptInterceptor.java

Modified: tomcat/trunk/java/org/apache/catalina/tribes/group/interceptors/EncryptInterceptor.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/tribes/group/interceptors/EncryptInterceptor.java?rev=1845203&r1=1845202&r2=1845203&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/tribes/group/interceptors/EncryptInterceptor.java (original)
+++ tomcat/trunk/java/org/apache/catalina/tribes/group/interceptors/EncryptInterceptor.java Tue Oct 30 09:00:33 2018
@@ -35,7 +35,7 @@ import org.apache.catalina.tribes.io.XBy
 import org.apache.catalina.tribes.util.StringManager;
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
-import org.apache.tomcat.util.buf.HexUtils;
+
 
 /**
  * Adds encryption using a pre-shared key.
@@ -196,10 +196,11 @@ public class EncryptInterceptor extends
      * @param keyBytes The encryption key.
      */
     public void setEncryptionKey(String keyBytes) {
-        if(null == keyBytes)
+        if (null == keyBytes) {
             setEncryptionKey((byte[])null);
-        else
-            setEncryptionKey(HexUtils.fromHexString(keyBytes.trim()));
+        } else {
+            setEncryptionKey(fromHexString(keyBytes.trim()));
+        }
     }
 
     /**
@@ -361,4 +362,49 @@ public class EncryptInterceptor extends
     private byte[] decrypt(byte[] bytes) throws IllegalBlockSizeException, BadPaddingException {
         return getDecryptionCipher().doFinal(bytes);
     }
+
+
+    // Copied from org.apache.tomcat.util.buf.HexUtils
+
+    private static final int[] DEC = {
+        00, 01, 02, 03, 04, 05, 06, 07,  8,  9, -1, -1, -1, -1, -1, -1,
+        -1, 10, 11, 12, 13, 14, 15, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+        -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
+        -1, 10, 11, 12, 13, 14, 15,
+    };
+
+
+    private static int getDec(int index) {
+        // Fast for correct values, slower for incorrect ones
+        try {
+            return DEC[index - '0'];
+        } catch (ArrayIndexOutOfBoundsException ex) {
+            return -1;
+        }
+    }
+
+
+    private static byte[] fromHexString(String input) {
+        if (input == null) {
+            return null;
+        }
+
+        if ((input.length() & 1) == 1) {
+            // Odd number of characters
+            throw new IllegalArgumentException(sm.getString("hexUtils.fromHex.oddDigits"));
+        }
+
+        char[] inputChars = input.toCharArray();
+        byte[] result = new byte[input.length() >> 1];
+        for (int i = 0; i < result.length; i++) {
+            int upperNibble = getDec(inputChars[2*i]);
+            int lowerNibble =  getDec(inputChars[2*i + 1]);
+            if (upperNibble < 0 || lowerNibble < 0) {
+                // Non hex character
+                throw new IllegalArgumentException(sm.getString("hexUtils.fromHex.nonHex"));
+            }
+            result[i] = (byte) ((upperNibble << 4) + lowerNibble);
+        }
+        return result;
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r1845203 - /tomcat/trunk/java/org/apache/catalina/tribes/group/interceptors/EncryptInterceptor.java

Posted by Mark Thomas <ma...@apache.org>.
On 30/10/18 09:29, Rémy Maucherat wrote:
> On Tue, Oct 30, 2018 at 10:02 AM Mark Thomas <ma...@apache.org> wrote:
> 
>> On 30/10/18 09:00, markt@apache.org wrote:
>>> Author: markt
>>> Date: Tue Oct 30 09:00:33 2018
>>> New Revision: 1845203
>>>
>>> URL: http://svn.apache.org/viewvc?rev=1845203&view=rev
>>> Log:
>>> Copy code to avoid unwanted dependency.
>>
>> The other option is to add a dependency to tomcat-util.jar. Copying a
>> small amount of code seemed like the better solution but it wouldn't
>> take much to convince me to add the dependency. Thoughts?
>>
>>
> I noticed tribes did not have any real dependencies, but for cloud I added
> some to tomcat.util: the json parser and the pem file. I'll remove
> StringUtils, it's not super useful.
> Is tribes actually used standalone ?

I've seen the odd user question that suggests that there are a small
number of users that use it standalone but I'd guess the numbers are
very small.

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r1845203 - /tomcat/trunk/java/org/apache/catalina/tribes/group/interceptors/EncryptInterceptor.java

Posted by Rémy Maucherat <re...@apache.org>.
On Tue, Oct 30, 2018 at 10:02 AM Mark Thomas <ma...@apache.org> wrote:

> On 30/10/18 09:00, markt@apache.org wrote:
> > Author: markt
> > Date: Tue Oct 30 09:00:33 2018
> > New Revision: 1845203
> >
> > URL: http://svn.apache.org/viewvc?rev=1845203&view=rev
> > Log:
> > Copy code to avoid unwanted dependency.
>
> The other option is to add a dependency to tomcat-util.jar. Copying a
> small amount of code seemed like the better solution but it wouldn't
> take much to convince me to add the dependency. Thoughts?
>
>
I noticed tribes did not have any real dependencies, but for cloud I added
some to tomcat.util: the json parser and the pem file. I'll remove
StringUtils, it's not super useful.
Is tribes actually used standalone ?

Rémy

Re: svn commit: r1845203 - /tomcat/trunk/java/org/apache/catalina/tribes/group/interceptors/EncryptInterceptor.java

Posted by Mark Thomas <ma...@apache.org>.
On 30/10/18 09:00, markt@apache.org wrote:
> Author: markt
> Date: Tue Oct 30 09:00:33 2018
> New Revision: 1845203
> 
> URL: http://svn.apache.org/viewvc?rev=1845203&view=rev
> Log:
> Copy code to avoid unwanted dependency.

The other option is to add a dependency to tomcat-util.jar. Copying a
small amount of code seemed like the better solution but it wouldn't
take much to convince me to add the dependency. Thoughts?

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org