Connect async via TLS is different on Windows and Linux.
- Dominant language
- C#
- Stars
- 5.1k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the bug
Connect async via TLS is different on Windows and Linux.
### Which component is your bug related to?
- Client
### To Reproduce
Steps to reproduce the behavior:
1. Use MQTTnet v4.3.6.1152.
2. Build the client code below.
3. Run the code on Windows and Linux. Do not provide any certificates. The code does not use any certificates by design.
4. See error on Windows and Linux.
### Actual behavior
Windows:
* ConnectAsync method throws an exception ("Authentication failed because the remote party sent a TLS alert: 'HandshakeFailure'.").
* CertificateValidationHandler event is not raised.
* RemoteCertificateValidationCallback method is not called.
Linux (Yocto v3.4):
* ConnectAsync method throws an exception ("The remote certificate was rejected by the provided RemoteCertificateValidationCallback").
* CertificateValidationHandler event is raised.
* RemoteCertificateValidationCallback method is called.
### Expected behavior
Flow and errors should be the same on Windows and Linux.
### Code example
public async void Connect()
{
try
{
var factory = new MqttFactory();
var client = factory.CreateMqttClient();
var options = new MqttClientTlsOptions();
options.UseTls = true;
options.CertificateValidationHandler = RemoteCertificateValidationCallback;
var optionsBuilder = new MqttClientOptionsBuilder()
.WithTcpServer("", 8883)
.WithTlsOptions(options);
MqttClientConnectResult result = await client.ConnectAsync(optionsBuilder.Build()).ConfigureAwait(false);
Log.Info($"Connected with result code: {result.ResultCode}. Reason: {result.ReasonString}).");
}
catch (Exception ex)
{
Log.Error($"Connection failed. {ex.Message}");
}
}
private bool RemoteCertificateValidationCallback(MqttClientCertificateValidationEventArgs arg)
{
// do nothing
return false;
}
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with MqttClientTlsOptions and the client ConnectAsync path, then compare TLS callback and error handling on Windows and Linux. Reproduce the example using MQTTnet v4.3.6.1152 without client certificates. Done means the callback flow and resulting errors are consistent across both platforms.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- networking, security
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100