Compare commits
9 Commits
all-contri
...
2.5.0
Author | SHA1 | Date | |
---|---|---|---|
abe306a649 | |||
41ceb78f6c | |||
8e192f2363 | |||
affc256ca2 | |||
b3ac739a35 | |||
3b53537077 | |||
3fad9a7a7d | |||
8973608f59 | |||
8af6505f6d |
43
fido2/ctap.c
43
fido2/ctap.c
@ -437,7 +437,19 @@ static unsigned int get_credential_id_size(CTAP_credentialDescriptor * cred)
|
|||||||
static int ctap2_user_presence_test()
|
static int ctap2_user_presence_test()
|
||||||
{
|
{
|
||||||
device_set_status(CTAPHID_STATUS_UPNEEDED);
|
device_set_status(CTAPHID_STATUS_UPNEEDED);
|
||||||
return ctap_user_presence_test(CTAP2_UP_DELAY_MS);
|
int ret = ctap_user_presence_test(CTAP2_UP_DELAY_MS);
|
||||||
|
if ( ret > 0 )
|
||||||
|
{
|
||||||
|
return CTAP1_ERR_SUCCESS;
|
||||||
|
}
|
||||||
|
else if (ret < 0)
|
||||||
|
{
|
||||||
|
return CTAP2_ERR_KEEPALIVE_CANCEL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return CTAP2_ERR_ACTION_TIMEOUT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int ctap_make_auth_data(struct rpId * rp, CborEncoder * map, uint8_t * auth_data_buf, uint32_t * len, CTAP_credInfo * credInfo)
|
static int ctap_make_auth_data(struct rpId * rp, CborEncoder * map, uint8_t * auth_data_buf, uint32_t * len, CTAP_credInfo * credInfo)
|
||||||
@ -470,19 +482,11 @@ static int ctap_make_auth_data(struct rpId * rp, CborEncoder * map, uint8_t * au
|
|||||||
int but;
|
int but;
|
||||||
|
|
||||||
but = ctap2_user_presence_test(CTAP2_UP_DELAY_MS);
|
but = ctap2_user_presence_test(CTAP2_UP_DELAY_MS);
|
||||||
|
check_retr(but);
|
||||||
if (!but)
|
|
||||||
{
|
|
||||||
return CTAP2_ERR_OPERATION_DENIED;
|
|
||||||
}
|
|
||||||
else if (but < 0) // Cancel
|
|
||||||
{
|
|
||||||
return CTAP2_ERR_KEEPALIVE_CANCEL;
|
|
||||||
}
|
|
||||||
|
|
||||||
device_set_status(CTAPHID_STATUS_PROCESSING);
|
device_set_status(CTAPHID_STATUS_PROCESSING);
|
||||||
|
|
||||||
authData->head.flags = (but << 0);
|
authData->head.flags = (1 << 0); // User presence
|
||||||
authData->head.flags |= (ctap_is_pin_set() << 2);
|
authData->head.flags |= (ctap_is_pin_set() << 2);
|
||||||
|
|
||||||
|
|
||||||
@ -707,10 +711,7 @@ uint8_t ctap_make_credential(CborEncoder * encoder, uint8_t * request, int lengt
|
|||||||
}
|
}
|
||||||
if (MC.pinAuthEmpty)
|
if (MC.pinAuthEmpty)
|
||||||
{
|
{
|
||||||
if (!ctap2_user_presence_test(CTAP2_UP_DELAY_MS))
|
check_retr( ctap2_user_presence_test(CTAP2_UP_DELAY_MS) );
|
||||||
{
|
|
||||||
return CTAP2_ERR_OPERATION_DENIED;
|
|
||||||
}
|
|
||||||
return ctap_is_pin_set() == 1 ? CTAP2_ERR_PIN_AUTH_INVALID : CTAP2_ERR_PIN_NOT_SET;
|
return ctap_is_pin_set() == 1 ? CTAP2_ERR_PIN_AUTH_INVALID : CTAP2_ERR_PIN_NOT_SET;
|
||||||
}
|
}
|
||||||
if ((MC.paramsParsed & MC_requiredMask) != MC_requiredMask)
|
if ((MC.paramsParsed & MC_requiredMask) != MC_requiredMask)
|
||||||
@ -1143,10 +1144,7 @@ uint8_t ctap_get_assertion(CborEncoder * encoder, uint8_t * request, int length)
|
|||||||
|
|
||||||
if (GA.pinAuthEmpty)
|
if (GA.pinAuthEmpty)
|
||||||
{
|
{
|
||||||
if (!ctap2_user_presence_test(CTAP2_UP_DELAY_MS))
|
check_retr( ctap2_user_presence_test(CTAP2_UP_DELAY_MS) );
|
||||||
{
|
|
||||||
return CTAP2_ERR_OPERATION_DENIED;
|
|
||||||
}
|
|
||||||
return ctap_is_pin_set() == 1 ? CTAP2_ERR_PIN_AUTH_INVALID : CTAP2_ERR_PIN_NOT_SET;
|
return ctap_is_pin_set() == 1 ? CTAP2_ERR_PIN_AUTH_INVALID : CTAP2_ERR_PIN_NOT_SET;
|
||||||
}
|
}
|
||||||
if (GA.pinAuthPresent)
|
if (GA.pinAuthPresent)
|
||||||
@ -1656,14 +1654,11 @@ uint8_t ctap_request(uint8_t * pkt_raw, int length, CTAP_RESPONSE * resp)
|
|||||||
break;
|
break;
|
||||||
case CTAP_RESET:
|
case CTAP_RESET:
|
||||||
printf1(TAG_CTAP,"CTAP_RESET\n");
|
printf1(TAG_CTAP,"CTAP_RESET\n");
|
||||||
if (ctap2_user_presence_test(CTAP2_UP_DELAY_MS))
|
status = ctap2_user_presence_test(CTAP2_UP_DELAY_MS);
|
||||||
|
if (status == CTAP1_ERR_SUCCESS)
|
||||||
{
|
{
|
||||||
ctap_reset();
|
ctap_reset();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
status = CTAP2_ERR_OPERATION_DENIED;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case GET_NEXT_ASSERTION:
|
case GET_NEXT_ASSERTION:
|
||||||
printf1(TAG_CTAP,"CTAP_NEXT_ASSERTION\n");
|
printf1(TAG_CTAP,"CTAP_NEXT_ASSERTION\n");
|
||||||
|
@ -131,7 +131,7 @@
|
|||||||
#define PIN_LOCKOUT_ATTEMPTS 8 // Number of attempts total
|
#define PIN_LOCKOUT_ATTEMPTS 8 // Number of attempts total
|
||||||
#define PIN_BOOT_ATTEMPTS 3 // number of attempts per boot
|
#define PIN_BOOT_ATTEMPTS 3 // number of attempts per boot
|
||||||
|
|
||||||
#define CTAP2_UP_DELAY_MS 5000
|
#define CTAP2_UP_DELAY_MS 29000
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
@ -49,6 +49,7 @@
|
|||||||
#define CTAP2_ERR_PIN_POLICY_VIOLATION 0x37
|
#define CTAP2_ERR_PIN_POLICY_VIOLATION 0x37
|
||||||
#define CTAP2_ERR_PIN_TOKEN_EXPIRED 0x38
|
#define CTAP2_ERR_PIN_TOKEN_EXPIRED 0x38
|
||||||
#define CTAP2_ERR_REQUEST_TOO_LARGE 0x39
|
#define CTAP2_ERR_REQUEST_TOO_LARGE 0x39
|
||||||
|
#define CTAP2_ERR_ACTION_TIMEOUT 0x3A
|
||||||
#define CTAP1_ERR_OTHER 0x7F
|
#define CTAP1_ERR_OTHER 0x7F
|
||||||
#define CTAP2_ERR_SPEC_LAST 0xDF
|
#define CTAP2_ERR_SPEC_LAST 0xDF
|
||||||
#define CTAP2_ERR_EXTENSION_FIRST 0xE0
|
#define CTAP2_ERR_EXTENSION_FIRST 0xE0
|
||||||
|
@ -55,11 +55,43 @@ static int is_physical_button_pressed()
|
|||||||
|
|
||||||
static int is_touch_button_pressed()
|
static int is_touch_button_pressed()
|
||||||
{
|
{
|
||||||
return tsc_read_button(0) || tsc_read_button(1);
|
int is_pressed = (tsc_read_button(0) || tsc_read_button(1));
|
||||||
|
#ifndef IS_BOOTLOADER
|
||||||
|
if (is_pressed)
|
||||||
|
{
|
||||||
|
// delay for debounce, and longer than polling timer period.
|
||||||
|
delay(95);
|
||||||
|
return (tsc_read_button(0) || tsc_read_button(1));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
return is_pressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
int (*IS_BUTTON_PRESSED)() = is_physical_button_pressed;
|
int (*IS_BUTTON_PRESSED)() = is_physical_button_pressed;
|
||||||
|
|
||||||
|
static void edge_detect_touch_button()
|
||||||
|
{
|
||||||
|
static uint8_t last_touch = 0;
|
||||||
|
uint8_t current_touch = 0;
|
||||||
|
if (is_touch_button_pressed == IS_BUTTON_PRESSED)
|
||||||
|
{
|
||||||
|
current_touch = (tsc_read_button(0) || tsc_read_button(1));
|
||||||
|
|
||||||
|
// 1 sample per 25 ms
|
||||||
|
if ((millis() - __last_button_bounce_time) > 25)
|
||||||
|
{
|
||||||
|
// Detect "touch / rising edge"
|
||||||
|
if (!last_touch && current_touch)
|
||||||
|
{
|
||||||
|
__last_button_press_time = millis();
|
||||||
|
}
|
||||||
|
__last_button_bounce_time = millis();
|
||||||
|
last_touch = current_touch;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void request_from_nfc(bool request_active) {
|
void request_from_nfc(bool request_active) {
|
||||||
_RequestComeFromNFC = request_active;
|
_RequestComeFromNFC = request_active;
|
||||||
}
|
}
|
||||||
@ -78,19 +110,7 @@ void TIM6_DAC_IRQHandler()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
edge_detect_touch_button();
|
||||||
if (is_touch_button_pressed == IS_BUTTON_PRESSED)
|
|
||||||
{
|
|
||||||
if (IS_BUTTON_PRESSED())
|
|
||||||
{
|
|
||||||
// Only allow 1 press per 25 ms.
|
|
||||||
if ((millis() - __last_button_bounce_time) > 25)
|
|
||||||
{
|
|
||||||
__last_button_press_time = millis();
|
|
||||||
}
|
|
||||||
__last_button_bounce_time = millis();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifndef IS_BOOTLOADER
|
#ifndef IS_BOOTLOADER
|
||||||
// NFC sending WTX if needs
|
// NFC sending WTX if needs
|
||||||
@ -142,7 +162,6 @@ void device_set_status(uint32_t status)
|
|||||||
|
|
||||||
int device_is_button_pressed()
|
int device_is_button_pressed()
|
||||||
{
|
{
|
||||||
|
|
||||||
return IS_BUTTON_PRESSED();
|
return IS_BUTTON_PRESSED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -703,9 +703,6 @@ void apdu_process(uint8_t buf0, uint8_t *apduptr, APDU_STRUCT *apdu)
|
|||||||
// WTX_on(WTX_TIME_DEFAULT);
|
// WTX_on(WTX_TIME_DEFAULT);
|
||||||
request_from_nfc(true);
|
request_from_nfc(true);
|
||||||
ctap_response_init(&ctap_resp);
|
ctap_response_init(&ctap_resp);
|
||||||
delay(1);
|
|
||||||
printf1(TAG_NFC,"[%d] ", apdu->lc);
|
|
||||||
dump_hex1(TAG_NFC, apdu->data, apdu->lc);
|
|
||||||
status = ctap_request(apdu->data, apdu->lc, &ctap_resp);
|
status = ctap_request(apdu->data, apdu->lc, &ctap_resp);
|
||||||
request_from_nfc(false);
|
request_from_nfc(false);
|
||||||
// if (!WTX_off())
|
// if (!WTX_off())
|
||||||
@ -759,7 +756,8 @@ void apdu_process(uint8_t buf0, uint8_t *apduptr, APDU_STRUCT *apdu)
|
|||||||
case APDU_SOLO_RESET:
|
case APDU_SOLO_RESET:
|
||||||
if (apdu->lc == 4 && !memcmp(apdu->data, "\x12\x56\xab\xf0", 4)) {
|
if (apdu->lc == 4 && !memcmp(apdu->data, "\x12\x56\xab\xf0", 4)) {
|
||||||
printf1(TAG_NFC, "Reset...\r\n");
|
printf1(TAG_NFC, "Reset...\r\n");
|
||||||
delay(10);
|
nfc_write_response(buf0, SW_SUCCESS);
|
||||||
|
delay(20);
|
||||||
device_reboot();
|
device_reboot();
|
||||||
while(1);
|
while(1);
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user