MqttException(0) - javax.net.ssl.SSLHandshakeException:使用MQTTAndroid客户端进行握手失败

时间:2018-05-18 08:52:07

标签: android ssl mosquitto

这是我在Android客户端访问运行在我的raspberrypi上的mosquitto mqtt代理的错误

  

javax.net.ssl.SSLHandshakeException:SSL握手中止:ssl = 0x90e76d40:系统调用期间的I / O错误,同级连接重置

这是尝试连接的代码的一部分

  

keystore.bks包含我的CA.crt和client.crt

client = new MqttAndroidClient(getApplicationContext(), "ssl://192.168.43.112:1883", clientId);
InputStream input = getApplicationContext().getAssets().open("keystore.bks");
options = new MqttConnectOptions();
options.setSocketFactory(client.getSSLSocketFactory(input,"password"));
IMqttToken token = client.connect(options);
token.setActionCallback(new IMqttActionListener() {
    @Override
    public void onSuccess(IMqttToken asyncActionToken) {
         Log.d("Connection", "Connected to Broker ");
         //Toast.makeText(getApplicationContext(),"ConnectiontoMQTTBrokerMade", Toast.LENGTH_SHORT).show();
         pubConnect.setVisibility(View.INVISIBLE);
         pubDisconnect.setVisibility(View.VISIBLE);
         pubPub.setVisibility(View.VISIBLE);
         ipinputpublish.setVisibility(View.INVISIBLE);
         messagemqtt.setVisibility(View.VISIBLE);
    }

    @Override
    public void onFailure(IMqttToken asyncActionToken, Throwable exception) {
        //Toast.makeText(getApplicationContext(),"ConnectiontoMQTTBrokerRejected", Toast.LENGTH_SHORT).show();
        Toast.makeText(getApplicationContext(), exception.toString(), Toast.LENGTH_LONG).show();
        Log.e("Connection Error", exception.toString());
        Log.d("Connection", "Unable to connect to Broker");
    }
});

经纪人方面,我收到此日志

  

端口1883上192.168.43.1的新连接。

     

客户端出现套接字错误,断开连接。

mosquitto.conf -

pid_file /var/run/mosquitto.pid 
persistence true 
persistence_location /var/lib/mosquitto/ 
include_dir /etc/mosquitto/conf.d 

cafile /etc/mosquitto/ca_certificates/ca.crt 
certfile /etc/mosquitto/certs/server.crt 
keyfile /etc/mosquitto/certs/server.key 
require_certificate true

如果我使用

mosquitto_sub -t 'test/topic' -v --cafile ca.crt --cert client.crt --key client.key

它已订阅。

有人可以告诉我导致此错误的原因是什么吗?

0 个答案:

没有答案