3 Replies Latest reply on Jan 24, 2019 10:17 AM by dmjones

    Use a custom SSLSocketFactory in WildFly 10

    dmjones

      I would like WildFly 10 to use a bespoke SSLSocketFactory so that I can implement some funky TLS ciphersuites as part of security research.

       

      I've built a dummy factory that prints logs and passes them to the default provider. However, I can't get WildFly to use it.

       

      My current approach is to set the system property ssl.SocketFactory.provider to point at my class name, while dropping the JAR containing the class into standalone/lib/ext. I tried running the server with:

       

      standalone.sh -Dssl.SocketFactory.provider=<classname>

       

      But it doesn't appear to work. I see no log output and setting this to a nonsense value doesn't upset WildFly at all. I've also tried specifying this in the standalone/configuration/standalone.xml file:

       

      <server xmlns="urn:jboss:domain:4.0">

          <extensions>

              ...

          </extensions>

       

       

          <system-properties>

              <property name="ssl.SocketFactory.provider" value="<class name>"/>

          </system-properties>

       

      But the same thing happens. I also tried adding this to the bin/standalone.conf file, but no joy (although at least it printed my setting in the WildFly logs):

       

      if [ "x$JAVA_OPTS" = "x" ]; then

         JAVA_OPTS="-Xms64m -Xmx512m -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=256m -Djava.net.preferIPv4Stack=true"

         JAVA_OPTS="$JAVA_OPTS -Djboss.modules.system.pkgs=$JBOSS_MODULES_SYSTEM_PKGS -Djava.awt.headless=true"

         JAVA_OPTS="$JAVA_OPTS -Dssl.SocketFactory.provider=<class name>"

      else

        ...

       

      Can anyone advise how to approach this problem?

        • 1. Re: Use a custom SSLSocketFactory in WildFly 10
          mchoma

          ssl.SocketFactory.provider is security property not system property.

          1. So you should either configure directly in java.security file (if you are not JDK9+). example [1]

          2. Or you can set that in Elytron subsystem [2]

           

          There is chance elytron registers this system property too late. The first approach is safest.

           

          [1] IBM Knowledge Center

          [2] Security Property Migration - Latest WildFly Documentation - Project Documentation Editor

          1 of 1 people found this helpful
          • 2. Re: Use a custom SSLSocketFactory in WildFly 10
            dmjones

            Thanks for the pointers, Martin. Unfortunately, I still can't seem to get my provider loaded. Here's what I've tried:

             

            I added ssl.SocketFactory.provider=<my.class.name> to /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/security/java.security, on the basis that readlink -f `which java` pointed to /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java.

             

            I also enabled SSL debugging to see what's going on, by adding this line to my standalone.conf:

             

              JAVA_OPTS="$JAVA_OPTS -Djavax.net.debug=ssl

             

            The debugging output was produced, however I still saw no evidence of my code being used (it ought to be printing to stdout). I also can't see the log lines from this function https://hg.openjdk.java.net/jdk8/jdk8/jdk/file/687fd7c7986d/src/share/classes/javax/net/ssl/SSLSocketFactory.java#l88.

             

            I also tried adding my security property using this addition to my conf file:

             

              JAVA_OPTS="$JAVA_OPTS -Djavax.net.debug=ssl -Djava.security.properties=<path to a simple properties file>"

             

            but still no dice. It doesn't seem like WildFly is noticing my property. Or perhaps it's just ignoring it. I'd expect to see failures in the SSL logs if my class failed to load.

             

            I also wrote a quite Java file to test my provider is registered correctly:

             

            public static void main(String[] args) throws Exception {

              SocketFactory factory = SSLSocketFactory.getDefault();
               System.out.println(factory.getClass().getCanonicalName());
            }

             

            Executing this with java -Djavax.net.debug=ssl ... produced the expected results. I could see the log files indicating my provider was loaded, plus the outputs from my provider.

             

            Do you have any further suggestions to debug this? It seems like WildFly is not creating SSL sockets in the way I'm expecting and potentially ignoring my java.security settings.

            • 3. Re: Use a custom SSLSocketFactory in WildFly 10
              dmjones

              I've solved my problem by creating a security provider that implements "SSLContext.TLS". This provides me a hook to intercept how socket factories are constructed.

               

              By placing this provider at the top of the java.security providers list, I can intercept the things I need.