GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Merge commit from fork · lltopk/netty@3a023c0

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • handler/src
    • main/java/io/netty/handler/ssl/util
      • InsecureTrustManagerFactory.java
      • SimpleTrustManagerFactory.java
      • X509TrustManagerWrapper.java
    • test/java/io/netty/handler/ssl/util
      • SimpleTrustManagerFactoryTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎handler/src/main/java/io/netty/handler/ssl/util/InsecureTrustManagerFactory.java‎

Copy file name to clipboardExpand all lines: handler/src/main/java/io/netty/handler/ssl/util/InsecureTrustManagerFactory.java
+28-1Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@
2121
import io.netty.util.internal.logging.InternalLoggerFactory;
2222

2323
import javax.net.ssl.ManagerFactoryParameters;
24+
import javax.net.ssl.SSLEngine;
2425
import javax.net.ssl.TrustManager;
2526
import javax.net.ssl.TrustManagerFactory;
27+
import javax.net.ssl.X509ExtendedTrustManager;
2628
import javax.net.ssl.X509TrustManager;
29+
import java.net.Socket;
2730
import java.security.KeyStore;
31+
import java.security.cert.CertificateException;
2832
import java.security.cert.X509Certificate;
2933

3034
/**
@@ -41,7 +45,30 @@ public final class InsecureTrustManagerFactory extends SimpleTrustManagerFactory
4145

4246
public static final TrustManagerFactory INSTANCE = new InsecureTrustManagerFactory();
4347

44-
private static final TrustManager tm = new X509TrustManager() {
48+
// This needs to be X509ExtendedTrustManager so hostname verification is skipped as well.
49+
// Otherwise the JDK will internally wrap it with AbstractTrustManagerWrapper and add hostname verification
50+
// by itself.
51+
private static final TrustManager tm = new X509ExtendedTrustManager() {
52+
@Override
53+
public void checkClientTrusted(X509Certificate[] chain, String authType, Socket socket) {
54+
checkClientTrusted(chain, authType);
55+
}
56+
57+
@Override
58+
public void checkServerTrusted(X509Certificate[] chain, String authType, Socket socket) {
59+
checkServerTrusted(chain, authType);
60+
}
61+
62+
@Override
63+
public void checkClientTrusted(X509Certificate[] chain, String authType, SSLEngine engine) {
64+
checkClientTrusted(chain, authType);
65+
}
66+
67+
@Override
68+
public void checkServerTrusted(X509Certificate[] chain, String authType, SSLEngine engine) {
69+
checkServerTrusted(chain, authType);
70+
}
71+
4572
@Override
4673
public void checkClientTrusted(X509Certificate[] chain, String s) {
4774
if (logger.isDebugEnabled()) {
Collapse file

‎handler/src/main/java/io/netty/handler/ssl/util/SimpleTrustManagerFactory.java‎

Copy file name to clipboardExpand all lines: handler/src/main/java/io/netty/handler/ssl/util/SimpleTrustManagerFactory.java
-12Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
import javax.net.ssl.TrustManager;
2828
import javax.net.ssl.TrustManagerFactory;
2929
import javax.net.ssl.TrustManagerFactorySpi;
30-
import javax.net.ssl.X509ExtendedTrustManager;
31-
import javax.net.ssl.X509TrustManager;
3230

3331
/**
3432
* Helps to implement a custom {@link TrustManagerFactory}.
@@ -133,19 +131,9 @@ protected TrustManager[] engineGetTrustManagers() {
133131
TrustManager[] trustManagers = this.trustManagers;
134132
if (trustManagers == null) {
135133
trustManagers = parent.engineGetTrustManagers();
136-
wrapIfNeeded(trustManagers);
137134
this.trustManagers = trustManagers;
138135
}
139136
return trustManagers.clone();
140137
}
141-
142-
private static void wrapIfNeeded(TrustManager[] trustManagers) {
143-
for (int i = 0; i < trustManagers.length; i++) {
144-
final TrustManager tm = trustManagers[i];
145-
if (tm instanceof X509TrustManager && !(tm instanceof X509ExtendedTrustManager)) {
146-
trustManagers[i] = new X509TrustManagerWrapper((X509TrustManager) tm);
147-
}
148-
}
149-
}
150138
}
151139
}
Collapse file

‎handler/src/main/java/io/netty/handler/ssl/util/X509TrustManagerWrapper.java‎

Copy file name to clipboardExpand all lines: handler/src/main/java/io/netty/handler/ssl/util/X509TrustManagerWrapper.java
-73Lines changed: 0 additions & 73 deletions
This file was deleted.
Collapse file

‎handler/src/test/java/io/netty/handler/ssl/util/SimpleTrustManagerFactoryTest.java‎

Copy file name to clipboard
+71Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Copyright 2026 The Netty Project
3+
*
4+
* The Netty Project licenses this file to you under the Apache License,
5+
* version 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at:
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
package io.netty.handler.ssl.util;
17+
18+
import io.netty.util.internal.EmptyArrays;
19+
import org.junit.jupiter.api.Test;
20+
21+
import javax.net.ssl.ManagerFactoryParameters;
22+
import javax.net.ssl.TrustManager;
23+
import javax.net.ssl.X509TrustManager;
24+
import java.security.KeyStore;
25+
import java.security.cert.X509Certificate;
26+
27+
import static org.junit.jupiter.api.Assertions.assertEquals;
28+
import static org.junit.jupiter.api.Assertions.assertSame;
29+
30+
public class SimpleTrustManagerFactoryTest {
31+
32+
@Test
33+
public void testNotWrap() {
34+
final X509TrustManager tm = new X509TrustManager() {
35+
@Override
36+
public void checkClientTrusted(X509Certificate[] chain, String authType) {
37+
// NOOP
38+
}
39+
40+
@Override
41+
public void checkServerTrusted(X509Certificate[] chain, String authType) {
42+
// NOOP
43+
}
44+
45+
@Override
46+
public X509Certificate[] getAcceptedIssuers() {
47+
return EmptyArrays.EMPTY_X509_CERTIFICATES;
48+
}
49+
};
50+
SimpleTrustManagerFactory factory = new SimpleTrustManagerFactory() {
51+
@Override
52+
protected void engineInit(KeyStore keyStore) {
53+
// NOOP
54+
}
55+
56+
@Override
57+
protected void engineInit(ManagerFactoryParameters managerFactoryParameters) {
58+
// NOOP
59+
}
60+
61+
@Override
62+
protected TrustManager[] engineGetTrustManagers() {
63+
return new TrustManager[] { tm };
64+
}
65+
};
66+
67+
TrustManager[] tms = factory.getTrustManagers();
68+
assertEquals(1, tms.length);
69+
assertSame(tm, tms[0]);
70+
}
71+
}

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.