Azure will accept Cipher Suites that it will refuse to Use.
Note I did not Use "client->tls.ctx"
So the MQTT Code works as is.
The Only issue is it does not Return CONNAK and some error codes
This may be addressed in later versions. ( I did not Check). The data is available to the end user in the returned data.
Note: The DPS Server will will not accept the same Cipher Suites
To Minimize Cypher and use the Minimum Allowed Cipher
in Config.h:
#define USE_FAST_MATH
#define TFM_TIMING_RESISTANT
#define NO_WOLFSSL_SERVER
//#define NO_DSA // Needed for Base64 Encode
//#define NO_HMAC // Needed for sasTokenCreate
//#define NO_RSA // This allows ECDSA and RSA
#define NO_DES3 // Disable all the weak Ciphers ...
#define NO_DH
#define NO_MD4
#define NO_MD5
#define NO_PWDBASED
#define NO_RC4
#define NO_RABBIT
#define NO_HC128
#define NO_SHA
#define SHA_DIGEST_SIZE 20 // Cover Bug in NO_SHA
#define WOLFSSL_SHA512
//#define HAVE_AESCCM // for CBC
#define HAVE_AESGCM // for GCM
#define HAVE_ECC
#define HAVE_SUPPORTED_CURVES // Suppport to enable Supported curves
#define HAVE_TLS_EXTENSIONS /* for ECC Curve and SNI */
#define HAVE_ECC256 /* Enable the NIST Curve */
#define HAVE_CURVE25519 /* Enable the Modern Curve */
#define HAVE_ECC_SECP256R1 /* NIST P-256 for Azure compatibility */
#define HAVE_SNI // Server Name Enable
#define HAVE_MAX_FRAGMENT // Allow shorter TLS Packets
#define HAVE_TRUNCATED_HMAC // Allow shorter HMAC Packets
#define ENABLE_MQTT_TLS
#define NO_OLD_TLS // disable anything below TLS1.2
#define WOLFMQTT_NONBLOCK
in the mqtt_tls_cb:
static int mqtt_tls_cb(MqttClient* client)
{
const char* cipherSuites = "";
int rc = SSL_FAILURE;
client->tls.ctx = wolfSSL_CTX_new(wolfTLSv1_2_client_method());
if (client->tls.ctx)
{
wolfSSL_CTX_set_verify(client->tls.ctx, SSL_VERIFY_PEER, mqtt_tls_verify_cb);
if(azureDpsState == eDPS_STATE_STARTED)
{
cipherSuites = "ECDHE-RSA-AES128-GCM-SHA256"; // DPS Uses This (Azure Does Not)
}
else
{
cipherSuites = "ECDHE-ECDSA-AES128-GCM-SHA256"; // A Recommended Cipher for Azure
};
if(wolfSSL_CTX_SetMinVersion (client->tls.ctx, WOLFSSL_TLSV1_2) != SSL_SUCCESS)SYS_DEBUG_BreakPoint();
if(wolfSSL_CTX_UseSupportedCurve(client->tls.ctx, WOLFSSL_ECC_SECP256R1) != SSL_SUCCESS)SYS_DEBUG_BreakPoint();
if(wolfSSL_CTX_set_cipher_list (client->tls.ctx, cipherSuites) != SSL_SUCCESS)SYS_DEBUG_BreakPoint();
if(wolfSSL_CTX_UseSNI (client->tls.ctx, WOLFSSL_SNI_HOST_NAME, azureHostname, strnlen(azureHostname, sizeof(azureHostname))) != SSL_SUCCESS)SYS_DEBUG_BreakPoint();