implement change pin
This commit is contained in:
parent
2ab45b4830
commit
3301b36661
|
@ -0,0 +1,45 @@
|
|||
#include "card.h"
|
||||
#include "core.h"
|
||||
#include "keycard/keycard_cmdset.h"
|
||||
|
||||
void card_change_name() {
|
||||
|
||||
}
|
||||
|
||||
void card_change_pin() {
|
||||
SC_BUF(pin, KEYCARD_PIN_LEN);
|
||||
|
||||
if (ui_read_pin(pin, PIN_NEW_CODE) != CORE_EVT_UI_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
app_err_t err = keycard_cmd_change_credential(&g_core.keycard, KEYCARD_PIN, pin, KEYCARD_PIN_LEN);
|
||||
memset(pin, 0, KEYCARD_PIN_LEN);
|
||||
|
||||
if (err != ERR_OK) {
|
||||
ui_card_transport_error();
|
||||
}
|
||||
}
|
||||
|
||||
void card_change_puk() {
|
||||
SC_BUF(puk, KEYCARD_PUK_LEN);
|
||||
|
||||
if (ui_read_puk(puk, PUK_NEW_CODE) != CORE_EVT_UI_OK) {
|
||||
return;
|
||||
}
|
||||
|
||||
app_err_t err = keycard_cmd_change_credential(&g_core.keycard, KEYCARD_PUK, puk, KEYCARD_PUK_LEN);
|
||||
memset(puk, 0, KEYCARD_PUK_LEN);
|
||||
|
||||
if (err != ERR_OK) {
|
||||
ui_card_transport_error();
|
||||
}
|
||||
}
|
||||
|
||||
void card_change_pairing() {
|
||||
|
||||
}
|
||||
|
||||
void card_reset() {
|
||||
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef __CARD_SETTINGS__
|
||||
#define __CARD_SETTINGS__
|
||||
|
||||
#include "common.h"
|
||||
|
||||
void card_change_name();
|
||||
void card_change_pin();
|
||||
void card_change_puk();
|
||||
void card_change_pairing();
|
||||
void card_reset();
|
||||
|
||||
#endif
|
|
@ -1,3 +1,6 @@
|
|||
#ifndef __CORE_SETTINGS__
|
||||
#define __CORE_SETTINGS__
|
||||
|
||||
#include "common.h"
|
||||
#include <stdbool.h>
|
||||
|
||||
|
@ -25,3 +28,5 @@ void settings_commit();
|
|||
void settings_lcd_brightness();
|
||||
void settings_set_off_time();
|
||||
void settings_usb_onoff();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -89,6 +89,16 @@ app_err_t keycard_cmd_verify_pin(keycard_t* kc, uint8_t* pin) {
|
|||
return securechannel_send_apdu(&kc->sc, &kc->ch, &kc->apdu, pin, KEYCARD_PIN_LEN);
|
||||
}
|
||||
|
||||
app_err_t keycard_cmd_change_credential(keycard_t* kc, keycard_credentials_t type, uint8_t* credentials, uint8_t len) {
|
||||
APDU_RESET(&kc->apdu);
|
||||
APDU_CLA(&kc->apdu) = 0x80;
|
||||
APDU_INS(&kc->apdu) = 0x21;
|
||||
APDU_P1(&kc->apdu) = type;
|
||||
APDU_P2(&kc->apdu) = 0;
|
||||
|
||||
return securechannel_send_apdu(&kc->sc, &kc->ch, &kc->apdu, credentials, len);
|
||||
}
|
||||
|
||||
app_err_t keycard_cmd_unblock_pin(keycard_t* kc, uint8_t* pin, uint8_t* puk) {
|
||||
APDU_RESET(&kc->apdu);
|
||||
APDU_CLA(&kc->apdu) = 0x80;
|
||||
|
|
|
@ -4,10 +4,17 @@
|
|||
#include "keycard.h"
|
||||
#include "error.h"
|
||||
|
||||
typedef enum {
|
||||
KEYCARD_PIN = 0,
|
||||
KEYCARD_PUK,
|
||||
KEYCARD_PAIRING
|
||||
} keycard_credentials_t;
|
||||
|
||||
app_err_t keycard_cmd_select(keycard_t* kc, const uint8_t* aid, uint32_t len);
|
||||
app_err_t keycard_cmd_pair(keycard_t* kc, uint8_t step, uint8_t* data);
|
||||
app_err_t keycard_cmd_autopair(keycard_t* kc, const uint8_t* psk, pairing_t* pairing);
|
||||
app_err_t keycard_cmd_verify_pin(keycard_t* kc, uint8_t* pin);
|
||||
app_err_t keycard_cmd_change_credential(keycard_t* kc, keycard_credentials_t type, uint8_t* credentials, uint8_t len);
|
||||
app_err_t keycard_cmd_unblock_pin(keycard_t* kc, uint8_t* pin, uint8_t* puk);
|
||||
app_err_t keycard_cmd_get_status(keycard_t* kc);
|
||||
app_err_t keycard_cmd_init(keycard_t* kc, uint8_t* sc_pub, uint8_t* pin, uint8_t* puk, uint8_t* psk);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include "core/core.h"
|
||||
#include "core/card.h"
|
||||
#include "core/settings.h"
|
||||
#include "keycard/keycard.h"
|
||||
#include "pwr.h"
|
||||
|
@ -6,18 +7,39 @@
|
|||
|
||||
static inline void core_action_run(i18n_str_id_t menu) {
|
||||
switch(menu) {
|
||||
// Top Level
|
||||
case MENU_QRCODE:
|
||||
core_qr_run();
|
||||
break;
|
||||
case MENU_DISPLAY_PUBLIC:
|
||||
core_display_public();
|
||||
break;
|
||||
// Keycard
|
||||
case MENU_CARD_NAME:
|
||||
card_change_name();
|
||||
break;
|
||||
case MENU_CHANGE_PIN:
|
||||
card_change_pin();
|
||||
break;
|
||||
case MENU_CHANGE_PUK:
|
||||
card_change_puk();
|
||||
break;
|
||||
case MENU_CHANGE_PAIRING:
|
||||
card_change_pairing();
|
||||
break;
|
||||
case MENU_RESET_CARD:
|
||||
card_reset();
|
||||
break;
|
||||
// Device
|
||||
case MENU_INFO:
|
||||
break;
|
||||
case MENU_DB_UPDATE:
|
||||
updater_database_run();
|
||||
break;
|
||||
case MENU_DEV_AUTH:
|
||||
device_auth_run();
|
||||
break;
|
||||
// Settings
|
||||
case MENU_BRIGHTNESS:
|
||||
settings_lcd_brightness();
|
||||
break;
|
||||
|
@ -28,7 +50,7 @@ static inline void core_action_run(i18n_str_id_t menu) {
|
|||
settings_usb_onoff();
|
||||
break;
|
||||
default:
|
||||
//unhandled commands
|
||||
//unknown commands
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue