|
|
|
@ -23,6 +23,8 @@
|
|
|
|
|
|
|
|
|
|
#if MICROPY_PY_TREZORCONFIG
|
|
|
|
|
|
|
|
|
|
#include "embed/extmod/trezorobj.h"
|
|
|
|
|
|
|
|
|
|
#include "norcow.h"
|
|
|
|
|
#include "storage.h"
|
|
|
|
|
|
|
|
|
@ -46,7 +48,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorconfig_init_obj, mod_trezorconfig_ini
|
|
|
|
|
/// Check the given PIN. Returns True on success, False on failure.
|
|
|
|
|
/// '''
|
|
|
|
|
STATIC mp_obj_t mod_trezorconfig_check_pin(mp_obj_t pin, mp_obj_t waitcallback) {
|
|
|
|
|
uint32_t pin_i = mp_obj_get_int(pin);
|
|
|
|
|
uint32_t pin_i = trezor_obj_get_uint(pin);
|
|
|
|
|
if (sectrue != storage_check_pin(pin_i, waitcallback)) {
|
|
|
|
|
return mp_const_false;
|
|
|
|
|
}
|
|
|
|
@ -60,7 +62,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorconfig_check_pin_obj, mod_trezorconfi
|
|
|
|
|
/// success, False on failure.
|
|
|
|
|
/// '''
|
|
|
|
|
STATIC mp_obj_t mod_trezorconfig_unlock(mp_obj_t pin, mp_obj_t waitcallback) {
|
|
|
|
|
uint32_t pin_i = mp_obj_get_int(pin);
|
|
|
|
|
uint32_t pin_i = trezor_obj_get_uint(pin);
|
|
|
|
|
if (sectrue != storage_unlock(pin_i, waitcallback)) {
|
|
|
|
|
return mp_const_false;
|
|
|
|
|
}
|
|
|
|
@ -85,8 +87,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorconfig_has_pin_obj, mod_trezorconfig_
|
|
|
|
|
/// Change PIN. Returns True on success, False on failure.
|
|
|
|
|
/// '''
|
|
|
|
|
STATIC mp_obj_t mod_trezorconfig_change_pin(mp_obj_t pin, mp_obj_t newpin, mp_obj_t waitcallback) {
|
|
|
|
|
uint32_t pin_i = mp_obj_get_int(pin);
|
|
|
|
|
uint32_t newpin_i = mp_obj_get_int(newpin);
|
|
|
|
|
uint32_t pin_i = trezor_obj_get_uint(pin);
|
|
|
|
|
uint32_t newpin_i = trezor_obj_get_uint(newpin);
|
|
|
|
|
if (sectrue != storage_change_pin(pin_i, newpin_i, waitcallback)) {
|
|
|
|
|
return mp_const_false;
|
|
|
|
|
}
|
|
|
|
@ -99,8 +101,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_trezorconfig_change_pin_obj, mod_trezorconf
|
|
|
|
|
/// Gets a value of given key for given app (or empty bytes if not set).
|
|
|
|
|
/// '''
|
|
|
|
|
STATIC mp_obj_t mod_trezorconfig_get(size_t n_args, const mp_obj_t *args) {
|
|
|
|
|
uint8_t app = mp_obj_get_int(args[0]) & 0x7F;
|
|
|
|
|
uint8_t key = mp_obj_get_int(args[1]);
|
|
|
|
|
uint8_t app = trezor_obj_get_uint8(args[0]) & 0x7F;
|
|
|
|
|
uint8_t key = trezor_obj_get_uint8(args[1]);
|
|
|
|
|
if (n_args > 2 && args[2] == mp_const_true) {
|
|
|
|
|
app |= 0x80;
|
|
|
|
|
}
|
|
|
|
@ -119,8 +121,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_trezorconfig_get_obj, 2, 3, mod_t
|
|
|
|
|
/// Sets a value of given key for given app.
|
|
|
|
|
/// '''
|
|
|
|
|
STATIC mp_obj_t mod_trezorconfig_set(size_t n_args, const mp_obj_t *args) {
|
|
|
|
|
uint8_t app = mp_obj_get_int(args[0]) & 0x7F;
|
|
|
|
|
uint8_t key = mp_obj_get_int(args[1]);
|
|
|
|
|
uint8_t app = trezor_obj_get_uint8(args[0]) & 0x7F;
|
|
|
|
|
uint8_t key = trezor_obj_get_uint8(args[1]);
|
|
|
|
|
if (n_args > 3 && args[3] == mp_const_true) {
|
|
|
|
|
app |= 0x80;
|
|
|
|
|
}
|
|
|
|
|