Skip to content

Commit

Permalink
boot: cache keychain fields from storage earlier in boot sequence
Browse files Browse the repository at this point in the history
Also ensure unit key and wallet intialisations that use libwally are
only called after wally_init() has run.
  • Loading branch information
JamieDriver committed Dec 4, 2023
1 parent b49f0af commit daf50fd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
20 changes: 11 additions & 9 deletions main/keychain.c
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,17 @@ bool keychain_get_new_privatekey(uint8_t* privatekey, const size_t size)
return false;
}

bool keychain_init(void)
void keychain_init_cache(void)
{
// Cache whether we are restricted to main/test networks and whether we have an encrypted blob
network_type_restriction = storage_get_network_type_restriction();
has_encrypted_blob = keychain_pin_attempts_remaining() > 0;

// Cache the user key/passphrase preferences
key_flags = storage_get_key_flags();
}

bool keychain_init_unit_key(void)
{
uint8_t privatekey[EC_PRIVATE_KEY_LEN];
SENSITIVE_PUSH(privatekey, sizeof(privatekey));
Expand All @@ -646,13 +656,5 @@ bool keychain_init(void)
}
}
SENSITIVE_POP(privatekey);

// Cache whether we are restricted to main/test networks and whether we have an encrypted blob
network_type_restriction = storage_get_network_type_restriction();
has_encrypted_blob = keychain_pin_attempts_remaining() > 0;

// Cache the user key/passphrase preferences
key_flags = storage_get_key_flags();

return res;
}
3 changes: 2 additions & 1 deletion main/keychain.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ typedef struct {
typedef enum { PASSPHRASE_NEVER, PASSPHRASE_ONCE, PASSPHRASE_ALWAYS } passphrase_freq_t;
typedef enum { PASSPHRASE_WORDLIST, PASSPHRASE_FREETEXT } passphrase_type_t;

bool keychain_init(void);
void keychain_init_cache(void);
bool keychain_init_unit_key(void);
void keychain_set(const keychain_t* src, uint8_t userdata, bool temporary);
void keychain_clear(void);

Expand Down
5 changes: 3 additions & 2 deletions main/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static void boot_process(void)
JADE_ABORT();
}

wallet_init();
keychain_init_cache();
display_init();
gui_init();

Expand Down Expand Up @@ -153,8 +153,9 @@ static void boot_process(void)
#endif

jade_wally_init();
wallet_init();

if (!keychain_init()) {
if (!keychain_init_unit_key()) {
JADE_ABORT();
}

Expand Down

0 comments on commit daf50fd

Please sign in to comment.