More things
parent
3499cde3f8
commit
72c018bbe9
|
@ -64,9 +64,9 @@ int main(int argc, char **argv) {
|
||||||
goto next_tag;
|
goto next_tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mifare_desfire_select_application(tag, aid) != 0) {
|
if (mifare_desfire_select_application(tag, aid) < 0) {
|
||||||
// Check for old card with our key as master key
|
// Check for old card with our key as master key
|
||||||
res = mifare_desfire_authenticate(tag, 0, key_master);
|
res = mifare_desfire_authenticate_aes(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 =
|
res =
|
||||||
|
@ -79,7 +79,7 @@ int main(int argc, char **argv) {
|
||||||
|
|
||||||
// Card needs to have default null key as master
|
// Card needs to have default null key as master
|
||||||
res = mifare_desfire_authenticate(tag, 0, key_null);
|
res = mifare_desfire_authenticate(tag, 0, key_null);
|
||||||
if (res < 0) {
|
if (res < 0 && (res = mifare_desfire_authenticate_aes(tag, 0, key_null) < 0)) {
|
||||||
warnx("Could not authenticate: %d", res);
|
warnx("Could not authenticate: %d", res);
|
||||||
goto next_tag;
|
goto next_tag;
|
||||||
}
|
}
|
||||||
|
@ -91,24 +91,21 @@ int main(int argc, char **argv) {
|
||||||
warnx("Could not create application: %d", res);
|
warnx("Could not create application: %d", res);
|
||||||
goto next_tag;
|
goto next_tag;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Select it
|
// Select application again
|
||||||
res = mifare_desfire_select_application(tag, aid);
|
res = mifare_desfire_select_application(tag, aid);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
warnx("Application not selectable after creation: %d", res);
|
warnx("Application not selectable: %d", res);
|
||||||
goto next_tag;
|
goto next_tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Key should be null
|
|
||||||
res = mifare_desfire_authenticate_aes(tag, 0, key_null);
|
|
||||||
if (res < 0) {
|
|
||||||
warnx(
|
|
||||||
"Could not authenticate new application with default "
|
|
||||||
"key: %d",
|
|
||||||
res);
|
|
||||||
goto next_tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Key might still be null
|
||||||
|
res = mifare_desfire_authenticate_aes(tag, 0, key_null);
|
||||||
|
if (res >= 0 || mifare_desfire_authenticate(tag, 0, key_null) >= 0) {
|
||||||
|
warnx(
|
||||||
|
"Application is still using the default key");
|
||||||
|
|
||||||
// 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) {
|
||||||
|
@ -118,17 +115,33 @@ int main(int argc, char **argv) {
|
||||||
res);
|
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(
|
warnx(
|
||||||
"Could not authenticate new application with our key: "
|
"Could not authenticate new application with our key: "
|
||||||
"%d",
|
"%d",
|
||||||
res);
|
res);
|
||||||
goto next_tag;
|
goto next_tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
int found = 0;
|
||||||
|
size_t count = 0;
|
||||||
|
uint8_t key_data[RANDOM_UID_SIZE];
|
||||||
|
res = mifare_desfire_get_file_ids(tag, &key_data[0], &count);
|
||||||
|
if (res < 0) {
|
||||||
|
warnx("Could not list files: %d", res);
|
||||||
|
goto next_tag;
|
||||||
|
}
|
||||||
|
for (int j = 0; j < count; j++) {
|
||||||
|
if (key_data[j] == 0) {
|
||||||
|
found = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!found) {
|
||||||
// Create file
|
// Create file
|
||||||
res = mifare_desfire_create_std_data_file(
|
res = mifare_desfire_create_std_data_file(
|
||||||
tag, 0, 0, MDAR(0, 0, 0, 0), RANDOM_UID_SIZE);
|
tag, 0, 0, MDAR(0, 0, 0, 0), RANDOM_UID_SIZE);
|
||||||
|
@ -163,13 +176,6 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Authenticate with our key
|
|
||||||
res = mifare_desfire_authenticate_aes(tag, 0, key_master);
|
|
||||||
if (res < 0) {
|
|
||||||
warnx("Authentication on application failed: %d", res);
|
|
||||||
goto next_tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Grab UID
|
// Grab UID
|
||||||
uint8_t data[RANDOM_UID_SIZE];
|
uint8_t data[RANDOM_UID_SIZE];
|
||||||
res = mifare_desfire_read_data(tag, 0, 0, RANDOM_UID_SIZE, &data[0]);
|
res = mifare_desfire_read_data(tag, 0, 0, RANDOM_UID_SIZE, &data[0]);
|
||||||
|
|
Loading…
Reference in New Issue