1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-11-22 23:48:12 +00:00

core/slip39: do not populate MnemonicError's message; do not throw exceptions with mnemonic inside the message

This commit is contained in:
Tomas Susanka 2019-06-27 13:59:01 +02:00
parent 4f8022c5cd
commit c205acd3e1
2 changed files with 6 additions and 16 deletions

View File

@ -77,7 +77,7 @@ async def recovery_device(ctx, msg):
try:
secret = mnemonic_module.process_all(mnemonics)
except slip39.MnemonicError as e:
raise wire.ProcessError("Mnemonic is not valid: " + str(e))
raise wire.ProcessError("Mnemonic is not valid")
# show a number of remaining mnemonics for SLIP39
if secret is None and mnemonic_module == mnemonic.slip39:
await show_remaining_slip39_mnemonics(ctx, title, remaining)

View File

@ -365,11 +365,7 @@ def decode_mnemonic(mnemonic):
raise MnemonicError("Invalid mnemonic length.")
if not rs1024_verify_checksum(mnemonic_data):
raise MnemonicError(
'Invalid mnemonic checksum for "{} ...".'.format(
" ".join(mnemonic.split()[: _ID_EXP_LENGTH_WORDS + 2])
)
)
raise MnemonicError("Invalid mnemonic checksum.")
id_exp_int = _int_from_indices(mnemonic_data[:_ID_EXP_LENGTH_WORDS])
identifier = id_exp_int >> _ITERATION_EXP_LENGTH_BITS
@ -384,19 +380,13 @@ def decode_mnemonic(mnemonic):
if group_count < group_threshold:
raise MnemonicError(
'Invalid mnemonic "{} ...". Group threshold cannot be greater than group count.'.format(
" ".join(mnemonic.split()[: _ID_EXP_LENGTH_WORDS + 2])
)
"Invalid mnemonic. Group threshold cannot be greater than group count."
)
value_byte_count = bits_to_bytes(_RADIX_BITS * len(value_data) - padding_len)
value_int = _int_from_indices(value_data)
if value_data[0] >= 1 << (_RADIX_BITS - padding_len):
raise MnemonicError(
'Invalid mnemonic padding for "{} ...".'.format(
" ".join(mnemonic.split()[: _ID_EXP_LENGTH_WORDS + 2])
)
)
raise MnemonicError("Invalid mnemonic padding")
value = value_int.to_bytes(value_byte_count, "big")
return (
@ -612,8 +602,8 @@ def combine_mnemonics(mnemonics):
group_count,
)
raise MnemonicError(
'Wrong number of mnemonics. Expected {} mnemonics starting with "{} ...", but {} were provided.'.format(
group[0], mnemonic_from_indices(prefix), len(group[1])
"Wrong number of mnemonics. Expected {} mnemonics, but {} were provided.".format(
group[0], len(group[1])
)
)