Received fatal alert: handshake_failure

吃可爱长大的小学妹 提交于 2019-11-29 22:47:22

问题


I'm trying to send push notifications to my device using javapns library in liferay. Here's the code:

private void pushNotification(ActionRequest actionRequest,
            ActionResponse actionResponse) {

        try {
            System.out.println("Push");

            Push.alert("Hello World!", "ck.p12", "PASSPHRASE", false, "TOKEN");

        } catch (CommunicationException e) {
            System.out.println("CommunicationException");
            e.printStackTrace();
        } catch (KeystoreException e) {
            System.out.println("KeystoreException");
            e.printStackTrace();
        }

    }

I'm getting this error when the pushNotification is called:

ERROR [PushNotificationManager:450] Delivery error: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure

I've googled it but couldn't find any solution.

Does anyone know how to solve this problem?


回答1:


The javax.net.ssl.SSLHandshakeException exception is usually thrown when the server you're trying to connect to does not have a valid certificate from an authorized CA.

Put simply, the server you're attempting to connect to is most likely using a self-signed certificate and you have to accomodate for that in your Java code. This involves creating a custom KeyStore, etc. See this Stack Overflow answer for full implementation details.




回答2:


Set the following properties on the server

javax.net.ssl.keyStore=../keystore/keystoreFile.jks
javax.net.ssl.keyStorePassword=yourPassword
javax.net.ssl.trustStore=../keystore/keystoreFile.jks
javax.net.ssl.trustStorePassword=yourPassword
javax.net.debug=true

you can create your keystore using

keytool -genkey -alias myKeyStore -keyalg RSA -keystore /home/aniket/keystore/keystoreFile.jks



回答3:


This algo happens when for example the server only accept TLS and your client is trying to create a SSL connection... check also the server/client side config



来源:https://stackoverflow.com/questions/9498260/received-fatal-alert-handshake-failure

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!