【问题标题】:How to ByPass "No subject alternative names present" in Spring Integration?如何绕过 Spring Integration 中的“没有主题替代名称”?
【发布时间】:2023-03-15 12:27:01
【问题描述】:

我有一个项目,它使用 Spring Integration 通过 TCP 与我的客户端进行通信。我的客户要求我在此 TCP 通信中使用 SSL。当我尝试通过 SSL 建立 TCP 连接时,出现 No subject Alternative names present 错误。

我添加了这个代码块来绕过检查:

import org.springframework.integration.ip.tcp.connection.DefaultTcpSSLContextSupport;

import javax.net.ssl.*;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.X509Certificate;

public class CustomTCPSSLContextSupport extends DefaultTcpSSLContextSupport {
    public CustomTCPSSLContextSupport(String keyStore, String trustStore, String keyStorePassword, String trustStorePassword) {
        super(keyStore, trustStore, keyStorePassword, trustStorePassword);
    }

    @Override
    public SSLContext getSSLContext() throws NoSuchAlgorithmException, KeyManagementException {
        TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return null;
            }

            public void checkClientTrusted(X509Certificate[] certs, String authType) {
            }

            public void checkServerTrusted(X509Certificate[] certs, String authType) {
            }
        }
        };

        SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new java.security.SecureRandom());

        return sc;
    }
}

我是这样定义的:

<bean id="sslContextSupport" class="CustomTCPSSLContextSupport">
    <constructor-arg value="${keystore.path}"/>
    <constructor-arg value="${cacerts.path}"/>
    <constructor-arg value="changeit"/>
    <constructor-arg value="changeit"/>
</bean>

我在我的 tcp-connection-factory 中将此 sslContextSupport 用作 ssl-context-support 但没有影响。它仍然给出同样的错误。

如何在 Spring Integration 中完全绕过主题替代检查?

【问题讨论】:

    标签: spring ssl tcp spring-integration


    【解决方案1】:

    很高兴看到整个堆栈跟踪以确保您的 CustomTCPSSLContextSupport 确实在使用中。

    虽然我看到他们通常像这样实现“信任所有人”:

    static class TrustAllX509TrustManager implements X509TrustManager {
        TrustAllX509TrustManager() {
        }
    
        public void checkClientTrusted(X509Certificate[] x509Certificates, String s) {
        }
    
        public void checkServerTrusted(X509Certificate[] x509Certificates, String s) {
        }
    
        public X509Certificate[] getAcceptedIssuers() {
            return new X509Certificate[0];
        }
    }
    

    new X509Certificate[0] 的空数组,而不是像您的情况那样的 null

    sc.init() 在我看来没问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-20
      • 1970-01-01
      • 2018-09-08
      • 2014-04-25
      相关资源
      最近更新 更多