简体   繁体   English

默认 X509TrustManager 和通配符主机名验证?

[英]Default X509TrustManager and wildcard hostname validation?

I am constructing a default X509TrustManager that's gonna be used for hostname validations:我正在构建一个将用于主机名验证的默认 X509TrustManager:

        TrustManagerFactory trustManagerFactory = null;
    try {
        trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        trustManagerFactory.init((KeyStore) null);
        TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();

        for (int i = 0; i < trustManagers.length; i++) {
            TrustManager t = trustManagers[i];
            if (t instanceof X509TrustManager) {
                this.defaultTrustManager = (X509TrustManager) t;
                return;
            }
        }
    } catch (NoSuchAlgorithmException | KeyStoreException e) {
        throw new CelleryCellSTSException("Error while setting trust manager", e);
    }

However, I can't find out anywhere if this is gonna support wildcard certificates as well or do I need to build a custom trust manager just for that?但是,如果这也将支持通配符证书,或者我是否需要为此构建自定义信任管理器,我无法找到任何地方? Is there any documentation somewhere available on this, I would like to read more how wildcard validation really works if it supported?是否有任何可用的文档,如果支持,我想阅读更多通配符验证的真正工作原理? I'm using java 8 and 11, thanks.我正在使用 java 8 和 11,谢谢。

In Java 7 up the TrustManager's created by TrustManagerFactory do hostname checking if (and only if) an 'endpoint identification' algorithm is set for the particular connection being made (more exactly, the SSLSocket or SSLEngine ), see here for socket and here for engine .在 Java 7 中,由 TrustManagerFactory 创建的 TrustManager 执行主机名检查是否(且仅当)为正在建立的特定连接(更准确地说, SSLSocketSSLEngine )设置了“端点识别”算法,请参见此处的套接字此处的引擎. The supported algorithms HTTPS and LDAPS are actually implemented here (with HTTPS internally called TLS) which you can see handles valid wildcards (only in DNS name, not IP address) but rejects invalid ones. The supported algorithms HTTPS and LDAPS are actually implemented here (with HTTPS internally called TLS) which you can see handles valid wildcards (only in DNS name, not IP address) but rejects invalid ones.

HttpsURLConnection and 11-up java.net.http.HttpClient use the 'HTTPS' algorithm. HttpsURLConnection 和 11-up java.net.http.HttpClient 使用“HTTPS”算法。 For other ways of invoking JSSE, either your code or the relevant middleware must set endpoint-id if you want it done.对于调用 JSSE 的其他方式,如果您希望完成,您的代码或相关中间件必须设置端点 ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM