-
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
Mutual authentication with tls #757
Comments
.WithTls(o =>
{
o.UseTls = true;
o.Certificates = new List<byte[]>
{
new X509Certificate(@"C:/Users/liqia/Downloads/server/ca.pem", "").Export(X509ContentType.Cert),
new X509Certificate(@"C:\Users\liqia\Downloads\newclient\client.pfx", "").Export(X509ContentType.Cert)
};
o.CertificateValidationCallback = (x509Certificate, chain, sslPolicyErrors, mqttClientTcpOptions) => true;
}) I have generated the .pfx cert file and imported them. And I received the following exception:
|
You might take a look at this project: https://github.com/SeppPenner/NetCoreMQTTExampleJsonConfig/blob/b5159009f33e23b425313ac8cfcb361474c0688b/NetCoreMQTTExampleJsonConfig/Program.cs#L47. I'm using a certificate succssfully in there. |
try There is also a way to use the certs in their original pem and key format, but I am still working on a blog post for that! |
it's a server demo. but I need a client demo |
Sorry, I misunderstood you here. |
This is also something to be documented once it works. I can do that if we find a solution. |
So with my code, I can connect to AWS IoT on windows, but not on Linux. In my case I receive: I have a suspicion that both of these issues might be related to https://github.com/dotnet/corefx/issues/34740# my code is as follows:
with helper method:
FYI, This code needs .net core 3 due to |
Hi everyone, i'm facing a similar problem with my code. I found that on linux it doesn't send the certificate(we checked packets in the network and we can say that the certificate is not sent when we are in linux) to the broker (i'm tring to make it work an aks), while on a windows VM it connects and reads messages. linux image is: mcr.microsoft.com/dotnet/core/aspnet:3.0-alpine here is my code: ` var mqttBrokerCertPubKey = new X509Certificate(cAcertificatePath);
|
not sure if it helps, but I found that @networkfusion 's example works on Linux (using Docker) if I exclude the RootCA and set |
we were able to understand the cause of the issue reported by @EmanueleGiuliano. bottomline, we solved the problem by adding the certificate to the cert store. we achieved this by running the lines below before configuring the MqttClient:
this solved out issues both on Linux and Windows. At this stage I am wondering if installing the certificate in the personal store would make passing the certificate list to the MqttClientOptions useless (SChannel in Windows and OpenSSL or other PKI stacks in Linux should be able to figure out the right cert to use once it's available in the cert store). Perhaps this step should be included into the library code itself? also, it would be interesting to test if this same behavior could be reprod on a previous version of .NET Core |
It cannot solve the problem, under docker aspnet:3.0-alpine Windows is fine, but Linux reports errors. |
已解决,两种方案实现TLS连接:
|
I still get this issue in .NET 6... Adding CA Certificate and Client certificate to the Certstore does not fix it. Anyone else having this Problem? |
Your solution works fine! Thanks for saving me another 2 hours of headaches! |
Describe your question
I have a mqtt broker like emqx,it support mutual authentication with tls, I connect the broker successfully by using Mqtt.fx client software. but I don't known how to set the tls option with MQTTnet, The wiki is also not clearly. Can you can help me?
The Mqtt.fx screenshot.
Which project is your question related to?
Mqttnet version: 3.0.5
Net core version: 2.2
The text was updated successfully, but these errors were encountered: