CLIENT-CERT是SSL/TLS客户端认证的一种方式,它要求客户端提供有效的数字证书来验证身份。在Tomcat中配置CLIENT-CERT认证可以提供比基本认证或表单认证更高级别的安全性。
首先需要准备:
<Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
maxThreads="150" SSLEnabled="true" scheme="https" secure="true"
clientAuth="true" sslProtocol="TLS"
keystoreFile="conf/server.keystore" keystorePass="changeit"
truststoreFile="conf/server.truststore" truststorePass="changeit" />
关键参数:
clientAuth="true"
:要求客户端证书keystoreFile
:服务器密钥库truststoreFile
:信任库(包含CA证书)在需要保护的web应用的WEB-INF/web.xml中添加:
<security-constraint>
<web-resource-collection>
<web-resource-name>Protected Area</web-resource-name>
<url-pattern>/secure/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>*</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
<login-config>
<auth-method>CLIENT-CERT</auth-method>
</login-config>
在conf/tomcat-users.xml中添加用户角色映射:
<user username="CN=Client User, OU=IT, O=Company, L=City, ST=State, C=US"
roles="manager-gui,admin-gui" />
原因:客户端证书的颁发机构不在服务器的信任库中
解决:
原因:可能是不支持的协议或密码套件
解决: 在server.xml中添加协议和密码套件配置:
<Connector ...
sslEnabledProtocols="TLSv1.2,TLSv1.3"
ciphers="TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,..." />
原因:证书主题名称与预期不符
解决:
通过以上配置,您可以在Tomcat 8.5中有效地使用CLIENT-CERT认证来保护您的资源。