-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Support custom CA chain validation #1851
Conversation
How can I fix the build error?
|
#else | ||
public SslProtocols SslProtocol { get; set; } = SslProtocols.Tls12 | (SslProtocols)0x00003000 /*Tls13*/; | ||
#endif | ||
|
||
#if NET7_0_OR_GREATER | ||
public string CertificationAuthoritiesFile { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd recommend to make this API always visible but throw on the setter for <net7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other properties in this project are usually not available because they are excluded by the compiler. I would like to stick to this approach and avoid changing the strategy here.
TargetHost = targetHost, | ||
CipherSuitesPolicy = _tcpOptions.TlsOptions.CipherSuitesPolicy, | ||
EncryptionPolicy = _tcpOptions.TlsOptions.EncryptionPolicy, | ||
AllowRenegotiation = _tcpOptions.TlsOptions.AllowRenegotiation | ||
}; | ||
#if NET7_0_OR_GREATER | ||
if (!string.IsNullOrEmpty(_tcpOptions.TlsOptions.CertificationAuthoritiesFile)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another option: File.Exists
(error when doesn't exist would be nice but possibly just letting it error later is fine as well, follow existing conventions)
@@ -132,5 +132,13 @@ public MqttClientTlsOptionsBuilder WithCipherSuitesPolicy(EncryptionPolicy encry | |||
return this; | |||
} | |||
#endif | |||
|
|||
#if NET7_0_OR_GREATER | |||
public MqttClientTlsOptionsBuilder WithCertificationAuthoritiesFile(string pemFile) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another option will be WithCaFile
is shorter -not as descriptive as the other methods in this class - but is aligned with other mqtt tooling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The other methods and properties in this project usually take the "long" version or adopt the same name when it is simply mapped to a property in the .NET framework.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this comment is outdated, the last commit changed the signature to: public MqttClientTlsOptionsBuilder WithTrustChain(X509Certificate2Collection chain)
To align with .NET api this could be .WithCustomTrustChain
I think it would be good to support handling of certificate authorities directly within the MQTTnet library. Some observations and questions:
|
thanks @logicaloud for you comments:
|
@logicaloud with this 0b5dff5 I've addressed your comments:
|
Well, keep in mind this is on top of MqttTlsOptions, so I guess the TrustChain concept will be easier to get. |
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 connectionDetails
CertificationAuthoritiesFile
option to TlsOptionsWithCertificationAuthoritiesFile(string pemFile)
to TlsOptionsBuilderOverseeds #1848