Adding version header to show in lsusb command (bcdDevice) and major version in pkcs15-tool -D.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos 2022-03-08 18:43:30 +01:00
parent 9be78aade6
commit 4a0144ed2a
No known key found for this signature in database
GPG key ID: C0095B7870A4CCD3
5 changed files with 44 additions and 24 deletions

View file

@ -2,14 +2,14 @@ cmake_minimum_required(VERSION 3.13)
include(pico_sdk_import.cmake)
project(picohsm C CXX ASM)
project(pico_hsm C CXX ASM)
set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 17)
pico_sdk_init()
add_executable(picohsm)
add_executable(pico_hsm)
if (NOT DEFINED USB_VID)
set(USB_VID 0xFEFF)
@ -25,7 +25,7 @@ set_source_files_properties(
PROPERTIES COMPILE_DEFINITIONS "PACKAGE_VERSION=\"0.22.0\";OPENSC_CONF_PATH=\".\""
)
target_sources(picohsm PUBLIC
target_sources(pico_hsm PUBLIC
${CMAKE_CURRENT_LIST_DIR}/src/hsm/hsm2040.c
${CMAKE_CURRENT_LIST_DIR}/src/hsm/sc_hsm.c
${CMAKE_CURRENT_LIST_DIR}/src/usb/usb_descriptors.c
@ -72,7 +72,7 @@ target_sources(picohsm PUBLIC
${CMAKE_CURRENT_LIST_DIR}/OpenSC/src/libopensc/padding.c
)
target_include_directories(picohsm PUBLIC
target_include_directories(pico_hsm PUBLIC
${CMAKE_CURRENT_LIST_DIR}/src/fs
${CMAKE_CURRENT_LIST_DIR}/src/hsm
${CMAKE_CURRENT_LIST_DIR}/src/rng
@ -82,11 +82,11 @@ target_include_directories(picohsm PUBLIC
${CMAKE_CURRENT_LIST_DIR}/mbedtls/library
)
pico_add_extra_outputs(picohsm)
pico_add_extra_outputs(pico_hsm)
#target_compile_definitions(picohsm PRIVATE MBEDTLS_ECDSA_DETERMINISTIC=1)
#target_compile_definitions(pico_hsm PRIVATE MBEDTLS_ECDSA_DETERMINISTIC=1)
target_link_libraries(picohsm PRIVATE pico_stdlib tinyusb_device tinyusb_board pico_multicore hardware_flash hardware_sync hardware_adc pico_unique_id)
target_link_libraries(pico_hsm PRIVATE pico_stdlib tinyusb_device tinyusb_board pico_multicore hardware_flash hardware_sync hardware_adc pico_unique_id)
#
#project(flash_nuke C CXX ASM)

View file

@ -361,10 +361,6 @@ enum {
BLINK_SUSPENDED = (500 << 16) | 1000,
BLINK_PROCESSING = (50 << 16) | 50,
BLINK_RED = 18,
BLINK_GREEN = 19,
BLINK_BLUE = 20,
BLINK_ALWAYS_ON = UINT32_MAX,
BLINK_ALWAYS_OFF = 0
};
@ -1558,8 +1554,12 @@ void led_blinking_task()
{
static uint32_t start_ms = 0;
static uint8_t led_state = false;
static uint8_t led_color = BLINK_RED;
static uint8_t led_color = PICO_DEFAULT_LED_PIN;
#ifdef PICO_DEFAULT_LED_PIN_INVERTED
uint32_t interval = !led_state ? blink_interval_ms & 0xffff : blink_interval_ms >> 16;
#else
uint32_t interval = led_state ? blink_interval_ms & 0xffff : blink_interval_ms >> 16;
#endif
// Blink every interval ms
@ -1573,9 +1573,13 @@ void led_blinking_task()
void led_off_all()
{
gpio_put(18, 1);
gpio_put(19, 1);
gpio_put(20, 1);
#ifdef PIMORONI_TINY2040
gpio_put(TINY2040_LED_R_PIN, 1);
gpio_put(TINY2040_LED_G_PIN, 1);
gpio_put(TINY2040_LED_B_PIN, 1);
#else
gpio_put(PICO_DEFAULT_LED_PIN, 0);
#endif
}
extern void neug_task();
@ -1587,15 +1591,19 @@ int main(void)
struct apdu *a = &apdu;
struct ccid *c = &ccid;
printf("BOARD INIT\r\n");
board_init();
gpio_init(18);
gpio_set_dir(18, GPIO_OUT);
gpio_init(19);
gpio_set_dir(19, GPIO_OUT);
gpio_init(20);
gpio_set_dir(20, GPIO_OUT);
#ifdef PIMORONI_TINY2040
gpio_init(TINY2040_LED_R_PIN);
gpio_set_dir(TINY2040_LED_R_PIN, GPIO_OUT);
gpio_init(TINY2040_LED_G_PIN);
gpio_set_dir(TINY2040_LED_G_PIN, GPIO_OUT);
gpio_init(TINY2040_LED_B_PIN);
gpio_set_dir(TINY2040_LED_B_PIN, GPIO_OUT);
#else
gpio_init(PICO_DEFAULT_LED_PIN);
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
#endif
led_off_all();

View file

@ -8,6 +8,7 @@
#include "mbedtls/rsa.h"
#include "mbedtls/ecp.h"
#include "mbedtls/ecdsa.h"
#include "version.h"
const uint8_t sc_hsm_aid[] = {
11,
@ -195,7 +196,7 @@ int parse_token_info(const file_t *f, int mode) {
char *label = "PicoHSM";
char *manu = "Pol Henarejos";
sc_pkcs15_tokeninfo_t *ti = (sc_pkcs15_tokeninfo_t *)calloc(1, sizeof(sc_pkcs15_tokeninfo_t));
ti->version = 3;
ti->version = HSM_VERSION_MAJOR;
ti->flags = SC_PKCS15_TOKEN_PRN_GENERATION | SC_PKCS15_TOKEN_EID_COMPLIANT;
ti->label = (char *)calloc(strlen(label)+1, sizeof(char));
strlcpy(ti->label, label, strlen(label)+1);

10
src/hsm/version.h Normal file
View file

@ -0,0 +1,10 @@
#ifndef __VERSION_H_
#define __VERSION_H_
#define HSM_VERSION 0x0101
#define HSM_VERSION_MAJOR ((HSM_VERSION >> 8) & 0xff)
#define HSM_VERSION_MINOR (HSM_VERSION & 0xff)
#endif

View file

@ -27,6 +27,7 @@
#include "usb_descriptors.h"
#include "ccid.h"
#include "pico/unique_id.h"
#include "version.h"
/* A combination of interfaces must have a unique product id, since PC will save device driver after the first plug.
* Same VID/PID with different interface e.g MSC (first), then CDC (later) will possibly cause system error on PC.
@ -67,7 +68,7 @@ tusb_desc_device_t const desc_device =
.idVendor = (USB_VID),
.idProduct = (USB_PID),
.bcdDevice = (0x0301),
.bcdDevice = HSM_VERSION,
.iManufacturer = 1,
.iProduct = 2,