有谁知道如何在 Unity3D(使用 Tls1.2)上使用 m2mqtt?
Does anyone know how to use m2mqtt on Unity3D (with Tls1.2)?
我正在 Unity 中开发 AR 应用程序,我需要连接到启用了 TLS 协议的 MQTT 代理。
我能够成功连接到未启用 TLS 的 MQTT 代理(In unity),并且我可以使用管理员给我的 MQTT 资源管理器应用程序证书成功连接到启用 TLS 的代理。 (经纪人正在使用 TLS 1.2)
但是当我尝试使用 paho-m2mqtt Unity 中的 c# 库 (https://github.com/eclipse/paho.mqtt.m2mqtt) 连接到支持 TLS 的服务器时,出现以下异常:
Connection error: uPLibrary.Networking.M2Mqtt.Exceptions.MqttConnectionException: Exception connecting to the broker
---> System.ArgumentException: SSL/TLS protocol version not supported
这是我用来测试连接的代码(我将服务器证书、客户端证书和客户端密钥存储在 Assets/StreamingAssests,我可能错误地使用了证书在制作 MqttClient 时,但这是大多数人的连接方式):
public void connect(broker, port)
{
string caCertLoc = Application.streamingAssetsPath + "/ca.crt";
string clientCertLoc = Application.streamingAssetsPath + "/clientCert.crt";
X509Certificate2 caCert = new X509Certificate2(caCertLoc);
X509Certificate2 clientCert = new X509Certificate2(clientCertLoc);
MqttClient client = new MqttClient(broker, port, true,
X509Certificate.CreateFromCertFile(caCertLoc),
X509Certificate2.CreateFromCertFile(clientCertLoc),
MqttSslProtocols.TLSv1_2,
MyRemoteCertificateValidationCallback);
string clientId = Guid.NewGuid().ToString();
try
{
client.Connect(clientId);
}
catch (Exception e)
{
UnityEngine.Debug.LogError("Connection error: " + e);
}
}
我将不胜感激任何帮助,因为我完全坚持这一点。
我想通了,原来我使用的是旧的 .dll 用于 M2Mqtt - 上面的实现现在可以工作(唯一的变化是 clinetCert 必须是 .pfx)
我正在 Unity 中开发 AR 应用程序,我需要连接到启用了 TLS 协议的 MQTT 代理。
我能够成功连接到未启用 TLS 的 MQTT 代理(In unity),并且我可以使用管理员给我的 MQTT 资源管理器应用程序证书成功连接到启用 TLS 的代理。 (经纪人正在使用 TLS 1.2)
但是当我尝试使用 paho-m2mqtt Unity 中的 c# 库 (https://github.com/eclipse/paho.mqtt.m2mqtt) 连接到支持 TLS 的服务器时,出现以下异常:
Connection error: uPLibrary.Networking.M2Mqtt.Exceptions.MqttConnectionException: Exception connecting to the broker
---> System.ArgumentException: SSL/TLS protocol version not supported
这是我用来测试连接的代码(我将服务器证书、客户端证书和客户端密钥存储在 Assets/StreamingAssests,我可能错误地使用了证书在制作 MqttClient 时,但这是大多数人的连接方式):
public void connect(broker, port)
{
string caCertLoc = Application.streamingAssetsPath + "/ca.crt";
string clientCertLoc = Application.streamingAssetsPath + "/clientCert.crt";
X509Certificate2 caCert = new X509Certificate2(caCertLoc);
X509Certificate2 clientCert = new X509Certificate2(clientCertLoc);
MqttClient client = new MqttClient(broker, port, true,
X509Certificate.CreateFromCertFile(caCertLoc),
X509Certificate2.CreateFromCertFile(clientCertLoc),
MqttSslProtocols.TLSv1_2,
MyRemoteCertificateValidationCallback);
string clientId = Guid.NewGuid().ToString();
try
{
client.Connect(clientId);
}
catch (Exception e)
{
UnityEngine.Debug.LogError("Connection error: " + e);
}
}
我将不胜感激任何帮助,因为我完全坚持这一点。
我想通了,原来我使用的是旧的 .dll 用于 M2Mqtt - 上面的实现现在可以工作(唯一的变化是 clinetCert 必须是 .pfx)