StdPJ/Core/Src/Common/Shared/iot_flash_config.c
/* Warning:
 *  The device key pair should only be updated if the application uses it.
 *  The connection security mode may chosen by the user during the device configuration.
 *  Therefore, updateTLSCredentials() must be called only after the IoT device configuration has been selected.
 */
The device key pair should only be updated if the application uses it.
The connection security mode may chosen by the user during the device configuration.
Therefore, updateTLSCredentials() must be called only after the IoT device configuration has been selected.
The device key pair should only be updated if the application uses it . The connection security mode may chosen by the user during the device configuration . Therefore updateTLSCredentials () must be called only after the IoT device configuration has been selected .
int updateTLSCredentials(void)
{
  int ret = 0;
  if ( (checkTLSRootCA() == -1)
      || dialog_ask("\nDo you want to update the root CA certificate(s)? [y/n]\n") )
  {
    printf("\nUpdating TLS security credentials.\n");
    printf("\nEnter the x509 certificates or keys as per the following format:\n");
    printf("-----BEGIN CERTIFICATE-----\n");
    printf("YMPGn8u67GB9t+aEMr5P+1gmIgNb1LTV+/Xjli5wwOQuvfwu7uJBVcA0Ln0kcmnL\n");
    printf("R7EUQIN9Z/SG9jGr8XmksrUuEvmEF/Bibyc+E1ixVA0hmnM3oTDPb5Lc9un8rNsu\n");
    printf(".......\n");
    printf("-----END CERTIFICATE-----\n");
    printf("-----BEGIN CERTIFICATE-----\n");
    printf("YMPGn8u67GB9t+aEMr5P+1gmIgNb1LTV+/Xjli5wwOQuvfwu7uJBVcA0Ln0kcmnL\n");
    printf(".......\n");
    printf("-----END CERTIFICATE-----\n");
    printf("\n.......\n");
    ret = CaptureAndFlashPem("root CA",lUserConfigPtr->tls_root_ca_cert, false);
    if (ret == 0)
    {
      uint64_t magic = USER_CONF_MAGIC;
      ret = FLASH_update((uint32_t)&lUserConfigPtr->ca_tls_magic, &magic, sizeof(uint64_t));
    }
  }
  if ( (ret == 0) && app_needs_device_keypair() )
  {
    if (checkTLSDeviceConfig() == -1)
    {
      ret |= CaptureAndFlashPem("device certificate",lUserConfigPtr->tls_device_cert, false);
      ret |= CaptureAndFlashPem("device key",lUserConfigPtr->tls_device_key, true);
    }
    else
    {
      if (dialog_ask("Do you want to update the device certificate? [y/n]\n"))
      {
        ret |= CaptureAndFlashPem("device certificate",lUserConfigPtr->tls_device_cert, false);
      }
      if (dialog_ask("Do you want to update the device key? [y/n]\n"))
      {
        ret |= CaptureAndFlashPem("device key",lUserConfigPtr->tls_device_key, true);
      }
    }
    if (ret == 0)
    {
      uint64_t magic = USER_CONF_MAGIC;
      ret = FLASH_update((uint32_t)&lUserConfigPtr->device_tls_magic, &magic, sizeof(uint64_t));
    }
  }
  if (ret < 0)
  {
    msg_error("Failed updating the TLS configuration in Flash.\n");
  }
  return ret;
}
int updateTLSCredentials ( void ) { int ret = 0 ; if ( ( checkTLSRootCA ( ) == -1 ) || dialog_ask ( " \n \n " ) ) { printf ( " \n \n " ) ; printf ( " \n \n " ) ; printf ( " \n " ) ; printf ( " \n " ) ; printf ( " \n " ) ; printf ( " \n " ) ; printf ( " \n " ) ; printf ( " \n " ) ; printf ( " \n " ) ; printf ( " \n " ) ; printf ( " \n " ) ; printf ( " \n \n " ) ; ret = CaptureAndFlashPem ( " " , lUserConfigPtr -> tls_root_ca_cert , false ) ; if ( ret == 0 ) { uint64_t magic = USER_CONF_MAGIC ; ret = FLASH_update ( ( uint32_t ) & lUserConfigPtr -> ca_tls_magic , & magic , sizeof ( uint64_t ) ) ; } } if ( ( ret == 0 ) && app_needs_device_keypair ( ) ) { if ( checkTLSDeviceConfig ( ) == -1 ) { ret |= CaptureAndFlashPem ( " " , lUserConfigPtr -> tls_device_cert , false ) ; ret |= CaptureAndFlashPem ( " " , lUserConfigPtr -> tls_device_key , true ) ; } else { if ( dialog_ask ( " \n " ) ) { ret |= CaptureAndFlashPem ( " " , lUserConfigPtr -> tls_device_cert , false ) ; } if ( dialog_ask ( " \n " ) ) { ret |= CaptureAndFlashPem ( " " , lUserConfigPtr -> tls_device_key , true ) ; } } if ( ret == 0 ) { uint64_t magic = USER_CONF_MAGIC ; ret = FLASH_update ( ( uint32_t ) & lUserConfigPtr -> device_tls_magic , & magic , sizeof ( uint64_t ) ) ; } } if ( ret < 0 ) { msg_error ( " \n " ) ; } return ret ; }
Warning:
  The device key pair should only be updated if the application uses it.
Warning : The device key pair should only be updated if the application uses it .