Java 8 Swing应用程序:javax.net.ssl.SSLKeyException:RSA预主密钥错误

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

Java 8 Swing application: javax.net.ssl.SSLKeyException: RSA premaster secret error

问题

I have a Swing based Java application that uses Java 8 u161.
这是一个基于Swing的Java应用程序,使用Java 8 u161。

The jre that the application uses is stored in one of its directories (it doesn't use an installed jre).
应用程序使用的JRE存储在其一个目录中(它不使用已安装的JRE)。

One of the screens in the application approaches a Webshere that is installed on a distant server via HTTPS. The public key is installed on cacert in the client's jre\lib\security folder.
应用程序中的一个屏幕通过HTTPS访问远程服务器上安装的Webshere。公钥已安装在客户端的jre\lib\security文件夹中。

When the application runs as a standalone application, all is well: the handshake is completed successfully, the message is sent to the server and the returned code is 200 (OK).
当应用程序作为独立应用程序运行时,一切正常:握手成功完成,消息被发送到服务器并返回代码为200(OK)。

But when the application runs in collaboration with another application (a dotnet application that injects code to the Java application. I'm not even sure what exactly), a "javax.net.ssl.SSLKeyException: RSA premaster secret error" is thrown.
但是当应用程序与另一个应用程序协作运行时(一个将代码注入Java应用程序的DotNet应用程序,我甚至不确定具体是什么),会抛出"javax.net.ssl.SSLKeyException: RSA premaster secret error"异常。

Most similar problems on the internet were solved by uninstalling and reinstalling all the Java versions. But my Java is not installed, so I can't do that.
互联网上大多数类似的问题都通过卸载并重新安装所有Java版本来解决。但我的Java没有安装,所以我不能这样做。

I tripled checked that my Java application uses the correct jre- it does.
我多次检查过我的Java应用程序使用了正确的JRE - 是的。

I can't understand what causes this exception and I don't know what else to check.
我无法理解是什么导致了这个异常,也不知道还要检查什么。

Here is how I open the connection:
以下是我如何打开连接的代码:

URL servletUrl = new URL(urlStr); //throws java.net.MalformedURLException
HttpsURLConnection.setDefaultHostnameVerifier(new ChequesServletHostnameVerifier());
servletConnection = (HttpsURLConnection) servletUrl.openConnection(); //throws java.io.IOException
servletConnection.setDoOutput(true);
servletConnection.setUseCaches(false);
OutputStream os = servletConnection.getOutputStream(); //throws java.io.IOException

And here is the complete stacktrace:
以下是完整的堆栈跟踪:

英文:

I have a Swing based Java application that uses Java 8 u161.
The jre that the application uses is stored in one of its directories (it doesn't use an installed jre).
One of the screens in the application approaches a Webshere that is installed on a distant server via HTTPS. The public key is installed on cacert in the client's jre\lib\security folder.

When the application runs as a standalone application, all is well: the handshake is completed successfully, the message is sent to the server and the returned code is 200 (OK).
But when the application runs in collaboration with another application (a dotnet application that injects code to the Java application. I'm not even sure what exactly), a "javax.net.ssl.SSLKeyException: RSA premaster secret error" is thrown

Most similar problems on the internet were solved by uninstalling and reinstalling all the Java versions. But my Java is not installed, so I can't do that.

I tripled checked that my Java application uses the correct jre- it does.

I can't understand what causes this exception and I don't know what else to check.

Here is how I open the connection:

URL servletUrl = new URL(urlStr);  //throws java.net.MalformedURLException
HttpsURLConnection.setDefaultHostnameVerifier(new ChequesServletHostnameVerifier());
servletConnection = (HttpsURLConnection) servletUrl.openConnection();  //throws java.io.IOException
servletConnection.setDoOutput(true);
servletConnection.setUseCaches(false);
OutputStream os = servletConnection.getOutputStream();  //throws java.io.IOException

And here is the complete stacktrace:

javax.net.ssl.SSLKeyException: RSA premaster secret error
	at sun.security.ssl.RSAClientKeyExchange.<init>(Unknown Source)
	at sun.security.ssl.ClientHandshaker.serverHelloDone(Unknown Source)
	at sun.security.ssl.ClientHandshaker.processMessage(Unknown Source)
	at sun.security.ssl.Handshaker.processLoop(Unknown Source)
	at sun.security.ssl.Handshaker.process_record(Unknown Source)
	at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
	at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
	at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
	at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
	at sun.net.www.protocol.https.HttpsClient.afterConnect(Unknown Source)
	at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
	at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(Unknown Source)
	at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source)
	at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unknown Source)
	at qs.localtransactions.servlet.SrvltTxn.connect2Servlet(SrvltTxn.java:114)
	at qs.localtransactions.AmgImgBase.retrieveImagesFromServlet(AmgImgBase.java:562)
	at qs.localtransactions.AMGIMG91.sendAndReceive(AMGIMG91.java:27)
	at qs.localtransactions.AMGIMG.sendAndReceive(AMGIMG.java:32)
	at idb.messenger.sender.LocalBackendDispatcher.send(LocalBackendDispatcher.java:26)
	at qc.distribution.protocol.idb.QtMessengerIDB.sendAndReceive(QtMessengerIDB.java:127)
	at qc.distribution.QtTransaction.sendRemote(QtTransaction.java:3338)
	at qc.distribution.QtTransaction.send(QtTransaction.java:2528)
	at qc.distribution.QtTransaction.send(QtTransaction.java:1930)
	at qt.presentacion.QtLogic.send(QtLogic.java:800)
	at qt.presentacion.QtLogic.performObserverCommand(QtLogic.java:584)
	at qt.presentacion.logic.QtAction.evaluateSensitive(QtAction.java:536)
	at qt.presentacion.logic.QtAction.evaluate(QtAction.java:258)
	at qt.presentacion.logic.QtLogicEvaluator.evaluateActions(QtLogicEvaluator.java:472)
	at qt.presentacion.logic.QtLogicEvaluator.evaluate(QtLogicEvaluator.java:397)
	at qt.presentacion.logic.QtLogicRoutines.evaluateNotificationStack(QtLogicRoutines.java:582)
	at qt.presentacion.logic.QtLogicRoutines.evaluate(QtLogicRoutines.java:555)
	at qt.presentacion.logic.QtLogicEvaluator.update(QtLogicEvaluator.java:1431)
	at qt.presentacion.logic.QtLogicStackController.processNotification(QtLogicStackController.java:108)
	at qc.controls.observer.QtNotificator.notify(QtNotificator.java:65)
	at qt.presentacion.QtRadioButtonModel.setValid(QtRadioButtonModel.java:110)
	at qt.presentacion.QtRadioButton.radiobutton_ItemStateChanged(QtRadioButton.java:1111)
	at qt.presentacion.QtRadioButton.connEtoC2(QtRadioButton.java:150)
	at qt.presentacion.QtRadioButton.itemStateChanged(QtRadioButton.java:882)
	at javax.swing.AbstractButton.fireItemStateChanged(Unknown Source)
	at javax.swing.AbstractButton$Handler.itemStateChanged(Unknown Source)
	at javax.swing.DefaultButtonModel.fireItemStateChanged(Unknown Source)
	at qt.presentacion.QtRadioButtonModel.setSelected(QtRadioButtonModel.java:95)
	at javax.swing.ButtonGroup.setSelected(Unknown Source)
	at qt.presentacion.QtRadioButtonModel.setSelected(QtRadioButtonModel.java:89)
	at javax.swing.AbstractButton.setSelected(Unknown Source)
	at qt.presentacion.QtRadioButton.select(QtRadioButton.java:1181)
	at qt.presentacion.QtRadioButton.performObserverCommand(QtRadioButton.java:1045)
	at qt.presentacion.logic.QtAction.evaluateSensitive(QtAction.java:536)
	at qt.presentacion.logic.QtAction.evaluate(QtAction.java:258)
	at qt.presentacion.logic.QtLogicEvaluator.evaluateActions(QtLogicEvaluator.java:472)
	at qt.presentacion.logic.QtLogicEvaluator.evaluate(QtLogicEvaluator.java:397)
	at qt.presentacion.logic.QtLogicEvaluator.register(QtLogicEvaluator.java:1312)
	at qt.presentacion.QtLogic.registerEvaluators(QtLogic.java:741)
	at qt.presentacion.QtLogic.initState(QtLogic.java:510)
	at qt.presentacion.QtLogic.paint(QtLogic.java:529)
	at javax.swing.JComponent.paintChildren(Unknown Source)
	at javax.swing.JComponent.paint(Unknown Source)
	at qt.presentacion.QtPanel.paint(QtPanel.java:1995)
	at javax.swing.JComponent.paintChildren(Unknown Source)
	at javax.swing.JComponent.paint(Unknown Source)
	at javax.swing.JLayeredPane.paint(Unknown Source)
	at javax.swing.JComponent.paintChildren(Unknown Source)
	at javax.swing.JComponent.paint(Unknown Source)
	at javax.swing.JComponent.paintChildren(Unknown Source)
	at javax.swing.JComponent.paint(Unknown Source)
	at javax.swing.JComponent.paintChildren(Unknown Source)
	at javax.swing.JComponent.paint(Unknown Source)
	at javax.swing.JLayeredPane.paint(Unknown Source)
	at javax.swing.JComponent.paintChildren(Unknown Source)
	at javax.swing.JComponent.paint(Unknown Source)
	at javax.swing.JLayeredPane.paint(Unknown Source)
	at javax.swing.JComponent.paintChildren(Unknown Source)
	at javax.swing.JComponent.paint(Unknown Source)
	at javax.swing.JLayeredPane.paint(Unknown Source)
	at javax.swing.JComponent.paintChildren(Unknown Source)
	at javax.swing.JComponent.paint(Unknown Source)
	at javax.swing.JComponent.paintToOffscreen(Unknown Source)
	at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
	at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
	at javax.swing.RepaintManager.paint(Unknown Source)
	at javax.swing.JComponent._paintImmediately(Unknown Source)
	at javax.swing.JComponent.paintImmediately(Unknown Source)
	at javax.swing.RepaintManager$4.run(Unknown Source)
	at javax.swing.RepaintManager$4.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
	at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
	at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
	at javax.swing.RepaintManager.access$1200(Unknown Source)
	at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
	at java.awt.event.InvocationEvent.dispatch(Unknown Source)
	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
	at java.awt.EventQueue.access$500(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.awt.EventQueue$3.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
	at java.awt.EventQueue.dispatchEvent(Unknown Source)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
	at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.security.NoSuchAlgorithmException: SunTlsRsaPremasterSecret KeyGenerator not available
	at javax.crypto.KeyGenerator.<init>(KeyGenerator.java:169)
	at javax.crypto.KeyGenerator.getInstance(KeyGenerator.java:223)
	at sun.security.ssl.JsseJce.getKeyGenerator(Unknown Source)
	... 105 more

Any information with be appreciated.

答案1

得分: 1

像许多人在旧帖子中提到的那样,有关异常

> javax.net.ssl.SSLKeyException: RSA premaster secret error

这意味着混合了两个不同的Java版本。因此,重新安装Java有所帮助。

在我的情况下,显然dotnet应用程序将Java扩展文件夹设置为较旧的Java版本。当扩展配置设置为正确的Java版本时,问题得以解决。

英文:

Like many people mentioned in older posts regarding exception

>javax.net.ssl.SSLKeyException: RSA premaster secret error

it means that two different java versions are mixed. Therefore, reinstalling Java helps.

In my case, apparently, the dotnet application set the java extension folder to an older java version. When the extension configuration was set to the correct Java version, the problem was solved.

huangapple
  • 本文由 发表于 2020年8月13日 22:41:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/63397537.html
匿名

发表评论

匿名网友

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

确定