Add support to ESP32.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos 2024-08-20 00:23:22 +02:00
parent 8a5c734c41
commit 1051690b79
No known key found for this signature in database
GPG Key ID: C0095B7870A4CCD3
7 changed files with 31 additions and 26 deletions

View File

@ -17,6 +17,11 @@
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.13)
if(ESP_PLATFORM)
set(EXTRA_COMPONENT_DIRS src pico-keys-sdk/src)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
else()
if(ENABLE_EMULATION) if(ENABLE_EMULATION)
else() else()
include(pico_sdk_import.cmake) include(pico_sdk_import.cmake)
@ -33,6 +38,7 @@ pico_sdk_init()
endif() endif()
add_executable(pico_openpgp) add_executable(pico_openpgp)
endif()
set(SOURCES ${SOURCES} set(SOURCES ${SOURCES}
${CMAKE_CURRENT_LIST_DIR}/src/openpgp/openpgp.c ${CMAKE_CURRENT_LIST_DIR}/src/openpgp/openpgp.c
@ -47,7 +53,11 @@ set(INCLUDES ${INCLUDES}
set(USB_ITF_CCID 1) set(USB_ITF_CCID 1)
include(pico-keys-sdk/pico_keys_sdk_import.cmake) include(pico-keys-sdk/pico_keys_sdk_import.cmake)
if(ESP_PLATFORM)
project(pico_fido)
endif()
if(NOT ESP_PLATFORM)
target_sources(pico_openpgp PUBLIC ${SOURCES}) target_sources(pico_openpgp PUBLIC ${SOURCES})
target_include_directories(pico_openpgp PUBLIC ${INCLUDES}) target_include_directories(pico_openpgp PUBLIC ${INCLUDES})
@ -79,3 +89,4 @@ pico_add_extra_outputs(pico_openpgp)
target_link_libraries(pico_openpgp PRIVATE pico_keys_sdk pico_stdlib tinyusb_device tinyusb_board pico_multicore hardware_flash hardware_sync hardware_adc pico_unique_id hardware_rtc) target_link_libraries(pico_openpgp PRIVATE pico_keys_sdk pico_stdlib tinyusb_device tinyusb_board pico_multicore hardware_flash hardware_sync hardware_adc pico_unique_id hardware_rtc)
endif() endif()
endif()

@ -1 +1 @@
Subproject commit f4ad8e1af2e2657f3900f1e01db031d7d73d623b Subproject commit d379a39bd699a679e2f5e5605af95922dc35576f

View File

@ -41,7 +41,7 @@ int man_select(app_t *a) {
return CCID_OK; return CCID_OK;
} }
void __attribute__((constructor)) man_ctor() { INITIALIZER( man_ctor ) {
register_app(man_select, man_aid); register_app(man_select, man_aid);
} }
@ -79,9 +79,7 @@ int man_get_config() {
res_APDU[res_APDU_size++] = CAP_PIV | CAP_OPENPGP; res_APDU[res_APDU_size++] = CAP_PIV | CAP_OPENPGP;
res_APDU[res_APDU_size++] = TAG_SERIAL; res_APDU[res_APDU_size++] = TAG_SERIAL;
res_APDU[res_APDU_size++] = 4; res_APDU[res_APDU_size++] = 4;
#ifndef ENABLE_EMULATION memcpy(res_APDU + res_APDU_size, pico_serial.id, 4);
pico_get_unique_board_id_string((char *) res_APDU + res_APDU_size, 4);
#endif
res_APDU_size += 4; res_APDU_size += 4;
res_APDU[res_APDU_size++] = TAG_FORM_FACTOR; res_APDU[res_APDU_size++] = TAG_FORM_FACTOR;
res_APDU[res_APDU_size++] = 1; res_APDU[res_APDU_size++] = 1;

View File

@ -19,7 +19,7 @@
#define _MANAGEMENT_H_ #define _MANAGEMENT_H_
#include <stdlib.h> #include <stdlib.h>
#ifndef ENABLE_EMULATION #if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM)
#include "pico/stdlib.h" #include "pico/stdlib.h"
#endif #endif

View File

@ -15,7 +15,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifdef ESP_PLATFORM
#include "esp_compat.h"
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
#else
#include "common.h" #include "common.h"
#endif
#include "openpgp.h" #include "openpgp.h"
#include "version.h" #include "version.h"
#include "files.h" #include "files.h"
@ -58,7 +63,6 @@ char atr_openpgp[] = {
int openpgp_process_apdu(); int openpgp_process_apdu();
extern uint32_t board_button_read(void); extern uint32_t board_button_read(void);
static bool wait_button_pressed(uint16_t fid) { static bool wait_button_pressed(uint16_t fid) {
@ -166,11 +170,7 @@ void scan_files() {
file_t *ef; file_t *ef;
if ((ef = search_by_fid(EF_FULL_AID, NULL, SPECIFY_ANY))) { if ((ef = search_by_fid(EF_FULL_AID, NULL, SPECIFY_ANY))) {
ef->data = openpgp_aid_full; ef->data = openpgp_aid_full;
#ifndef ENABLE_EMULATION memcpy(ef->data + 12, pico_serial.id, 4);
pico_get_unique_board_id_string((char *) ef->data + 12, 4);
#else
memset((char *) ef->data + 12, 0, 4);
#endif
} }
bool reset_dek = false; bool reset_dek = false;
if ((ef = search_by_fid(EF_DEK, NULL, SPECIFY_ANY))) { if ((ef = search_by_fid(EF_DEK, NULL, SPECIFY_ANY))) {
@ -365,7 +365,7 @@ int openpgp_unload() {
extern char __StackLimit; extern char __StackLimit;
int heapLeft() { int heapLeft() {
#ifndef ENABLE_EMULATION #if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM)
char *p = malloc(256); // try to avoid undue fragmentation char *p = malloc(256); // try to avoid undue fragmentation
int left = &__StackLimit - p; int left = &__StackLimit - p;
free(p); free(p);
@ -392,7 +392,7 @@ int openpgp_select_aid(app_t *a) {
return CCID_OK; return CCID_OK;
} }
void __attribute__((constructor)) openpgp_ctor() { INITIALIZER( openpgp_ctor ) {
ccid_atr = (uint8_t *) atr_openpgp; ccid_atr = (uint8_t *) atr_openpgp;
register_app(openpgp_select_aid, openpgp_aid); register_app(openpgp_select_aid, openpgp_aid);
} }

View File

@ -19,7 +19,7 @@
#define __OPENPGP_H_ #define __OPENPGP_H_
#include "stdlib.h" #include "stdlib.h"
#ifndef ENABLE_EMULATION #if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM)
#include <pico/stdlib.h> #include <pico/stdlib.h>
#endif #endif

View File

@ -15,7 +15,12 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. * along with this program. If not, see <http://www.gnu.org/licenses/>.
*/ */
#ifdef ESP_PLATFORM
#include "esp_compat.h"
#define MBEDTLS_ALLOW_PRIVATE_ACCESS
#else
#include "common.h" #include "common.h"
#endif
#include "files.h" #include "files.h"
#include "apdu.h" #include "apdu.h"
#include "pico_keys.h" #include "pico_keys.h"
@ -23,9 +28,6 @@
#include "eac.h" #include "eac.h"
#include "crypto_utils.h" #include "crypto_utils.h"
#include "version.h" #include "version.h"
#ifndef ENABLE_EMULATION
#include "pico/unique_id.h"
#endif
#include "asn1.h" #include "asn1.h"
#include "mbedtls/aes.h" #include "mbedtls/aes.h"
#include "mbedtls/des.h" #include "mbedtls/des.h"
@ -77,14 +79,8 @@ uint8_t session_pwpiv[32];
int piv_process_apdu(); int piv_process_apdu();
static int get_serial() { static int get_serial() {
#ifndef ENABLE_EMULATION uint32_t serial = (pico_serial.id[0] & 0x7F) << 24 | pico_serial.id[1] << 16 | pico_serial.id[2] << 8 | pico_serial.id[3];
pico_unique_board_id_t unique_id;
pico_get_unique_board_id(&unique_id);
uint32_t serial = (unique_id.id[0] & 0x7F) << 24 | unique_id.id[1] << 16 | unique_id.id[2] << 8 | unique_id.id[3];
return serial; return serial;
#else
return 0;
#endif
} }
static int x509_create_cert(void *pk_ctx, uint8_t algo, uint8_t slot, bool attestation, uint8_t *buffer, size_t buffer_size) { static int x509_create_cert(void *pk_ctx, uint8_t algo, uint8_t slot, bool attestation, uint8_t *buffer, size_t buffer_size) {
@ -311,7 +307,7 @@ int piv_select_aid(app_t *a) {
return CCID_OK; return CCID_OK;
} }
void __attribute__((constructor)) piv_ctor() { INITIALIZER( piv_ctor ) {
register_app(piv_select_aid, piv_aid); register_app(piv_select_aid, piv_aid);
register_app(piv_select_aid, yk_aid); register_app(piv_select_aid, yk_aid);
} }