Skip to content

Commit

Permalink
Merge pull request #929 from AdoptOpenJDK/itw-922
Browse files Browse the repository at this point in the history
use reflection to call method with changed signature in Java 21
  • Loading branch information
janakmulani authored Dec 14, 2023
2 parents 51a7e3a + fdda861 commit d96e19d
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 d96e19d

Please sign in to comment.