mirror of
https://github.com/polhenarejos/pico-openpgp.git
synced 2024-09-20 03:10:10 +00:00
Add support to ESP32.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
parent
8a5c734c41
commit
1051690b79
@ -17,6 +17,11 @@
|
||||
|
||||
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)
|
||||
else()
|
||||
include(pico_sdk_import.cmake)
|
||||
@ -33,6 +38,7 @@ pico_sdk_init()
|
||||
endif()
|
||||
|
||||
add_executable(pico_openpgp)
|
||||
endif()
|
||||
|
||||
set(SOURCES ${SOURCES}
|
||||
${CMAKE_CURRENT_LIST_DIR}/src/openpgp/openpgp.c
|
||||
@ -47,7 +53,11 @@ set(INCLUDES ${INCLUDES}
|
||||
|
||||
set(USB_ITF_CCID 1)
|
||||
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_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)
|
||||
endif()
|
||||
endif()
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit f4ad8e1af2e2657f3900f1e01db031d7d73d623b
|
||||
Subproject commit d379a39bd699a679e2f5e5605af95922dc35576f
|
@ -41,7 +41,7 @@ int man_select(app_t *a) {
|
||||
return CCID_OK;
|
||||
}
|
||||
|
||||
void __attribute__((constructor)) man_ctor() {
|
||||
INITIALIZER( man_ctor ) {
|
||||
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++] = TAG_SERIAL;
|
||||
res_APDU[res_APDU_size++] = 4;
|
||||
#ifndef ENABLE_EMULATION
|
||||
pico_get_unique_board_id_string((char *) res_APDU + res_APDU_size, 4);
|
||||
#endif
|
||||
memcpy(res_APDU + res_APDU_size, pico_serial.id, 4);
|
||||
res_APDU_size += 4;
|
||||
res_APDU[res_APDU_size++] = TAG_FORM_FACTOR;
|
||||
res_APDU[res_APDU_size++] = 1;
|
||||
|
@ -19,7 +19,7 @@
|
||||
#define _MANAGEMENT_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#ifndef ENABLE_EMULATION
|
||||
#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM)
|
||||
#include "pico/stdlib.h"
|
||||
#endif
|
||||
|
||||
|
@ -15,7 +15,12 @@
|
||||
* 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"
|
||||
#endif
|
||||
#include "openpgp.h"
|
||||
#include "version.h"
|
||||
#include "files.h"
|
||||
@ -58,7 +63,6 @@ char atr_openpgp[] = {
|
||||
|
||||
int openpgp_process_apdu();
|
||||
|
||||
|
||||
extern uint32_t board_button_read(void);
|
||||
|
||||
static bool wait_button_pressed(uint16_t fid) {
|
||||
@ -166,11 +170,7 @@ void scan_files() {
|
||||
file_t *ef;
|
||||
if ((ef = search_by_fid(EF_FULL_AID, NULL, SPECIFY_ANY))) {
|
||||
ef->data = openpgp_aid_full;
|
||||
#ifndef ENABLE_EMULATION
|
||||
pico_get_unique_board_id_string((char *) ef->data + 12, 4);
|
||||
#else
|
||||
memset((char *) ef->data + 12, 0, 4);
|
||||
#endif
|
||||
memcpy(ef->data + 12, pico_serial.id, 4);
|
||||
}
|
||||
bool reset_dek = false;
|
||||
if ((ef = search_by_fid(EF_DEK, NULL, SPECIFY_ANY))) {
|
||||
@ -365,7 +365,7 @@ int openpgp_unload() {
|
||||
|
||||
extern char __StackLimit;
|
||||
int heapLeft() {
|
||||
#ifndef ENABLE_EMULATION
|
||||
#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM)
|
||||
char *p = malloc(256); // try to avoid undue fragmentation
|
||||
int left = &__StackLimit - p;
|
||||
free(p);
|
||||
@ -392,7 +392,7 @@ int openpgp_select_aid(app_t *a) {
|
||||
return CCID_OK;
|
||||
}
|
||||
|
||||
void __attribute__((constructor)) openpgp_ctor() {
|
||||
INITIALIZER( openpgp_ctor ) {
|
||||
ccid_atr = (uint8_t *) atr_openpgp;
|
||||
register_app(openpgp_select_aid, openpgp_aid);
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
#define __OPENPGP_H_
|
||||
|
||||
#include "stdlib.h"
|
||||
#ifndef ENABLE_EMULATION
|
||||
#if !defined(ENABLE_EMULATION) && !defined(ESP_PLATFORM)
|
||||
#include <pico/stdlib.h>
|
||||
#endif
|
||||
|
||||
|
@ -15,7 +15,12 @@
|
||||
* 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"
|
||||
#endif
|
||||
#include "files.h"
|
||||
#include "apdu.h"
|
||||
#include "pico_keys.h"
|
||||
@ -23,9 +28,6 @@
|
||||
#include "eac.h"
|
||||
#include "crypto_utils.h"
|
||||
#include "version.h"
|
||||
#ifndef ENABLE_EMULATION
|
||||
#include "pico/unique_id.h"
|
||||
#endif
|
||||
#include "asn1.h"
|
||||
#include "mbedtls/aes.h"
|
||||
#include "mbedtls/des.h"
|
||||
@ -77,14 +79,8 @@ uint8_t session_pwpiv[32];
|
||||
int piv_process_apdu();
|
||||
|
||||
static int get_serial() {
|
||||
#ifndef ENABLE_EMULATION
|
||||
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];
|
||||
uint32_t serial = (pico_serial.id[0] & 0x7F) << 24 | pico_serial.id[1] << 16 | pico_serial.id[2] << 8 | pico_serial.id[3];
|
||||
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) {
|
||||
@ -311,7 +307,7 @@ int piv_select_aid(app_t *a) {
|
||||
return CCID_OK;
|
||||
}
|
||||
|
||||
void __attribute__((constructor)) piv_ctor() {
|
||||
INITIALIZER( piv_ctor ) {
|
||||
register_app(piv_select_aid, piv_aid);
|
||||
register_app(piv_select_aid, yk_aid);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user