Skip to content

Commit

Permalink
Make downcast compatible with JDK9+
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Scheel <ascheel@redhat.com>
  • Loading branch information
cipherboy committed May 1, 2020
1 parent d92053d commit 971ffdd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
6 changes: 6 additions & 0 deletions 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 @@ -55,6 +56,11 @@ public JSSParameters(SSLParameters downcast) {
if (downcast.getNeedClientAuth()) {
setNeedClientAuth(downcast.getNeedClientAuth());
}

String[] alpn = JDKCompat.SSLParametersHelper.getApplicationProtocols(downcast);
if (alpn != null) {
setApplicationProtocols(alpn);
}
}

public JSSParameters(String[] cipherSuites) {
Expand Down
21 changes: 21 additions & 0 deletions org/mozilla/jss/util/JDKCompat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
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);
if (result instanceof String[]) {
return (String[]) result;
}
} catch (Throwable t) {}

return null;
}
}
}

0 comments on commit 971ffdd

Please sign in to comment.