Noga Knaz
Noga Knaz

Reputation: 11

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

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.

Upvotes: 0

Views: 656

Answers (1)

Noga Knaz
Noga Knaz

Reputation: 11

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.

Upvotes: 1

Related Questions