NetXDuo - Accepting an "untrusted" certificate

FlavioB 1 Reputation point
2022-08-05T07:02:55.213+00:00

Hi All,

I'm using the NetXDuo library to create a Mqtt Client on my embedded project.

The application works fine: the client designed using NetXDuo library is able to connect to a Mqtt broker both in plain mode and in secure mode (TLS).

In secure mode, It's needed to add the server's certificate to a trusted list (nx_secure_tls_trusted_certificate_add) in order to accept a remote certificate.

Below, my code:

  /* Initialize TLS module */  
  nx_secure_tls_initialize();  
  
  /* Create a TLS session */  
  ret = nx_secure_tls_session_create(TLS_session_ptr, &nx_crypto_tls_ciphers,crypto_metadata_client, sizeof(crypto_metadata_client));  
  if (ret != NX_SUCCESS)  
  {  
   for(;;) asm("NOP");  
  }  
  
  /* Need to allocate space for the certificate coming in from the broker. */  
  memset((certificate_ptr), 0, sizeof(NX_SECURE_X509_CERT));  
  
  ret = nx_secure_tls_session_time_function_set(TLS_session_ptr, nx_secure_tls_session_time_function);  
  
  if (ret != NX_SUCCESS)  
  {  
   for(;;) asm("NOP");  
  }  
  
  /* Allocate space for packet reassembly. */  
  ret = nx_secure_tls_session_packet_buffer_set(TLS_session_ptr, tls_packet_buffer,sizeof(tls_packet_buffer));  
  if (ret != NX_SUCCESS)  
  {  
   for(;;) asm("NOP");  
  }  
  
  /* allocate space for the certificate coming in from the remote host */  
  ret = nx_secure_tls_remote_certificate_allocate(TLS_session_ptr, certificate_ptr,tls_packet_buffer, sizeof(tls_packet_buffer));  
  if (ret != NX_SUCCESS)  
  {  
   for(;;) asm("NOP");  
  }  
  
  /* initialize Certificate to verify incoming server certificates. */  
  ret = nx_secure_x509_certificate_initialize(trusted_certificate_ptr, (UCHAR*)mosquitto_org_der,mosquitto_org_der_len, NX_NULL, 0, NULL, 0,NX_SECURE_X509_KEY_TYPE_NONE);  
  if (ret != NX_SUCCESS)  
  {  
    printf("Certificate issue..\nPlease make sure that your X509_certificate is valid. \n");  
    for(;;) asm("NOP");  
  }  
  
  /* Add a CA Certificate to our trusted store */  
  ret = nx_secure_tls_trusted_certificate_add(TLS_session_ptr, trusted_certificate_ptr);  
  if (ret != NX_SUCCESS)  
  {  
   for(;;) asm("NOP");  
  }  

As written above, the code above works fine, but it's necessary to know (and load) the server's certificate beforehand and it's not always easy to have it.

So, my question is that: is it possible to accept a remote certificate without verification ?

Of course, it's a less secure mode, but in a few cases it may be the only possible solution !

Thanks a lot for your support !

FlavioB

Azure RTOS
Azure RTOS
An Azure embedded development suite including a small but powerful operating system for resource-constrained devices.
341 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Tiejun Zhou 1,131 Reputation points Microsoft Employee
    2022-08-15T06:31:03.927+00:00

    @FlavioB , do you plan to skip certificate validation in product or just for development? By skipping certificate validation, the TLS session can always be under MITM attack. Which means, it is literally same as plain session. To trust server's certificate, you only need to add the root CA which is always publicly available for cloud provider. When the root CA is about to expire, an OTA update should be used to renew it.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.