hf mfdes chk: detect the secure channel per application

secureChannel was the constant DACEV1, and there was no way to override
it, so a card in LRP mode could never be authenticated - chk reported no
keys on a card 'hf mfdes detect' handles fine.  When the key settings
were unreadable it gave up instead of probing.

Work the channel out per AID: the key settings give the algo, and for an
AES app one AuthenticateLRPFirst probe separates EV1/EV2 from LRP, which
the settings byte cannot.  When the settings are unreadable, fall back to
DesfireCheckAuthCommands() the way detect does.  --schann d40|ev1|ev2|lrp
pins it and skips detection.  Only AES is tried on an LRP channel.

Also clear the session after a found key, so the next key number starts a
first auth rather than an EV2/LRP non-first one.

Co-Authored-By: Claude Opus 5 (1M context)
This commit is contained in:
iceman1001andClaude Opus 5 (1M context) committed 2026-09-11 11:08:45 +02:00
1 parent 2610d0cfc2
commit cec0e800ab
3 files changed
+112 -22

No files matched your search

+5 -3
View File
@@ -7372,7 +7372,8 @@
"hf mfdes chk --aid 123456 -f mfdes_default_keys -> check keys against AID 0x123456",
"hf mfdes chk --aid 123456 --pattern1b -j keys -> check all 1-byte keys pattern on AID 0x123456 and save found keys to `keys.json`",
"hf mfdes chk --aid 123456 --pattern2b --startp2b FA00 -> check all 2-byte keys pattern on AID 0x123456. Start from key FA00FA00...FA00",
"hf mfdes chk --aid 123456 -k 000102030405060708090a0b0c0d0e0f -> check key on AID 0x123456"
"hf mfdes chk --aid 123456 -k 000102030405060708090a0b0c0d0e0f -> check key on AID 0x123456",
"hf mfdes chk -f mfdes_default_keys --schann lrp -> check keys, forcing the LRP secure channel"
],
"offline": false,
"options": [
@@ -7387,9 +7388,10 @@
"-v, --verbose Verbose output",
"--kdf <0|1|2> Key Derivation Function (KDF) (0=None, 1=AN10922, 2=Gallagher)",
"-i, --kdfi <hex> KDF input (1-31 hex bytes)",
"--schann <d40|ev1|ev2|lrp> Secure channel (default: detected per application)",
"-a, --apdu Show APDU requests and responses"
],
"usage": "hf mfdes chk [-hva] [--aid <hex>] [-k <hex>] [-f <fn>] [--pattern1b] [--pattern2b] [--startp2b <pattern>] [-j <fn>] [--kdf <0|1|2>] [-i <hex>]"
"usage": "hf mfdes chk [-hva] [--aid <hex>] [-k <hex>] [-f <fn>] [--pattern1b] [--pattern2b] [--startp2b <pattern>] [-j <fn>] [--kdf <0|1|2>] [-i <hex>] [--schann <d40|ev1|ev2|lrp>]"
},
"hf mfdes chkeysettings": {
"command": "hf mfdes chkeysettings",
@@ -16494,6 +16496,6 @@
"metadata": {
"commands_extracted": 918,
"extracted_by": "PM3Help2JSON v1.00",
"extracted_on": "2026-09-11T08:39:52+00:00"
"extracted_on": "2026-09-11T09:05:59+00:00"
}
}