From dd714815141ded7f2b81ea494ddd21119f67842f Mon Sep 17 00:00:00 2001 From: The MMGen Project Date: Wed, 2 Sep 2026 13:52:44 +0000 Subject: [PATCH] tx.file: refuse to parse legacy TX files for signing ops See 852cdeda Instead of checking before signing, check before parsing. --- mmgen/tx/file.py | 8 ++++++++ mmgen/tx/unsigned.py | 7 +------ test/cmdtest_d/autosign.py | 2 ++ 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/mmgen/tx/file.py b/mmgen/tx/file.py index 52aa57e7..126cd0cf 100755 --- a/mmgen/tx/file.py +++ b/mmgen/tx/file.py @@ -22,6 +22,7 @@ tx.file: Transaction file operations for the MMGen suite import os, json +from ..cfg import gc from ..util import ymsg, make_chksum_6, die from ..obj import MMGenObject, HexStr, MMGenTxID, CoinTxID, MMGenTxComment @@ -133,6 +134,13 @@ class MMGenTxFile(MMGenObject): tx = self.tx tx.file_format = 'legacy' + if 'sign' in gc.prog_name: + m = 'Request to sign legacy-format transaction. Has your online installation been compromised?' + if tx.cfg.test_suite: + ymsg(m) + else: + die('LegacyTxSignRequestError', m) + def deserialize(raw_data, *, desc): from ast import literal_eval try: diff --git a/mmgen/tx/unsigned.py b/mmgen/tx/unsigned.py index 118458b8..b148e441 100755 --- a/mmgen/tx/unsigned.py +++ b/mmgen/tx/unsigned.py @@ -13,7 +13,7 @@ tx.unsigned: unsigned transaction class """ from .completed import Completed -from ..util import die, remove_dups +from ..util import remove_dups class Unsigned(Completed): desc = 'unsigned transaction' @@ -23,11 +23,6 @@ class Unsigned(Completed): # Return signed object or False. Don’t exit or raise exception, unless fatal: async def sign(self, keys, *, tx_num_str=''): - if self.file_format == 'legacy': # fatal - die('LegacyTxSignRequestError', - 'Request to sign legacy-format transaction. ' - 'Has your online installation been compromised?') - try: self.check_correct_chain() except Exception as e: diff --git a/test/cmdtest_d/autosign.py b/test/cmdtest_d/autosign.py index 052f0eca..43dc2bb0 100755 --- a/test/cmdtest_d/autosign.py +++ b/test/cmdtest_d/autosign.py @@ -930,6 +930,8 @@ class CmdTestAutosign(CmdTestAutosignBase): if exc_exit_val: return do_return() + t.expect('compromised') + t.expect( f'{self.tx_count} {tx_desc}{suf(self.tx_count)} signed' if self.tx_count else f'No unsigned {tx_desc}s')