跳到主要内容
ecdsa.com
Java (JSSE / PKIX)Java

错误信息

java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty

也可能输出为

  • javax.net.ssl.SSLException: (internal_error) Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty
  • the trustAnchors parameter must be non-empty

JDK 25 报告为“javax.net.ssl.SSLException: (internal_error) Unexpected error: java.security.InvalidAlgorithmParameterException: the trustAnchors parameter must be non-empty”,异常原因链中还有“java.lang.RuntimeException: Unexpected error: …”。如果信任库路径根本不存在,报出的则是“PKIX path building failed”。

Java (JSSE / PKIX) — the trust store the JVM loaded contains no trusted certificates

含义

JVM 加载的信任库中没有任何受信任证书条目,因此 PKIX 验证器连一个信任锚都没有,拒绝启动。这发生在检查任何证书之前:文件存在且能打开,但就 TLS 信任而言它是空的。该进程的每个 HTTPS 连接都会以同样的方式失败。

原因

修复方法

  1. 1.

    统计受信任条目的数量

    keytool -list 会显示其中的条目;信任库中必须有 trustedCertEntry 行。与 JDK 的默认信任库对比一下。

    bash
    # How many trusted certificates does the store hold? (0 reproduces this error)
    keytool -list -keystore "$TRUSTSTORE" -storepass "$TRUSTSTORE_PASSWORD" | grep -c trustedCertEntry
    keytool -list -cacerts -storepass changeit | grep -c trustedCertEntry    # the JDK's default store
  2. 2.

    恢复 JDK 的默认信任库

    在 Debian 和 Ubuntu 上,重新安装 ca-certificates-java 会重新生成 /etc/ssl/certs/java/cacerts;在 Alpine 上,它由 java-cacerts 软件包提供。

    bash
    # Debian/Ubuntu OpenJDK packages build cacerts from the system CA bundle
    sudo apt-get install --reinstall ca-certificates-java
    sudo update-ca-certificates -f
    # Alpine
    apk add --no-cache java-cacerts
  3. 3.

    把密钥库和信任库分开

    通过 javax.net.ssl.keyStore 传入你自己的证书和密钥,通过 javax.net.ssl.trustStore 传入 CA 证书。

    bash
    # Key store (your key + certificate) and trust store (CAs you trust) are different files
    java -Djavax.net.ssl.keyStore=client.p12   -Djavax.net.ssl.keyStorePassword=changeit \
         -Djavax.net.ssl.trustStore=truststore.p12 -Djavax.net.ssl.trustStorePassword=changeit -jar app.jar

相关错误

浏览完整的签名错误库