我正在尝试将经过验证的 SSL 证书添加到我的 Java 应用程序。 Java 应用充当转换服务。它监听特定 URL 的端口。它通过字符串查找和替换来转换请求的主体。然后 Java 应用程序将数据转换为内部服务。
我已将自签名 SSL 证书添加到应用程序。然而,这并不能很好地工作。在 SoapUI 中它工作正常。当我尝试使用 basicHttpBinding 和 HttpWebRequest 从 C# 应用程序调用它时,出现以下错误:
Unhandled Exception: System.Net.WebException:
The underlying connection was closed:
Could not establish trust relationship for the SSL/TLS secure channel. --->
System.Security.Authentication.AuthenticationException: The remote certificate
is invalid according to the validation procedure.
所以我删除了那个证书并添加了一个签名证书。此证书当前附加到 java 应用程序正在监听的域。当我尝试运行 Java 应用程序时,出现以下异常:
java.net.SocketException: java.security.NoSuchAlgorithmException: Error constructing
implementation (algorithm: Default, provider: SunJSSE, class:
com.sun.net.ssl.internal.ssl.DefaultSSLContextImpl)
设置 key 和信任库的 Java 代码:
loadConfig();
loadTransforms();
// Set Trust/Key stores
System.setProperty("javax.net.ssl.keyStore", keyFile);
System.setProperty("javax.net.ssl.keyStorePassword", keyPassword);
System.setProperty("javax.net.ssl.trustStore", keyFile);
System.setProperty("javax.net.ssl.trustStorePassword", keyPassword);
TransformationServer server = new TransformationServer();
server.runServer(mode);
证书存储在 key 和信任库中。有人有什么想法吗?
最佳答案
寻求不同的解决方案。我已将以下配置添加到 WinForm 应用程序。
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing="true" />
</settings>
</system.net>
所以 Java 仍在使用自签名证书。
编辑: 请求 header 中的行结尾有问题。它不符合某些 http RFC 标准。
关于java - Java 应用程序运行时验证的 ssl 证书抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17958666/