问题描述
我有一个使用Java 8 u161的基于Swing的Java应用程序。 应用程序使用的jre存储在其目录之一中(它不使用已安装的jre)。 应用程序中的屏幕之一接近Webshere,该Webshere通过HTTPS安装在远程服务器上。公钥安装在客户端的jre \ lib \ security文件夹中的cacert上。
当应用程序作为独立应用程序运行时,一切都很好:握手成功完成,消息发送到服务器,返回的代码为200(确定)。 但是,当应用程序与另一个应用程序(将代码注入Java应用程序的dotnet应用程序)协同运行时,会抛出“ javax.net.ssl.SSLKeyException:RSA premaster秘密错误”
通过卸载并重新安装所有Java版本,可以解决Internet上大多数类似的问题。但是我的Java没有安装,所以我不能这样做。
我检查了三倍,以确保我的Java应用程序使用了正确的jre。
我不知道是什么原因导致此异常,我也不知道还要检查什么。
这是我打开连接的方式:
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
这是完整的堆栈跟踪:
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
任何信息都值得赞赏。
解决方法
就像在较早的帖子中提到的许多关于异常的人一样
javax.net.ssl.SSLKeyException:RSA premaster机密错误
表示两个不同的Java版本混合在一起。因此,重新安装Java会有帮助。
在我看来,dotnet应用程序将Java扩展文件夹设置为较旧的Java版本。将扩展名配置设置为正确的Java版本后,问题已解决。