cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dk...@apache.org
Subject svn commit: r1212156 - /cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/configuration/jsse/spring/TLSParameterJaxBUtils.java
Date Thu, 08 Dec 2011 22:00:09 GMT
Author: dkulp
Date: Thu Dec  8 22:00:09 2011
New Revision: 1212156

URL: http://svn.apache.org/viewvc?rev=1212156&view=rev
Log:
[CXF-3895] Support for the Jetty OBF: prefixed passwords

Modified:
    cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/configuration/jsse/spring/TLSParameterJaxBUtils.java

Modified: cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/configuration/jsse/spring/TLSParameterJaxBUtils.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/configuration/jsse/spring/TLSParameterJaxBUtils.java?rev=1212156&r1=1212155&r2=1212156&view=diff
==============================================================================
--- cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/configuration/jsse/spring/TLSParameterJaxBUtils.java
(original)
+++ cxf/trunk/rt/transports/http/src/main/java/org/apache/cxf/configuration/jsse/spring/TLSParameterJaxBUtils.java
Thu Dec  8 22:00:09 2011
@@ -103,7 +103,7 @@ public final class TLSParameterJaxBUtils
                     : KeyStore.getDefaultType();
 
         char[] password = kst.isSetPassword()
-                    ? kst.getPassword().toCharArray()
+                    ? deobfuscate(kst.getPassword())
                     : null;
 
         KeyStore keyStore = !kst.isSetProvider()
@@ -193,6 +193,26 @@ public final class TLSParameterJaxBUtils
         return factory.generateCertificates(is);
     }
 
+    private static char[] deobfuscate(String s) {
+        // From the Jetty org.eclipse.jetty.http.security.Password class
+        if (!s.startsWith("OBF:")) {
+            return s.toCharArray();
+        }
+        s = s.substring(4);
+
+        char[] b = new char[s.length() / 2];
+        int l = 0;
+        for (int i = 0; i < s.length(); i += 4) {
+            String x = s.substring(i, i + 4);
+            int i0 = Integer.parseInt(x, 36);
+            int i1 = i0 / 256;
+            int i2 = i0 % 256;
+            b[l++] = (char) ((i1 + i2 - 254) / 2);
+        }
+
+        return new String(b, 0, l).toCharArray();
+    }    
+    
     /**
      * This method converts the JAXB KeyManagersType into a list of
      * JSSE KeyManagers.
@@ -212,7 +232,7 @@ public final class TLSParameterJaxBUtils
                      : KeyManagerFactory.getDefaultAlgorithm();
 
         char[] keyPass = kmc.isSetKeyPassword()
-                     ? kmc.getKeyPassword().toCharArray()
+                     ? deobfuscate(kmc.getKeyPassword())
                      : null;
 
         KeyManagerFactory fac =



Mime
View raw message