From 6e2e73f8e754b1c986b4b011cdb5d0bf39b93887 Mon Sep 17 00:00:00 2001 From: rido-min Date: Fri, 22 Sep 2023 22:18:29 -0700 Subject: [PATCH] fix order --- .../MqttClientCaFileCertificateValidationHandler.cs | 11 ++--------- .../Client/Options/MqttClientTlsOptionsBuilder.cs | 2 +- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/Source/MQTTnet/Client/Options/MqttClientCaFileCertificateValidationHandler.cs b/Source/MQTTnet/Client/Options/MqttClientCaFileCertificateValidationHandler.cs index 60fce664b..0aad9d0a2 100644 --- a/Source/MQTTnet/Client/Options/MqttClientCaFileCertificateValidationHandler.cs +++ b/Source/MQTTnet/Client/Options/MqttClientCaFileCertificateValidationHandler.cs @@ -22,8 +22,8 @@ internal static bool Handle(MqttClientCertificateValidationEventArgs cvArgs) string caFile = cvArgs.ClientOptions.TlsOptions.CaFile; if (!string.IsNullOrEmpty(caFile)) { +#if NET6_0_OR_GREATER X509Certificate2Collection caCerts = new X509Certificate2Collection(); -#if NET6_0_OR_GREATER caCerts.ImportFromPemFile(caFile); cvArgs.Chain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust; cvArgs.Chain.ChainPolicy.CustomTrustStore.AddRange(caCerts); @@ -36,21 +36,14 @@ internal static bool Handle(MqttClientCertificateValidationEventArgs cvArgs) } return res; #else - return false; + throw new InvalidOperationException("WithCaFile requires .NET6 or greater"); #endif - } else { -#if NET6_0_OR_GREATER - Trace.TraceWarning($"CaFile '{caFile}' not found."); -#endif return false; } } -#if NET6_0_OR_GREATER - Trace.TraceWarning(cvArgs.SslPolicyErrors.ToString()); -#endif return false; } } diff --git a/Source/MQTTnet/Client/Options/MqttClientTlsOptionsBuilder.cs b/Source/MQTTnet/Client/Options/MqttClientTlsOptionsBuilder.cs index 8da97bbc2..5dc5d96ac 100644 --- a/Source/MQTTnet/Client/Options/MqttClientTlsOptionsBuilder.cs +++ b/Source/MQTTnet/Client/Options/MqttClientTlsOptionsBuilder.cs @@ -144,8 +144,8 @@ public MqttClientTlsOptionsBuilder WithCaFile(string caFile) { throw new InvalidOperationException("WithCaFile cannot be used with a custom Certificate Validation Handler"); } - _tlsOptions.CaFile = caFile; WithCertificateValidationHandler(MqttClientCaFileCertificateValidationHandler.Handle); + _tlsOptions.CaFile = caFile; return this; } #endif