javax.net.ssl.SSLException: java.lang.RuntimeException: Unexpected error: java.security.InvalidAlgor

本文详细阐述了在使用Tomcat部署应用时遇到SSL启动错误的解决方案,包括配置JVM参数、导入证书到推荐的Java信任库、以及解决信任锚问题的方法。提供了从配置文件修改到实际操作的完整指南。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在tomcat中启动报错

重要解决方法:

在catalina.sh中, 加入:

JAVA_OPTS='-Xms4096m -Xmx7048m -XX:MaxNewSize=1024m -XX:MaxPermSize=512m -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false' -Djavax.net.ssl.keyStore=/home/monitor/server-4.6.6/hq-engine/hq-server/id.keystore 

如此

Cause

The JVM cannot find the javax.net.ssl.trustStore required for SSL, or it does not contain the required certificates.

For standard installations, we do not recommend this JVM argument is used, and rather your certificates are added to the JVM's default keystore, which is typically located in $JAVA_HOME/jre/lib/security/cacerts or the keystore used by your Tomcat, as in our Running JIRA over SSL or HTTPS documentation.

Resolution

Follow our Connecting to SSL services documentation. This will guide you through obtaining the certificate of the service you're accessing and importing it into the recommended Java keystore.

(warning) If you're using a non-standard keystore, such as the one specified in Tomcat, please import the certificate into that keystore.


http://blog.chinaunix.net/uid-26284318-id-3069142.html



the detail :

http://architecturalatrocities.com/post/19073788679/fixing-the-trustanchors-problem-when-running


关于配置:

http://blog.chintoju.com/2013/03/jdk-jbosstomcat-ssl-issue-the-trusta.html

在bin/catalina.sh中, 加入:

-Djavax.net.ssl.trustStore=<TRUST_STORE_LOCATION>
-Djavax.net.ssl.trustStorePassword=<TRUST_STORE_PASSWORD> 

____________________________________________________________
JAVA_OPTS='-Xms4096m -Xmx7048m -XX:MaxNewSize=1024m -XX:MaxPermSize=512m -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false' -Djavax.net.ssl.keyStore=/home/monitor/server-4.6.6/hq-engine/hq-server/id.keystore 

关于探讨, 

http://stackoverflow.com/questions/4764611/java-security-invalidalgorithmparameterexception-the-trustanchors-parameter-mus

中提供了一种方法:

When I copied my jre/lib/security/cacerts file from windows to linux, it worked fine.



根据提供的引用内容,你遇到的问题是javax.net.ssl.SSLException: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty。这个错误通常是由于缺少信任锚点导致的。信任锚点是用于验证SSL证书的根证书。解决这个问题的方法是确保信任锚点参数不为空。 以下是一种解决方法: ```java import.security.KeyStore; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import javax.net.ssl.TrustManager; import javax.net.ssl.TrustManagerFactory; import javax.net.ssl.X509TrustManager; public class CustomTrustManager implements X509TrustManager { private X509TrustManager defaultTrustManager; public CustomTrustManager() throws Exception { // 获取默认的信任管理器 TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()); trustManagerFactory.init((KeyStore) null); TrustManager[] trustManagers = trustManagerFactory.getTrustManagers(); for (TrustManager trustManager : trustManagers) { if (trustManager instanceof X509TrustManager) { defaultTrustManager = (X509TrustManager) trustManager; return; } } throw new Exception("Failed to initialize default trust manager."); } @Override public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException { defaultTrustManager.checkClientTrusted(chain, authType); } @Override public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException { if (chain == null || chain.length == 0) { throw new CertificateException("No certificates found in the chain."); } defaultTrustManager.checkServerTrusted(chain, authType); } @Override public X509Certificate[] getAcceptedIssuers() { return defaultTrustManager.getAcceptedIssuers(); } } ``` 你可以使用上述代码创建一个自定义的信任管理器,并将其设置为SSL上下文的信任管理器。这样就可以解决javax.net.ssl.SSLException: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty的问题。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

不止鱼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值