Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mqtt Nuget Version 4.3.x not connecting via TLS #1830

Closed
alberk8 opened this issue Sep 6, 2023 · 0 comments · Fixed by #1833
Closed

Mqtt Nuget Version 4.3.x not connecting via TLS #1830

alberk8 opened this issue Sep 6, 2023 · 0 comments · Fixed by #1833
Labels
bug Something isn't working

Comments

@alberk8
Copy link

alberk8 commented Sep 6, 2023

Describe the bug

MQTT TLS connection ends up with error below. The earlier nuget version 4.2.1.781 works.
Tested on .Net 6 and 7

MQTTnet.Adapter.MqttConnectingFailedException: 'Error while authenticating. Expected at least 770 bytes but there are only 3 bytes'

Which component is your bug related to?

  • ManagedClient

To Reproduce

Steps to reproduce the behavior:

  1. Using this version of MQTTnet 'nuget 4.3.0.858'.
  2. Run this code
 static async Task Main(string[] args)
 {
     string _topic = "/monitor";
     Console.WriteLine("Starting Part 1");
    
     string clientID = Guid.NewGuid().ToString();
     var options = new MqttClientOptionsBuilder()
       .WithClientId(clientID)
       .WithTcpServer((opt) =>
         {
         opt.Server = "broker.emqx.io";
         opt.Port = 8883;
         opt.TlsOptions = new MqttClientTlsOptions { 
				UseTls = true, 
				SslProtocol = System.Security.Authentication.SslProtocols.Tls12 
					      |	System.Security.Authentication.SslProtocols.Tls13 };

         })
        .WithCleanSession()
        .Build();

       using var mqttClient = new MqttFactory().CreateMqttClient();
       var connResult = await mqttClient.ConnectAsync(options, CancellationToken.None);
       Console.WriteLine($"Connection Result: {connResult.ResultCode}");
  
       if (connResult.ResultCode == MqttClientConnectResultCode.Success)
       {
         var result = await mqttClient.PublishAsync(new MqttApplicationMessage 
         { 
             Topic = _topic + "/data", 
             Payload = Encoding.UTF8.GetBytes("123") 
         });
      }
       else
       {
         Console.WriteLine(connResult.ReasonString);
       }

     Console.ReadKey();
 
 }

Expected behavior

There should be no error. Previous version of the nuget works.

Screenshots

If applicable, add screenshots to help explain your problem.

Additional context / logging

Add any other context about the problem here.
Include debugging or logging information here:

\\ Put your logging output here.

Code example

Please provide full code examples below where possible to make it easier for the developers to check your issues.

Ideally a Unit Test (which shows the error) is provided so that the behavior can be reproduced easily.

@alberk8 alberk8 added the bug Something isn't working label Sep 6, 2023
@chkr1011 chkr1011 linked a pull request Sep 6, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant