Skip to content

Commit

Permalink
use reflection to call method with changed signature in Java 21
Browse files Browse the repository at this point in the history
  • Loading branch information
sclassen committed Dec 5, 2023
1 parent 758e702 commit fdda861
Showing 1 changed file with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.security.CodeSigner;
import java.security.KeyStore;
import java.security.Timestamp;
Expand All @@ -64,6 +65,7 @@
import java.util.regex.Pattern;
import java.util.zip.ZipException;

import static java.lang.Boolean.TRUE;
import static java.time.temporal.ChronoUnit.MONTHS;

/**
Expand Down Expand Up @@ -609,7 +611,7 @@ private void checkCertUsage(final CertPath certPath, final X509Certificate userC

final NetscapeCertTypeExtension extn = new NetscapeCertTypeExtension(encoded);

if (!extn.get(NetscapeCertTypeExtension.OBJECT_SIGNING)) {
if (!hasObjectSigningExtension(extn)) {
certs.get(certPath).setBadNetscapeCertType();
}
}
Expand All @@ -618,6 +620,18 @@ private void checkCertUsage(final CertPath certPath, final X509Certificate userC
}
}

private static boolean hasObjectSigningExtension(NetscapeCertTypeExtension extn) throws IOException {
// method return type of "NetscapeCertTypeExtension.get()" has changed from Boolean to boolean with Java 21
try {
final Method getMethod = NetscapeCertTypeExtension.class.getDeclaredMethod("get", String.class);
final Object result = getMethod.invoke(extn, NetscapeCertTypeExtension.OBJECT_SIGNING);
return result == TRUE;
} catch (Exception e) {
LOG.error("Failed to get object_signing from extension", e);
return false;
}
}

/**
* Returns if all jars are signed.
*
Expand Down

0 comments on commit fdda861

Please sign in to comment.