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->aid = u2f_aid;
a->process_apdu = u2f_process_apdu; a->process_apdu = u2f_process_apdu;
a->unload = u2f_unload; a->unload = u2f_unload;
return a; return CCID_OK;
}
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->aid = fido_aid;
a->process_apdu = fido_process_apdu; a->process_apdu = fido_process_apdu;
a->unload = fido_unload; a->unload = fido_unload;
return a; return CCID_OK;
}
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->aid = man_aid;
a->process_apdu = man_process_apdu; a->process_apdu = man_process_apdu;
a->unload = man_unload; a->unload = man_unload;
sprintf((char *) res_APDU, "%d.%d.0", PICO_FIDO_VERSION_MAJOR, PICO_FIDO_VERSION_MINOR); sprintf((char *) res_APDU, "%d.%d.0", PICO_FIDO_VERSION_MAJOR, PICO_FIDO_VERSION_MINOR);
res_APDU_size = strlen((char *) res_APDU); res_APDU_size = strlen((char *) res_APDU);
apdu.ne = res_APDU_size; apdu.ne = res_APDU_size;
scan_all(); scan_all();
return a; return CCID_OK;
}
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,9 +68,7 @@ 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->aid = oath_aid;
a->process_apdu = oath_process_apdu; a->process_apdu = oath_process_apdu;
a->unload = oath_unload; a->unload = oath_unload;
res_APDU_size = 0; res_APDU_size = 0;
@@ -105,13 +103,11 @@ app_t *oath_select(app_t *a, const uint8_t *aid, uint8_t aid_len) {
res_APDU[res_APDU_size++] = 1; res_APDU[res_APDU_size++] = 1;
res_APDU[res_APDU_size++] = ALG_HMAC_SHA1; res_APDU[res_APDU_size++] = ALG_HMAC_SHA1;
apdu.ne = res_APDU_size; apdu.ne = res_APDU_size;
return a; return CCID_OK;
}
return NULL;
} }
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,9 +116,7 @@ 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->aid = otp_aid;
a->process_apdu = otp_process_apdu; a->process_apdu = otp_process_apdu;
a->unload = otp_unload; a->unload = otp_unload;
if (file_has_data(search_dynamic_file(EF_OTP_SLOT1)) || if (file_has_data(search_dynamic_file(EF_OTP_SLOT1)) ||
@@ -132,9 +130,7 @@ app_t *otp_select(app_t *a, const uint8_t *aid, uint8_t aid_len) {
memmove(res_APDU, res_APDU + 1, 6); memmove(res_APDU, res_APDU + 1, 6);
res_APDU_size = 6; res_APDU_size = 6;
apdu.ne = res_APDU_size; apdu.ne = res_APDU_size;
return a; return CCID_OK;
}
return NULL;
} }
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;
} }