Fix AID selection.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos
2023-10-28 20:57:53 +02:00
parent 28e979939a
commit 599fd706ce
4 changed files with 61 additions and 49 deletions

View File

@@ -33,9 +33,12 @@ int u2f_unload();
int u2f_process_apdu(); int u2f_process_apdu();
int u2f_select(app_t *a) { int u2f_select(app_t *a) {
a->process_apdu = u2f_process_apdu; if (cap_supported(CAP_U2F)) {
a->unload = u2f_unload; a->process_apdu = u2f_process_apdu;
return CCID_OK; a->unload = u2f_unload;
return CCID_OK;
}
return CCID_ERR_FILE_NOT_FOUND;
} }
void __attribute__((constructor)) u2f_ctor() { void __attribute__((constructor)) u2f_ctor() {

View File

@@ -55,9 +55,12 @@ const uint8_t atr_fido[] = {
}; };
int fido_select(app_t *a) { int fido_select(app_t *a) {
a->process_apdu = fido_process_apdu; if (cap_supported(CAP_FIDO2)) {
a->unload = fido_unload; a->process_apdu = fido_process_apdu;
return CCID_OK; a->unload = fido_unload;
return CCID_OK;
}
return CCID_ERR_FILE_NOT_FOUND;
} }
void __attribute__((constructor)) fido_ctor() { void __attribute__((constructor)) fido_ctor() {

View File

@@ -69,41 +69,44 @@ const uint8_t oath_aid[] = {
}; };
int oath_select(app_t *a) { int oath_select(app_t *a) {
a->process_apdu = oath_process_apdu; if (cap_supported(CAP_OATH)) {
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); file_t *ef_otp_pin = search_by_fid(EF_OTP_PIN, NULL, SPECIFY_EF);
if (file_has_data(ef_otp_pin)) { if (file_has_data(ef_otp_pin)) {
const uint8_t *pin_data = file_get_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++] = 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++] = 1;
res_APDU[res_APDU_size++] = *pin_data; res_APDU[res_APDU_size++] = ALG_HMAC_SHA1;
apdu.ne = res_APDU_size;
return CCID_OK;
} }
res_APDU[res_APDU_size++] = TAG_ALGO; return CCID_ERR_FILE_NOT_FOUND;
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() {

View File

@@ -117,20 +117,23 @@ const uint8_t otp_aid[] = {
}; };
int otp_select(app_t *a) { int otp_select(app_t *a) {
a->process_apdu = otp_process_apdu; if (cap_supported(CAP_OTP)) {
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 CCID_OK;
} }
else { return CCID_ERR_FILE_NOT_FOUND;
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[] =