Test Details Overview

Require seeds and keys to be exactly 64 hex digits (#5209)

* Add strict hex parsers for seeds and keys

decode_hex reads a 256-bit value from anywhere between 1 and 64 hex digits, padding the missing digits with leading zeros, and at 64 characters it also takes 0x followed by 62 digits, or a leading minus sign that wraps the value around. A seed or key that is mistyped or cut short therefore still decodes, as a different seed or key.

try_parse_raw_key, for seeds and private keys, and try_parse_public_key accept exactly 64 ASCII hex digits and nothing else.

* Require 64 hex digit seeds and keys in RPC actions

The RPC actions that take a seed or key decoded it with decode_hex, so a seed missing a digit became a different seed: wallet_change_seed replaced the wallet's seed with it and cleared the accounts, wallet_create restored a wallet from it, and deterministic_key derived its keys.

wallet_change_seed, wallet_create, deterministic_key, wallet_add, key_expand, block_create, sign, epoch_upgrade and account_get now take seeds and keys only as exactly 64 hex digits and answer any other text with their existing Bad seed, Bad private key or Bad public key error. Clients that drop leading zeros have to pad to 64 digits.

sign replaced any error from reading the key, such as Bad private key or a wallet error, with the error for a missing key whenever it ended up without one. It now keeps the earlier error.

* Require 64 hex digit seeds and keys in CLI commands

The CLI commands that take a seed or key decoded it with decode_hex, so a seed missing a digit became a different seed: --wallet_change_seed replaced the wallet's seed with it and --wallet_create restored a wallet from it. --key_expand and --account_get ignored the decode result and printed keys for whatever a failed decode left behind.

--wallet_create and --wallet_change_seed, through --seed and the legacy --key, --wallet_add_adhoc, --key_expand, --account_get and nano_node --debug_bootstrap_generate now take exactly 64 hex digits and fail with their invalid seed or key message otherwise.

* Require 64 hex digit seeds and keys in the Qt wallet

Import seed decoded the typed seed with decode_hex, so a seed missing a digit passed as a different seed and, once confirmed with 'clear keys', replaced the wallet's seed and cleared its accounts. Its "length must be 64" message only showed for text that failed to decode, such as a seed that was too long. Import adhoc key took a short private key the same way.

Both now take exactly 64 hex digits. Import seed keeps its messages, picking one by the length of the text.

* Fix wallet index comments claiming a 64 digit check

The comments above the two loops over the wallet index said entries are skipped unless they parse as a 64-char hex wallet id. try_parse_wallet_id accepts fewer digits too, padding them with leading zeros, so the comments now only promise a hex wallet id. The loops behave the same: wallet tables are named with all 64 digits, and send_action_ids does not parse.

__________

Type: commit

Hash: dd508906e69c97b16498fab4043647b526585f4d

Created: yesterday

__________

gr0v1ty/nano-node:dd508906e69c97b16498fab4043647b526585f4d

Test Results

Test Case Status Duration Median Deviation Log Graph