如何强制 tomcat 重新加载受信任的证书?
我的 Web 应用程序使用 2 向 SSL 连接器(又名“客户端身份验证”):
<Connector port="8084" SSLEnabled="true" maxThreads="10" minSpareThreads="3" maxSpareThreads="5"
enableLookups="false" disableUploadTimeout="true" acceptCount="100" scheme="https" secure="true"
clientAuth="true" truststoreFile="conf/keystore.kst" truststoreType="JCEKS" sslProtocol="TLS" URIEncoding="UTF-8"
keystoreFile="conf/keystore.kst" keystoreType="JCEKS" keyAlias="myAlias"
ciphers="TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_3DES_EDE_CBC_SHA,SSL_RSA_WITH_3DES_EDE_CBC_SHA"/>
我的问题是,当 Tomcat 服务器正在运行并且我使用新的受信任证书更新密钥库,甚至从中删除受信任证书时,连接器不会“注意到这些变化。
到目前为止我已经尝试过:
1)停止、重新初始化(反射)和启动连接器 - 不起作用。
2) 实现我自己的 SSLContext,从密钥库重新加载证书。 好吧,这里我错过了向 tomcat 注册此 SSLContext 的部分(以便 tomcat 将在连接器中使用它来进行新的传入连接)
有很多关于此问题的帖子,但没有真正的解决方案:
http://www.delphifaq.com/faq/f5003.shtml
http://jcalcote.wordpress.com/tag/truststore
(本文仅描述如何从客户端重新创建 SSLcontext(缺少服务器端))
有什么想法吗?
还有另一个相关问题:
如何强制 Tomcat Web 应用程序在更新后重新加载信任存储,
但答案还不够,因为我不想构建新的类加载器。
谢谢。
My WebApp uses a Connector for 2-Way SSL (aka "Client Authentication"):
<Connector port="8084" SSLEnabled="true" maxThreads="10" minSpareThreads="3" maxSpareThreads="5"
enableLookups="false" disableUploadTimeout="true" acceptCount="100" scheme="https" secure="true"
clientAuth="true" truststoreFile="conf/keystore.kst" truststoreType="JCEKS" sslProtocol="TLS" URIEncoding="UTF-8"
keystoreFile="conf/keystore.kst" keystoreType="JCEKS" keyAlias="myAlias"
ciphers="TLS_RSA_WITH_AES_128_CBC_SHA,TLS_RSA_WITH_3DES_EDE_CBC_SHA,SSL_RSA_WITH_3DES_EDE_CBC_SHA"/>
My problem is that while the Tomcat server is running and I update the keystore with new trusted certifictaes , or even delete trusted certificates from it , the connector doesn't notice the changes.
What I've tried so far:
1) Stopping , Re-Initializing (reflection) and starting the Connector - didn't work.
2) Implementing my own SSLContext that reloads the certificates from the keystore.
Well , here I'm missing the part of registering this SSLContext with tomcat (so that tomcat will use it in the connector for new incoming connections)
There are many posts on this matter but no real solution:
http://www.delphifaq.com/faq/f5003.shtml
http://jcalcote.wordpress.com/tag/truststore
(This article describes only how to recreate SSLcontext from the client side (missing the server side))
Any Ideas?
There's another related question :
How do I force a tomcat web application reload the trust store after I update it
but the answer there is not sufficient since I don't want to build a new ClassLoader.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
现在从 Tomcat v8.5.24 开始有一个解决方案。
他们引入了两种方法:
reloadSslHostConfig(String hostName) - 重新加载特定主机
reloadSslHostConfigs() - 重新加载所有
它们可以通过多种方式调用:
方式 1 和方式 2 的详细信息可以轻松在线获得。
如何使用方法 3 的详细信息:
查找下面的示例代码:
主协议类:
server.xml 中的连接器应将其作为协议提及:
希望这会有所帮助。
There is now a solution to this starting with Tomcat v8.5.24.
They introduced 2 methods named:
reloadSslHostConfig(String hostName) - to reload a specific host
reloadSslHostConfigs() - reload all
They can be called in various ways:
Details of way 1 and way 2 are easily available online.
Details of how to go about using way 3:
Find sample code below:
Main protocol class:
Connector in server.xml should mention this as the protocol:
Hope this helps.
如果您的连接器将 bindOnInit 属性设置为 false(从 Tomcat 6.x 开始存在),则:
来自 org.apache.tomcat.util.net.AbstractEndpoint Tomcat 8.0.29 的代码片段:
然后您可以停止 &更新密钥和信任存储后,通过 JMX 启动连接器。
In case your connector has the bindOnInit property set to false (exist starting Tomcat 6.x), which:
Code snippets from org.apache.tomcat.util.net.AbstractEndpoint Tomcat 8.0.29:
Then you can stop & start the connector through JMX after updates to your keys and trust stores.
Tomcat HTTP/1.1 协议处理程序可以重新加载密钥库。
如果您使用嵌入式 Tomcat 或有某种方式访问 Tomcat 连接器,那么您可以要求协议处理程序按需重新加载密钥库和信任库,而无需重新启动连接器。
The Tomcat HTTP/1.1 protocol handler can reload keystores.
If you are using embedded Tomcat or have some way of accessing the Tomcat Connector, then then you ask the protocol hander to reload the keystores and trust stores on demand without restarting the connector.
最简单的方法是以编程方式读取密钥库,从中获取 SSL 上下文并使用它来建立连接。
The easiest way is read the keystore programmatically, get a SSL context from that and use it to make connection.