Skip to content

Commit

Permalink
Fix not working certificate selection (#78)
Browse files Browse the repository at this point in the history
* Pass the selected certificate (with password) from the UI to the internal MQTT client

* Add MQTT specific words to spell checker dictionary.
  • Loading branch information
chkr1011 authored Feb 17, 2024
1 parent bd05fa8 commit fd296ad
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
24 changes: 24 additions & 0 deletions Source/Services/Mqtt/MqttClientService.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Net.Security;
using System.Security.Authentication;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Threading;
using mqttMultimeter.Controls;
using mqttMultimeter.Pages.Connection;
Expand Down Expand Up @@ -95,6 +98,27 @@ public async Task<MqttClientConnectResult> Connect(ConnectionItemViewModel item)
o.IgnoreCertificateChainErrors = item.ServerOptions.IgnoreCertificateErrors;
o.IgnoreCertificateRevocationErrors = item.ServerOptions.IgnoreCertificateErrors;
o.CertificateValidationHandler = item.ServerOptions.IgnoreCertificateErrors ? _ => true : null;
if (!string.IsNullOrEmpty(item.SessionOptions.CertificatePath))
{
X509Certificate2Collection certificates = new();
if (string.IsNullOrEmpty(item.SessionOptions.CertificatePassword))
{
certificates.Add(new X509Certificate2(item.SessionOptions.CertificatePath));
}
else
{
certificates.Add(new X509Certificate2(item.SessionOptions.CertificatePath, item.SessionOptions.CertificatePassword));
}
o.Certificates = certificates;
o.ApplicationProtocols = new List<SslApplicationProtocol>
{
// TODO: Consider exposing this in the UI.
new("mqtt")
};
}
});
}

Expand Down
9 changes: 9 additions & 0 deletions Source/mqttMultimeter.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -241,5 +241,14 @@
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAlwaysTreatStructAsNotReorderableMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Avalonia/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=CONNACK/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=PINGREQ/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=PINGRESP/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=PUBACK/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=PUBCOMP/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=PUBREC/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=PUBREL/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=SUBACK/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tnet/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=UNSUBACK/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Viewbox/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

0 comments on commit fd296ad

Please sign in to comment.