Connection to mosquitto using tls1.3 with only ca.crt
- Dominant language
- C#
- Stars
- 5.1k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
I am working on an app which is to connect to a mosquitto broker using tls1.3. I will only get a ca.crt from the broker and no client certificates will be used.
My 1st question is am I doing it in a correct way (code below) as I could not find any example of connection using only a ca.crt.
My 2nd question is, When I use below code and configuration I keep getting the following exception:
"The client and server cannot communicate, because they do not possess a common algorithm". The exception does not change when I downgrade to tls1.2. Also, when I try to connect using a python app it works like a charm.
I am using .NetFramework 4.6.2,
mosquitto.conf
```
acl_file ./configs/acl.acl
password_file ./configs/pwfile
allow_anonymous false
listener 8883
cafile ./certs/ca.crt
certfile ./certs/root.crt
keyfile ./certs/root.key
tls_version tlsv1.3
```
I am creating the client in the following way:
```
ServicePointManager.SecurityProtocol = (SecurityProtocolType) 12288;
var caCert = X509Certificate.CreateFromSignedFile(CertificatePath);
var mqttFactory = new MqttFactory();
var tlsOptions = new MqttClientTlsOptions
{
UseTls = true,
Certificates = new List { caCert },
SslProtocol = (SslProtocols)12288,
CertificateValidationHandler = delegate { return true; },
IgnoreCertificateChainErrors = true,
IgnoreCertificateRevocationErrors = true,
AllowUntrustedCertificates = true
};
var options = new MqttClientOptions
{
ClientId = clientId,
ProtocolVersion = MqttProtocolVersion.V311,
ChannelOptions = new MqttClientTcpOptions
{
Server = "localhost",
Port = 8883,
TlsOptions = tlsOptions
}
};
if (options.ChannelOptions == null)
{
throw new InvalidOperationException();
}
options.Credentials = new MqttClientCredentials
{
Username = "username",
Password = Encoding.UTF8.GetBytes("password")
};
options.CleanSession = true;
options.KeepAlivePeriod = TimeSpan.FromSeconds(5);
var client = mqttFactory.CreateMqttClient();
client.ConnectedHandler = new MqttClientConnectedHandlerDelegate(ShowConnected);
client.DisconnectedHandler = new MqttClientDisconnectedHandlerDelegate(ShowDisConnected);
await client.ConnectAsync(options);
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.