Skip to content

Commit

Permalink
JDK 21 support (#673)
Browse files Browse the repository at this point in the history
  • Loading branch information
vharseko authored Oct 24, 2023
1 parent f4a878b commit b35950d
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
java: [ '8', '11', '17', '19' ]
java: [ '8', '11', '17', '21' ]
os: [ 'ubuntu-latest', 'macos-latest', 'windows-latest' ]
fail-fast: false
steps:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.cert.CertificateFactory;
import java.security.cert.X509CRL;
import java.security.cert.X509Certificate;
Expand Down Expand Up @@ -68,6 +70,7 @@
import sun.security.util.DerValue;
import sun.security.util.ObjectIdentifier;
import sun.security.x509.CertificateExtensions;
import sun.security.x509.DistributionPoint;
import sun.security.x509.GeneralName;
import sun.security.x509.GeneralNameInterface;
import sun.security.x509.GeneralNames;
Expand Down Expand Up @@ -564,16 +567,53 @@ private void getTokenFromSubjectAltExt(X509Certificate cert)
new X509CertImpl(cert.getEncoded());
X509CertInfo cinfo =
new X509CertInfo(certImpl.getTBSCertificate());
CertificateExtensions exts = (CertificateExtensions)
cinfo.get(X509CertInfo.EXTENSIONS);
SubjectAlternativeNameExtension altNameExt =
(SubjectAlternativeNameExtension)
exts.get(SubjectAlternativeNameExtension.NAME);

CertificateExtensions exts=null;
//exts = (CertificateExtensions)cinfo.get(X509CertInfo.EXTENSIONS);
try {//jdk21
Method m=cinfo.getClass().getDeclaredMethod("getExtensions");
exts = (CertificateExtensions)m.invoke(cinfo);
}
catch (NoSuchMethodException|InvocationTargetException e) {
try {
Method m=cinfo.getClass().getDeclaredMethod("get",String.class);
exts = (CertificateExtensions)m.invoke(cinfo,X509CertInfo.EXTENSIONS);
}
catch (NoSuchMethodException|InvocationTargetException e2) {
throw new RuntimeException(e2);
}
}

SubjectAlternativeNameExtension altNameExt=null;
//altNameExt = (SubjectAlternativeNameExtension)exts.get(SubjectAlternativeNameExtension.NAME);
try {//jdk21
Method m=exts.getClass().getDeclaredMethod("getExtension",String.class);
altNameExt = (SubjectAlternativeNameExtension)m.invoke(exts,SubjectAlternativeNameExtension.NAME);
}
catch (NoSuchMethodException|InvocationTargetException e) {
try {//jdk21
Method m=exts.getClass().getDeclaredMethod("get",String.class);
altNameExt = (SubjectAlternativeNameExtension)m.invoke(exts,SubjectAlternativeNameExtension.NAME);
}
catch (NoSuchMethodException|InvocationTargetException e2) {
throw new RuntimeException(e2);
}
}
if (altNameExt != null) {
GeneralNames names = (GeneralNames) altNameExt.get
(SubjectAlternativeNameExtension.SUBJECT_NAME);

GeneralNames names=null;
//names = (GeneralNames) altNameExt.get(SubjectAlternativeNameExtension.SUBJECT_NAME);
try {
Method m=altNameExt.getClass().getDeclaredMethod("getNames");
names = (GeneralNames)m.invoke(altNameExt);
}
catch (NoSuchMethodException|InvocationTargetException e) {
try {
Method m=altNameExt.getClass().getDeclaredMethod("get",String.class);
names = (GeneralNames)m.invoke(altNameExt,"SubjectAlternativeName");
}
catch (NoSuchMethodException|InvocationTargetException e2) {
throw new RuntimeException(e2);
}
}
GeneralName generalname = null;
Iterator itr = (Iterator) names.iterator();
while ((userTokenId == null) && itr.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.GeneralSecurityException;
Expand Down Expand Up @@ -362,17 +364,30 @@ private IssuingDistributionPointExtension getCRLIDPExt(X509CRL crl) {
*
* @param dpExt
*/
private synchronized X509CRL
@SuppressWarnings("unchecked")
private synchronized X509CRL
getUpdateCRLFromCrlDP(CRLDistributionPointsExtension dpExt) {
// Get CRL Distribution points
if (dpExt == null) {
return null;
}

List dps = null;
List<DistributionPoint> dps = null;
try {
dps = (List) dpExt.get(CRLDistributionPointsExtension.POINTS);
} catch (IOException ioex) {
try { //jdk21
Method m=dpExt.getClass().getDeclaredMethod("getDistributionPoints");
dps = (List<DistributionPoint>)m.invoke(dpExt);
}
catch (NoSuchMethodException|InvocationTargetException e) {
try {
Method m=dpExt.getClass().getDeclaredMethod("get",String.class);
dps = (List<DistributionPoint>)m.invoke(dpExt,"points");
}
catch (NoSuchMethodException|InvocationTargetException e2) {
throw new RuntimeException(e2);
}
}
} catch (Throwable ioex) {
if (debug.warningEnabled()) {
debug.warning("AMCRLStore.getUpdateCRLFromCrlDP: ", ioex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ public SimpleTaskExecutor answer(InvocationOnMock invocation) throws Throwable {

// Then
debug("Waiting for tasks to complete");
task1.join(TimeUnit.SECONDS.toMillis(10));
task2.join(TimeUnit.SECONDS.toMillis(10));
task3.join(TimeUnit.SECONDS.toMillis(10));
task1.join(TimeUnit.SECONDS.toMillis(100));
task2.join(TimeUnit.SECONDS.toMillis(100));
task3.join(TimeUnit.SECONDS.toMillis(100));

assertThat(task1.isAlive()).as("Task 1 thread running").isFalse();
assertThat(task2.isAlive()).as("Task 2 thread running").isFalse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,13 @@
package com.iplanet.security.x509;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import java.util.*;


import sun.security.util.BitArray;
import sun.security.util.DerInputStream;
import sun.security.util.DerOutputStream;
import sun.security.util.DerValue;
import sun.security.util.ObjectIdentifier;
import sun.security.x509.AVA;
import sun.security.x509.Extension;
import sun.security.x509.GeneralNames;
Expand Down Expand Up @@ -162,7 +158,7 @@ public class IssuingDistributionPointExtension extends Extension {


// cached hashCode value
private volatile int hashCode;
//private volatile int hashCode;


/**
Expand Down Expand Up @@ -432,15 +428,19 @@ public void setIndirectCRL(boolean indirectCRL) {
* @param out the DerOutputStream to write the extension to.
* @exception IOException on encoding errors.
*/
public void encode(OutputStream out) throws IOException {
DerOutputStream tmp = new DerOutputStream();
if (this.extensionValue == null) {
this.extensionId = PKIXExtensions.IssuingDistributionPoint_Id;
this.critical = true;
encodeThis();
}
super.encode(tmp);
out.write(tmp.toByteArray());
public void encode(DerOutputStream out) {
try {
DerOutputStream tmp = new DerOutputStream();
if (this.extensionValue == null) {
this.extensionId = PKIXExtensions.IssuingDistributionPoint_Id;
this.critical = true;
encodeThis();
}
super.encode(tmp);
out.write(tmp.toByteArray());
}catch(IOException e) {
throw new RuntimeException(e);
}
}

// Encode this extension value
Expand Down Expand Up @@ -571,7 +571,7 @@ private static AVA[] derValueToAVAs(DerValue derValue)
private static void encodeRDN(RDN rdn, DerOutputStream derOut)
throws IOException {

List avas = rdn.avas();
List<AVA> avas = rdn.avas();
AVA[] avaArray = (AVA[])avas.toArray(new AVA[avas.size()]);
derOut.putOrderedSetOf(DerValue.tag_Set, avaArray);
}
Expand Down
13 changes: 6 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1233,13 +1233,13 @@
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-jsr223</artifactId>
<version>3.0.13</version>
<version>3.0.19</version>
</dependency>
<!-- Groovy JSON parsing support -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-json</artifactId>
<version>3.0.13</version>
<version>3.0.19</version>
</dependency>
<dependency>
<!-- MIT licensed: http://groovy-sandbox.kohsuke.org/license.html -->
Expand Down Expand Up @@ -1718,10 +1718,10 @@
</dependency>
<!-- Powermock -->
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.12.19</version>
<scope>test</scope>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.14.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
Expand Down Expand Up @@ -2097,7 +2097,6 @@
<configuration>
<argLine>${java.surefire.options}</argLine>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<forkMode>once</forkMode>
</configuration>
<executions>
<execution>
Expand Down

0 comments on commit b35950d

Please sign in to comment.