From f1fc9adaed8e3b1ef652e0cca1a69265df26b13b Mon Sep 17 00:00:00 2001 From: oSPANNERo <25675033+oSPANNERo@users.noreply.github.com> Date: Mon, 17 Aug 2026 19:06:19 -0400 Subject: [PATCH] fix(mifare): preserve readable Key B in sector trailer dumps --- CHANGELOG.md | 1 + client/src/cmdhfmf.c | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d2f28c41e..4f50b6cf6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] +- Fixed `hf mf dump` replacing readable sector trailer Key B values with values from the key file (@oSPANNERo) - Added `hf felica seacauth1` command - Added `lf trovan` commands to support Trovan Animal ID (@iceman1001) - Added `hf mf gdmgetblk/gdmgethidblk/gdmsethidblk/gdmsetuid/gdmwipe/gdmsetsig` (@0x6r1an0y) diff --git a/client/src/cmdhfmf.c b/client/src/cmdhfmf.c index 6707ad17d..2ebc9a608 100644 --- a/client/src/cmdhfmf.c +++ b/client/src/cmdhfmf.c @@ -1085,9 +1085,12 @@ static int mfc_read_tag(iso14a_card_select_t *card, uint8_t *carddata, uint8_t n uint8_t *data = resp.data.asBytes; if (mfIsSectorTrailerBasedOnBlocks(sectorNo, blockNo)) { - // sector trailer. Fill in the keys. + // sector trailer. Key A is never readable; preserve Key B when ACL allows it. memcpy(data, keyA + (sectorNo * MIFARE_KEY_SIZE), MIFARE_KEY_SIZE); - memcpy(data + 10, keyB + (sectorNo * MIFARE_KEY_SIZE), MIFARE_KEY_SIZE); + uint8_t trailer_acl = mf_get_accesscondition(3, &data[6]); + if (trailer_acl != 0 && trailer_acl != 1 && trailer_acl != 2) { + memcpy(data + 10, keyB + (sectorNo * MIFARE_KEY_SIZE), MIFARE_KEY_SIZE); + } } memcpy(carddata + (MFBLOCK_SIZE * (mfFirstBlockOfSector(sectorNo) + blockNo)), data, MFBLOCK_SIZE);