Fix wrong TLS usage (#1833)

* Fix wrong usage of TLS options

* Fix public broker tests

* Update ReleaseNotes.md
This commit is contained in:
Christian
2023-09-06 20:08:35 +02:00
committed by GitHub
parent cae7206733
commit 6fdee9e0db
5 changed files with 26 additions and 16 deletions
@@ -32,7 +32,12 @@ namespace MQTTnet.Client
throw new InvalidOperationException("A channel must be set.");
}
var tlsOptions = _tlsOptions;
// The user can specify the TCP options with already configured TLS options
// or start with TLS settings not knowing which transport will be used (depending
// on the order of called methods from the builder).
// The builder prefers the explicitly set TLS options!
var tlsOptions = _tlsOptions ?? _tcpOptions?.TlsOptions;
if (_tlsParameters != null)
{
if (_tlsParameters?.UseTls == true)
@@ -46,13 +46,13 @@ namespace MQTTnet.Implementations
var uri = _options.Uri;
if (!uri.StartsWith("ws://", StringComparison.OrdinalIgnoreCase) && !uri.StartsWith("wss://", StringComparison.OrdinalIgnoreCase))
{
if (_options.TlsOptions?.UseTls == false)
if (_options.TlsOptions?.UseTls == true)
{
uri = "ws://" + uri;
uri = "wss://" + uri;
}
else
{
uri = "wss://" + uri;
uri = "ws://" + uri;
}
}