Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds WithCaFile TlsOption to validate the connection with X509ChainPolicy.CustomRootTrust #1848

Closed
wants to merge 4 commits into from

Conversation

ridomin
Copy link
Contributor

@ridomin ridomin commented Sep 23, 2023

Summary

Most MQTT clients from Paho (python, Java, GO) and even mosquitto-clients, allow to specify a CaFile to connect to TLS endpoints protected with certificates issued by a private CA.

A good example is test.mosquitto.org:8883 that requires https://test.mosquitto.org/ssl/mosquitto.org.crt to validate the server connection

Details

  • Adds a CaFile option to TlsOptions
  • Adds a WithCaFile(string caFile) to TlsOptionsBuilder
  • Adds a new CertificateValidationHandler to configure the X509 chain without revocation.
  • Adds a new sample, including the test.mosquitto.org CaFile (this might require to be updated when it gets expired in 2030 :) )

CertificateValidationHandler cannot be set within WithCaFile to avoid overriding the handler.

Not use sure if the #IF DEFS can be optimized to other platforms, since the custom chain validator was added in .NET 5, but targeting .NET6 since .NET5 is already out of support.

caCerts.ImportFromPemFile(caFile);
cvArgs.Chain.ChainPolicy.TrustMode = X509ChainTrustMode.CustomRootTrust;
cvArgs.Chain.ChainPolicy.CustomTrustStore.AddRange(caCerts);
cvArgs.Chain.ChainPolicy.RevocationMode = X509RevocationMode.NoCheck;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private CAs are very likely to do not offer revocation endpoints.


public MqttClientTlsOptionsBuilder WithCaFile(string caFile)
{
if (_tlsOptions.CertificateValidationHandler != null)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WithCaFile needs to configure the CertificateValidationHandler, if it was manually assigned this throws an exception.

@ridomin ridomin changed the title Adds CaFile TlsOption Adds WithCaFile TlsOption to validate the connection with X509ChainPolicy.CustomRootTrust Sep 23, 2023
@ridomin
Copy link
Contributor Author

ridomin commented Sep 23, 2023

.. apologies for the 4 commits, ready to review now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants