You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I´me getting exception "An existing connection was forcibly closed by the remote host." at every time a call the ConnectAsync() method.
My certificates are valid, test with mosquitto_pub and mosquitto_sub works, and by the debug the certificates are loaded and correct.
my code is:
`
string broker = "mqtt-i.kverkom.sk";
int port = 8883;
var caCertificate = new X509Certificate2("c:\cert\kverkom-ca-bundle.pem");
X509Certificate2Collection? certificates = null;
certificates = new X509Certificate2Collection();
certificates.Add(caCertificate);
X509Certificate2 clientCertificate = new X509Certificate2("c:\cert\kverkom-int-client.pfx", "pwd");//has private key
// Load the client certificate
List certs = new List { };
certs.Add(clientCertificate);
var tlsOptions = new MqttClientTlsOptionsBuilder()
.WithClientCertificates(certs)
.WithCertificateValidationHandler(_ => true)
.WithAllowUntrustedCertificates(true)
.UseTls(true)
.WithIgnoreCertificateChainErrors(true)
.WithIgnoreCertificateRevocationErrors(true)
.WithTrustChain(certificates)
.Build();
var options = new MqttClientOptionsBuilder()
.WithTcpServer(broker, port) // Use the appropriate port for your connection
.WithTlsOptions(tlsOptions)
.Build();
MqttClientFactory factory = new MqttClientFactory();
var connectResult = await mqttClient.ConnectAsync(options, CancellationToken.None);
`
but every time the result is exception, that the remote side closes the connection (TCP RST).
The host requires authentication with client certificate through TLS, the certificate is valid and also the CA certificate is valid, as I can connect without problems using the utility mosquitto_sub.
Any help is welcome
Thanks
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I´me getting exception "An existing connection was forcibly closed by the remote host." at every time a call the ConnectAsync() method.
My certificates are valid, test with mosquitto_pub and mosquitto_sub works, and by the debug the certificates are loaded and correct.
my code is:
`
`
but every time the result is exception, that the remote side closes the connection (TCP RST).
The host requires authentication with client certificate through TLS, the certificate is valid and also the CA certificate is valid, as I can connect without problems using the utility mosquitto_sub.
Any help is welcome
Thanks
Beta Was this translation helpful? Give feedback.
All reactions