From c205acd3e186787c789fb1b3fdce0bfe35f08969 Mon Sep 17 00:00:00 2001 From: Tomas Susanka Date: Thu, 27 Jun 2019 13:59:01 +0200 Subject: [PATCH] core/slip39: do not populate MnemonicError's message; do not throw exceptions with mnemonic inside the message --- core/src/apps/management/recovery_device.py | 2 +- core/src/trezor/crypto/slip39.py | 20 +++++--------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/core/src/apps/management/recovery_device.py b/core/src/apps/management/recovery_device.py index f48f691749..1f2052a029 100644 --- a/core/src/apps/management/recovery_device.py +++ b/core/src/apps/management/recovery_device.py @@ -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) diff --git a/core/src/trezor/crypto/slip39.py b/core/src/trezor/crypto/slip39.py index ea1247fdcb..f2dc23018e 100644 --- a/core/src/trezor/crypto/slip39.py +++ b/core/src/trezor/crypto/slip39.py @@ -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]) ) )