Formatting
This commit is contained in:
parent
084866dbbc
commit
3499cde3f8
|
@ -69,7 +69,12 @@ int main(int argc, char **argv) {
|
||||||
res = mifare_desfire_authenticate(tag, 0, key_master);
|
res = mifare_desfire_authenticate(tag, 0, key_master);
|
||||||
if (res >= 0) {
|
if (res >= 0) {
|
||||||
warnx("Old tag detected: %s", tag_uid);
|
warnx("Old tag detected: %s", tag_uid);
|
||||||
res = mifare_desfire_change_key(tag, 0, key_master, key_null);
|
res =
|
||||||
|
mifare_desfire_change_key(tag, 0, key_null, key_master);
|
||||||
|
if (res < 0) {
|
||||||
|
warnx("Could not change key: %d", res);
|
||||||
|
goto next_tag;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Card needs to have default null key as master
|
// Card needs to have default null key as master
|
||||||
|
@ -80,7 +85,8 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// create application
|
// create application
|
||||||
res = mifare_desfire_create_application_aes(tag, aid, MDAPP_SETTINGS(0, 1, 0, 0, 1), 1);
|
res = mifare_desfire_create_application_aes(
|
||||||
|
tag, aid, MDAPP_SETTINGS(0, 1, 0, 0, 1), 1);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
warnx("Could not create application: %d", res);
|
warnx("Could not create application: %d", res);
|
||||||
goto next_tag;
|
goto next_tag;
|
||||||
|
@ -96,26 +102,36 @@ int main(int argc, char **argv) {
|
||||||
// Key should be null
|
// Key should be null
|
||||||
res = mifare_desfire_authenticate_aes(tag, 0, key_null);
|
res = mifare_desfire_authenticate_aes(tag, 0, key_null);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
warnx("Could not authenticate new application with default key: %d", res);
|
warnx(
|
||||||
|
"Could not authenticate new application with default "
|
||||||
|
"key: %d",
|
||||||
|
res);
|
||||||
goto next_tag;
|
goto next_tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update to our key
|
// Update to our key
|
||||||
res = mifare_desfire_change_key(tag, 0, key_master, key_null);
|
res = mifare_desfire_change_key(tag, 0, key_master, key_null);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
warnx("Could not change key of new application to master key: %d", res);
|
warnx(
|
||||||
|
"Could not change key of new application to master "
|
||||||
|
"key: %d",
|
||||||
|
res);
|
||||||
goto next_tag;
|
goto next_tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Authenticate with new key
|
// Authenticate with new key
|
||||||
res = mifare_desfire_authenticate_aes(tag, 0, key_master);
|
res = mifare_desfire_authenticate_aes(tag, 0, key_master);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
warnx("Could not authenticate new application with our key: %d", res);
|
warnx(
|
||||||
|
"Could not authenticate new application with our key: "
|
||||||
|
"%d",
|
||||||
|
res);
|
||||||
goto next_tag;
|
goto next_tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create file
|
// Create file
|
||||||
res = mifare_desfire_create_std_data_file(tag, 0, 0, MDAR(0, 0, 0, 0), RANDOM_UID_SIZE);
|
res = mifare_desfire_create_std_data_file(
|
||||||
|
tag, 0, 0, MDAR(0, 0, 0, 0), RANDOM_UID_SIZE);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
warnx("Could not create data file: %d", res);
|
warnx("Could not create data file: %d", res);
|
||||||
goto next_tag;
|
goto next_tag;
|
||||||
|
@ -130,7 +146,8 @@ int main(int argc, char **argv) {
|
||||||
goto next_tag;
|
goto next_tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (RANDOM_UID_SIZE != read(fd, &uid_data[0], RANDOM_UID_SIZE)) {
|
if (RANDOM_UID_SIZE !=
|
||||||
|
read(fd, &uid_data[0], RANDOM_UID_SIZE)) {
|
||||||
warnx("Could not read data from /dev/random");
|
warnx("Could not read data from /dev/random");
|
||||||
goto next_tag;
|
goto next_tag;
|
||||||
}
|
}
|
||||||
|
@ -138,7 +155,8 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write data
|
// Write data
|
||||||
res = mifare_desfire_write_data(tag, 0, 0, RANDOM_UID_SIZE, &uid_data[0]);
|
res = mifare_desfire_write_data(tag, 0, 0, RANDOM_UID_SIZE,
|
||||||
|
&uid_data[0]);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
warnx("Could not write UID data to tag: %d", res);
|
warnx("Could not write UID data to tag: %d", res);
|
||||||
goto next_tag;
|
goto next_tag;
|
||||||
|
|
|
@ -3,4 +3,3 @@
|
||||||
|
|
||||||
int init(nfc_context **context, nfc_device **device);
|
int init(nfc_context **context, nfc_device **device);
|
||||||
void poll_target(nfc_device *device);
|
void poll_target(nfc_device *device);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user