Request device certificate
This commit is contained in:
esp32_device/main
@ -124,7 +124,8 @@ void app_main(void)
|
||||
case DevEnrollUnknown:
|
||||
ESP_LOGI(TAG, "Device unknown, need to enroll!");
|
||||
|
||||
// TODO : remove certificate if present
|
||||
// Remove certificate if present
|
||||
storage_set_dev_cert("");
|
||||
|
||||
// Enroll device
|
||||
ESP_LOGI(TAG, "Enroll device");
|
||||
@ -138,10 +139,30 @@ void app_main(void)
|
||||
}
|
||||
|
||||
// Wait before next try
|
||||
system_sleep(60);
|
||||
if (!validated)
|
||||
system_sleep(60);
|
||||
};
|
||||
|
||||
// TODO : retrieve certificate if missing
|
||||
// Retrieve device certificate if missing
|
||||
ESP_LOGI(TAG, "Check device certificate");
|
||||
if (storage_get_dev_cert(NULL) == 0)
|
||||
{
|
||||
char *dev_cert = secure_api_get_dev_certificate();
|
||||
if (!dev_cert)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to fetch device certificate!");
|
||||
reboot();
|
||||
}
|
||||
storage_set_dev_cert(dev_cert);
|
||||
free(dev_cert);
|
||||
}
|
||||
|
||||
// Print device certificate for debugging purposes
|
||||
ESP_LOGI(TAG, "Get device certificate");
|
||||
char *dev_certificate = calloc(DEV_CERT_MAX_BYTES, 1);
|
||||
assert(storage_get_dev_cert(dev_certificate) > 0);
|
||||
ESP_LOGI(TAG, "Current device certificate:\n%s", dev_certificate);
|
||||
free(dev_certificate);
|
||||
|
||||
ESP_LOGI(TAG, "Starting main loop");
|
||||
system_sleep(120);
|
||||
|
Reference in New Issue
Block a user