From 815510db0b837cf1fbba0e265664f9390d5c71eb Mon Sep 17 00:00:00 2001 From: "Jamie C. Driver" Date: Thu, 25 Jul 2024 16:35:17 +0100 Subject: [PATCH] psbt: explicit check of lead magic bytes before attempting full parse --- main/process/sign_psbt.c | 11 +++++++++++ test_data/psbt_tm_liquid.json | 7 +++++++ test_jade.py | 21 ++++++++++++++++----- 3 files changed, 34 insertions(+), 5 deletions(-) create mode 100644 test_data/psbt_tm_liquid.json diff --git a/main/process/sign_psbt.c b/main/process/sign_psbt.c index f3e94c18..e1796d03 100644 --- a/main/process/sign_psbt.c +++ b/main/process/sign_psbt.c @@ -31,6 +31,9 @@ bool show_btc_fee_confirmation_activity(const struct wally_tx* tx, const output_ static void wally_free_psbt_wrapper(void* psbt) { JADE_WALLY_VERIFY(wally_psbt_free((struct wally_psbt*)psbt)); } +// From https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki +static const uint8_t PSBT_MAGIC_PREFIX[5] = { 0x70, 0x73, 0x62, 0x74, 0xFF }; // 'psbt' + 0xff + // Cache what type of inputs we are signing #define PSBT_SIGNING_SINGLESIG 0x1 #define PSBT_SIGNING_MULTISIG 0x2 @@ -992,6 +995,14 @@ bool deserialise_psbt(const uint8_t* psbt_bytes, const size_t psbt_len, struct w { JADE_ASSERT(psbt_bytes); JADE_INIT_OUT_PPTR(psbt_out); + + // Sanity check lead bytes before attempting full parse + // NOTE: libwally supports PSET (elements) which Jade does not as yet. + if (psbt_len < sizeof(PSBT_MAGIC_PREFIX) || memcmp(psbt_bytes, PSBT_MAGIC_PREFIX, sizeof(PSBT_MAGIC_PREFIX))) { + JADE_LOGE("Unexpected leading 'magic' bytes for PSBT"); + return false; + } + return wally_psbt_from_bytes(psbt_bytes, psbt_len, WALLY_PSBT_PARSE_FLAG_STRICT, psbt_out) == WALLY_OK && *psbt_out; } diff --git a/test_data/psbt_tm_liquid.json b/test_data/psbt_tm_liquid.json new file mode 100644 index 00000000..1c4f489f --- /dev/null +++ b/test_data/psbt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VUzRYwhdFyrIEKvK2cbwR70rfniMHGu9ZCUMT246JyCRAoPybPHDWHCXL5eu/tr87VORsgnXLLCWvVB/k5ZLV80ss7UaxSq0oN4IYFbjVsBsa/bx0X4wCAY4BDBD0xs68fPZlxWD6DLbQpeWRdfrDiYHVh8E3z7doUBtsi0ERBw4mZklh1DuHbaitj8So10xXa+AFvNux9cXI6p2nDvAtQf8BHBzZXQFQwEAAbizFsncFEWWN03ONdOB6LATsWOHBTHxj8VTHfg7o7yfuY1Lswpehq8gJtzAy2Ia7Fa+6ob4mW390s7jGQWQQHYH/ARwc2V0BiEDHBC7x4EJZHqFf9VlN1oRDl4cnrITcPSwtNkOkBVCEtkH/ARwc2V0ByEDkhw8KuduCbxt48/nJDs1CTw0PyPFgHDfnNQBU0cOzeYH/ARwc2V0CAQBAAAAB/wEcHNldAlJIAAAAAAAAAVJgcHKJfRHxt5ZnD2sGEyhtTBl89EaXX/v6GscI0XIVl8uwYnFc0lwqHozi6iINYc74Q9wRa9ChR60FZbVy5BQ9wf8BHBzZXQKQwEAATMpvTmBYRUD3eWil/8pEusr7qCj1X5hlZ1g/wefQNsaffd2meP/up9GY82uPaqXQUGB/2bXVFBCuGQl+V+7mdUAAQMI/wAAAAAAAAABBAAH/ARwc2V0AiBtUhw47B6hVzSuIrfEYGRBKCnA0FefCnE9HATt6XkCbwA=" + }, + "expected_error": "Failed to extract psbt from passed bytes" +} diff --git a/test_jade.py b/test_jade.py index f470ef8a..f259d14f 100644 --- a/test_jade.py +++ b/test_jade.py @@ -69,12 +69,14 @@ def _h2b_test_case(testcase): testcase['expected_output'] = h2b(testcase['expected_output']) elif 'psbt' in testcase['input']: - # sign-psbt data testcase['input']['psbt'] = base64.b64decode(testcase['input']['psbt']) - testcase['expected_output']['psbt'] = base64.b64decode(testcase['expected_output']['psbt']) - if 'txn' in testcase['expected_output']: - testcase['expected_output']['txn'] = h2b(testcase['expected_output']['txn']) + if 'expected_output' in testcase: + expected_output = testcase['expected_output'] + expected_output['psbt'] = base64.b64decode(expected_output['psbt']) + + if 'txn' in expected_output: + expected_output['txn'] = h2b(expected_output['txn']) elif 'message' in testcase['input']: # sign-msg test data @@ -2652,7 +2654,16 @@ def test_sign_liquid_tx(jadeapi, has_psram, has_ble, pattern): def test_sign_psbt(jadeapi, cases): for txn_data in _get_test_cases(cases): - rslt = jadeapi.sign_psbt(txn_data['input']['network'], txn_data['input']['psbt']) + try: + rslt = jadeapi.sign_psbt(txn_data['input']['network'], txn_data['input']['psbt']) + except JadeError as err: + # Check expected error + assert 'expected_output' not in txn_data + assert err.message == txn_data['expected_error'] + continue + + # Othewise, should have worked, check expected output + assert 'expected_error' not in txn_data assert rslt == txn_data['expected_output']['psbt'], base64.b64encode(rslt).decode() # Optionally test extracted tx