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 <noreply@anthropic.com>
This commit is contained in:
Gabriele GristinaandClaude Opus 5.5 committed 2026-11-12 18:49:27 +01:00
1 parent 3bfa83b92f
commit 2bbaf340f4
4 files changed
+12 -1

No files matched your search

+1
View File
@@ -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)
+3 -1
View File
@@ -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);
+7
View File
@@ -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;
}
+1
View File
@@ -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