I'm trying to simply connect to the AWS IoT Mqtt broker and get the following:
"Error while authenticating. Extended authentication handler is not yet supported"
The policies for the thing is set for subscription, connection, receive and publish. I search for some answers but didn't find anything even close to this issue.
Below is the code I'm using, any help would be greatly appreciated.
public async Task MqttConnect()
{
try
{
// Create a new MQTT client.
var factory = new MqttFactory();
var mqttClient = factory.CreateMqttClient();
var caCert = X509Certificate.CreateFromCertFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"certificates\AmazonRootCA1.pem"));
var clientCert = new X509Certificate2(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"certificates\Alt-ThingCert.pfx"), "");
//This is a helper class to allow verifying a root CA separately from the Windows root store
rootCertificateTrust = new RootCertificateTrust();
rootCertificateTrust.AddCert(caCert);
// Certificate based authentication
List<X509Certificate> certs = new List<X509Certificate>
{
caCert,
clientCert
};
//Set things up for our MQTTNet client
//NOTE: AWS does NOT support will topics or retained messages
//If you attempt to use either, it will disconnect with little explanation
MqttClientOptionsBuilderTlsParameters tlsOptions = new MqttClientOptionsBuilderTlsParameters();
tlsOptions.Certificates = certs;
tlsOptions.SslProtocol = System.Security.Authentication.SslProtocols.Tls12;
tlsOptions.UseTls = true;
tlsOptions.AllowUntrustedCertificates = true;
tlsOptions.CertificateValidationHandler += rootCertificateTrust.VerifyServerCertificate;
var options = new MqttClientOptionsBuilder()
.WithTcpServer(MQTT_Host, MQTT_Port)
.WithClientId(Guid.NewGuid().ToString())
.WithTls(tlsOptions)
.WithProtocolVersion(MQTTnet.Formatter.MqttProtocolVersion.V500)
.Build();
await mqttClient.ConnectAsync(options, CancellationToken.None);
var message = new MqttApplicationMessageBuilder()
.WithTopic("HeartBeats")
.WithPayload("Hello World")
.Build();
await mqttClient.PublishAsync(message, CancellationToken.None);
Console.WriteLine("==>message sent");
}
catch(Exception ex)
{
string msg = ex.Message;
}
}
I executed the code and get an error when trying to connect to AWS IoT.
"Error while authenticating. Extended authentication handler is not yet supported"