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

Send client and root CA certificate #1175

Open
michal7bk opened this issue Jun 2, 2021 · 3 comments
Open

Send client and root CA certificate #1175

michal7bk opened this issue Jun 2, 2021 · 3 comments
Labels
question It is a question regarding the project

Comments

@michal7bk
Copy link

Describe your question

I have a pkcs12 file that contains the client certificate, CA, and private key.
Moquette Server (specific application requirements) expects that client using Certificates must send the full certificate chain, including the uploaded CA certificate.
Using the code below, the server only receives the client's certificate. Is it possible using MQTTnet to send also CA_Certificate?

        var cSource = new CancellationTokenSource();
        var cToken = cSource.Token;
        Console.CancelKeyPress += (sender, eventArgs) =>cSource.Cancel();
        try {
            var caCert = new X509Certificate("caCert.crt");
            var clientCert = new X509Certificate2( @ "certificate.pfx", "somePassword");
            var options = new MqttClientOptionsBuilder()
                    .WithClientId(clientId)
                    .WithTcpServer(serverUrl, serverPort)
                    .WithKeepAlivePeriod(new TimeSpan(0, 0, 0, 300))
                    .WithCleanSession(true)
                    .WithTls(new MqttClientOptionsBuilderTlsParameters() {
                        UseTls =true,
                        AllowUntrustedCertificates =true,
                        IgnoreCertificateChainErrors =true,
                        IgnoreCertificateRevocationErrors =true,
                        SslProtocol =System.Security.Authentication.SslProtocols.Tls12,
                        Certificates =new List<X509Certificate>
                        {
                            clientCert, caCert
                        },
                    })
                    .Build();
            var factory = new MqttFactory();
            var client = factory.CreateMqttClient();
            client.ConnectAsync(options, cToken).Wait(cToken);
        }
    }```
<PackageReference Include="MQTTnet" Version="3.0.15" />
@michal7bk michal7bk added the question It is a question regarding the project label Jun 2, 2021
@pallavc8y
Copy link

Team MQTTnet,

I am also facing the same issue.
Could you please prioritize it and help us here.

@chkr1011
Copy link
Collaborator

I am no certificate expert so I cannot help much here. But you may need to search around the APIs from .NET directly because this library uses them directly without doing something special.

@justoke
Copy link

justoke commented Jun 28, 2021

I'd suggest you use something like MQTT Explorer as it has certificate support and try out your certificate chain to get the working combination for the mqtt server you are trying to access via MQTTnet.

For the mosquitto server, I used this guide http:https://www.steves-internet-guide.com/mosquitto-tls/ and was able to configure my mosquitto server to support a self signed certificate. From this guide I only had to copy the CA certificate file to the MQTT Explorer client.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question It is a question regarding the project
Projects
None yet
Development

No branches or pull requests

4 participants