Commit 3f4682b8 authored by Mati's avatar Mati

Merge tag 'upstream/0.10.6'

Upstream version 0.10.6
parents a25d895a 429af185
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.68 for mfoc 0.10.5.
# Generated by GNU Autoconf 2.68 for mfoc 0.10.6.
#
# Report bugs to <mifare@nethemba.com>.
#
......@@ -560,8 +560,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='mfoc'
PACKAGE_TARNAME='mfoc'
PACKAGE_VERSION='0.10.5'
PACKAGE_STRING='mfoc 0.10.5'
PACKAGE_VERSION='0.10.6'
PACKAGE_STRING='mfoc 0.10.6'
PACKAGE_BUGREPORT='mifare@nethemba.com'
PACKAGE_URL=''
......@@ -1259,7 +1259,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures mfoc 0.10.5 to adapt to many kinds of systems.
\`configure' configures mfoc 0.10.6 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
......@@ -1325,7 +1325,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of mfoc 0.10.5:";;
short | recursive ) echo "Configuration of mfoc 0.10.6:";;
esac
cat <<\_ACEOF
......@@ -1422,7 +1422,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
mfoc configure 0.10.5
mfoc configure 0.10.6
generated by GNU Autoconf 2.68
Copyright (C) 2010 Free Software Foundation, Inc.
......@@ -1898,7 +1898,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by mfoc $as_me 0.10.5, which was
It was created by mfoc $as_me 0.10.6, which was
generated by GNU Autoconf 2.68. Invocation command line was
$ $0 $@
......@@ -3575,7 +3575,7 @@ fi
# Define the identity of the package.
PACKAGE='mfoc'
VERSION='0.10.5'
VERSION='0.10.6'
cat >>confdefs.h <<_ACEOF
......@@ -5267,7 +5267,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by mfoc $as_me 0.10.5, which was
This file was extended by mfoc $as_me 0.10.6, which was
generated by GNU Autoconf 2.68. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
......@@ -5333,7 +5333,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
mfoc config.status 0.10.5
mfoc config.status 0.10.6
configured by $0, generated by GNU Autoconf 2.68,
with options \\"\$ac_cs_config\\"
......
AC_INIT([mfoc],[0.10.5],[mifare@nethemba.com])
AC_INIT([mfoc],[0.10.6],[mifare@nethemba.com])
AC_CONFIG_MACRO_DIR([m4])
......
......@@ -311,7 +311,6 @@ continue2:
uint8_t lfsr_rollback_bit(struct Crypto1State *s, uint32_t in, int fb);
uint8_t lfsr_rollback_byte(struct Crypto1State *s, uint32_t in, int fb);
uint32_t lfsr_rollback_word(struct Crypto1State *s, uint32_t in, int fb);
uint32_t *lfsr_prefix_ks(uint8_t ks[8], int isodd);
/** lfsr_rollback_bit
......
This diff is collapsed.
......@@ -36,36 +36,36 @@ typedef struct {
uint32_t median;
uint32_t num_distances;
uint32_t tolerance;
uint8_t parity[3]; // used for 3 bits of parity information
uint8_t parity[3]; // used for 3 bits of parity information
} denonce; // Revealed information about nonce
typedef struct {
nfc_target nt;
nfc_target nt;
sector *sectors; // Allocate later, we do not know the number of sectors yet
sector e_sector; // Exploit sector
sector e_sector; // Exploit sector
uint8_t num_sectors;
uint8_t num_blocks;
uint32_t authuid;
bool b4K;
uint32_t authuid;
bool b4K;
} mftag;
typedef struct {
uint64_t *possibleKeys;
uint32_t size;
uint64_t *possibleKeys;
uint32_t size;
} pKeys;
typedef struct {
uint64_t *brokenKeys;
int32_t size;
uint64_t *brokenKeys;
uint32_t size;
} bKeys;
typedef struct {
nfc_device *pdi;
nfc_device *pdi;
} mfreader;
typedef struct {
uint64_t key;
int count;
uint64_t key;
int count;
} countKeys;
......
......@@ -3,7 +3,7 @@
*
* Copyright (C) 2009 Roel Verdult
* Copyright (C) 2010 Romain Tartière
* Copyright (C) 2010, 2011 Romuald Conty
* Copyright (C) 2010, 2011, 2013 Romuald Conty
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
......@@ -28,10 +28,23 @@
* Note that this license only applies on the examples, NFC library itself is under LGPL
*
*/
/**
* @file mifare.c
* @brief provide samples structs and functions to manipulate MIFARE Classic and Ultralight tags using libnfc
*/
/*
* This implementation was written based on information provided by the
* following document:
*
* MIFARE Classic Specification
* MF1ICS50
* Functional specification
* Rev. 5.3 - 29 January 2008
* http://www.nxp.com/acrobat/other/identification/M001053_MF1ICS50_rev5_3.pdf
*/
#include "mifare.h"
#include <string.h>
......@@ -39,25 +52,33 @@
#include <nfc/nfc.h>
/**
* @brief Execute a MIFARE Classic Command
* @return Returns true if action was successfully performed; otherwise returns false.
* @brief Execute a MIFARE Classic command
* @return Returns NFC_SUCCESS if action was successfully performed; otherwise returns error code (negative value).
* @param pmp Some commands need additional information. This information should be supplied in the mifare_param union.
*
* The specified MIFARE command will be executed on the tag. There are different commands possible, they all require the destination block number.
* The specified MIFARE command will be executed on the tag. There are
* different commands possible, they all require the destination block number.
*
* @note There are three different types of information (Authenticate, Data and Value).
*
* First an authentication must take place using Key A or B. It requires a 48 bit Key (6 bytes) and the UID.
* They are both used to initialize the internal cipher-state of the PN53X chip (http://libnfc.org/hardware/pn53x-chip).
* After a successful authentication it will be possible to execute other commands (e.g. Read/Write).
* The MIFARE Classic Specification (http://www.nxp.com/acrobat/other/identification/M001053_MF1ICS50_rev5_3.pdf) explains more about this process.
*
* Like libnfc's functions, this one returns negative value on error (libnfc's
* error code) but two of them need a special attention in this context (MIFARE
* Classic):
* - NFC_EMFCAUTHFAIL, "MIFARE authentication failed", means key is not valid
* on specified sector.
* - NFC_ERFTRANS, "Invalid received frame", when occurs on MIFARE command
* read or write after a successful authentication, means permissions allowed
* by current acces bytes are not sufficient to process the command.
*/
bool
int
nfc_initiator_mifare_cmd(nfc_device *pnd, const mifare_cmd mc, const uint8_t ui8Block, mifare_param *pmp)
{
uint8_t abtRx[265];
size_t szParamLen;
uint8_t abtCmd[265];
//bool bEasyFraming;
abtCmd[0] = mc; // The MIFARE Classic command
abtCmd[1] = ui8Block; // The block address (1K=0x00..0x39, 4K=0x00..0xff)
......@@ -89,7 +110,7 @@ nfc_initiator_mifare_cmd(nfc_device *pnd, const mifare_cmd mc, const uint8_t ui8
// Please fix your code, you never should reach this statement
default:
return false;
return NFC_EINVARG;
break;
}
......@@ -98,40 +119,23 @@ nfc_initiator_mifare_cmd(nfc_device *pnd, const mifare_cmd mc, const uint8_t ui8
memcpy(abtCmd + 2, (uint8_t *) pmp, szParamLen);
// FIXME: Save and restore bEasyFraming
// bEasyFraming = nfc_device_get_property_bool (pnd, NP_EASY_FRAMING, &bEasyFraming);
if (nfc_device_set_property_bool(pnd, NP_EASY_FRAMING, true) < 0) {
nfc_perror(pnd, "nfc_device_set_property_bool");
return false;
int res;
if ((res = nfc_device_set_property_bool(pnd, NP_EASY_FRAMING, true)) < 0) {
return res;
}
// Fire the mifare command
int res;
if ((res = nfc_initiator_transceive_bytes(pnd, abtCmd, 2 + szParamLen, abtRx, sizeof(abtRx), -1)) < 0) {
if (res == NFC_ERFTRANS) {
// "Invalid received frame", usual means we are
// authenticated on a sector but the requested MIFARE cmd (read, write)
// is not permitted by current acces bytes;
// So there is nothing to do here.
} else {
nfc_perror(pnd, "nfc_initiator_transceive_bytes");
}
// XXX nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, bEasyFraming);
return false;
}
/* XXX
if (nfc_device_set_property_bool (pnd, NP_EASY_FRAMING, bEasyFraming) < 0) {
nfc_perror (pnd, "nfc_device_set_property_bool");
return false;
return res;
}
*/
// When we have executed a read command, copy the received bytes into the param
if (mc == MC_READ) {
if (res == 16) {
memcpy(pmp->mpd.abtData, abtRx, 16);
} else {
return false;
return NFC_EINVARG;
}
}
// Command succesfully executed
return true;
return NFC_SUCCESS;
}
......@@ -3,7 +3,7 @@
*
* Copyright (C) 2009 Roel Verdult
* Copyright (C) 2010 Romain Tartière
* Copyright (C) 2010, 2011 Romuald Conty
* Copyright (C) 2010, 2011, 2013 Romuald Conty
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
......@@ -35,12 +35,12 @@
*/
#ifndef _LIBNFC_MIFARE_H_
# define _LIBNFC_MIFARE_H_
#define _LIBNFC_MIFARE_H_
# include <nfc/nfc-types.h>
#include <nfc/nfc-types.h>
// Compiler directive, set struct alignment to 1 uint8_t for compatibility
# pragma pack(1)
#pragma pack(1)
typedef enum {
MC_AUTH_A = 0x60,
......@@ -76,7 +76,7 @@ typedef union {
// Reset struct alignment to default
# pragma pack()
bool nfc_initiator_mifare_cmd(nfc_device *pnd, const mifare_cmd mc, const uint8_t ui8Block, mifare_param *pmp);
int nfc_initiator_mifare_cmd(nfc_device *pnd, const mifare_cmd mc, const uint8_t ui8Block, mifare_param *pmp);
// Compiler directive, set struct alignment to 1 uint8_t for compatibility
# pragma pack(1)
......
/*-
* Public platform independent Near Field Communication (NFC) library examples
* Free/Libre Near Field Communication (NFC) library
*
* Copyright (C) 2009 Roel Verdult
* Copyright (C) 2010, 2011 Romain Tartière
* Copyright (C) 2009, 2010, 2011, 2012 Romuald Conty
* Libnfc historical contributors:
* Copyright (C) 2009 Roel Verdult
* Copyright (C) 2009-2013 Romuald Conty
* Copyright (C) 2010-2012 Romain Tartière
* Copyright (C) 2010-2013 Philippe Teuwen
* Copyright (C) 2012-2013 Ludovic Rousseau
* Additional contributors of this file:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
......@@ -115,10 +119,10 @@ print_hex_par(const uint8_t *pbtData, const size_t szBits, const uint8_t *pbtDat
}
void
print_nfc_target(const nfc_target nt, bool verbose)
print_nfc_target(const nfc_target *pnt, bool verbose)
{
char *s;
str_nfc_target(&s, nt, verbose);
str_nfc_target(&s, pnt, verbose);
printf("%s", s);
free(s);
nfc_free(s);
}
/*-
* Public platform independent Near Field Communication (NFC) library examples
* Free/Libre Near Field Communication (NFC) library
*
* Copyright (C) 2009 Roel Verdult
* Copyright (C) 2010 Romain Tartière
* Copyright (C) 2010, 2011, 2012 Romuald Conty
* Libnfc historical contributors:
* Copyright (C) 2009 Roel Verdult
* Copyright (C) 2009-2013 Romuald Conty
* Copyright (C) 2010-2012 Romain Tartière
* Copyright (C) 2010-2013 Philippe Teuwen
* Copyright (C) 2012-2013 Ludovic Rousseau
* Additional contributors of this file:
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
......@@ -94,6 +98,6 @@ void print_hex(const uint8_t *pbtData, const size_t szLen);
void print_hex_bits(const uint8_t *pbtData, const size_t szBits);
void print_hex_par(const uint8_t *pbtData, const size_t szBits, const uint8_t *pbtDataPar);
void print_nfc_target(const nfc_target nt, bool verbose);
void print_nfc_target(const nfc_target *pnt, bool verbose);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment