Skip to content

Commit 7604ef0

Browse files
authored
Fixed Mqtt Certification validator if given Path for Certificates is null. (#263)
1 parent 6bfa1c9 commit 7604ef0

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

umatiGateway/Core/Mqtt/MqttProvider.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,9 +218,11 @@ private bool ValidateServerCertificate(MqttClientCertificateValidationEventArgs
218218
Logger.Info($"Valid From : {serverCertificate.NotBefore}");
219219
Logger.Info($"Valid Until : {serverCertificate.NotAfter}");
220220
Logger.Info($"Key Algorithm : {serverCertificate.GetKeyAlgorithm()}");
221+
string servercertificatePath = this.app.ActiveConfiguration.MqttProviderConfig.ServerCertificatePath;
222+
string customCertificatePath = this.app.ActiveConfiguration.MqttProviderConfig.CustomCaCertificatePath;
221223

222224
// Zertifikat speichern, falls nicht vorhanden
223-
if (!File.Exists(this.app.ActiveConfiguration.MqttProviderConfig.ServerCertificatePath))
225+
if (servercertificatePath != null && !File.Exists(servercertificatePath))
224226
{
225227
Logger.Info("Saving server certificate to disk.");
226228
File.WriteAllBytes(this.app.ActiveConfiguration.MqttProviderConfig.ServerCertificatePath, serverCertificate.Export(X509ContentType.Cert));
@@ -251,7 +253,7 @@ private bool ValidateServerCertificate(MqttClientCertificateValidationEventArgs
251253
}
252254

253255
// Schritt 2: Validierung mit benutzerdefinierter CA (falls vorhanden)
254-
if (File.Exists(this.app.ActiveConfiguration.MqttProviderConfig.CustomCaCertificatePath))
256+
if (customCertificatePath != null && File.Exists(customCertificatePath))
255257
{
256258
var customCaCertificate = new X509Certificate2(File.ReadAllBytes(this.app.ActiveConfiguration.MqttProviderConfig.CustomCaCertificatePath));
257259
using var customChain = new X509Chain();

0 commit comments

Comments
 (0)