From 2bbaf340f4806bcafa2e0e68be516d7c9836b489 Mon Sep 17 00:00:00 2001 From: Gabriele Gristina Date: Thu, 12 Nov 2026 18:49:27 +0100 Subject: [PATCH] hf gallagher test: fix the known vector and MES tests, run in make check Two of the five tests failed on master. gallagher_decode_creds() descrambled the caller's buffer in place, so test_known_vector_creds() compared the encoding with its own input after the decode had changed it. gallagher_construct_credential() never set csn_len, so test_MES() encoded with an uninitialised CSN length and got 9C24CC5C instead of 4F36B74E, the formats/mes.md vector. The command printed no overall result and make check did not run it, so no automated run showed the failures. gallagher_decode_creds() now decodes a copy, the constructor sets csn_len, GallagherTest() prints "Tests ( ok )" or "Tests ( fail )" as DesfireTest() does, and pm3_tests.sh runs hf gallagher test with the other hf self-tests. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 1 + client/src/mifare/gallaghercore.c | 4 +++- client/src/mifare/gallaghertest.c | 7 +++++++ tools/pm3_tests.sh | 1 + 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3415c5cc3..467fc8389 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 gallagher test` - the known vector and MES tests failed, it printed no overall result and `make check` did not run it (@matrix) - Added AIDs `A0000003820013000101` and `A0000003820017000101` (HID configuration cards) to aidlist.json (@iceman1001) - Changed `hf ntag424 getfs` - without `--fileno` it lists the settings of every file on the card; NTAG 424 has no GetFileIDs, so file numbers 0-31 are probed and a number the card never answers makes the list incomplete (PM3_EPARTIAL) (@iceman1001) diff --git a/client/src/mifare/gallaghercore.c b/client/src/mifare/gallaghercore.c index 3caba0b0a..19f924d29 100644 --- a/client/src/mifare/gallaghercore.c +++ b/client/src/mifare/gallaghercore.c @@ -86,6 +86,7 @@ int gallagher_construct_credential(GallagherCredentials_t *creds, uint8_t region creds->issue_level = issue; creds->mes = mes; memcpy(creds->csn, csn, csn_len); + creds->csn_len = csn_len; memcpy(creds->site_key, site_key, 16); return PM3_SUCCESS; } @@ -117,7 +118,8 @@ int gallagher_parse_cad(uint8_t *cad, uint8_t region, uint16_t facility) { void gallagher_decode_creds(uint8_t *eight_bytes, GallagherCredentials_t *creds) { - uint8_t *arr = eight_bytes; + uint8_t arr[8]; + memcpy(arr, eight_bytes, sizeof(arr)); descramble(arr, 8); diff --git a/client/src/mifare/gallaghertest.c b/client/src/mifare/gallaghertest.c index 5fd1ef7ed..eab528893 100644 --- a/client/src/mifare/gallaghertest.c +++ b/client/src/mifare/gallaghertest.c @@ -188,10 +188,17 @@ static bool test_MES(void) { bool GallagherTest(bool verbose) { bool result = true; + + PrintAndLogEx(INFO, "------ " _CYAN_("Gallagher tests") " ------"); + result &= test_CAD(); result &= test_creds(); result &= test_known_vector_creds(); result &= test_mad_crc(); result &= test_MES(); + + PrintAndLogEx(INFO, "---------------------------"); + PrintAndLogEx(SUCCESS, "Tests ( %s )", (result) ? _GREEN_("ok") : _RED_("fail")); + PrintAndLogEx(NORMAL, ""); return result; } diff --git a/tools/pm3_tests.sh b/tools/pm3_tests.sh index 8b9b82159..7df729fd8 100755 --- a/tools/pm3_tests.sh +++ b/tools/pm3_tests.sh @@ -786,6 +786,7 @@ while true; do if ! CheckExecute "hf mfdes test" "$CLIENTBIN -c 'hf mfdes test'" "Tests \( ok"; then break; fi if ! CheckExecute "hf gst test" "$CLIENTBIN -c 'hf gst test'" "Tests \( ok"; then break; fi if ! CheckExecute "hf saflok test" "$CLIENTBIN -c 'hf saflok test'" "Tests \( ok"; then break; fi + if ! CheckExecute "hf gallagher test" "$CLIENTBIN -c 'hf gallagher test'" "Tests \( ok"; then break; fi if ! CheckExecute "mad test" "$CLIENTBIN -c 'mad test'" "Tests \( ok"; then break; fi if ! CheckExecute "hf waveshare load" "$CLIENTBIN -c 'hf waveshare load -m 6 -f tools/lena.bmp -s dither.bmp' && echo '34ff55fe7257876acf30dae00eb0e439 dither.bmp' | md5sum -c -" "dither.bmp: OK"; then break; fi if ! CheckExecute "hf goodisplay load" "$CLIENTBIN -c 'hf goodisplay load -m 2 -f tools/lena.bmp -s gd_dither.bmp' && echo '3738750a8ce7f89913c7af012acfc1fa gd_dither.bmp' | md5sum -c -" "gd_dither.bmp: OK"; then break; fi