Skip to content

Commit

Permalink
Simplify code. Based on PR #651 by wonyongChoi05
Browse files Browse the repository at this point in the history
  • Loading branch information
markt-asf committed Sep 5, 2023
1 parent 3cbca9c commit f650ea7
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions java/org/apache/coyote/ajp/AjpProcessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -1131,10 +1133,10 @@ protected final void populateRequestAttributeRemoteHost() {
@Override
protected final void populateSslRequestAttributes() {
if (!certificates.isNull()) {
List<X509Certificate> jsseCerts = new ArrayList<>();
ByteChunk certData = certificates.getByteChunk();
X509Certificate jsseCerts[] = null;
ByteArrayInputStream bais = new ByteArrayInputStream(certData.getBytes(), certData.getStart(),
certData.getLength());
ByteArrayInputStream bais =
new ByteArrayInputStream(certData.getBytes(), certData.getStart(), certData.getLength());
// Fill the elements.
try {
CertificateFactory cf;
Expand All @@ -1146,21 +1148,13 @@ protected final void populateSslRequestAttributes() {
}
while (bais.available() > 0) {
X509Certificate cert = (X509Certificate) cf.generateCertificate(bais);
if (jsseCerts == null) {
jsseCerts = new X509Certificate[1];
jsseCerts[0] = cert;
} else {
X509Certificate[] temp = new X509Certificate[jsseCerts.length + 1];
System.arraycopy(jsseCerts, 0, temp, 0, jsseCerts.length);
temp[jsseCerts.length] = cert;
jsseCerts = temp;
}
jsseCerts.add(cert);
}
} catch (CertificateException | NoSuchProviderException e) {
getLog().error(sm.getString("ajpprocessor.certs.fail"), e);
return;
}
request.setAttribute(SSLSupport.CERTIFICATE_KEY, jsseCerts);
request.setAttribute(SSLSupport.CERTIFICATE_KEY, jsseCerts.toArray(new X509Certificate[0]));
}
}

Expand Down

0 comments on commit f650ea7

Please sign in to comment.