我有一个多租户网络服务,我想使用相互 SSL/TLS 身份验证以及用户身份验证。这意味着我需要解析用户和用户允许的证书,这只能在建立 SSL 连接后发生。然后我将使用PKIXCertPathBuilderResult
请求中传递的客户端证书来验证信任链。
在带有 openssl 连接器的 Tomcat 中,可以使用optional_no_ca
mode,它请求客户端证书但不对其进行验证。
使用 Jetty 9.x,我尝试配置以下SslContextFactory
选项无济于事:
ValidateCerts=false
ValidatePeerCerts=false
TrustAll=true
如何在 Jetty 9.x 中实现这一点?
2019 年编辑:要求访问系统的所有客户端设备都需要 SSL 证书。证书链和其他证书属性的验证将由应用程序执行,该应用程序还能够从外部来源查找丢失的证书根。这与规范相反 - 通常,应用程序服务器将在 SSL 连接设置期间使用已知可信 CA 的预配置静态列表执行证书链验证。如果无法找到信任,则拒绝 SSL 连接。
虽然TrustAll
似乎是可能的解决方案,但它只有在没有提供 TrustStore和KeyStore时才有效。然后您无法使用常规客户端进行连接,因为服务器在握手期间没有证书可提供。
要获得合理的 trustAll 模式,唯一的选择似乎是扩展SslContextFactory
:
package media.alu.jetty;
/**
* SslContextFactoryRelaxed is used to configure SSL connectors
* as well as HttpClient. It holds all SSL parameters and
* creates SSL context based on these parameters to be
* used by the SSL connectors.
*
* TrustAll really means trustAll!
*/
@ManagedObject
public class SslContextFactoryRelaxed extends SslContextFactory
{
private String _keyManagerFactoryAlgorithm = DEFAULT_KEYMANAGERFACTORY_ALGORITHM;
private String _trustManagerFactoryAlgorithm = DEFAULT_TRUSTMANAGERFACTORY_ALGORITHM;
@Override
protected TrustManager[] getTrustManagers(KeyStore trustStore, Collection<? extends CRL> crls) throws Exception
{
TrustManager[] managers = null;
if (trustStore != null)
{
if (isTrustAll()) {
managers = TRUST_ALL_CERTS;
}
// Revocation checking is only supported for PKIX algorithm
else if (isValidatePeerCerts() && "PKIX".equalsIgnoreCase(getTrustManagerFactoryAlgorithm()))
{
PKIXBuilderParameters pbParams = newPKIXBuilderParameters(trustStore, crls);
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(_trustManagerFactoryAlgorithm);
trustManagerFactory.init(new CertPathTrustManagerParameters(pbParams));
managers = trustManagerFactory.getTrustManagers();
}
else
{
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(_trustManagerFactoryAlgorithm);
trustManagerFactory.init(trustStore);
managers = trustManagerFactory.getTrustManagers();
}
}
return managers;
}
}
使用:
编辑 $jetty.home/etc/jetty-ssl-context.xml
一世。改变:
<Configure id="sslContextFactory" class="org.eclipse.jetty.util.ssl.SslContextFactory">
至:
<Configure id="sslContextFactory" class="media.alu.jetty.SslContextFactoryRelaxed">
ii. 添加<Set name="TrustAll">TRUE</Set>
为<Configure id="sslContextFactory">
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句