Skip to content

Commit

Permalink
Introduce JDK8+ compatibility layer
Browse files Browse the repository at this point in the history
ALPN support merged in JDK9 and will eventually be backported into JDK8.
However, not every consumer of JSS will necessarily upgrade to a newer
JDK8 version. While support has landed upstream, Fedora 32 and Fedora 33
haven't yet seen a backport yet. This likely means that RHEL also won't
see a backport.

Introduce a small reflection-based compatibility layer to see if the
class supports ALPN and if so, use the value from it.

Signed-off-by: Alexander Scheel <[email protected]>
  • Loading branch information
cipherboy committed Oct 6, 2020
1 parent b3fbd05 commit 2b9b4e4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion org/mozilla/jss/ssl/javax/JSSParameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import javax.net.ssl.*;
import java.util.*;

import org.mozilla.jss.util.JDKCompat;
import org.mozilla.jss.ssl.*;

/**
Expand Down Expand Up @@ -56,7 +57,7 @@ public JSSParameters(SSLParameters downcast) {
setNeedClientAuth(downcast.getNeedClientAuth());
}

String[] alpn = downcast.getApplicationProtocols(downcast);
String[] alpn = JDKCompat.SSLParametersHelper.getApplicationProtocols(downcast);
if (alpn != null) {
setApplicationProtocols(alpn);
}
Expand Down
22 changes: 22 additions & 0 deletions org/mozilla/jss/util/JDKCompat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

package org.mozilla.jss.util;

import java.lang.reflect.Method;

import javax.net.ssl.SSLParameters;

public class JDKCompat {
public static class SSLParametersHelper {
public static String[] getApplicationProtocols(SSLParameters inst) {
try {
Method getter = inst.getClass().getMethod("getApplicationProtocols");
Object result = getter.invoke(inst);
return (String[]) result;
} catch (NoSuchMethodException nsme) {
return null;
} catch (Throwable t) {
throw new RuntimeException(t.getMessage(), t);
}
}
}
}

0 comments on commit 2b9b4e4

Please sign in to comment.