fix(S2-b): use authenticated WSS on standard TLS port
This commit is contained in:
@@ -73,7 +73,7 @@ public sealed class SettingsService
|
|||||||
|
|
||||||
public int MqttPort
|
public int MqttPort
|
||||||
{
|
{
|
||||||
get => Preferences.Default.Get(MqttPortKey, 8884);
|
get => Preferences.Default.Get(MqttPortKey, 443);
|
||||||
set => Preferences.Default.Set(MqttPortKey, value);
|
set => Preferences.Default.Set(MqttPortKey, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -185,6 +185,9 @@ public sealed class MqttSyncService : IMqttSyncService
|
|||||||
{
|
{
|
||||||
Host = _settings.MqttHost,
|
Host = _settings.MqttHost,
|
||||||
Port = _settings.MqttPort,
|
Port = _settings.MqttPort,
|
||||||
|
WebSocketUri = _settings.MqttPort == 443
|
||||||
|
? $"wss://{_settings.MqttHost}/mqtt"
|
||||||
|
: null,
|
||||||
ClientId = _settings.MqttClientId,
|
ClientId = _settings.MqttClientId,
|
||||||
Username = _settings.MqttOrgId,
|
Username = _settings.MqttOrgId,
|
||||||
Password = password,
|
Password = password,
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public sealed partial class SettingsViewModel : ObservableObject
|
|||||||
private string _mqttHost = "";
|
private string _mqttHost = "";
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private string _mqttPort = "8884";
|
private string _mqttPort = "443";
|
||||||
|
|
||||||
[ObservableProperty]
|
[ObservableProperty]
|
||||||
private string _mqttOrgId = "";
|
private string _mqttOrgId = "";
|
||||||
|
|||||||
@@ -58,7 +58,7 @@
|
|||||||
<Switch Grid.Column="1" IsToggled="{Binding MqttEnabled}" />
|
<Switch Grid.Column="1" IsToggled="{Binding MqttEnabled}" />
|
||||||
</Grid>
|
</Grid>
|
||||||
<Entry Text="{Binding MqttHost}" Placeholder="dev.hub.umagul.net" />
|
<Entry Text="{Binding MqttHost}" Placeholder="dev.hub.umagul.net" />
|
||||||
<Entry Text="{Binding MqttPort}" Placeholder="8884" Keyboard="Numeric" />
|
<Entry Text="{Binding MqttPort}" Placeholder="443 (WSS) or 8884 (MQTTS)" Keyboard="Numeric" />
|
||||||
<Entry Text="{Binding MqttOrgId}" Placeholder="Organization ID / MQTT username" />
|
<Entry Text="{Binding MqttOrgId}" Placeholder="Organization ID / MQTT username" />
|
||||||
<Entry Text="{Binding MqttPassword}" Placeholder="New MQTT password (stored securely)" IsPassword="True" />
|
<Entry Text="{Binding MqttPassword}" Placeholder="New MQTT password (stored securely)" IsPassword="True" />
|
||||||
<Label Text="{Binding MqttClientId, StringFormat='Client: {0}'}" FontSize="10" TextColor="Gray" />
|
<Label Text="{Binding MqttClientId, StringFormat='Client: {0}'}" FontSize="10" TextColor="Gray" />
|
||||||
|
|||||||
@@ -11,7 +11,10 @@ namespace FieldLogger.Sync;
|
|||||||
public sealed record MqttBrokerConfig
|
public sealed record MqttBrokerConfig
|
||||||
{
|
{
|
||||||
public required string Host { get; init; }
|
public required string Host { get; init; }
|
||||||
public int Port { get; init; } = 8884;
|
public int Port { get; init; } = 443;
|
||||||
|
/// <summary>When set, use MQTT over secure WebSockets (normally
|
||||||
|
/// wss://dev.hub.umagul.net/mqtt) instead of raw MQTTS.</summary>
|
||||||
|
public string? WebSocketUri { get; init; }
|
||||||
public bool UseTls { get; init; } = true;
|
public bool UseTls { get; init; } = true;
|
||||||
public required string ClientId { get; init; }
|
public required string ClientId { get; init; }
|
||||||
/// <summary>Interim credential (username = orgId, password = scoped per-org secret).
|
/// <summary>Interim credential (username = orgId, password = scoped per-org secret).
|
||||||
@@ -52,8 +55,13 @@ public sealed class MqttnetTransport : IMqttTransport, IAsyncDisposable
|
|||||||
|
|
||||||
_ackTopic = ackTopic;
|
_ackTopic = ackTopic;
|
||||||
|
|
||||||
var options = new MqttClientOptionsBuilder()
|
var builder = new MqttClientOptionsBuilder();
|
||||||
.WithTcpServer(_config.Host, _config.Port)
|
if (string.IsNullOrWhiteSpace(_config.WebSocketUri))
|
||||||
|
builder.WithTcpServer(_config.Host, _config.Port);
|
||||||
|
else
|
||||||
|
builder.WithWebSocketServer(options => options.WithUri(_config.WebSocketUri));
|
||||||
|
|
||||||
|
var options = builder
|
||||||
.WithClientId(_config.ClientId)
|
.WithClientId(_config.ClientId)
|
||||||
.WithProtocolVersion(MQTTnet.Formatter.MqttProtocolVersion.V500)
|
.WithProtocolVersion(MQTTnet.Formatter.MqttProtocolVersion.V500)
|
||||||
.WithCleanSession(false) // persistent session (durable)
|
.WithCleanSession(false) // persistent session (durable)
|
||||||
|
|||||||
Reference in New Issue
Block a user