Ready to build JWT
This commit is contained in:
		
							
								
								
									
										3
									
								
								esp32_device/.vscode/settings.json
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										3
									
								
								esp32_device/.vscode/settings.json
									
									
									
									
										vendored
									
									
								
							@@ -46,6 +46,7 @@
 | 
			
		||||
    "string_view": "c",
 | 
			
		||||
    "format": "c",
 | 
			
		||||
    "span": "c",
 | 
			
		||||
    "regex": "c"
 | 
			
		||||
    "regex": "c",
 | 
			
		||||
    "stdlib.h": "c"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
idf_component_register(SRCS "secure_api.c" "http_client.c" "ethernet.c" "unsecure_api.c" "system.c" "crypto.c" "random.c" "storage.c" "main.c"
 | 
			
		||||
idf_component_register(SRCS "jwt.c" "secure_api.c" "http_client.c" "ethernet.c" "unsecure_api.c" "system.c" "crypto.c" "random.c" "storage.c" "main.c"
 | 
			
		||||
                        "dev_name.c"
 | 
			
		||||
                    INCLUDE_DIRS ".")
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										9
									
								
								esp32_device/main/jwt.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								esp32_device/main/jwt.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#include "jwt.h"
 | 
			
		||||
 | 
			
		||||
char *jwt_gen(cJSON *payload)
 | 
			
		||||
{
 | 
			
		||||
    return strdup("TODO:)");
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										24
									
								
								esp32_device/main/jwt.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								esp32_device/main/jwt.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,24 @@
 | 
			
		||||
/**
 | 
			
		||||
 * JWT utilities
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <stddef.h>
 | 
			
		||||
#include "cJSON.h"
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
extern "C"
 | 
			
		||||
{
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Sign JWT token
 | 
			
		||||
     *
 | 
			
		||||
     * Return encoded JWT or NULL in case of failure
 | 
			
		||||
     */
 | 
			
		||||
    char *jwt_gen(cJSON *payload);
 | 
			
		||||
 | 
			
		||||
#ifdef __cplusplus
 | 
			
		||||
}
 | 
			
		||||
#endif
 | 
			
		||||
@@ -10,6 +10,7 @@
 | 
			
		||||
#include "dev_name.h"
 | 
			
		||||
#include "storage.h"
 | 
			
		||||
#include "http_client.h"
 | 
			
		||||
#include "jwt.h"
 | 
			
		||||
 | 
			
		||||
#include "esp_log.h"
 | 
			
		||||
 | 
			
		||||
@@ -196,6 +197,27 @@ char *secure_api_get_dev_certificate()
 | 
			
		||||
 | 
			
		||||
void *secure_api_sync_device()
 | 
			
		||||
{
 | 
			
		||||
    cJSON *obj = cJSON_CreateObject();
 | 
			
		||||
    if (!obj)
 | 
			
		||||
    {
 | 
			
		||||
        ESP_LOGE(TAG, "Failed allocate memory to store JSON object!");
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    cJSON_AddItemToObject(obj, "info", genDevInfo());
 | 
			
		||||
 | 
			
		||||
    char *encoded_req = jwt_gen(obj);
 | 
			
		||||
    cJSON_Delete(obj);
 | 
			
		||||
 | 
			
		||||
    if (!encoded_req)
 | 
			
		||||
    {
 | 
			
		||||
        ESP_LOGE(TAG, "Failed to encode JWT!");
 | 
			
		||||
        return NULL;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    printf("JWT: %s\n", encoded_req);
 | 
			
		||||
    free(encoded_req);
 | 
			
		||||
 | 
			
		||||
    printf("here implement sync device logic\n");
 | 
			
		||||
    return NULL;
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user