gpt4 book ai didi

ssl - TLS 与 mosquitto 的连接错误

转载 作者:太空宇宙 更新时间:2023-11-03 14:39:34 29 4
gpt4 key购买 nike

我用mosquitto做broker,客户端用Paho,用tcp连接好像没问题,然后想用TLS,问题来了。我首先生成了 ca.key,ca.crt,然后我用它生成了 server.crt、server.key、c​​lient.crt、client.key;然后我尝试在 https://github.com/Lunatictwo/mqtt-ssl-java 中编写代码,这是我的代码:

public static void main(String[] args) {
// TODO Auto-generated method stub
String address = "ssl://192.168.100.46:8883";
String topic = "topic0";
String caFilePath = "SSL/ca.crt";
String clientCrtFilePath = "SSL/client.crt";
String clientKeyFilePath = "SSL/client.key";
String keyPassword = "1234567890";
MemoryPersistence persistence = new MemoryPersistence();
try {
MqttConnectOptions options = new MqttConnectOptions();
options.setCleanSession(false);
options.setSocketFactory(SslUtil.getSocketFactory(caFilePath,clientCrtFilePath,clientKeyFilePath,keyPassword));

MqttClient client;
client = new MqttClient(address,"java-client",persistence);
client.connect(options);
client.subscribe(topic);
client.setCallback(new MyCallback());

MqttMessage message = new MqttMessage();
message.setPayload("MosquittoClient连接成功".getBytes());
client.publish(topic,message);

client.disconnect();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

当我运行这个演示时,我在 mosquitto 中得到了这个:

New connection from 192.168.100.46 on port 8883.
1496799343: OpenSSL Error: error:140890B2:SSL routines:SSL3_GET_CLIENT_CERTIFICATE:no certificate returned
1496799343: Socket error on client (null), disconnecting.
1496799343: New connection from 192.168.100.46 on port 8883.
1496799343: OpenSSL Error: error:140890B2:SSL routines:SSL3_GET_CLIENT_CERTIFICATE:no certificate returned
1496799343: Socket error on client (null), disconnecting.

这是 eclipse 中的信息:

MqttException (0) - java.net.SocketException: Software caused connection abort: socket write error
at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:38)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:690)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.SocketException: Software caused connection abort: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:109)
at java.net.SocketOutputStream.write(SocketOutputStream.java:153)
at sun.security.ssl.OutputRecord.writeBuffer(OutputRecord.java:431)
at sun.security.ssl.OutputRecord.write(OutputRecord.java:417)
at sun.security.ssl.SSLSocketImpl.writeRecordInternal(SSLSocketImpl.java:876)
at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:847)
at sun.security.ssl.SSLSocketImpl.writeRecord(SSLSocketImpl.java:717)
at sun.security.ssl.Handshaker.sendChangeCipherSpec(Handshaker.java:1077)
at sun.security.ssl.ClientHandshaker.sendChangeCipherAndFinish(ClientHandshaker.java:1222)
at sun.security.ssl.ClientHandshaker.serverHelloDone(ClientHandshaker.java:1134)
at sun.security.ssl.ClientHandshaker.processMessage(ClientHandshaker.java:348)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:979)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:914)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1062)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1375)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1403)
at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1387)
at org.eclipse.paho.client.mqttv3.internal.SSLNetworkModule.start(SSLNetworkModule.java:97)
at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:676)
... 1 more

我的客户似乎没有将其证书发送给代理,但它不应该自动发送证书吗?谢谢你的帮助。

最佳答案

您正在 Github 中使用我的代码。看来您的证书文件没有效果。确保目录“./SSL”中的所有 ca 文件。你最好生成ca文件再试一次。

关于ssl - TLS 与 mosquitto 的连接错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44402227/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com