Manage to perfom secure request
This commit is contained in:
@ -7,6 +7,7 @@
|
||||
#include "system.h"
|
||||
#include "crypto.h"
|
||||
#include "unsecure_api.h"
|
||||
#include "secure_api.h"
|
||||
#include "ethernet.h"
|
||||
#include "constants.h"
|
||||
|
||||
@ -18,12 +19,14 @@ void app_main(void)
|
||||
|
||||
ESP_LOGI(TAG, "SolarEnergy WT32-ETH01 device");
|
||||
|
||||
// Initialize storage
|
||||
if (storage_init() == false)
|
||||
{
|
||||
ESP_LOGE(TAG, "Failed to init storage!\n");
|
||||
reboot();
|
||||
}
|
||||
|
||||
// Give a name to the device
|
||||
if (dev_generate_name())
|
||||
{
|
||||
ESP_LOGI(TAG, "Generated a new device name\n");
|
||||
@ -33,6 +36,7 @@ void app_main(void)
|
||||
ESP_LOGI(TAG, "Dev name: %s\n", name);
|
||||
free(name);
|
||||
|
||||
// Generate private key, if needed
|
||||
if (crypto_gen_priv_key())
|
||||
{
|
||||
ESP_LOGI(TAG, "Generated device private key!\n");
|
||||
@ -40,14 +44,17 @@ void app_main(void)
|
||||
ESP_LOGI(TAG, "Device private key:\n");
|
||||
crypto_print_priv_key();
|
||||
|
||||
// Show current private key
|
||||
char *csr = crypto_get_csr();
|
||||
ESP_LOGI(TAG, "Current CSR:\n%s\n", csr);
|
||||
free(csr);
|
||||
|
||||
// Initialize network stack
|
||||
ESP_LOGI(TAG, "Initialize network\n");
|
||||
ethernet_init();
|
||||
ethernet_wait_for_network();
|
||||
|
||||
// Get if secure origin endpoint is known
|
||||
ESP_LOGI(TAG, "Check secure origin\n");
|
||||
if (storage_get_secure_origin(NULL) == 0)
|
||||
{
|
||||
@ -61,12 +68,14 @@ void app_main(void)
|
||||
free(sec_ori);
|
||||
}
|
||||
|
||||
// Print secure origin endpoint for debugging purposes
|
||||
ESP_LOGI(TAG, "Get secure origin\n");
|
||||
char *sec_ori = calloc(SEC_ORIG_LEN, 1);
|
||||
assert(storage_get_secure_origin(sec_ori) > 0);
|
||||
ESP_LOGI(TAG, "Current secure origin: %s", sec_ori);
|
||||
free(sec_ori);
|
||||
|
||||
// Check if root CA is available locally
|
||||
ESP_LOGI(TAG, "Check root CA");
|
||||
if (storage_get_root_ca(NULL) == 0)
|
||||
{
|
||||
@ -80,12 +89,18 @@ void app_main(void)
|
||||
free(root_ca);
|
||||
}
|
||||
|
||||
// Print root CA for debugging purposes
|
||||
ESP_LOGI(TAG, "Get root CA");
|
||||
char *root_ca = calloc(ROOT_CA_MAX_BYTES, 1);
|
||||
assert(storage_get_root_ca(root_ca) > 0);
|
||||
ESP_LOGI(TAG, "Current root CA:\n%s", root_ca);
|
||||
free(root_ca);
|
||||
|
||||
// Check current device enrollment status
|
||||
ESP_LOGI(TAG, "Check enrollment status");
|
||||
int status = secure_api_get_device_enrollment_status();
|
||||
printf("Current enrollment status: %d\n", status);
|
||||
|
||||
system_sleep(120);
|
||||
|
||||
reboot();
|
||||
|
Reference in New Issue
Block a user