-
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
UWP TLS can't connect #202
Comments
Hi there, I'm facing the exact same problem. I found out, that the problem occurs in constructing the Certificate from the IBuffer (see source here). It's no problem to parse the certificate from an *.crt-file. However, then the MQTT client is lacking the private key required for authentication purposes. I also tried parsing the *.pfx-file with the X509Certificate2 class first (which works). But after exporting it from the X509Certificate2 object and putting it into the Certificate, it fails:
@433MHz do you have any solutions regarding this issue? |
Hey, I changed my approach to have an encrypted connection. Trusted certs are no problems for the client in UWP. Think about using a trusted cert! I didn't followed this problem any longer, but i would be interested, if you get an answer :) |
This worked for me:
|
Hi, As @asthomas suggested, I am using a PFX file which includes the private key, client certificate, and certificate chain (i.e. VeriSign). My code looks like that:
However, on startAsync method a MqttManagedProcessFailedEventArgs is thrown with message "Cannot find the requested object.". In order to check that certificates and key are correct, I tested them via MQTTfx and the result is positive (e.g. it connects, subscribes, etc. ) May anyone point me in the right direction, please? ;-) |
There is a brief update: the very same code works like a charm in a .NET Core application (i.e. Console App .NET core); it connects, subscribes, publishes, and exchanges messages. |
This is quite strange. Because the UWP implementation cannot be changed. It is just a flag indicating that the underlying stream should use TLS. But the flag says "SocketProtectionLevel.Tls12". Is it maybe a different version of TLS? |
Hi @chkr1011 , that seems definitely strange... Amazon states that they use TLS 1.2 on their pages and tutorials; so, there should not be any issue : P.S. I did some testing by changing tls versions and mqtt protocol versions, but the issue is still the same :( |
For completeness, here the StackTrace of failed event arg:
|
Hi,
Since days i'm trying to implement TLS for my UWP App.
The client works fine unencrypted but as soon as i want to use TLS with my pfx certificate (cert and key file), the client returns me an error.
I'm new in handling certificates in UWP but i'm sure this should work!
It doesn't matter if i read the pfx certificate directly via the File.ReadAllBytes() or via the X509Certificate, i get the same error...
My code to setup the client:
var certificate = new X509Certificate("client.pfx");
var options = new MQTTnet.ManagedClient.ManagedMqttClientOptionsBuilder()
.WithAutoReconnectDelay(TimeSpan.FromSeconds(5))
.WithClientOptions(new MQTTnet.Client.MqttClientOptionsBuilder()
.WithClientId("efgjbjucgufgugf")
.WithTcpServer("192.168.0.205", 8883)
.WithTls(true, true, true, certificate.Export(X509ContentType.SerializedCert))
.Build())
.Build();
Trace - The german error means "The requested object could not be found"
Initialize ---> System.Runtime.InteropServices.COMException: Das angeforderte Objekt wurde nicht gefunden.
Initialize
at Windows.Security.Cryptography.Certificates.Certificate..ctor(IBuffer certBlob)
at MQTTnet.Implementations.MqttTcpChannel.LoadCertificate(MqttClientTcpOptions options)
at MQTTnet.Implementations.MqttTcpChannel.d__16.MoveNext()
--- End of inner exception stack trace ---
at MQTTnet.Internal.TaskExtensions.d__0.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MQTTnet.Adapter.MqttChannelAdapter.d__14.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at MQTTnet.Client.MqttClient.d__22.MoveNext()
Thanks!
The text was updated successfully, but these errors were encountered: