Adapted to new selection AID method.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos
2023-10-28 20:53:06 +02:00
parent 849221fd95
commit 28e979939a
5 changed files with 75 additions and 87 deletions

View File

@@ -32,18 +32,14 @@ const uint8_t u2f_aid[] = {
int u2f_unload(); int u2f_unload();
int u2f_process_apdu(); int u2f_process_apdu();
app_t *u2f_select(app_t *a, const uint8_t *aid, uint8_t aid_len) { int u2f_select(app_t *a) {
if (!memcmp(aid, u2f_aid + 1, MIN(aid_len, u2f_aid[0])) && cap_supported(CAP_U2F)) { a->process_apdu = u2f_process_apdu;
a->aid = u2f_aid; a->unload = u2f_unload;
a->process_apdu = u2f_process_apdu; return CCID_OK;
a->unload = u2f_unload;
return a;
}
return NULL;
} }
void __attribute__((constructor)) u2f_ctor() { void __attribute__((constructor)) u2f_ctor() {
register_app(u2f_select); register_app(u2f_select, u2f_aid);
} }
int u2f_unload() { int u2f_unload() {

View File

@@ -33,6 +33,7 @@
#include <math.h> #include <math.h>
#include "management.h" #include "management.h"
#include "ctap_hid.h" #include "ctap_hid.h"
#include "version.h"
int fido_process_apdu(); int fido_process_apdu();
int fido_unload(); int fido_unload();
@@ -53,27 +54,30 @@ const uint8_t atr_fido[] = {
0x75, 0x62, 0x69, 0x4b, 0x65, 0x79, 0x40 0x75, 0x62, 0x69, 0x4b, 0x65, 0x79, 0x40
}; };
app_t *fido_select(app_t *a, const uint8_t *aid, uint8_t aid_len) { int fido_select(app_t *a) {
if (!memcmp(aid, fido_aid + 1, MIN(aid_len, fido_aid[0])) && cap_supported(CAP_FIDO2)) { a->process_apdu = fido_process_apdu;
a->aid = fido_aid; a->unload = fido_unload;
a->process_apdu = fido_process_apdu; return CCID_OK;
a->unload = fido_unload;
return a;
}
return NULL;
} }
void __attribute__((constructor)) fido_ctor() { void __attribute__((constructor)) fido_ctor() {
#if defined(USB_ITF_CCID) || defined(ENABLE_EMULATION) #if defined(USB_ITF_CCID) || defined(ENABLE_EMULATION)
ccid_atr = atr_fido; ccid_atr = atr_fido;
#endif #endif
register_app(fido_select); register_app(fido_select, fido_aid);
} }
int fido_unload() { int fido_unload() {
return CCID_OK; return CCID_OK;
} }
uint8_t get_version_major() {
return PICO_FIDO_VERSION_MAJOR;
}
uint8_t get_version_minor() {
return PICO_FIDO_VERSION_MINOR;
}
mbedtls_ecp_group_id fido_curve_to_mbedtls(int curve) { mbedtls_ecp_group_id fido_curve_to_mbedtls(int curve) {
if (curve == FIDO2_CURVE_P256) { if (curve == FIDO2_CURVE_P256) {
return MBEDTLS_ECP_DP_SECP256R1; return MBEDTLS_ECP_DP_SECP256R1;

View File

@@ -31,22 +31,18 @@ const uint8_t man_aid[] = {
0xa0, 0x00, 0x00, 0x05, 0x27, 0x47, 0x11, 0x17 0xa0, 0x00, 0x00, 0x05, 0x27, 0x47, 0x11, 0x17
}; };
extern void scan_all(); extern void scan_all();
app_t *man_select(app_t *a, const uint8_t *aid, uint8_t aid_len) { int man_select(app_t *a) {
if (!memcmp(aid, man_aid + 1, MIN(aid_len, man_aid[0]))) { a->process_apdu = man_process_apdu;
a->aid = man_aid; a->unload = man_unload;
a->process_apdu = man_process_apdu; sprintf((char *) res_APDU, "%d.%d.0", PICO_FIDO_VERSION_MAJOR, PICO_FIDO_VERSION_MINOR);
a->unload = man_unload; res_APDU_size = strlen((char *) res_APDU);
sprintf((char *) res_APDU, "%d.%d.0", PICO_FIDO_VERSION_MAJOR, PICO_FIDO_VERSION_MINOR); apdu.ne = res_APDU_size;
res_APDU_size = strlen((char *) res_APDU); scan_all();
apdu.ne = res_APDU_size; return CCID_OK;
scan_all();
return a;
}
return NULL;
} }
void __attribute__((constructor)) man_ctor() { void __attribute__((constructor)) man_ctor() {
register_app(man_select); register_app(man_select, man_aid);
} }
int man_unload() { int man_unload() {

View File

@@ -68,50 +68,46 @@ const uint8_t oath_aid[] = {
0xa0, 0x00, 0x00, 0x05, 0x27, 0x21, 0x01 0xa0, 0x00, 0x00, 0x05, 0x27, 0x21, 0x01
}; };
app_t *oath_select(app_t *a, const uint8_t *aid, uint8_t aid_len) { int oath_select(app_t *a) {
if (!memcmp(aid, oath_aid + 1, MIN(aid_len, oath_aid[0])) && cap_supported(CAP_OATH)) { a->process_apdu = oath_process_apdu;
a->aid = oath_aid; a->unload = oath_unload;
a->process_apdu = oath_process_apdu; res_APDU_size = 0;
a->unload = oath_unload; res_APDU[res_APDU_size++] = TAG_T_VERSION;
res_APDU_size = 0; res_APDU[res_APDU_size++] = 3;
res_APDU[res_APDU_size++] = TAG_T_VERSION; res_APDU[res_APDU_size++] = PICO_FIDO_VERSION_MAJOR;
res_APDU[res_APDU_size++] = 3; res_APDU[res_APDU_size++] = PICO_FIDO_VERSION_MINOR;
res_APDU[res_APDU_size++] = PICO_FIDO_VERSION_MAJOR; res_APDU[res_APDU_size++] = 0;
res_APDU[res_APDU_size++] = PICO_FIDO_VERSION_MINOR; res_APDU[res_APDU_size++] = TAG_NAME;
res_APDU[res_APDU_size++] = 0; res_APDU[res_APDU_size++] = 8;
res_APDU[res_APDU_size++] = TAG_NAME;
res_APDU[res_APDU_size++] = 8;
#ifndef ENABLE_EMULATION #ifndef ENABLE_EMULATION
pico_get_unique_board_id((pico_unique_board_id_t *) (res_APDU + res_APDU_size)); pico_get_unique_board_id((pico_unique_board_id_t *) (res_APDU + res_APDU_size));
res_APDU_size += 8; res_APDU_size += 8;
#else #else
memset(res_APDU + res_APDU_size, 0, 8); res_APDU_size += 8; memset(res_APDU + res_APDU_size, 0, 8); res_APDU_size += 8;
#endif #endif
if (file_has_data(search_dynamic_file(EF_OATH_CODE)) == true) { if (file_has_data(search_dynamic_file(EF_OATH_CODE)) == true) {
random_gen(NULL, challenge, sizeof(challenge)); random_gen(NULL, challenge, sizeof(challenge));
res_APDU[res_APDU_size++] = TAG_CHALLENGE; res_APDU[res_APDU_size++] = TAG_CHALLENGE;
res_APDU[res_APDU_size++] = sizeof(challenge); res_APDU[res_APDU_size++] = sizeof(challenge);
memcpy(res_APDU + res_APDU_size, challenge, sizeof(challenge)); memcpy(res_APDU + res_APDU_size, challenge, sizeof(challenge));
res_APDU_size += sizeof(challenge); res_APDU_size += sizeof(challenge);
}
file_t *ef_otp_pin = search_by_fid(EF_OTP_PIN, NULL, SPECIFY_EF);
if (file_has_data(ef_otp_pin)) {
const uint8_t *pin_data = file_get_data(ef_otp_pin);
res_APDU[res_APDU_size++] = TAG_PIN_COUNTER;
res_APDU[res_APDU_size++] = 1;
res_APDU[res_APDU_size++] = *pin_data;
}
res_APDU[res_APDU_size++] = TAG_ALGO;
res_APDU[res_APDU_size++] = 1;
res_APDU[res_APDU_size++] = ALG_HMAC_SHA1;
apdu.ne = res_APDU_size;
return a;
} }
return NULL; file_t *ef_otp_pin = search_by_fid(EF_OTP_PIN, NULL, SPECIFY_EF);
if (file_has_data(ef_otp_pin)) {
const uint8_t *pin_data = file_get_data(ef_otp_pin);
res_APDU[res_APDU_size++] = TAG_PIN_COUNTER;
res_APDU[res_APDU_size++] = 1;
res_APDU[res_APDU_size++] = *pin_data;
}
res_APDU[res_APDU_size++] = TAG_ALGO;
res_APDU[res_APDU_size++] = 1;
res_APDU[res_APDU_size++] = ALG_HMAC_SHA1;
apdu.ne = res_APDU_size;
return CCID_OK;
} }
void __attribute__((constructor)) oath_ctor() { void __attribute__((constructor)) oath_ctor() {
register_app(oath_select); register_app(oath_select, oath_aid);
} }
int oath_unload() { int oath_unload() {

View File

@@ -116,25 +116,21 @@ const uint8_t otp_aid[] = {
0xa0, 0x00, 0x00, 0x05, 0x27, 0x20, 0x01 0xa0, 0x00, 0x00, 0x05, 0x27, 0x20, 0x01
}; };
app_t *otp_select(app_t *a, const uint8_t *aid, uint8_t aid_len) { int otp_select(app_t *a) {
if (!memcmp(aid, otp_aid + 1, MIN(aid_len, otp_aid[0])) && cap_supported(CAP_OTP)) { a->process_apdu = otp_process_apdu;
a->aid = otp_aid; a->unload = otp_unload;
a->process_apdu = otp_process_apdu; if (file_has_data(search_dynamic_file(EF_OTP_SLOT1)) ||
a->unload = otp_unload; file_has_data(search_dynamic_file(EF_OTP_SLOT2))) {
if (file_has_data(search_dynamic_file(EF_OTP_SLOT1)) || config_seq = 1;
file_has_data(search_dynamic_file(EF_OTP_SLOT2))) {
config_seq = 1;
}
else {
config_seq = 0;
}
otp_status();
memmove(res_APDU, res_APDU + 1, 6);
res_APDU_size = 6;
apdu.ne = res_APDU_size;
return a;
} }
return NULL; else {
config_seq = 0;
}
otp_status();
memmove(res_APDU, res_APDU + 1, 6);
res_APDU_size = 6;
apdu.ne = res_APDU_size;
return CCID_OK;
} }
uint8_t modhex_tab[] = uint8_t modhex_tab[] =
@@ -308,7 +304,7 @@ int otp_button_pressed(uint8_t slot) {
} }
void __attribute__((constructor)) otp_ctor() { void __attribute__((constructor)) otp_ctor() {
register_app(otp_select); register_app(otp_select, otp_aid);
button_pressed_cb = otp_button_pressed; button_pressed_cb = otp_button_pressed;
} }