Skip to content

Commit

Permalink
fix order
Browse files Browse the repository at this point in the history
  • Loading branch information
rido-min committed Sep 23, 2023
1 parent 68ca3be commit 6e2e73f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6e2e73f

Please sign in to comment.