-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* validating chain * refactor after chain * split dps and hub certs * skip chain test * import chain * use gw in rido Co-authored-by: rido-min <[email protected]>
- Loading branch information
Showing
26 changed files
with
610 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/MQTTnet.Extensions.MultiCloud/Connections/X509ChainValidator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
using MQTTnet.Client; | ||
using System.Diagnostics; | ||
using System.Security.Cryptography.X509Certificates; | ||
|
||
namespace MQTTnet.Extensions.MultiCloud.Connections | ||
{ | ||
internal static class X509ChainValidator | ||
{ | ||
internal static bool ValidateChain(X509Certificate cert, string caCertFile) | ||
{ | ||
X509Chain chain = new(); | ||
chain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck; | ||
chain.ChainPolicy.RevocationFlag = X509RevocationFlag.ExcludeRoot; | ||
chain.ChainPolicy.VerificationFlags = X509VerificationFlags.NoFlag; | ||
chain.ChainPolicy.VerificationTime = DateTime.Now; | ||
chain.ChainPolicy.UrlRetrievalTimeout = new TimeSpan(0, 0, 0); | ||
X509Certificate2Collection caCerts = new(); | ||
caCerts.ImportFromPemFile(caCertFile); | ||
chain.ChainPolicy.CustomTrustStore.AddRange(caCerts); | ||
chain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust; | ||
var x5092 = new X509Certificate2(cert); | ||
var res = chain.Build(x5092); | ||
if (res == false) | ||
{ | ||
Trace.TraceError($"Error validating TLS chain for cert: '{cert.Subject}' issued by '{cert.Issuer}'"); | ||
Trace.TraceError($"Loaded {caCerts.Count} certs from caFile: {caCertFile} "); | ||
caCerts.ToList().ForEach(c => Trace.TraceError(c.Subject)); | ||
chain.ChainStatus.ToList().ForEach(s => Trace.TraceError(s.StatusInformation)); | ||
} | ||
return res; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.