mirror of
https://github.com/polhenarejos/pico-keys-sdk
synced 2026-06-08 05:23:35 +02:00
29
src/main.c
29
src/main.c
@@ -237,6 +237,35 @@ bool wait_button() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool set_rtc = false;
|
||||||
|
|
||||||
|
bool has_set_rtc() {
|
||||||
|
return set_rtc;
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_rtc_time(time_t t) {
|
||||||
|
#ifdef PICO_PLATFORM
|
||||||
|
struct timespec tv = {.tv_sec = t, .tv_nsec = 0};
|
||||||
|
aon_timer_set_time(&tv);
|
||||||
|
#else
|
||||||
|
struct timeval tv = {.tv_sec = t, .tv_usec = 0};
|
||||||
|
settimeofday(&tv, NULL);
|
||||||
|
#endif
|
||||||
|
set_rtc = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
time_t get_rtc_time() {
|
||||||
|
#ifdef PICO_PLATFORM
|
||||||
|
struct timespec tv;
|
||||||
|
aon_timer_get_time(&tv);
|
||||||
|
return tv.tv_sec;
|
||||||
|
#else
|
||||||
|
struct timeval tv;
|
||||||
|
gettimeofday(&tv, NULL);
|
||||||
|
return tv.tv_sec;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
struct apdu apdu;
|
struct apdu apdu;
|
||||||
|
|
||||||
void init_rtc() {
|
void init_rtc() {
|
||||||
|
|||||||
@@ -61,6 +61,15 @@
|
|||||||
#include "pico/util/queue.h"
|
#include "pico/util/queue.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef PICO_PLATFORM
|
||||||
|
#include "pico/bootrom.h"
|
||||||
|
#include "hardware/watchdog.h"
|
||||||
|
#include "pico/aon_timer.h"
|
||||||
|
#else
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <time.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
extern bool wait_button();
|
extern bool wait_button();
|
||||||
|
|
||||||
extern void low_flash_init_core1();
|
extern void low_flash_init_core1();
|
||||||
@@ -242,4 +251,8 @@ extern uint8_t pico_serial_hash[32];
|
|||||||
#define multicore_launch_func_core1(a) multicore_launch_core1((void (*) (void))a)
|
#define multicore_launch_func_core1(a) multicore_launch_core1((void (*) (void))a)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
extern bool has_set_rtc();
|
||||||
|
extern time_t get_rtc_time();
|
||||||
|
extern void set_rtc_time(time_t tv_sec);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
27
src/rescue.c
27
src/rescue.c
@@ -19,14 +19,6 @@
|
|||||||
#include "apdu.h"
|
#include "apdu.h"
|
||||||
#include "pico_keys_version.h"
|
#include "pico_keys_version.h"
|
||||||
#include "otp.h"
|
#include "otp.h"
|
||||||
#ifdef PICO_PLATFORM
|
|
||||||
#include "pico/bootrom.h"
|
|
||||||
#include "hardware/watchdog.h"
|
|
||||||
#include "pico/aon_timer.h"
|
|
||||||
#else
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <time.h>
|
|
||||||
#endif
|
|
||||||
#include "mbedtls/ecdsa.h"
|
#include "mbedtls/ecdsa.h"
|
||||||
#include "mbedtls/sha256.h"
|
#include "mbedtls/sha256.h"
|
||||||
#include "random.h"
|
#include "random.h"
|
||||||
@@ -38,7 +30,6 @@ extern char __flash_binary_end;
|
|||||||
|
|
||||||
int rescue_process_apdu();
|
int rescue_process_apdu();
|
||||||
int rescue_unload();
|
int rescue_unload();
|
||||||
bool set_rtc = false;
|
|
||||||
|
|
||||||
const uint8_t rescue_aid[] = {
|
const uint8_t rescue_aid[] = {
|
||||||
8,
|
8,
|
||||||
@@ -220,14 +211,7 @@ int cmd_write() {
|
|||||||
uint32_t t = (apdu.data[0] << 24) | (apdu.data[1] << 16) | (apdu.data[2] << 8) | apdu.data[3];
|
uint32_t t = (apdu.data[0] << 24) | (apdu.data[1] << 16) | (apdu.data[2] << 8) | apdu.data[3];
|
||||||
tv_sec = (time_t)t;
|
tv_sec = (time_t)t;
|
||||||
}
|
}
|
||||||
#ifdef PICO_PLATFORM
|
set_rtc_time(tv_sec);
|
||||||
struct timespec tv = {.tv_sec = tv_sec, .tv_nsec = 0};
|
|
||||||
aon_timer_set_time(&tv);
|
|
||||||
#else
|
|
||||||
struct timeval tv = {.tv_sec = tv_sec, .tv_usec = 0};
|
|
||||||
settimeofday(&tv, NULL);
|
|
||||||
#endif
|
|
||||||
set_rtc = true;
|
|
||||||
}
|
}
|
||||||
led_3_blinks();
|
led_3_blinks();
|
||||||
return SW_OK();
|
return SW_OK();
|
||||||
@@ -277,16 +261,15 @@ int cmd_read() {
|
|||||||
if (p2 != 0x1 && p2 != 0x2) {
|
if (p2 != 0x1 && p2 != 0x2) {
|
||||||
return SW_INCORRECT_P1P2();
|
return SW_INCORRECT_P1P2();
|
||||||
}
|
}
|
||||||
if (!set_rtc) {
|
if (!has_set_rtc()) {
|
||||||
return SW_CONDITIONS_NOT_SATISFIED();
|
return SW_CONDITIONS_NOT_SATISFIED();
|
||||||
}
|
}
|
||||||
res_APDU_size = 0;
|
res_APDU_size = 0;
|
||||||
|
time_t tv_sec = get_rtc_time();
|
||||||
#ifdef PICO_PLATFORM
|
#ifdef PICO_PLATFORM
|
||||||
struct timespec tv;
|
struct timespec tv = {.tv_sec = tv_sec, .tv_nsec = 0};
|
||||||
aon_timer_get_time(&tv);
|
|
||||||
#else
|
#else
|
||||||
struct timeval tv;
|
struct timeval tv = {.tv_sec = tv_sec, .tv_usec = 0};
|
||||||
gettimeofday(&tv, NULL);
|
|
||||||
#endif
|
#endif
|
||||||
if (p2 == 0x1) {
|
if (p2 == 0x1) {
|
||||||
struct tm *tm = localtime(&tv.tv_sec);
|
struct tm *tm = localtime(&tv.tv_sec);
|
||||||
|
|||||||
Reference in New Issue
Block a user