mirror of
https://github.com/LedgerHQ/openpgp-card-app
synced 2024-11-09 07:10:30 +00:00
Code bugfix
- Fix APDU Set Slot to refresh the current key slot - Fix Manage Security Environment bad parameter - Fix set offset in APDU buffer (io buffers) - Fix ui_info empty string - Fix Nanos Main menu bad display
This commit is contained in:
parent
4257be08b5
commit
f336a1988f
@ -16,6 +16,7 @@
|
||||
*****************************************************************************/
|
||||
|
||||
#include "gpg_vars.h"
|
||||
#include "gpg_ux.h"
|
||||
#include "cx_errors.h"
|
||||
|
||||
void gpg_apdu_select_data(unsigned int ref, int record) {
|
||||
@ -281,7 +282,7 @@ int gpg_apdu_put_data(unsigned int ref) {
|
||||
break;
|
||||
|
||||
case 0x01F2:
|
||||
if ((N_gpg_pstate->config_slot[2] & 2) == 0) {
|
||||
if ((N_gpg_pstate->config_slot[2] & 1) == 0) {
|
||||
sw = SW_CONDITIONS_NOT_SATISFIED;
|
||||
break;
|
||||
}
|
||||
@ -291,6 +292,9 @@ int gpg_apdu_put_data(unsigned int ref) {
|
||||
break;
|
||||
}
|
||||
G_gpg_vstate.slot = G_gpg_vstate.work.io_buffer[G_gpg_vstate.io_offset];
|
||||
G_gpg_vstate.kslot = (gpg_key_slot_t *) &N_gpg_pstate->keys[G_gpg_vstate.slot];
|
||||
gpg_mse_reset();
|
||||
ui_CCID_reset();
|
||||
sw = SW_OK;
|
||||
break;
|
||||
|
||||
|
@ -408,7 +408,7 @@ int gpg_dispatch() {
|
||||
|
||||
/* --- MSE --- */
|
||||
case INS_MSE:
|
||||
sw = gpg_apdu_mse(tag);
|
||||
sw = gpg_apdu_mse();
|
||||
break;
|
||||
|
||||
/* --- PSO --- */
|
||||
|
@ -21,8 +21,8 @@
|
||||
#include "os_utils.h"
|
||||
|
||||
/*
|
||||
* io_buff: contains current message part
|
||||
* io_off: offset in current message part
|
||||
* io_buffer: contains current message part
|
||||
* io_offset: offset in current message part
|
||||
* io_length: length of current message part
|
||||
*/
|
||||
|
||||
@ -40,7 +40,7 @@ void gpg_io_set_offset(unsigned int offset) {
|
||||
break;
|
||||
default:
|
||||
LEDGER_ASSERT(offset < G_gpg_vstate.io_length, "Bad offset!");
|
||||
G_gpg_vstate.io_offset = G_gpg_vstate.io_length;
|
||||
G_gpg_vstate.io_offset = offset;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -60,7 +60,7 @@ int gpg_apdu_mse() {
|
||||
return SW_WRONG_DATA;
|
||||
}
|
||||
|
||||
gpg_mse_set(crt, ref);
|
||||
gpg_mse_set(G_gpg_vstate.io_p2, ref);
|
||||
gpg_io_discard(1);
|
||||
return SW_OK;
|
||||
}
|
||||
|
@ -39,3 +39,5 @@ const char *const C_NOT_ALLOWED = "Not Allowed ";
|
||||
const char *const C_DEFAULT_MODE = "Default mode";
|
||||
|
||||
const char *const C_UIF_LOCKED = "UIF locked";
|
||||
|
||||
const char *const C_EMPTY = "";
|
||||
|
@ -43,6 +43,8 @@ extern const char *const C_DEFAULT_MODE;
|
||||
extern const char *const C_UIF_LOCKED;
|
||||
extern const char *const C_UIF_INVALID;
|
||||
|
||||
extern const char *const C_EMPTY;
|
||||
|
||||
#define PICSTR(x) ((char *) PIC(x))
|
||||
|
||||
#define TEMPLATE_TYPE PICSTR(C_TEMPLATE_TYPE)
|
||||
@ -65,5 +67,6 @@ extern const char *const C_UIF_INVALID;
|
||||
#define DEFAULT_MODE PICSTR(C_DEFAULT_MODE)
|
||||
#define UIF_LOCKED PICSTR(C_UIF_LOCKED)
|
||||
#define UIF_INVALID PICSTR(C_UIF_INVALID)
|
||||
#define EMPTY PICSTR(C_EMPTY)
|
||||
|
||||
#endif
|
||||
|
@ -429,7 +429,7 @@ static void validate_pin() {
|
||||
sizeof(G_gpg_vstate.menu),
|
||||
" %d tries remaining",
|
||||
pin->counter);
|
||||
ui_info(WRONG_PIN, NULL, ui_menu_main_display, 0);
|
||||
ui_info(WRONG_PIN, EMPTY, ui_menu_main_display, 0);
|
||||
return;
|
||||
}
|
||||
offset = 1 + G_gpg_vstate.work.io_buffer[0];
|
||||
@ -441,7 +441,7 @@ static void validate_pin() {
|
||||
gpg_io_discard(1);
|
||||
gpg_io_insert_u16(SW_CONDITIONS_NOT_SATISFIED);
|
||||
gpg_io_do(IO_RETURN_AFTER_TX);
|
||||
ui_info(PIN_DIFFERS, NULL, ui_menu_main_display, 0);
|
||||
ui_info(PIN_DIFFERS, EMPTY, ui_menu_main_display, 0);
|
||||
} else {
|
||||
sw = gpg_pin_set(gpg_pin_get_pin(G_gpg_vstate.io_p2),
|
||||
G_gpg_vstate.work.io_buffer + offset + 1,
|
||||
@ -666,7 +666,7 @@ void ui_menu_tmpl_set_action(unsigned int value) {
|
||||
if (dest != NULL) {
|
||||
nvm_write(dest, NULL, sizeof(gpg_key_t));
|
||||
nvm_write(&dest->attributes, &attributes, sizeof(attributes));
|
||||
ui_info(OK, NULL, ui_menu_template_display, 0);
|
||||
ui_info(OK, EMPTY, ui_menu_template_display, 0);
|
||||
} else {
|
||||
ui_info(INVALID_SELECTION, TEMPLATE_KEY, ui_menu_template_display, 0);
|
||||
}
|
||||
@ -791,7 +791,7 @@ void ui_menu_pinmode_action(unsigned int value) {
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ui_info(INVALID_SELECTION, NULL, ui_menu_pinmode_display, 0);
|
||||
ui_info(INVALID_SELECTION, EMPTY, ui_menu_pinmode_display, 0);
|
||||
return;
|
||||
}
|
||||
G_gpg_vstate.pinmode = value;
|
||||
@ -862,7 +862,7 @@ void ui_menu_uifmode_action(unsigned int value) {
|
||||
uif = &G_gpg_vstate.kslot->aut.UIF[0];
|
||||
break;
|
||||
default:
|
||||
ui_info(INVALID_SELECTION, NULL, ui_menu_uifmode_display, 0);
|
||||
ui_info(INVALID_SELECTION, EMPTY, ui_menu_uifmode_display, 0);
|
||||
return;
|
||||
}
|
||||
if (uif[0] == 0) {
|
||||
@ -872,7 +872,7 @@ void ui_menu_uifmode_action(unsigned int value) {
|
||||
new_uif = 0;
|
||||
nvm_write(&uif[0], &new_uif, 1);
|
||||
} else /*if (uif[0] == 2 )*/ {
|
||||
ui_info(UIF_LOCKED, NULL, ui_menu_uifmode_display, 0);
|
||||
ui_info(UIF_LOCKED, EMPTY, ui_menu_uifmode_display, 0);
|
||||
return;
|
||||
}
|
||||
ui_menu_uifmode_display(value);
|
||||
@ -1016,8 +1016,8 @@ const ux_menu_entry_t ui_menu_main[] = {
|
||||
const bagl_element_t *ui_menu_main_predisplay(const ux_menu_entry_t *entry,
|
||||
bagl_element_t *element) {
|
||||
if (entry == &ui_menu_main[0]) {
|
||||
memset(G_gpg_vstate.menu, 0, sizeof(G_gpg_vstate.menu));
|
||||
if (element->component.userid == 0x21) {
|
||||
memset(G_gpg_vstate.menu, 0, sizeof(G_gpg_vstate.menu));
|
||||
memmove(G_gpg_vstate.menu, (void *) (N_gpg_pstate->name.value), 12);
|
||||
if (G_gpg_vstate.menu[0] == 0) {
|
||||
memmove(G_gpg_vstate.menu, "<No Name>", 9);
|
||||
@ -1042,7 +1042,9 @@ const bagl_element_t *ui_menu_main_predisplay(const ux_menu_entry_t *entry,
|
||||
snprintf(G_gpg_vstate.menu, sizeof(G_gpg_vstate.menu), "ID: %x", serial);
|
||||
#endif
|
||||
}
|
||||
element->text = G_gpg_vstate.menu;
|
||||
if (G_gpg_vstate.menu[0] != 0) {
|
||||
element->text = G_gpg_vstate.menu;
|
||||
}
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
@ -55,9 +55,7 @@ UX_STEP_CB(ux_menu_popup_1_step,
|
||||
|
||||
UX_FLOW(ux_flow_popup, &ux_menu_popup_1_step);
|
||||
|
||||
void ui_info(const char *msg1, const char *msg2, const void *menu_display, unsigned int value) {
|
||||
UNUSED(menu_display);
|
||||
UNUSED(value);
|
||||
void ui_info(const char *msg1, const char *msg2) {
|
||||
snprintf(G_gpg_vstate.menu, sizeof(G_gpg_vstate.menu), "%s. %s", msg1, msg2);
|
||||
ux_flow_init(0, ux_flow_popup, NULL);
|
||||
};
|
||||
@ -339,7 +337,7 @@ static void validate_pin() {
|
||||
sizeof(G_gpg_vstate.menu),
|
||||
" %d tries remaining",
|
||||
pin->counter);
|
||||
ui_info(WRONG_PIN, G_gpg_vstate.menu, ui_menu_main_display, 0);
|
||||
ui_info(WRONG_PIN, G_gpg_vstate.menu);
|
||||
} else {
|
||||
ui_menu_main_display(0);
|
||||
}
|
||||
@ -364,7 +362,7 @@ static void validate_pin() {
|
||||
sizeof(G_gpg_vstate.menu),
|
||||
" %d tries remaining",
|
||||
pin->counter);
|
||||
ui_info(WRONG_PIN, NULL, ui_menu_main_display, 0);
|
||||
ui_info(WRONG_PIN, EMPTY);
|
||||
return;
|
||||
}
|
||||
offset = 1 + G_gpg_vstate.work.io_buffer[0];
|
||||
@ -376,7 +374,7 @@ static void validate_pin() {
|
||||
gpg_io_discard(1);
|
||||
gpg_io_insert_u16(SW_CONDITIONS_NOT_SATISFIED);
|
||||
gpg_io_do(IO_RETURN_AFTER_TX);
|
||||
ui_info(PIN_DIFFERS, NULL, ui_menu_main_display, 0);
|
||||
ui_info(PIN_DIFFERS, EMPTY);
|
||||
} else {
|
||||
sw = gpg_pin_set(gpg_pin_get_pin(G_gpg_vstate.io_p2),
|
||||
G_gpg_vstate.work.io_buffer + offset + 1,
|
||||
@ -799,7 +797,7 @@ void ui_menu_pinmode_action(unsigned int value) {
|
||||
if (value == 128) {
|
||||
if (G_gpg_vstate.pinmode != N_gpg_pstate->config_pin[0]) {
|
||||
if (G_gpg_vstate.pinmode == PIN_MODE_TRUST) {
|
||||
ui_info(DEFAULT_MODE, NOT_ALLOWED, ui_menu_pinmode_display, 0);
|
||||
ui_info(DEFAULT_MODE, NOT_ALLOWED);
|
||||
return;
|
||||
}
|
||||
// set new mode
|
||||
@ -827,12 +825,12 @@ void ui_menu_pinmode_action(unsigned int value) {
|
||||
|
||||
case PIN_MODE_TRUST:
|
||||
if (!gpg_pin_is_verified(PIN_ID_PW3)) {
|
||||
ui_info(PIN_ADMIN, NOT_VERIFIED, ui_menu_pinmode_display, 0);
|
||||
ui_info(PIN_ADMIN, NOT_VERIFIED);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ui_info(INVALID_SELECTION, NULL, ui_menu_pinmode_display, 0);
|
||||
ui_info(INVALID_SELECTION, EMPTY);
|
||||
return;
|
||||
}
|
||||
G_gpg_vstate.pinmode = value;
|
||||
@ -922,7 +920,7 @@ void ui_menu_uifmode_action(unsigned int value) {
|
||||
uif = &G_gpg_vstate.kslot->aut.UIF[0];
|
||||
break;
|
||||
default:
|
||||
ui_info(INVALID_SELECTION, NULL, ui_menu_uifmode_display, 0);
|
||||
ui_info(INVALID_SELECTION, EMPTY);
|
||||
return;
|
||||
}
|
||||
if (uif[0] == 0) {
|
||||
@ -932,7 +930,7 @@ void ui_menu_uifmode_action(unsigned int value) {
|
||||
new_uif = 0;
|
||||
nvm_write(&uif[0], &new_uif, 1);
|
||||
} else /*if (uif[0] == 2 )*/ {
|
||||
ui_info(UIF_LOCKED, NULL, ui_menu_uifmode_display, 0);
|
||||
ui_info(UIF_LOCKED, EMPTY);
|
||||
return;
|
||||
}
|
||||
ui_menu_uifmode_display(value);
|
||||
|
Loading…
Reference in New Issue
Block a user