mirror of
https://github.com/LedgerHQ/openpgp-card-app
synced 2024-11-09 07:10:30 +00:00
PRODUCT: Change Key slots management
- Only a single slot for "Nanos" - 3 slots for other platforms - No more Variants to manage, only OpenPGP is a valid App Name
This commit is contained in:
parent
f336a1988f
commit
9f3130e88b
18
Makefile
18
Makefile
@ -25,20 +25,7 @@ include $(BOLOS_SDK)/Makefile.defines
|
||||
# Mandatory configuration #
|
||||
########################################
|
||||
# Application name
|
||||
ifeq ($(APPNAME),)
|
||||
APPNAME = OpenPGP
|
||||
endif
|
||||
ifeq ($(APPNAME),OpenPGP)
|
||||
ifeq ($(TARGET_NAME),TARGET_NANOS)
|
||||
GPG_MULTISLOT:=0
|
||||
else
|
||||
GPG_MULTISLOT:=1
|
||||
endif
|
||||
else ifeq ($(APPNAME),OpenPGP.XL)
|
||||
GPG_MULTISLOT:=1
|
||||
else
|
||||
$(error APPNAME ($(APPNAME)) is not set or unknown)
|
||||
endif
|
||||
|
||||
# Application version
|
||||
APPVERSION_M = 2
|
||||
@ -85,11 +72,7 @@ PATH_APP_LOAD_PARAMS = "2152157255'"
|
||||
# * It must at least contains one value.
|
||||
# * Values can be the app ticker or anything else but should be unique.
|
||||
VARIANT_PARAM = APPNAME
|
||||
ifeq ($(TARGET_NAME),TARGET_NANOS)
|
||||
VARIANT_VALUES = OpenPGP OpenPGP.XL
|
||||
else
|
||||
VARIANT_VALUES = OpenPGP
|
||||
endif
|
||||
|
||||
# Enabling DEBUG flag will enable PRINTF and disable optimizations
|
||||
#DEBUG = 1
|
||||
@ -135,7 +118,6 @@ DISABLE_STANDARD_WEBUSB = 1
|
||||
# Main app configuration #
|
||||
########################################
|
||||
|
||||
DEFINES += GPG_MULTISLOT=$(GPG_MULTISLOT)
|
||||
DEFINES += CUSTOM_IO_APDU_BUFFER_SIZE=\(255+5+64\)
|
||||
DEFINES += HAVE_USB_CLASS_CCID
|
||||
DEFINES += HAVE_RSA
|
||||
|
@ -20,6 +20,7 @@
|
||||
|
||||
#include "lcx_sha3.h"
|
||||
#include "usbd_ccid_if.h"
|
||||
#include "bolos_target.h"
|
||||
|
||||
/* cannot send more that F0 bytes in CCID, why? do not know for now
|
||||
* So set up length to F0 minus 2 bytes for SW
|
||||
@ -37,10 +38,10 @@
|
||||
#define GPG_MIN_PW1_LENGTH 6
|
||||
#define GPG_MIN_PW3_LENGTH 8
|
||||
|
||||
#if GPG_MULTISLOT
|
||||
#define GPG_KEYS_SLOTS 3
|
||||
#else
|
||||
#ifdef TARGET_NANOS
|
||||
#define GPG_KEYS_SLOTS 1
|
||||
#else
|
||||
#define GPG_KEYS_SLOTS 3
|
||||
#endif
|
||||
|
||||
#define GPG_KEY_ATTRIBUTES_LENGTH 12
|
||||
|
@ -19,12 +19,6 @@
|
||||
#ifndef GPG_UX_H
|
||||
#define GPG_UX_H
|
||||
|
||||
#if GPG_MULTISLOT
|
||||
#if GPG_KEYS_SLOTS != 3
|
||||
#error menu definition not correct for current value of GPG_KEYS_SLOTS
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define STR(x) #x
|
||||
#define XSTR(x) STR(x)
|
||||
|
||||
|
@ -33,10 +33,6 @@ void ui_menu_tmpl_type_action(unsigned int value);
|
||||
void ui_menu_seedmode_action(unsigned int value);
|
||||
void ui_menu_reset_action(unsigned int value);
|
||||
|
||||
#if GPG_MULTISLOT
|
||||
void ui_menu_slot_action(unsigned int value);
|
||||
#endif
|
||||
|
||||
const ux_menu_entry_t ui_menu_settings[];
|
||||
void ui_menu_main_display(unsigned int value);
|
||||
unsigned int ui_pinentry_action_button(unsigned int button_mask, unsigned int button_mask_counter);
|
||||
@ -899,22 +895,6 @@ void ui_menu_reset_action(unsigned int value) {
|
||||
ui_menu_main_display(0);
|
||||
}
|
||||
|
||||
/* ------------------------------ RESET KEY SLOT ----------------------------- */
|
||||
|
||||
void ui_menu_reset_slot_action(unsigned int value);
|
||||
|
||||
const ux_menu_entry_t ui_menu_reset_slot[] = {
|
||||
{NULL, NULL, 0, NULL, "Really Reset ?", NULL, 0, 0},
|
||||
{NULL, ui_menu_main_display, 0, &C_icon_back, "No", NULL, 61, 40},
|
||||
{NULL, ui_menu_reset_slot_action, 0, NULL, "Yes", NULL, 0, 0},
|
||||
UX_MENU_END};
|
||||
|
||||
void ui_menu_reset_slot_action(unsigned int value) {
|
||||
UNUSED(value);
|
||||
gpg_install_slot(G_gpg_vstate.kslot);
|
||||
ui_menu_main_display(0);
|
||||
}
|
||||
|
||||
/* ------------------------------- SETTINGS UX ------------------------------- */
|
||||
|
||||
const ux_menu_entry_t ui_menu_settings[] = {
|
||||
@ -923,70 +903,9 @@ const ux_menu_entry_t ui_menu_settings[] = {
|
||||
{NULL, ui_menu_pinmode_display, 0, NULL, "PIN mode", NULL, 0, 0},
|
||||
{NULL, ui_menu_uifmode_display, 0, NULL, "UIF mode", NULL, 0, 0},
|
||||
{ui_menu_reset, NULL, 0, NULL, "Reset App", NULL, 0, 0},
|
||||
{ui_menu_reset_slot, NULL, 0, NULL, "Reset Slot", NULL, 0, 0},
|
||||
{NULL, ui_menu_main_display, 2, &C_icon_back, "Back", NULL, 61, 40},
|
||||
UX_MENU_END};
|
||||
|
||||
/* --------------------------------- SLOT UX --------------------------------- */
|
||||
|
||||
#if GPG_MULTISLOT
|
||||
|
||||
const ux_menu_entry_t ui_menu_slot[] = {
|
||||
{NULL, NULL, -1, NULL, "Choose:", NULL, 0, 0},
|
||||
{NULL, ui_menu_slot_action, 1, NULL, "", NULL, 0, 0},
|
||||
{NULL, ui_menu_slot_action, 2, NULL, "", NULL, 0, 0},
|
||||
{NULL, ui_menu_slot_action, 3, NULL, "", NULL, 0, 0},
|
||||
{NULL, ui_menu_slot_action, 128, NULL, "Set Default", NULL, 0, 0},
|
||||
{NULL, ui_menu_main_display, 1, &C_icon_back, "Back", NULL, 61, 40},
|
||||
UX_MENU_END};
|
||||
|
||||
const bagl_element_t *ui_menu_slot_predisplay(const ux_menu_entry_t *entry,
|
||||
bagl_element_t *element) {
|
||||
unsigned int slot;
|
||||
if (element->component.userid == 0x20) {
|
||||
for (slot = 1; slot <= 3; slot++) {
|
||||
if (entry == &ui_menu_slot[slot]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (slot != 4) {
|
||||
snprintf(G_gpg_vstate.menu,
|
||||
sizeof(G_gpg_vstate.menu),
|
||||
"Slot %d %s %s",
|
||||
slot,
|
||||
slot == N_gpg_pstate->config_slot[1] + 1 ? "#" : " ", /* default */
|
||||
slot == G_gpg_vstate.slot + 1 ? "+" : " " /* selected*/);
|
||||
element->text = G_gpg_vstate.menu;
|
||||
}
|
||||
}
|
||||
return element;
|
||||
}
|
||||
|
||||
void ui_menu_slot_display(unsigned int value) {
|
||||
UX_MENU_DISPLAY(value, ui_menu_slot, ui_menu_slot_predisplay);
|
||||
}
|
||||
|
||||
void ui_menu_slot_action(unsigned int value) {
|
||||
unsigned char s;
|
||||
|
||||
if (value == 128) {
|
||||
s = G_gpg_vstate.slot;
|
||||
nvm_write((void *) (&N_gpg_pstate->config_slot[1]), &s, 1);
|
||||
value = s + 1;
|
||||
} else {
|
||||
s = (unsigned char) (value - 1);
|
||||
if (s != G_gpg_vstate.slot) {
|
||||
G_gpg_vstate.slot = s;
|
||||
G_gpg_vstate.kslot = (gpg_key_slot_t *) &N_gpg_pstate->keys[G_gpg_vstate.slot];
|
||||
gpg_mse_reset();
|
||||
ui_CCID_reset();
|
||||
}
|
||||
}
|
||||
// redisplay first entry of the idle menu
|
||||
ui_menu_slot_display(value);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* --------------------------------- INFO UX --------------------------------- */
|
||||
|
||||
const ux_menu_entry_t ui_menu_info[] = {
|
||||
@ -1005,9 +924,6 @@ const ux_menu_entry_t ui_menu_info[] = {
|
||||
|
||||
const ux_menu_entry_t ui_menu_main[] = {
|
||||
{NULL, NULL, 0, NULL, "", "", 0, 0},
|
||||
#if GPG_MULTISLOT
|
||||
{NULL, ui_menu_slot_display, 0, NULL, "Select slot", NULL, 0, 0},
|
||||
#endif
|
||||
{ui_menu_settings, NULL, 0, NULL, "Settings", NULL, 0, 0},
|
||||
{ui_menu_info, NULL, 0, NULL, "About", NULL, 0, 0},
|
||||
{NULL, (void *) os_sched_exit, 0, &C_icon_dashboard, "Quit app", NULL, 50, 29},
|
||||
@ -1032,15 +948,7 @@ const bagl_element_t *ui_menu_main_predisplay(const ux_menu_entry_t *entry,
|
||||
if (element->component.userid == 0x22) {
|
||||
unsigned int serial = U4BE(G_gpg_vstate.kslot->serial, 0);
|
||||
memset(G_gpg_vstate.menu, 0, sizeof(G_gpg_vstate.menu));
|
||||
#if GPG_MULTISLOT
|
||||
snprintf(G_gpg_vstate.menu,
|
||||
sizeof(G_gpg_vstate.menu),
|
||||
"ID: %x / %d",
|
||||
serial,
|
||||
G_gpg_vstate.slot + 1);
|
||||
#else
|
||||
snprintf(G_gpg_vstate.menu, sizeof(G_gpg_vstate.menu), "ID: %x", serial);
|
||||
#endif
|
||||
}
|
||||
if (G_gpg_vstate.menu[0] != 0) {
|
||||
element->text = G_gpg_vstate.menu;
|
||||
|
@ -32,10 +32,6 @@ void ui_menu_tmpl_type_action(unsigned int value);
|
||||
void ui_menu_seedmode_action(unsigned int value);
|
||||
void ui_menu_reset_action(unsigned int value);
|
||||
|
||||
#if GPG_MULTISLOT
|
||||
void ui_menu_slot_action(unsigned int value);
|
||||
#endif
|
||||
|
||||
void ui_menu_settings_display(unsigned int value);
|
||||
void ui_menu_main_display(unsigned int value);
|
||||
unsigned int ui_pinentry_action_button(unsigned int button_mask, unsigned int button_mask_counter);
|
||||
@ -966,29 +962,6 @@ void ui_menu_reset_action(unsigned int value) {
|
||||
ui_menu_main_display(0);
|
||||
}
|
||||
|
||||
/* ------------------------------ RESET KEY SLOT ----------------------------- */
|
||||
|
||||
void ui_menu_reset_slot_action(unsigned int value);
|
||||
|
||||
UX_STEP_CB(ux_menu_reset_slot_1_step,
|
||||
bnn,
|
||||
ui_menu_settings_display(4),
|
||||
{"Ooops, NO!", "Do not reset", "the key slot"});
|
||||
|
||||
UX_STEP_CB(ux_menu_reset_slot_2_step, bn, ui_menu_reset_slot_action(0), {"YES!", "Reset the slot"});
|
||||
|
||||
UX_FLOW(ux_flow_reset_slot, &ux_menu_reset_slot_1_step, &ux_menu_reset_slot_2_step);
|
||||
|
||||
void ui_menu_reset_slot_display(unsigned int value) {
|
||||
ux_flow_init(value, ux_flow_reset_slot, NULL);
|
||||
}
|
||||
|
||||
void ui_menu_reset_slot_action(unsigned int value) {
|
||||
UNUSED(value);
|
||||
gpg_install_slot(G_gpg_vstate.kslot);
|
||||
ui_menu_main_display(0);
|
||||
}
|
||||
|
||||
/* ------------------------------- SETTINGS UX ------------------------------- */
|
||||
|
||||
const char *const settings_getter_values[] =
|
||||
@ -1030,8 +1003,6 @@ void ui_menu_settings_display(unsigned int value) {
|
||||
|
||||
/* --------------------------------- SLOT UX --------------------------------- */
|
||||
|
||||
#if GPG_MULTISLOT
|
||||
|
||||
void ui_menu_slot_action(unsigned int value);
|
||||
void ui_menu_slot_predisplay(void);
|
||||
|
||||
@ -1116,7 +1087,6 @@ void ui_menu_slot_action(unsigned int value) {
|
||||
}
|
||||
ui_menu_slot_display(G_gpg_vstate.slot);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* --------------------------------- INFO UX --------------------------------- */
|
||||
|
||||
@ -1161,9 +1131,7 @@ UX_STEP_NOCB_INIT(ux_menu_main_1_step,
|
||||
G_gpg_vstate.ux_buff2,
|
||||
});
|
||||
|
||||
#if GPG_MULTISLOT
|
||||
UX_STEP_CB(ux_menu_main_2_step, pb, ui_menu_slot_display(0), {&C_icon_coggle, "Select Slot"});
|
||||
#endif
|
||||
|
||||
UX_STEP_CB(ux_menu_main_3_step, pb, ui_menu_settings_display(0), {&C_icon_coggle, "Settings"});
|
||||
|
||||
@ -1173,9 +1141,7 @@ UX_STEP_CB(ux_menu_main_5_step, pb, os_sched_exit(0), {&C_icon_dashboard_x, "Qui
|
||||
|
||||
UX_FLOW(ux_flow_main,
|
||||
&ux_menu_main_1_step,
|
||||
#if GPG_MULTISLOT
|
||||
&ux_menu_main_2_step,
|
||||
#endif
|
||||
&ux_menu_main_3_step,
|
||||
&ux_menu_main_4_step,
|
||||
&ux_menu_main_5_step);
|
||||
@ -1195,15 +1161,11 @@ void ui_menu_main_predisplay() {
|
||||
|
||||
unsigned int serial = U4BE(G_gpg_vstate.kslot->serial, 0);
|
||||
memset(G_gpg_vstate.ux_buff2, 0, sizeof(G_gpg_vstate.ux_buff2));
|
||||
#if GPG_MULTISLOT
|
||||
snprintf(G_gpg_vstate.ux_buff2,
|
||||
sizeof(G_gpg_vstate.ux_buff2),
|
||||
"ID: %x / %d",
|
||||
serial,
|
||||
G_gpg_vstate.slot + 1);
|
||||
#else
|
||||
snprintf(G_gpg_vstate.ux_buff2, sizeof(G_gpg_vstate.ux_buff2), "ID: %x", serial);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ui_menu_main_display(unsigned int value) {
|
||||
|
Loading…
Reference in New Issue
Block a user