Skip to content

Commit 5fc068c

Browse files
eirbjofl4via
authored andcommitted
[UNDERTOW-2645] Remove uses of classes in the 'javax.security.cert' package
1 parent 5b0918d commit 5fc068c

File tree

7 files changed

+6
-105
lines changed

7 files changed

+6
-105
lines changed

core/src/main/java/io/undertow/protocols/ssl/SNISSLEngine.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import javax.net.ssl.SSLPeerUnverifiedException;
3434
import javax.net.ssl.SSLSession;
3535
import javax.net.ssl.SSLSessionContext;
36-
import javax.security.cert.X509Certificate;
3736

3837
import io.undertow.UndertowMessages;
3938

@@ -257,10 +256,6 @@ public Certificate[] getLocalCertificates() {
257256
return null;
258257
}
259258

260-
public X509Certificate[] getPeerCertificateChain() throws SSLPeerUnverifiedException {
261-
throw new UnsupportedOperationException();
262-
}
263-
264259
public Principal getPeerPrincipal() throws SSLPeerUnverifiedException {
265260
throw new UnsupportedOperationException();
266261
}

core/src/main/java/io/undertow/server/BasicSSLSessionInfo.java

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424

2525
import javax.net.ssl.SSLPeerUnverifiedException;
2626
import javax.net.ssl.SSLSession;
27-
import javax.security.cert.CertificateException;
28-
import javax.security.cert.X509Certificate;
2927
import java.io.ByteArrayInputStream;
3028
import java.io.IOException;
3129
import java.nio.charset.StandardCharsets;
@@ -41,7 +39,6 @@ public class BasicSSLSessionInfo implements SSLSessionInfo {
4139
private final byte[] sessionId;
4240
private final String cypherSuite;
4341
private final java.security.cert.Certificate[] peerCertificate;
44-
private final X509Certificate[] certificate;
4542
private final Integer keySize;
4643
private final String secureProtocol;
4744

@@ -52,9 +49,8 @@ public class BasicSSLSessionInfo implements SSLSessionInfo {
5249
* @param certificate A string representation of the client certificate
5350
* @param keySize The key-size used by the cypher
5451
* @throws java.security.cert.CertificateException If the client cert could not be decoded
55-
* @throws CertificateException If the client cert could not be decoded
5652
*/
57-
public BasicSSLSessionInfo(byte[] sessionId, String cypherSuite, String certificate, Integer keySize) throws java.security.cert.CertificateException, CertificateException {
53+
public BasicSSLSessionInfo(byte[] sessionId, String cypherSuite, String certificate, Integer keySize) throws java.security.cert.CertificateException {
5854
this(sessionId, cypherSuite, certificate, keySize, null);
5955
}
6056

@@ -66,9 +62,8 @@ public BasicSSLSessionInfo(byte[] sessionId, String cypherSuite, String certific
6662
* @param keySize The key-size used by the cypher
6763
* @param secureProtocol the secure protocol, example {@code TLSv1.2}
6864
* @throws java.security.cert.CertificateException If the client cert could not be decoded
69-
* @throws CertificateException If the client cert could not be decoded
7065
*/
71-
public BasicSSLSessionInfo(byte[] sessionId, String cypherSuite, String certificate, Integer keySize, String secureProtocol) throws java.security.cert.CertificateException, CertificateException {
66+
public BasicSSLSessionInfo(byte[] sessionId, String cypherSuite, String certificate, Integer keySize, String secureProtocol) throws java.security.cert.CertificateException {
7267
this.sessionId = sessionId;
7368
this.cypherSuite = cypherSuite;
7469
this.keySize = keySize;
@@ -79,26 +74,13 @@ public BasicSSLSessionInfo(byte[] sessionId, String cypherSuite, String certific
7974
ByteArrayInputStream stream = new ByteArrayInputStream(certificateBytes);
8075
Collection<? extends java.security.cert.Certificate> certCol = cf.generateCertificates(stream);
8176
this.peerCertificate = new java.security.cert.Certificate[certCol.size()];
82-
X509Certificate[] legacyCertificate = new X509Certificate[certCol.size()];
8377
int i=0;
8478
for(java.security.cert.Certificate cert : certCol) {
8579
this.peerCertificate[i] = cert;
86-
if (legacyCertificate != null) {
87-
try {
88-
legacyCertificate[i] = X509Certificate.getInstance(cert.getEncoded());
89-
} catch (CertificateException ce) {
90-
// [UNDERTOW-1969] We don't care about deprecated JDK methods failure caused by the fact newer JDKs
91-
// doesn't support them anymore. "this.certificate" is used only by deprecated method
92-
// {@link SSLSessionInfo.getPeerCertificateChain()} which call should be avoided by API users.
93-
legacyCertificate = null;
94-
}
95-
}
9680
i++;
9781
}
98-
this.certificate = legacyCertificate;
9982
} else {
10083
this.peerCertificate = null;
101-
this.certificate = null;
10284
}
10385
}
10486

@@ -108,9 +90,8 @@ public BasicSSLSessionInfo(byte[] sessionId, String cypherSuite, String certific
10890
* @param cypherSuite The cypher suite name
10991
* @param certificate A string representation of the client certificate
11092
* @throws java.security.cert.CertificateException If the client cert could not be decoded
111-
* @throws CertificateException If the client cert could not be decoded
11293
*/
113-
public BasicSSLSessionInfo(byte[] sessionId, String cypherSuite, String certificate) throws java.security.cert.CertificateException, CertificateException {
94+
public BasicSSLSessionInfo(byte[] sessionId, String cypherSuite, String certificate) throws java.security.cert.CertificateException {
11495
this(sessionId, cypherSuite, certificate, null);
11596
}
11697

@@ -120,9 +101,8 @@ public BasicSSLSessionInfo(byte[] sessionId, String cypherSuite, String certific
120101
* @param cypherSuite The cypher suite name
121102
* @param certificate A string representation of the client certificate
122103
* @throws java.security.cert.CertificateException If the client cert could not be decoded
123-
* @throws CertificateException If the client cert could not be decoded
124104
*/
125-
public BasicSSLSessionInfo(String sessionId, String cypherSuite, String certificate) throws java.security.cert.CertificateException, CertificateException {
105+
public BasicSSLSessionInfo(String sessionId, String cypherSuite, String certificate) throws java.security.cert.CertificateException {
126106
this(sessionId == null ? null : fromHex(sessionId), cypherSuite, certificate, null);
127107
}
128108

@@ -133,9 +113,8 @@ public BasicSSLSessionInfo(String sessionId, String cypherSuite, String certific
133113
* @param certificate A string representation of the client certificate
134114
* @param keySize The key-size used by the cypher
135115
* @throws java.security.cert.CertificateException If the client cert could not be decoded
136-
* @throws CertificateException If the client cert could not be decoded
137116
*/
138-
public BasicSSLSessionInfo(String sessionId, String cypherSuite, String certificate, Integer keySize) throws java.security.cert.CertificateException, CertificateException {
117+
public BasicSSLSessionInfo(String sessionId, String cypherSuite, String certificate, Integer keySize) throws java.security.cert.CertificateException {
139118
this(sessionId == null ? null : fromHex(sessionId), cypherSuite, certificate, keySize);
140119
}
141120

@@ -147,9 +126,8 @@ public BasicSSLSessionInfo(String sessionId, String cypherSuite, String certific
147126
* @param keySize The key-size used by the cypher
148127
* @param secureProtocol the secure protocol, example {@code TLSv1.2}
149128
* @throws java.security.cert.CertificateException If the client cert could not be decoded
150-
* @throws CertificateException If the client cert could not be decoded
151129
*/
152-
public BasicSSLSessionInfo(String sessionId, String cypherSuite, String certificate, Integer keySize, String secureProtocol) throws java.security.cert.CertificateException, CertificateException {
130+
public BasicSSLSessionInfo(String sessionId, String cypherSuite, String certificate, Integer keySize, String secureProtocol) throws java.security.cert.CertificateException {
153131
this(sessionId == null ? null : fromHex(sessionId), cypherSuite, certificate, keySize, secureProtocol);
154132
}
155133

@@ -185,15 +163,6 @@ public java.security.cert.Certificate[] getPeerCertificates() throws SSLPeerUnve
185163
return peerCertificate;
186164
}
187165

188-
@Deprecated
189-
@Override
190-
public X509Certificate[] getPeerCertificateChain() throws SSLPeerUnverifiedException {
191-
if (certificate == null) {
192-
throw UndertowMessages.MESSAGES.peerUnverified();
193-
}
194-
return certificate;
195-
}
196-
197166
@Override
198167
public void renegotiate(HttpServerExchange exchange, SslClientAuthMode sslClientAuthMode) throws IOException {
199168
throw UndertowMessages.MESSAGES.renegotiationNotSupported();

core/src/main/java/io/undertow/server/ConnectionSSLSessionInfo.java

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
import javax.net.ssl.SSLPeerUnverifiedException;
2727
import javax.net.ssl.SSLSession;
28-
import javax.security.cert.X509Certificate;
2928

3029
import org.xnio.ChannelListener;
3130
import org.xnio.IoUtils;
@@ -98,32 +97,6 @@ public Certificate[] getPeerCertificates() throws SSLPeerUnverifiedException, Re
9897
}
9998
}
10099

101-
@Override
102-
@Deprecated(since="2.2.3", forRemoval=false)
103-
public X509Certificate[] getPeerCertificateChain() throws SSLPeerUnverifiedException, RenegotiationRequiredException {
104-
if (unverified != null) {
105-
throw unverified;
106-
}
107-
if (renegotiationRequiredException != null) {
108-
throw renegotiationRequiredException;
109-
}
110-
try {
111-
return channel.getSslSession().getPeerCertificateChain();
112-
} catch (SSLPeerUnverifiedException e) {
113-
try {
114-
SslClientAuthMode sslClientAuthMode = channel.getOption(Options.SSL_CLIENT_AUTH_MODE);
115-
if (sslClientAuthMode == SslClientAuthMode.NOT_REQUESTED) {
116-
renegotiationRequiredException = RENEGOTIATION_REQUIRED_EXCEPTION;
117-
throw renegotiationRequiredException;
118-
}
119-
} catch (IOException ioe) {
120-
// ignore, will not actually happen
121-
}
122-
unverified = PEER_UNVERIFIED_EXCEPTION;
123-
throw unverified;
124-
}
125-
}
126-
127100
@Override
128101
public void renegotiate(HttpServerExchange exchange, SslClientAuthMode sslClientAuthMode) throws IOException {
129102
if ("TLSv1.3".equals(channel.getSslSession().getProtocol())) {

core/src/main/java/io/undertow/server/SSLSessionInfo.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,6 @@ default int getKeySize() {
100100
*/
101101
java.security.cert.Certificate[] getPeerCertificates() throws javax.net.ssl.SSLPeerUnverifiedException, RenegotiationRequiredException;
102102

103-
/**
104-
* This method is no longer supported on java 15 and should be avoided.
105-
* @deprecated in favor of {@link #getPeerCertificates()} because {@link SSLSession#getPeerCertificateChain()}
106-
* throws java 15.
107-
* @see SSLSession#getPeerCertificateChain()
108-
*/
109-
@Deprecated(since="2.2.3", forRemoval=false)
110-
javax.security.cert.X509Certificate[] getPeerCertificateChain() throws javax.net.ssl.SSLPeerUnverifiedException, RenegotiationRequiredException;
111-
112103
/**
113104
* Renegotiate in a blocking manner. This will set the client aut
114105
*

core/src/main/java/io/undertow/server/protocol/ajp/AjpRequestParseState.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,6 @@ BasicSSLSessionInfo createSslSessionInfo() {
128128
return new BasicSSLSessionInfo(sessionId, cypher, cert, keySize);
129129
} catch (CertificateException e) {
130130
return null;
131-
} catch (javax.security.cert.CertificateException e) {
132-
return null;
133131
}
134132
}
135133

core/src/main/java/io/undertow/server/protocol/http2/Http2SslSessionInfo.java

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.security.cert.Certificate;
2323
import javax.net.ssl.SSLPeerUnverifiedException;
2424
import javax.net.ssl.SSLSession;
25-
import javax.security.cert.X509Certificate;
2625
import org.xnio.Options;
2726
import org.xnio.SslClientAuthMode;
2827

@@ -70,24 +69,6 @@ public Certificate[] getPeerCertificates() throws SSLPeerUnverifiedException, Re
7069
}
7170
}
7271

73-
@Override
74-
public X509Certificate[] getPeerCertificateChain()
75-
throws SSLPeerUnverifiedException, RenegotiationRequiredException {
76-
try {
77-
return channel.getSslSession().getPeerCertificateChain();
78-
} catch (SSLPeerUnverifiedException e) {
79-
try {
80-
SslClientAuthMode sslClientAuthMode = channel.getOption(Options.SSL_CLIENT_AUTH_MODE);
81-
if (sslClientAuthMode == SslClientAuthMode.NOT_REQUESTED) {
82-
throw new RenegotiationRequiredException();
83-
}
84-
} catch (IOException e1) {
85-
// ignore, will not actually happen
86-
}
87-
throw e;
88-
}
89-
}
90-
9172
@Override
9273
public void renegotiate(HttpServerExchange exchange, SslClientAuthMode sslClientAuthMode) throws IOException {
9374
throw UndertowMessages.MESSAGES.renegotiationNotSupported();

core/src/main/java/io/undertow/util/Certificates.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,6 @@ public class Certificates {
2828

2929
public static final String END_CERT = "-----END CERTIFICATE-----";
3030

31-
@Deprecated (since = "2.3.0", forRemoval=true)
32-
public static String toPem(final javax.security.cert.X509Certificate certificate)
33-
throws javax.security.cert.CertificateEncodingException {
34-
return toPem(certificate.getEncoded());
35-
}
36-
3731
/**
3832
* Converts a certificate to PEM format.
3933
* @param certificate the Certificate to recode

0 commit comments

Comments
 (0)