Java default Certificates missing, even if they are in the correct location and I'm not acutally using any

huangapple go评论68阅读模式
英文:

Java default Certificates missing, even if they are in the correct location and I'm not acutally using any

问题

以下是您提供的文本的中文翻译:

每当我运行任何尝试运行纯Java代码的程序(编程程序、环境以及一些基于它的编译程序时),都会出现问题。但不影响使用Java的应用程序。

例如,当我尝试运行Gradle时,会出现错误:

sun.security.validator.ValidatorException: PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求的目标的有效认证路径

其他程序也会出现类似的情况。

我已经卸载了所有的JDK和JRE文件,并重新安装它们,并更改了JAVA_HOME和Path变量,但仍然出现该错误。我没有连接到任何SSL或其他自定义服务器,只是默认的Java服务器,所以我不明白为什么cacerts文件中的默认证书不起作用。我认为,但我不确定,这是在Java更新后发生的。从那时起,大约两个月前,就一直这样。

顺便说一下,我尝试使用keytool,但它需要一个在Java 17中我没有的.cer文件(据我所知)。

这是跟踪信息:

javax.net.ssl.SSLHandshakeException: PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求的目标的有效认证路径
    at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:131)
    at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:378)
    at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:321)
    at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:316)
    at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.checkServerCerts(CertificateMessage.java:654)
    at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.onCertificate(CertificateMessage.java:473)
    at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.consume(CertificateMessage.java:369)
    at java.base/sun.security.ssl.SSLHandshake.consume(SSLHandshake.java:396)
    at java.base/sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:480)
    at java.base/sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:458)
    at java.base/sun.security.ssl.TransportContext.dispatch(TransportContext.java:201)
    at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:172)
    at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1506)
    at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1421)
    at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:455)
    at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:426)
    at java.base/sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:589)
    at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:187)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1665)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1589)
    at java.base/java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:529)
    at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:308)
    at net.minecraftforge.installer.DownloadUtils.getConnection(DownloadUtils.java:243)
    at net.minecraftforge.installer.DownloadUtils.downloadManifest(DownloadUtils.java:307)
    at net.minecraftforge.installer.json.Util.getVanillaVersion(Util.java:73)
    at net.minecraftforge.installer.actions.ServerInstall.run(ServerInstall.java:86)
    at net.minecraftforge.installer.InstallerPanel.run(InstallerPanel.java:423)
    at net.minecraftforge.installer.SimpleInstaller.launchGui(SimpleInstaller.java:175)
    at net.minecraftforge.installer.SimpleInstaller.main(SimpleInstaller.java:147)
Caused by: sun.security.validator.ValidatorException: PKIX路径构建失败:sun.security.provider.certpath.SunCertPathBuilderException:无法找到请求的目标的有效认证路径
    at java.base/sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:439)
    at java.base/sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:306)
    at java.base/sun.security.validator.Validator.validate(Validator.java:264)
    at java.base/sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:231)
    at java.base/sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:132)
    at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.checkServerCerts(CertificateMessage.java:638)
    ... 24 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: 无法找到请求的目标的有效认证路径
    at java.base/sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:146)
    at java.base/sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:127)
    at java.base/java.security.cert.CertPathBuilder.build(CertPathBuilder.java:297)
    at java.base/sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:434)
    ... 29 more
无法下载版本清单,找不到服务器jar URL。

希望这对您有所帮助。如果您需要进一步的帮助,请告诉我。

英文:

Any time I run any program that tries to run pure Java code (Coding programs, ENVs and some compiled programs based on it. It does not effect apps that are using Java tho)

For example when I try to run Gradle it gives me an error:

sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Same for other programs

I have uninstalled all jdk and jre files and reinstalled them and changed the JAVA_HOME and Path variable but still it gives me that error. I don't connect to any SSL or other custom servers just the default java ones, so I don't understand why the default certificates in the cacerts file do not work. I think, but I'm not sure, it happened when Java updated. Since then, like 2 months ago, it was like this

Btw I did try to use keytool but it requires a .cer file witch I don't have in Java 17 (to my knowledge)

Here is the trace

javax.net.ssl.SSLHandshakeException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:131)
    at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:378)
    at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:321)
    at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:316)
    at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.checkServerCerts(CertificateMessage.java:654)
    at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.onCertificate(CertificateMessage.java:473)
    at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.consume(CertificateMessage.java:369)
    at java.base/sun.security.ssl.SSLHandshake.consume(SSLHandshake.java:396)
    at java.base/sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:480)
    at java.base/sun.security.ssl.HandshakeContext.dispatch(HandshakeContext.java:458)
    at java.base/sun.security.ssl.TransportContext.dispatch(TransportContext.java:201)
    at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:172)
    at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1506)
    at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1421)
    at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:455)
    at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:426)
    at java.base/sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:589)
    at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:187)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1665)
    at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1589)
    at java.base/java.net.HttpURLConnection.getResponseCode(HttpURLConnection.java:529)
    at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getResponseCode(HttpsURLConnectionImpl.java:308)
    at net.minecraftforge.installer.DownloadUtils.getConnection(DownloadUtils.java:243)
    at net.minecraftforge.installer.DownloadUtils.downloadManifest(DownloadUtils.java:307)
    at net.minecraftforge.installer.json.Util.getVanillaVersion(Util.java:73)
    at net.minecraftforge.installer.actions.ServerInstall.run(ServerInstall.java:86)
    at net.minecraftforge.installer.InstallerPanel.run(InstallerPanel.java:423)
    at net.minecraftforge.installer.SimpleInstaller.launchGui(SimpleInstaller.java:175)
    at net.minecraftforge.installer.SimpleInstaller.main(SimpleInstaller.java:147)
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at java.base/sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:439)
    at java.base/sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:306)
    at java.base/sun.security.validator.Validator.validate(Validator.java:264)
    at java.base/sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:231)
    at java.base/sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:132)
    at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.checkServerCerts(CertificateMessage.java:638)
    ... 24 more
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
    at java.base/sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:146)
    at java.base/sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:127)
    at java.base/java.security.cert.CertPathBuilder.build(CertPathBuilder.java:297)
    at java.base/sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:434)
    ... 29 more
Failed to download version manifest, can not find server jar URL.

答案1

得分: 0

这是与注册表和Windows文件有关的问题。出于某种原因,某个程序在System32文件夹中创建了一个不必要的文件。只需从C:\Windows\System32\drivers\etc目录中删除host/hosts和类似命名的任何文件,问题就会得到解决!

英文:

This was a problem with the registry and windows files. For some reason some program made an unnecessary file in the System32 folder. Just remove the host/hosts and any files named like that from the C:\Windows\System32\drivers\etc directory and it will be fixed!!!

huangapple
  • 本文由 发表于 2023年5月25日 05:03:03
  • 转载请务必保留本文链接:https://go.coder-hub.com/76327386.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定