Adding custom command to set datetime.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos 2022-04-03 19:57:56 +02:00
parent c9855f7214
commit 2905dcc8c0
No known key found for this signature in database
GPG key ID: C0095B7870A4CCD3
3 changed files with 26 additions and 1 deletions

View file

@ -119,7 +119,7 @@ pico_add_extra_outputs(pico_hsm)
#target_compile_definitions(pico_hsm PRIVATE MBEDTLS_ECDSA_DETERMINISTIC=1)
target_link_libraries(pico_hsm 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 hardware_rtc)
#
#project(flash_nuke C CXX ASM)

View file

@ -33,6 +33,7 @@
#include "pico/multicore.h"
#include "random.h"
#include "hsm2040.h"
#include "hardware/rtc.h"
extern void do_flash();
extern void low_flash_init();
@ -1628,6 +1629,7 @@ int main(void)
gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
#endif
#endif
led_off_all();
@ -1638,6 +1640,8 @@ int main(void)
random_init();
low_flash_init();
rtc_init();
while (1)
{

View file

@ -32,6 +32,7 @@
#include "cvcerts.h"
#include "crypto_utils.h"
#include "dkek.h"
#include "hardware/rtc.h"
const uint8_t sc_hsm_aid[] = {
11,
@ -1676,6 +1677,24 @@ static int cmd_derive_asym() {
return SW_OK();
}
static int cmd_datetime() {
if (P1(apdu) != 0x0 || P2(apdu) != 0x0)
return SW_INCORRECT_P1P2();
if (apdu.cmd_apdu_data_len != 8)
return SW_WRONG_LENGTH();
datetime_t dt;
dt.year = (apdu.cmd_apdu_data[0] << 8) | (apdu.cmd_apdu_data[1]);
dt.month = apdu.cmd_apdu_data[2];
dt.day = apdu.cmd_apdu_data[3];
dt.dotw = apdu.cmd_apdu_data[4];
dt.hour = apdu.cmd_apdu_data[5];
dt.min = apdu.cmd_apdu_data[6];
dt.sec = apdu.cmd_apdu_data[7];
if (!rtc_set_datetime(&dt))
return SW_WRONG_DATA();
return SW_OK();
}
typedef struct cmd
{
uint8_t ins;
@ -1697,6 +1716,7 @@ typedef struct cmd
#define INS_DERIVE_ASYM 0x76
#define INS_CIPHER_SYM 0x78
#define INS_CHALLENGE 0x84
#define INS_DATETIME 0x88
#define INS_SELECT_FILE 0xA4
#define INS_READ_BINARY 0xB0
#define INS_READ_BINARY_ODD 0xB1
@ -1724,6 +1744,7 @@ static const cmd_t cmds[] = {
{ INS_DECRYPT_ASYM, cmd_decrypt_asym },
{ INS_CIPHER_SYM, cmd_cipher_sym },
{ INS_DERIVE_ASYM, cmd_derive_asym },
{ INS_DATETIME, cmd_datetime },
{ 0x00, 0x0}
};