From f650ea788df8067baa4267ac4df806ba1bff1853 Mon Sep 17 00:00:00 2001 From: Mark Thomas Date: Tue, 5 Sep 2023 11:22:49 +0100 Subject: [PATCH] Simplify code. Based on PR #651 by wonyongChoi05 --- java/org/apache/coyote/ajp/AjpProcessor.java | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/java/org/apache/coyote/ajp/AjpProcessor.java b/java/org/apache/coyote/ajp/AjpProcessor.java index ccf2e78ba1d5..9b6063ef3332 100644 --- a/java/org/apache/coyote/ajp/AjpProcessor.java +++ b/java/org/apache/coyote/ajp/AjpProcessor.java @@ -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; @@ -1131,10 +1133,10 @@ protected final void populateRequestAttributeRemoteHost() { @Override protected final void populateSslRequestAttributes() { if (!certificates.isNull()) { + List 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; @@ -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])); } }