Compare commits
8 Commits
mfoc-0.10.
...
mfoc-0.10.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
658d77ec0d | ||
|
|
a13df02f79 | ||
|
|
001049599f | ||
|
|
a978ac16a9 | ||
|
|
1c2ff2b263 | ||
|
|
d1c676b01d | ||
|
|
9e636c9885 | ||
|
|
ef75599d75 |
90
ChangeLog
90
ChangeLog
@@ -0,0 +1,90 @@
|
||||
2011-05-18 09:18 rconty@il4p.fr
|
||||
|
||||
* src/mfoc.c: mfoc: improve tests made before running and show tag
|
||||
info using print_nfc_iso14443a_info()
|
||||
|
||||
2011-04-08 15:19 rconty@il4p.fr
|
||||
|
||||
* src/mfoc.c: mfoc: try to disconnect() the device on error.
|
||||
|
||||
2011-04-08 10:05 rconty@il4p.fr
|
||||
|
||||
* src/mfoc.c: mfoc: show errors then exit on mf_configure()
|
||||
|
||||
2011-04-08 09:32 rconty@il4p.fr
|
||||
|
||||
* src/mfoc.c: mfoc: apply a patch suggested by Valentijn Sessink.
|
||||
See Issue 56.
|
||||
|
||||
2011-04-08 09:17 rconty@il4p.fr
|
||||
|
||||
* src/mfoc.c: mfoc: minors fixes and indent.
|
||||
|
||||
2011-04-08 08:54 rconty@il4p.fr
|
||||
|
||||
* src/mfoc.c: mfoc: show error (using nfc_perror) then exit if some
|
||||
nfc_* functions failed on init.
|
||||
|
||||
2011-04-08 08:35 rconty@il4p.fr
|
||||
|
||||
* src/mfoc.c: mfoc: minor debug improvements.
|
||||
|
||||
2011-04-04 12:28 rconty@il4p.fr
|
||||
|
||||
* configure.ac, src/mfoc.c: mfoc: minor fixes/enhancements and
|
||||
version bumping
|
||||
|
||||
2011-04-04 10:38 rconty@il4p.fr
|
||||
|
||||
* src/mfoc.c, src/mifare.c: mfoc: hide authentication errors
|
||||
|
||||
2011-04-04 10:01 rconty@il4p.fr
|
||||
|
||||
* src/mifare.c, src/mifare.h, src/nfc-utils.c, src/nfc-utils.h:
|
||||
mfoc: sync nfc-utils.h/c and mifare.c/h with libnfc's ones.
|
||||
|
||||
2011-02-21 16:26 rtartiere@il4p.fr
|
||||
|
||||
* src/Makefile.am: mfox: Unbreak autotools on FreeBSD.
|
||||
|
||||
2011-02-02 10:46 rconty@il4p.fr
|
||||
|
||||
* src/mfoc.c: mfoc: use strtoll() function in order to retrieve
|
||||
64bits wide value. (Fixes Issue 55)
|
||||
|
||||
2010-11-18 11:20 rconty@il4p.fr
|
||||
|
||||
* configure.ac: mfoc: bump package version
|
||||
|
||||
2010-11-18 11:18 rconty@il4p.fr
|
||||
|
||||
* src/nfc-utils.c, src/nfc-utils.h: mfoc: sync nfc-utils.* from
|
||||
libnfc
|
||||
|
||||
2010-11-02 09:36 rconty@il4p.fr
|
||||
|
||||
* configure.ac, src/mfoc.c, src/mfoc.h, src/nfc-utils.c,
|
||||
src/nfc-utils.h: mfoc: upgrade code to work with develoment
|
||||
version of libnfc (upcomming 1.4.0)
|
||||
Update code to match with the new API;
|
||||
Sync nfc-utils.[ch] from libnfc's repo;
|
||||
Update ./configure to detect libnfc 1.4.0;
|
||||
|
||||
2010-09-14 09:38 rconty@il4p.fr
|
||||
|
||||
* ., AUTHORS, Makefile.in, aclocal.m4, autogen.sh, config.h,
|
||||
config.h.in, configure, configure.ac, depcomp, install-sh,
|
||||
missing, src, src/Makefile.am, src/mfoc.c, src/mifare.c,
|
||||
src/mifare.h, src/nfc-utils.c, src/nfc-utils.h: mfoc: update code
|
||||
in order to use libnfc 1.3.9, minor clean up, and minor
|
||||
enhancements.
|
||||
|
||||
2010-09-14 09:34 rconty@il4p.fr
|
||||
|
||||
* ., AUTHORS, COPYING, ChangeLog, INSTALL, Makefile.am,
|
||||
Makefile.in, NEWS, README, TODO, aclocal.m4, autogen.sh,
|
||||
config.h, config.h.in, configure, configure.ac, depcomp,
|
||||
install-sh, missing, src, src/Makefile.am, src/crapto1.c,
|
||||
src/crapto1.h, src/crypto1.c, src/mfoc.c, src/mfoc.h: Import MFOC
|
||||
0.08 from http://www.nethemba.com/mfoc.tar.bz2 on 13th Sept 2010
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
AC_INIT([mfoc], [0.10.1], [mifare@nethemba.com])
|
||||
AC_INIT([mfoc], [0.10.2], [mifare@nethemba.com])
|
||||
|
||||
AC_CONFIG_MACRO_DIR([m4])
|
||||
|
||||
|
||||
136
src/mfoc.c
136
src/mfoc.c
@@ -30,6 +30,8 @@
|
||||
URL http://www.cs.ru.nl/~petervr/papers/grvw_2009_pickpocket.pdf
|
||||
*/
|
||||
|
||||
/* vim: set ts=2 sw=2 et: */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
@@ -48,6 +50,11 @@
|
||||
#include "mfoc.h"
|
||||
|
||||
int main(int argc, char * const argv[]) {
|
||||
const nfc_modulation_t nm = {
|
||||
.nmt = NMT_ISO14443A,
|
||||
.nbr = NBR_106,
|
||||
};
|
||||
|
||||
int ch, i, k, n, j, m, o;
|
||||
int key, block;
|
||||
int succeed = 1;
|
||||
@@ -157,11 +164,53 @@ int main(int argc, char * const argv[]) {
|
||||
|
||||
// Initialize reader/tag structures
|
||||
mf_init(&t, &r);
|
||||
// Configure reader settings
|
||||
mf_configure(r.pdi);
|
||||
mf_select_tag(r.pdi, &(t.nt));
|
||||
|
||||
if (!nfc_initiator_init (r.pdi)) {
|
||||
nfc_perror (r.pdi, "nfc_initiator_init");
|
||||
goto error;
|
||||
}
|
||||
// Drop the field for a while, so can be reset
|
||||
if (!nfc_configure(r.pdi, NDO_ACTIVATE_FIELD, true)) {
|
||||
nfc_perror (r.pdi, "nfc_configure activate field");
|
||||
goto error;
|
||||
}
|
||||
// Let the reader only try once to find a tag
|
||||
if (!nfc_configure(r.pdi, NDO_INFINITE_SELECT, false)) {
|
||||
nfc_perror (r.pdi, "nfc_configure infinite select");
|
||||
goto error;
|
||||
}
|
||||
// Configure the CRC and Parity settings
|
||||
if (!nfc_configure(r.pdi, NDO_HANDLE_CRC, true)) {
|
||||
nfc_perror (r.pdi, "nfc_configure crc");
|
||||
goto error;
|
||||
}
|
||||
if (!nfc_configure(r.pdi, NDO_HANDLE_PARITY, true)) {
|
||||
nfc_perror (r.pdi, "nfc_configure parity");
|
||||
goto error;
|
||||
}
|
||||
|
||||
/*
|
||||
// wait for tag to appear
|
||||
for (i=0;!nfc_initiator_select_passive_target(r.pdi, nm, NULL, 0, &t.nt) && i < 10; i++) zsleep (100);
|
||||
*/
|
||||
|
||||
// mf_select_tag(r.pdi, &(t.nt));
|
||||
if (!nfc_initiator_select_passive_target (r.pdi, nm, NULL, 0, &t.nt)) {
|
||||
nfc_perror (r.pdi, "nfc_initiator_select_passive_target");
|
||||
goto error;
|
||||
}
|
||||
|
||||
// Save tag uid and info about block size (b4K)
|
||||
// Test if a compatible MIFARE tag is used
|
||||
if ((t.nt.nti.nai.btSak & 0x08) == 0) {
|
||||
ERR ("only Mifare Classic is supported");
|
||||
goto error;
|
||||
}
|
||||
|
||||
// TODO: Support Mifare Classic with 7 bytes UID ?
|
||||
if (t.nt.nti.nai.szUidLen != 4) {
|
||||
ERR ("only Mifare Classic with UID on 4 bytes are supported");
|
||||
}
|
||||
// Save tag's block size (b4K)
|
||||
t.b4K = (t.nt.nti.nai.abtAtqa[1] == 0x02);
|
||||
t.uid = (uint32_t) bytes_to_num(t.nt.nti.nai.abtUid, 4);
|
||||
|
||||
@@ -171,15 +220,15 @@ int main(int argc, char * const argv[]) {
|
||||
t.sectors = (void *) calloc(t.num_sectors, sizeof(sector));
|
||||
if (t.sectors == NULL) {
|
||||
ERR ("Cannot allocate memory for t.sectors");
|
||||
exit (EXIT_FAILURE);
|
||||
goto error;
|
||||
}
|
||||
if ((pk = (void *) malloc(sizeof(pKeys))) == NULL) {
|
||||
ERR ("Cannot allocate memory for pk");
|
||||
exit (EXIT_FAILURE);
|
||||
goto error;
|
||||
}
|
||||
if ((bk = (void *) malloc(sizeof(bKeys))) == NULL) {
|
||||
ERR ("Cannot allocate memory for bk");
|
||||
exit (EXIT_FAILURE);
|
||||
goto error;
|
||||
} else {
|
||||
bk->brokenKeys = NULL;
|
||||
bk->size = 0;
|
||||
@@ -188,22 +237,15 @@ int main(int argc, char * const argv[]) {
|
||||
d.distances = (void *) calloc(d.num_distances, sizeof(u_int32_t));
|
||||
if (d.distances == NULL) {
|
||||
ERR ("Cannot allocate memory for t.distances");
|
||||
exit (EXIT_FAILURE);
|
||||
goto error;
|
||||
}
|
||||
|
||||
// Test if a compatible MIFARE tag is used
|
||||
if ((t.nt.nti.nai.btSak & 0x08) == 0) {
|
||||
ERR ("inserted tag is not a MIFARE Classic");
|
||||
nfc_disconnect(r.pdi);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Initialize t.sectors, keys are not known yet
|
||||
for (i = 0; i < (t.num_sectors); ++i) {
|
||||
t.sectors[i].foundKeyA = t.sectors[i].foundKeyB = false;
|
||||
}
|
||||
|
||||
fprintf(stdout, "Found MIFARE Classic %cK card with uid: %08x\n", (t.b4K ? '4' : '1'), t.uid);
|
||||
print_nfc_iso14443a_info (t.nt.nti.nai, true);
|
||||
|
||||
// Try to authenticate to all sectors with default keys
|
||||
// Set the authentication information (uid)
|
||||
@@ -462,7 +504,10 @@ int main(int argc, char * const argv[]) {
|
||||
|
||||
// Disconnect device and exit
|
||||
nfc_disconnect(r.pdi);
|
||||
return 0;
|
||||
exit (EXIT_SUCCESS);
|
||||
error:
|
||||
nfc_disconnect(r.pdi);
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
void usage(FILE * stream, int errno) {
|
||||
@@ -495,16 +540,34 @@ void mf_init(mftag *t, mfreader *r) {
|
||||
}
|
||||
|
||||
void mf_configure(nfc_device_t* pdi) {
|
||||
nfc_initiator_init(pdi);
|
||||
if (!nfc_initiator_init (pdi)) {
|
||||
nfc_perror (pdi, "nfc_initiator_init");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
// Drop the field for a while, so can be reset
|
||||
nfc_configure(pdi,NDO_ACTIVATE_FIELD,false);
|
||||
if (!nfc_configure(pdi, NDO_ACTIVATE_FIELD, false)) {
|
||||
nfc_perror (pdi, "nfc_configure activate field");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
// Let the reader only try once to find a tag
|
||||
nfc_configure(pdi,NDO_INFINITE_SELECT,false);
|
||||
if (!nfc_configure(pdi, NDO_INFINITE_SELECT, false)) {
|
||||
nfc_perror (pdi, "nfc_configure infinite select");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
// Configure the CRC and Parity settings
|
||||
nfc_configure(pdi,NDO_HANDLE_CRC,true);
|
||||
nfc_configure(pdi,NDO_HANDLE_PARITY,true);
|
||||
if (!nfc_configure(pdi, NDO_HANDLE_CRC, true)) {
|
||||
nfc_perror (pdi, "nfc_configure crc");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
if (!nfc_configure(pdi, NDO_HANDLE_PARITY, true)) {
|
||||
nfc_perror (pdi, "nfc_configure parity");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
// Enable the field so more power consuming cards can power themselves up
|
||||
nfc_configure(pdi,NDO_ACTIVATE_FIELD,true);
|
||||
if (!nfc_configure(pdi, NDO_ACTIVATE_FIELD, true)) {
|
||||
nfc_perror (pdi, "nfc_configure activate field");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
void mf_select_tag(nfc_device_t* pdi, nfc_target_t* pnt) {
|
||||
@@ -557,7 +620,8 @@ void mf_anticollision(mftag t, mfreader r) {
|
||||
.nbr = NBR_106,
|
||||
};
|
||||
if (!nfc_initiator_select_passive_target(r.pdi, nm, NULL, 0, &t.nt)) {
|
||||
ERR ("\n\n!Error: tag has been removed");
|
||||
nfc_perror (r.pdi, "nfc_initiator_select_passive_target");
|
||||
ERR ("Tag has been removed");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
@@ -596,14 +660,14 @@ int mf_enhanced_auth(int e_sector, int a_sector, mftag t, mfreader r, denonce *d
|
||||
|
||||
// We need full control over the CRC
|
||||
if (!nfc_configure(r.pdi, NDO_HANDLE_CRC, false)) {
|
||||
nfc_perror (r.pdi, "nfc_configure");
|
||||
nfc_perror (r.pdi, "nfc_configure crc");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Request plain tag-nonce
|
||||
// fprintf(stdout, "\t[Nt]:\t");
|
||||
// TODO: Set NDO_EASY_FRAMING option only once if possible
|
||||
if (!nfc_configure (r.pdi, NDO_EASY_FRAMING, false)) {
|
||||
nfc_perror (r.pdi, "nfc_configure");
|
||||
nfc_perror (r.pdi, "nfc_configure framing");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -649,8 +713,11 @@ int mf_enhanced_auth(int e_sector, int a_sector, mftag t, mfreader r, denonce *d
|
||||
}
|
||||
|
||||
// Finally we want to send arbitrary parity bits
|
||||
nfc_configure(r.pdi, NDO_HANDLE_PARITY, false);
|
||||
|
||||
if (!nfc_configure(r.pdi, NDO_HANDLE_PARITY, false)) {
|
||||
nfc_perror (r.pdi, "nfc_configure parity");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Transmit reader-answer
|
||||
// fprintf(stdout, "\t{Ar}:\t");
|
||||
// print_hex_par(ArEnc, 64, ArEncPar);
|
||||
@@ -745,6 +812,17 @@ int mf_enhanced_auth(int e_sector, int a_sector, mftag t, mfreader r, denonce *d
|
||||
ERR ("while requesting encrypted tag-nonce");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Finally we want to send arbitrary parity bits
|
||||
if (!nfc_configure(r.pdi, NDO_HANDLE_PARITY, true)) {
|
||||
nfc_perror (r.pdi, "nfc_configure parity restore M");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (!nfc_configure(r.pdi, NDO_HANDLE_CRC, true)) {
|
||||
nfc_perror (r.pdi, "nfc_configure crc restore M");
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
// Save the encrypted nonce
|
||||
NtEnc = bytes_to_num(Rx, 4);
|
||||
|
||||
Reference in New Issue
Block a user