You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by co...@apache.org on 2018/06/29 17:03:49 UTC

[cxf] branch master updated: Flip the JDK version check to assume the stronger version by default. Also remove the (Synchronized) System.getProperty from the CryptoUtils

This is an automated email from the ASF dual-hosted git repository.

coheigea pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/cxf.git


The following commit(s) were added to refs/heads/master by this push:
     new 876f8d0  Flip the JDK version check to assume the stronger version by default. Also remove the (Synchronized) System.getProperty from the CryptoUtils
876f8d0 is described below

commit 876f8d0f0bf583373f86590c8ac77cf2b96a1518
Author: Colm O hEigeartaigh <co...@apache.org>
AuthorDate: Fri Jun 29 18:02:51 2018 +0100

    Flip the JDK version check to assume the stronger version by default. Also remove the (Synchronized) System.getProperty from the CryptoUtils
---
 .../main/java/org/apache/cxf/helpers/JavaUtils.java   | 19 ++++++++++++++++---
 .../apache/cxf/rt/security/crypto/CryptoUtils.java    | 11 +++--------
 2 files changed, 19 insertions(+), 11 deletions(-)

diff --git a/core/src/main/java/org/apache/cxf/helpers/JavaUtils.java b/core/src/main/java/org/apache/cxf/helpers/JavaUtils.java
index 93dc443..4c7ab9b 100644
--- a/core/src/main/java/org/apache/cxf/helpers/JavaUtils.java
+++ b/core/src/main/java/org/apache/cxf/helpers/JavaUtils.java
@@ -27,7 +27,7 @@ public final class JavaUtils {
 
     /** Use this character as suffix */
     static final char KEYWORD_PREFIX = '_';
-   
+
     /**
      * These are java keywords as specified at the following URL.
      * http://java.sun.com/docs/books/jls/third_edition/html/lexical.html#3.9
@@ -47,13 +47,21 @@ public final class JavaUtils {
     ));
 
     private static boolean isJava9Compatible;
-    
+    private static boolean isJava8Before161;
+
     static {
         String version = System.getProperty("java.version");
+        try {
+            isJava8Before161 = version != null && version.startsWith("1.8.0")
+                && Integer.parseInt(version.substring(6)) < 161;
+        } catch (NumberFormatException ex) {
+            isJava8Before161 = false;
+        }
+
         if (version.indexOf('.') > 0) {
             version = version.substring(0, version.indexOf('.'));
         }
-        
+
         setJava9Compatible(Integer.valueOf(version) >= 9);
     }
 
@@ -84,4 +92,9 @@ public final class JavaUtils {
     private static void setJava9Compatible(boolean java9Compatible) {
         JavaUtils.isJava9Compatible = java9Compatible;
     }
+
+    public static boolean isJava8Before161() {
+        return isJava8Before161;
+    }
+
 }
diff --git a/rt/security/src/main/java/org/apache/cxf/rt/security/crypto/CryptoUtils.java b/rt/security/src/main/java/org/apache/cxf/rt/security/crypto/CryptoUtils.java
index c6a899b..b3d2016 100644
--- a/rt/security/src/main/java/org/apache/cxf/rt/security/crypto/CryptoUtils.java
+++ b/rt/security/src/main/java/org/apache/cxf/rt/security/crypto/CryptoUtils.java
@@ -545,12 +545,11 @@ public final class CryptoUtils {
                 result = c.doFinal(bytes);
             } else {
                 if (blockSize == -1) {
-                    if (JavaUtils.isJava9Compatible() || isJava8Release161OrLater(System.getProperty("java.version"))) {
+                    if (JavaUtils.isJava8Before161()) {
+                        blockSize = secretKey instanceof PublicKey ? 117 : 128;
+                    } else {
                         //the default block size is 256 when use private key under java9
                         blockSize = secretKey instanceof PublicKey ? 117 : 256;
-                    } else {
-
-                        blockSize = secretKey instanceof PublicKey ? 117 : 128;
                     }
                 }
                 boolean updateRequired = keyProps != null && keyProps.getAdditionalData() != null;
@@ -575,10 +574,6 @@ public final class CryptoUtils {
         }
     }
 
-    private static boolean isJava8Release161OrLater(String javaVersion) {
-        return javaVersion.startsWith("1.8.0_") && Integer.parseInt(javaVersion.substring(6)) >= 161;
-    }
-
     public static Cipher initCipher(Key secretKey, KeyProperties keyProps, int mode)  throws SecurityException {
         try {
             String algorithm = keyProps != null && keyProps.getKeyAlgo() != null