2014-04-29 12:26:51 +00:00
|
|
|
/*
|
2019-06-17 18:27:55 +00:00
|
|
|
* This file is part of the Trezor project, https://trezor.io/
|
2014-04-29 12:26:51 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Pavol Rusnak <stick@satoshilabs.com>
|
|
|
|
*
|
|
|
|
* This library is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2019-01-25 10:58:23 +00:00
|
|
|
#ifndef __CONFIG_H__
|
|
|
|
#define __CONFIG_H__
|
2014-04-29 12:26:51 +00:00
|
|
|
|
|
|
|
#include "bip32.h"
|
2019-10-17 11:25:47 +00:00
|
|
|
#include "messages-common.pb.h"
|
2018-07-10 14:58:00 +00:00
|
|
|
#include "messages-management.pb.h"
|
2014-04-29 12:26:51 +00:00
|
|
|
|
2017-12-18 21:16:05 +00:00
|
|
|
#define STORAGE_FIELD(TYPE, NAME) \
|
2019-03-29 16:10:31 +00:00
|
|
|
bool has_##NAME; \
|
|
|
|
TYPE NAME;
|
2017-12-18 21:16:05 +00:00
|
|
|
|
|
|
|
#define STORAGE_STRING(NAME, SIZE) \
|
2019-03-29 16:10:31 +00:00
|
|
|
bool has_##NAME; \
|
|
|
|
char NAME[SIZE];
|
2017-12-18 21:16:05 +00:00
|
|
|
|
|
|
|
#define STORAGE_BYTES(NAME, SIZE) \
|
2019-03-29 16:10:31 +00:00
|
|
|
bool has_##NAME; \
|
|
|
|
struct { \
|
|
|
|
uint32_t size; \
|
|
|
|
uint8_t bytes[SIZE]; \
|
|
|
|
} NAME;
|
2017-12-18 21:16:05 +00:00
|
|
|
|
2019-03-29 16:10:31 +00:00
|
|
|
#define STORAGE_BOOL(NAME) STORAGE_FIELD(bool, NAME)
|
|
|
|
#define STORAGE_NODE(NAME) STORAGE_FIELD(StorageHDNode, NAME)
|
|
|
|
#define STORAGE_UINT32(NAME) STORAGE_FIELD(uint32_t, NAME)
|
2017-12-18 21:16:05 +00:00
|
|
|
|
|
|
|
typedef struct {
|
2019-03-29 16:10:31 +00:00
|
|
|
uint32_t depth;
|
|
|
|
uint32_t fingerprint;
|
|
|
|
uint32_t child_num;
|
|
|
|
struct {
|
|
|
|
uint32_t size;
|
|
|
|
uint8_t bytes[32];
|
|
|
|
} chain_code;
|
|
|
|
|
|
|
|
STORAGE_BYTES(private_key, 32);
|
|
|
|
STORAGE_BYTES(public_key, 33);
|
2017-12-18 21:16:05 +00:00
|
|
|
} StorageHDNode;
|
|
|
|
|
|
|
|
typedef struct _Storage {
|
2019-03-29 16:10:31 +00:00
|
|
|
uint32_t version;
|
|
|
|
|
|
|
|
STORAGE_NODE(node)
|
|
|
|
STORAGE_STRING(mnemonic, 241)
|
|
|
|
STORAGE_BOOL(passphrase_protection)
|
|
|
|
STORAGE_UINT32(pin_failed_attempts)
|
|
|
|
STORAGE_STRING(pin, 10)
|
|
|
|
STORAGE_STRING(language, 17)
|
|
|
|
STORAGE_STRING(label, 33)
|
|
|
|
STORAGE_BOOL(imported)
|
|
|
|
STORAGE_BYTES(homescreen, 1024)
|
|
|
|
STORAGE_UINT32(u2f_counter)
|
|
|
|
STORAGE_BOOL(needs_backup)
|
|
|
|
STORAGE_UINT32(flags)
|
|
|
|
STORAGE_NODE(u2froot)
|
|
|
|
STORAGE_BOOL(unfinished_backup)
|
|
|
|
STORAGE_UINT32(auto_lock_delay_ms)
|
|
|
|
STORAGE_BOOL(no_backup)
|
2017-12-18 21:16:05 +00:00
|
|
|
} Storage;
|
|
|
|
|
2019-01-25 10:58:23 +00:00
|
|
|
extern Storage configUpdate;
|
2017-08-22 17:00:25 +00:00
|
|
|
|
2020-08-14 07:55:27 +00:00
|
|
|
#define MAX_PIN_LEN 50
|
2019-03-29 16:10:31 +00:00
|
|
|
#define MAX_LABEL_LEN 32
|
|
|
|
#define MAX_LANGUAGE_LEN 16
|
|
|
|
#define MAX_MNEMONIC_LEN 240
|
|
|
|
#define HOMESCREEN_SIZE 1024
|
|
|
|
#define UUID_SIZE 12
|
2020-11-18 18:06:39 +00:00
|
|
|
|
|
|
|
#if DEBUG_LINK
|
2020-07-21 14:41:04 +00:00
|
|
|
#define MIN_AUTOLOCK_DELAY_MS (10 * 1000U) // 10 seconds
|
2020-11-18 18:06:39 +00:00
|
|
|
#else
|
|
|
|
#define MIN_AUTOLOCK_DELAY_MS (60 * 1000U) // 1 minute
|
|
|
|
#endif
|
|
|
|
#define MAX_AUTOLOCK_DELAY_MS 0x20000000U // ~6 days
|
2014-04-29 12:26:51 +00:00
|
|
|
|
2019-01-25 10:58:23 +00:00
|
|
|
void config_init(void);
|
|
|
|
void session_clear(bool lock);
|
2020-08-25 14:04:36 +00:00
|
|
|
void session_endCurrentSession(void);
|
2020-02-13 09:39:24 +00:00
|
|
|
void config_lockDevice(void);
|
2014-04-29 12:26:51 +00:00
|
|
|
|
2019-01-25 10:58:23 +00:00
|
|
|
void config_loadDevice(const LoadDevice *msg);
|
2016-04-19 16:23:12 +00:00
|
|
|
|
2020-01-20 14:00:07 +00:00
|
|
|
const uint8_t *config_getSeed(void);
|
2014-04-29 12:26:51 +00:00
|
|
|
|
2019-01-25 10:58:23 +00:00
|
|
|
bool config_getU2FRoot(HDNode *node);
|
2020-01-20 14:00:07 +00:00
|
|
|
bool config_getRootNode(HDNode *node, const char *curve);
|
2014-04-29 12:26:51 +00:00
|
|
|
|
2019-01-25 10:58:23 +00:00
|
|
|
bool config_getLabel(char *dest, uint16_t dest_size);
|
|
|
|
void config_setLabel(const char *label);
|
2014-04-29 12:26:51 +00:00
|
|
|
|
2019-01-25 10:58:23 +00:00
|
|
|
bool config_getLanguage(char *dest, uint16_t dest_size);
|
|
|
|
void config_setLanguage(const char *lang);
|
2014-12-13 18:29:27 +00:00
|
|
|
|
2019-01-25 10:58:23 +00:00
|
|
|
void config_setPassphraseProtection(bool passphrase_protection);
|
2019-02-07 15:06:07 +00:00
|
|
|
bool config_getPassphraseProtection(bool *passphrase_protection);
|
2019-01-25 10:58:23 +00:00
|
|
|
|
|
|
|
bool config_getHomescreen(uint8_t *dest, uint16_t dest_size);
|
|
|
|
void config_setHomescreen(const uint8_t *data, uint32_t size);
|
2015-02-04 20:27:07 +00:00
|
|
|
|
2020-02-13 09:39:24 +00:00
|
|
|
uint8_t *session_startSession(const uint8_t *received_session_id);
|
2014-04-29 12:26:51 +00:00
|
|
|
|
2019-02-05 19:40:58 +00:00
|
|
|
bool config_setMnemonic(const char *mnemonic);
|
2019-01-25 10:58:23 +00:00
|
|
|
bool config_containsMnemonic(const char *mnemonic);
|
2020-04-28 07:23:51 +00:00
|
|
|
bool config_hasMnemonic(void);
|
2019-01-25 10:58:23 +00:00
|
|
|
bool config_getMnemonic(char *dest, uint16_t dest_size);
|
2019-03-29 16:10:31 +00:00
|
|
|
bool config_getMnemonicBytes(uint8_t *dest, uint16_t dest_size,
|
|
|
|
uint16_t *real_size);
|
2017-08-22 07:17:05 +00:00
|
|
|
|
2017-12-18 21:16:05 +00:00
|
|
|
#if DEBUG_LINK
|
2019-02-13 16:12:55 +00:00
|
|
|
bool config_dumpNode(HDNodeType *node);
|
2019-02-14 14:13:47 +00:00
|
|
|
bool config_getPin(char *dest, uint16_t dest_size);
|
2017-12-18 21:16:05 +00:00
|
|
|
#endif
|
2017-06-26 13:44:01 +00:00
|
|
|
|
2019-02-25 12:54:44 +00:00
|
|
|
bool config_unlock(const char *pin);
|
2019-01-25 10:58:23 +00:00
|
|
|
bool config_hasPin(void);
|
|
|
|
bool config_changePin(const char *old_pin, const char *new_pin);
|
2019-02-08 15:08:55 +00:00
|
|
|
bool session_isUnlocked(void);
|
2014-04-29 12:26:51 +00:00
|
|
|
|
2019-10-23 17:20:08 +00:00
|
|
|
bool config_hasWipeCode(void);
|
|
|
|
bool config_changeWipeCode(const char *pin, const char *wipe_code);
|
|
|
|
|
2019-01-25 10:58:23 +00:00
|
|
|
uint32_t config_nextU2FCounter(void);
|
|
|
|
void config_setU2FCounter(uint32_t u2fcounter);
|
2015-11-02 23:08:18 +00:00
|
|
|
|
2019-01-25 10:58:23 +00:00
|
|
|
bool config_isInitialized(void);
|
2014-04-29 12:26:51 +00:00
|
|
|
|
2019-02-07 15:06:07 +00:00
|
|
|
bool config_getImported(bool *imported);
|
2019-01-25 10:58:23 +00:00
|
|
|
void config_setImported(bool imported);
|
2017-08-22 07:17:05 +00:00
|
|
|
|
2019-02-07 15:06:07 +00:00
|
|
|
bool config_getNeedsBackup(bool *needs_backup);
|
2019-01-25 10:58:23 +00:00
|
|
|
void config_setNeedsBackup(bool needs_backup);
|
2017-06-26 17:45:12 +00:00
|
|
|
|
2019-02-07 15:06:07 +00:00
|
|
|
bool config_getUnfinishedBackup(bool *unfinished_backup);
|
2019-01-25 10:58:23 +00:00
|
|
|
void config_setUnfinishedBackup(bool unfinished_backup);
|
2018-04-04 10:42:52 +00:00
|
|
|
|
2019-02-07 15:06:07 +00:00
|
|
|
bool config_getNoBackup(bool *no_backup);
|
2019-01-25 10:58:23 +00:00
|
|
|
void config_setNoBackup(void);
|
2018-10-04 15:19:37 +00:00
|
|
|
|
2019-01-25 10:58:23 +00:00
|
|
|
void config_applyFlags(uint32_t flags);
|
2019-02-07 15:06:07 +00:00
|
|
|
bool config_getFlags(uint32_t *flags);
|
2017-07-17 16:36:09 +00:00
|
|
|
|
2019-01-25 10:58:23 +00:00
|
|
|
uint32_t config_getAutoLockDelayMs(void);
|
|
|
|
void config_setAutoLockDelayMs(uint32_t auto_lock_delay_ms);
|
2018-03-13 10:35:49 +00:00
|
|
|
|
2021-05-21 17:55:21 +00:00
|
|
|
SafetyCheckLevel config_getSafetyCheckLevel(void);
|
|
|
|
void config_setSafetyCheckLevel(SafetyCheckLevel safety_check_level);
|
|
|
|
|
2019-01-25 10:58:23 +00:00
|
|
|
void config_wipe(void);
|
2017-07-31 00:26:28 +00:00
|
|
|
|
2019-03-29 16:10:31 +00:00
|
|
|
extern char config_uuid_str[2 * UUID_SIZE + 1];
|
2014-04-29 12:26:51 +00:00
|
|
|
|
|
|
|
#endif
|