Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added ChangeLog
Empty file.
Empty file added NEWS
Empty file.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ terminal, will display the two bytes of data starting with byte 6.
Building mfterm
---------------

Standard: ./configure; make; make install
Standard: ./autogen.sh; ./configure; make; make install

See INSTALL file for details.

Expand Down
6 changes: 6 additions & 0 deletions mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,19 @@ int compute_mac(const unsigned char* input,

// Generate a key schedule. Don't be picky, allow bad keys.
DES_key_schedule schedule;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
DES_set_key_unchecked(&des_key, &schedule);
#pragma GCC diagnostic pop

// IV is all zeroes
unsigned char ivec[] = { 0, 0, 0, 0, 0, 0, 0, 0 };

// Compute the DES in CBC
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
DES_ncbc_encrypt(padded_input, output, length, &schedule, &ivec, 1);
#pragma GCC diagnostic pop

// Move up and truncate (we only want 8 bytes)
for (int i = 0; i < 8; ++i)
Expand Down
3 changes: 3 additions & 0 deletions mfterm.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,10 @@ char* completion_sub_cmd_generator(const char* text, int state) {

// Extract command and sub-command
char buff[128];
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-truncation"
strncpy(buff, name, sizeof(buff));
#pragma GCC diagnostic pop
char* cmd = strtok(buff, " ");
char* sub = strtok(NULL, " ");

Expand Down
66 changes: 55 additions & 11 deletions tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,66 @@ void strip_non_auth_data(mf_tag_t* tag);
int load_mfd(const char* fn, mf_tag_t* tag);
int save_mfd(const char* fn, const mf_tag_t* tag);

int load_mfd(const char* fn, mf_tag_t* tag) {
FILE* mfd_file = fopen(fn, "rb");
int load_mfd_4k(const char *fn, mf_tag_t *tag);

if (mfd_file == NULL) {
printf("Could not open file: %s\n", fn);
return 1;
}
int append_to_4k(const char *fn);

if (fread(tag, 1, sizeof(mf_tag_t), mfd_file) != sizeof(mf_tag_t)) {
int load_mfd(const char *fn, mf_tag_t *tag) {
int result = load_mfd_4k(fn, tag);
if (result == 0) {
return 0;
}
if (result == 2) {
return 1;
}

if (append_to_4k(fn) == 1) {
return 1;
}

if (load_mfd_4k(fn, tag) == 0) {
return 0;
}
printf("Could not read file: %s\n", fn);
fclose(mfd_file);
return 1;
}
}

fclose(mfd_file);
return 0;
int append_to_4k(const char *fn) {
FILE *mfd_file_to_append = fopen(fn, "a");
if (mfd_file_to_append == NULL) {
printf("Could not open file: %s\n", fn);
return 1;
}

fseek(mfd_file_to_append, 0, SEEK_END);
long currentSize = ftell(mfd_file_to_append);
long initialSize = currentSize;
if (initialSize != 1024) {
printf("File needs to be either 1k or 4k\n");
return 1;
}
while (currentSize < 4096) {
fputc('0', mfd_file_to_append);
currentSize++;
}

fclose(mfd_file_to_append);
printf("Zeros appended for %ld to %ld\n", initialSize, currentSize);
return 0;
}

int load_mfd_4k(const char *fn, mf_tag_t *tag) {
FILE* mfd_file = fopen(fn, "rb");
if (mfd_file == NULL) {
printf("Could not open file: %s\n", fn);
return 2;
}

if (fread(tag, 1, sizeof(mf_tag_t), mfd_file) == sizeof(mf_tag_t)) {
fclose(mfd_file);
return 0;
}
return 1;
}

int save_mfd(const char* fn, const mf_tag_t* tag) {
Expand Down
2 changes: 1 addition & 1 deletion tag.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void print_tag_bytes(size_t first_byte, size_t last_byte);
void print_keys(const mf_tag_t* tag, mf_size_t size);
void print_ac(const mf_tag_t* tag);

// Return a hex string representationon of the key
// Return a hex string representation of the key
const char* sprint_key(const uint8_t* key);

// Parse the string and set the key. Return the key, or NULL on error.
Expand Down