Commit c501e972 by developer2

For Mifare Plus in SL3 uses Mifare Classic functions with AES key calculated from Crypto 1 key.

parent 61aa701b
......@@ -10,7 +10,7 @@ all : help
info :
echo "-------------------------------------------------------------------------"
echo "Building executables"
echo "---> version: 1.0"
echo "---> version: 1.2"
echo "-------------------------------------------------------------------------"
echo
......
......@@ -103,7 +103,7 @@
<termios.h>
"../src/ufr.h"
1568102144 source:f:\git\ufr\c-examples\ufr-mf-examples-c\src\main.cpp
1572247520 source:f:\git\ufr\c-examples\ufr-mf-examples-c\src\main.cpp
<iostream>
<conio.h>
<windows.h>
......@@ -111,7 +111,7 @@
<termios.h>
"../src/ufr.h"
1568102110 f:\git\ufr\c-examples\ufr-mf-examples-c\src\ufr.h
1572246757 f:\git\ufr\c-examples\ufr-mf-examples-c\src\ufr.h
<string>
<iostream>
<sstream>
......@@ -119,12 +119,12 @@
<string.h>
"../lib/include/uFCoder.h"
1567176167 f:\git\ufr\c-examples\ufr-mf-examples-c\lib\include\ufcoder.h
1569828183 f:\git\ufr\c-examples\ufr-mf-examples-c\lib\include\ufcoder.h
<stdint.h>
<stddef.h>
<jni.h>
1568358096 source:f:\git\ufr\c-examples\ufr-mf-examples-c\src\ufr.cpp
1572247408 source:f:\git\ufr\c-examples\ufr-mf-examples-c\src\ufr.cpp
"../src/ufr.h"
<conio.h>
<windows.h>
......
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Release" />
<File name="src\ufr.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<ActiveTarget name="Debug" />
<File name="src\ufr.cpp" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="1344" topLine="7" />
<Cursor1 position="36879" topLine="1347" />
</Cursor>
</File>
<File name="src\main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\ufr.h" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2476" topLine="77" />
<Cursor1 position="1323" topLine="3" />
</Cursor>
</File>
<File name="src\ufr.cpp" open="1" top="1" tabpos="2" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<File name="src\main.cpp" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="44679" topLine="1503" />
<Cursor1 position="6151" topLine="224" />
</Cursor>
</File>
</CodeBlocks_layout_file>
lib @ f6206f5b
Subproject commit 1c5b468431bfad9a2152c5deb92a4525bd14ff79
Subproject commit f6206f5b0f67f82287011a0ebb375b7643c94943
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -253,12 +253,6 @@ void menu(char key)
printf("--------------------------------------------------\n");
break;
case 'k':
case 'K':
operation_ReaderKeyWriteAes();
printf("--------------------------------------------------\n");
break;
case 'f':
case 'F':
operation_ValueBlockInSectorRead();
......@@ -283,8 +277,8 @@ void menu(char key)
printf("--------------------------------------------------\n");
break;
case 'l':
case 'L':
case 'k':
case 'K':
operation_ReaderKeyWrite();
printf("--------------------------------------------------\n");
break;
......@@ -295,8 +289,8 @@ void menu(char key)
printf("--------------------------------------------------\n");
break;
case 'm':
case 'M':
case 'l':
case 'L':
operation_SamKeyWrite();
printf("--------------------------------------------------\n");
break;
......
......@@ -20,7 +20,6 @@ uint8_t auth_key = MIFARE_AUTHENT1A;
uint8_t auth_key_aes;
uint8_t key_index = 0;
uint8_t PK_CRYPTO1_key[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
uint8_t PK_AES_key[16] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
bool sam_used = false;
......@@ -61,49 +60,6 @@ void ConvertStringToUint8Array(std::string str, uint8_t *array)
}
}
bool isCardMifarePlus()
{
UFR_STATUS status;
uint8_t card_type;
status = GetDlogicCardType(&card_type);
if(!status)
{
if(card_type == DL_MIFARE_PLUS_S_2K_SL3 || card_type == DL_MIFARE_PLUS_X_2K_SL3
|| card_type == DL_MIFARE_PLUS_EV1_2K_SL3 || card_type == DL_MIFARE_PLUS_S_4K_SL3
|| card_type == DL_MIFARE_PLUS_X_4K_SL3 || card_type == DL_MIFARE_PLUS_EV1_4K_SL3)
{
if(auth_key == MIFARE_AUTHENT1A)
{
auth_key_aes = MIFARE_PLUS_AES_AUTHENT1A;
}
else if(auth_key == MIFARE_AUTHENT1B)
{
auth_key_aes = MIFARE_PLUS_AES_AUTHENT1B;
}
return true;
}
else
{
if(auth_key == MIFARE_PLUS_AES_AUTHENT1A)
{
auth_key = MIFARE_AUTHENT1A;
}
else if(auth_key == MIFARE_PLUS_AES_AUTHENT1B)
{
auth_key = MIFARE_AUTHENT1B;
}
return false;
}
}
else
{
return false;
}
}
bool open_sam(void)
{
UFR_STATUS status;
......@@ -129,7 +85,7 @@ void usage(void)
printCurrentAuthConfig();
printf("+------------------------------------------------+\n"
"| Block (Read/Write) and Linear (Read/Write) |\n"
"| version 1.0 |\n");
"| version 1.2 |\n");
cout << "| DLL version " << GetDllVersionStr() << " |\n";
cout <<"+------------------------------------------------+\n";
printf(" For exit, hit escape.\n");
......@@ -153,9 +109,8 @@ void usage(void)
" (h) - Value block in sector increment\n"
" (i) - Value block in sector decrement\n"
" (j) - Sector trailer write\n"
" (k) - Reader key write (AES)\n"
" (l) - Reader key write (CRYPTO 1)\n"
" (m) - SAM key write\n");
" (k) - Reader key write (CRYPTO 1)\n"
" (l) - SAM key write\n");
printf("--------------------------------------------------\n");
}
......@@ -314,53 +269,22 @@ void changeKeyIndex()
void changeProvidedKey()
{
int choice;
cout << "What key do you want to change?" << endl;
cout << "1. Provided key (CRYPTO 1 key)" << endl;
cout << "2. Provided key (AES key)" << endl;
scanf("%d%*c", &choice);
fflush(stdin);
string new_key = "";
if(choice == 1)
{
cout << "Enter new provided CRYPTO 1 key (6 bytes) with any delimiter:" << endl;
getline(cin, new_key);
cout << "Enter new provided CRYPTO 1 key (6 bytes) with any delimiter:" << endl;
getline(cin, new_key);
new_key = eraseDelimiters(new_key);
new_key = eraseDelimiters(new_key);
if(new_key.length() != 12)
{
cout << "Key must be 6 bytes long" << endl;
}
else
{
convertStrToByteArray(new_key, PK_CRYPTO1_key);
}
fflush(stdin);
}
else if(choice == 2)
if(new_key.length() != 12)
{
cout << "Enter new provided AES key (16 bytes) with any delimiter:" << endl;
getline(cin, new_key);
new_key = eraseDelimiters(new_key);
if(new_key.length() != 32)
{
cout << "Key must be 16 bytes long" << endl;
}
else
{
convertStrToByteArray(new_key, PK_AES_key);
}
fflush(stdin);
cout << "Key must be 6 bytes long" << endl;
}
else
{
cout << "Wrong input, choose 1 or 2" << endl;
convertStrToByteArray(new_key, PK_CRYPTO1_key);
}
fflush(stdin);
}
......@@ -399,14 +323,7 @@ void operation_BlockRead()
status = BlockRead_AKM2(data, block_address, auth_key);
break;
case 4:
if(isCardMifarePlus())
{
status = BlockRead_PK(data, block_address, auth_key_aes, PK_AES_key);
}
else
{
status = BlockRead_PK(data, block_address, auth_key, PK_CRYPTO1_key);
}
status = BlockRead_PK(data, block_address, auth_key, PK_CRYPTO1_key);
break;
case 5:
status = BlockReadSamKey(data, block_address, auth_key, key_index);
......@@ -459,14 +376,7 @@ void operation_BlockInSectorRead()
status = BlockInSectorRead_AKM2(data, sector_address, block_address, auth_key);
break;
case 4:
if(isCardMifarePlus())
{
status = BlockInSectorRead_PK(data, sector_address, block_address, auth_key_aes, PK_AES_key);
}
else
{
status = BlockInSectorRead_PK(data, sector_address, block_address, auth_key, PK_CRYPTO1_key);
}
status = BlockInSectorRead_PK(data, sector_address, block_address, auth_key, PK_CRYPTO1_key);
break;
case 5:
status = BlockInSectorReadSamKey(data, sector_address, block_address, auth_key, key_index);
......@@ -531,15 +441,7 @@ void operation_BlockWrite()
status = BlockWrite_AKM2(data, block_address, auth_key);
break;
case 4:
if(isCardMifarePlus())
{
status = BlockWrite_PK(data, block_address, auth_key_aes, PK_AES_key);
}
else
{
status = BlockWrite_PK(data, block_address, auth_key, PK_CRYPTO1_key);
}
status = BlockWrite_PK(data, block_address, auth_key, PK_CRYPTO1_key);
break;
case 5:
status = BlockWriteSamKey(data, block_address, auth_key, key_index);
......@@ -601,15 +503,7 @@ void operation_BlockInSectorWrite()
status = BlockInSectorWrite_AKM2(data, sector_address, block_address, auth_key);
break;
case 4:
if(isCardMifarePlus())
{
status = BlockInSectorWrite_PK(data, sector_address, block_address, auth_key_aes, PK_AES_key);
}
else
{
status = BlockInSectorWrite_PK(data, sector_address, block_address, auth_key, PK_CRYPTO1_key);
}
status = BlockInSectorWrite_PK(data, sector_address, block_address, auth_key, PK_CRYPTO1_key);
break;
case 5:
status = BlockInSectorWriteSamKey(data, sector_address, block_address, auth_key, key_index);
......@@ -661,15 +555,7 @@ void operation_LinearRead()
break;
case 4:
if(isCardMifarePlus())
{
status = LinearRead_PK(data, linear_addr, data_length, &bytes_returned, auth_key, PK_AES_key);
}
else
{
status = LinearRead_PK(data, linear_addr, data_length, &bytes_returned, auth_key, PK_CRYPTO1_key);
}
status = LinearRead_PK(data, linear_addr, data_length, &bytes_returned, auth_key, PK_CRYPTO1_key);
break;
case 5:
......@@ -735,14 +621,7 @@ void operation_LinearWrite()
break;
case 4:
if(isCardMifarePlus())
{
status = LinearWrite_PK(data, linear_addr, data_length, &bytes_written, auth_key, PK_AES_key);
}
else
{
status = LinearWrite_PK(data, linear_addr, data_length, &bytes_written, auth_key, PK_CRYPTO1_key);
}
status = LinearWrite_PK(data, linear_addr, data_length, &bytes_written, auth_key, PK_CRYPTO1_key);
break;
case 5:
......@@ -789,11 +668,9 @@ void printCurrentAuthConfig()
switch(auth_key)
{
case MIFARE_AUTHENT1A:
case MIFARE_PLUS_AES_AUTHENT1A:
auth_key_str = "KEY A";
break;
case MIFARE_AUTHENT1B:
case MIFARE_PLUS_AES_AUTHENT1B:
auth_key_str = "KEY B";
break;
}
......@@ -802,7 +679,6 @@ void printCurrentAuthConfig()
conf << "Authentication key : " << auth_key_str << endl;
conf << "Key index : " << to_string(key_index) << endl;
conf << "Provided key (CRYPTO 1): " << ConvertToHexArray(PK_CRYPTO1_key, 6, " ") << endl;
conf << "Provided key (AES key): " << ConvertToHexArray(PK_AES_key, 16, " ") << endl;
cout << conf.str() << endl;
}
......@@ -845,44 +721,6 @@ void operation_ReaderKeyWrite()
}
}
void operation_ReaderKeyWriteAes()
{
UFR_STATUS status;
uint8_t reader_key[16];
uint8_t reader_key_index;
string rk_str = "";
uint32_t rk_index;
cout << "Enter key index in the reader you want to write:" << endl;
scanf("%d%*c", &rk_index);
fflush(stdin);
cout << "Enter new key (16 bytes hex) with any delimiter:" << endl;
getline(cin, rk_str);
rk_str = eraseDelimiters(rk_str);
if(rk_str.length() != 32)
{
cout << "Key must be 16 bytes long" << endl;
return;
}
reader_key_index = rk_index;
convertStrToByteArray(rk_str, reader_key);
status = uFR_int_DesfireWriteAesKey(reader_key_index, reader_key);
if(!status)
{
cout << "AES key at index " << (int)reader_key_index << " successfully written into reader" << endl;
}
else
{
cout << "Error, status is " << UFR_Status2String(status) << endl;
}
}
void operation_SamKeyWrite(void)
{
UFR_STATUS status;
......@@ -1049,14 +887,7 @@ void operation_ValueBlockRead()
status = ValueBlockRead_AKM2(&value, &value_addr, block_address, auth_key);
break;
case 4:
if(isCardMifarePlus())
{
status = ValueBlockRead_PK(&value, &value_addr, block_address, auth_key_aes, PK_AES_key);
}
else
{
status = ValueBlockRead_PK(&value, &value_addr, block_address, auth_key, PK_CRYPTO1_key);
}
status = ValueBlockRead_PK(&value, &value_addr, block_address, auth_key, PK_CRYPTO1_key);
break;
case 5:
status = ValueBlockReadSamKey(&value, &value_addr, block_address, auth_key, key_index);
......@@ -1109,14 +940,7 @@ void operation_ValueBlockWrite()
status = ValueBlockWrite_AKM2(value, value_addr, block_address, auth_key);
break;
case 4:
if(isCardMifarePlus())
{
status = ValueBlockWrite_PK(value, value_addr, block_address, auth_key_aes, PK_AES_key);
}
else
{
status = ValueBlockWrite_PK(value, value_addr, block_address, auth_key, PK_CRYPTO1_key);
}
status = ValueBlockWrite_PK(value, value_addr, block_address, auth_key, PK_CRYPTO1_key);
break;
case 5:
status = ValueBlockWriteSamKey(value, value_addr, block_address, auth_key, key_index);
......@@ -1163,14 +987,7 @@ void operation_ValueBlockIncrement()
status = ValueBlockIncrement_AKM2(value, block_address, auth_key);
break;
case 4:
if(isCardMifarePlus())
{
status = ValueBlockIncrement_PK(value, block_address, auth_key_aes, PK_AES_key);
}
else
{
status = ValueBlockIncrement_PK(value, block_address, auth_key, PK_CRYPTO1_key);
}
status = ValueBlockIncrement_PK(value, block_address, auth_key, PK_CRYPTO1_key);
break;
case 5:
status = ValueBlockIncrementSamKey(value, block_address, auth_key, key_index);
......@@ -1217,14 +1034,7 @@ void operation_ValueBlockDecrement()
status = ValueBlockDecrement_AKM2(value, block_address, auth_key);
break;
case 4:
if(isCardMifarePlus())
{
status = ValueBlockDecrement_PK(value, block_address, auth_key_aes, PK_AES_key);
}
else
{
status = ValueBlockDecrement_PK(value, block_address, auth_key, PK_CRYPTO1_key);
}
status = ValueBlockDecrement_PK(value, block_address, auth_key, PK_CRYPTO1_key);
break;
case 5:
status = ValueBlockDecrementSamKey(value, block_address, auth_key, key_index);
......@@ -1272,14 +1082,7 @@ void operation_ValueBlockInSectorRead()
status = ValueBlockInSectorRead_AKM2(&value, &value_addr, sector_address, block_address, auth_key);
break;
case 4:
if(isCardMifarePlus())
{
status = ValueBlockInSectorRead_PK(&value, &value_addr, sector_address, block_address, auth_key_aes, PK_AES_key);
}
else
{
status = ValueBlockInSectorRead_PK(&value, &value_addr, sector_address, block_address, auth_key, PK_CRYPTO1_key);
}
status = ValueBlockInSectorRead_PK(&value, &value_addr, sector_address, block_address, auth_key, PK_CRYPTO1_key);
break;
case 5:
status = ValueBlockInSectorReadSamKey(&value, &value_addr, sector_address, block_address, auth_key, key_index);
......@@ -1338,14 +1141,7 @@ void operation_ValueBlockInSectorWrite()
status = ValueBlockInSectorWrite_AKM2(value, value_addr, sector_address, block_address, auth_key);
break;
case 4:
if(isCardMifarePlus())
{
status = ValueBlockInSectorWrite_PK(value, value_addr, sector_address, block_address, auth_key_aes, PK_AES_key);
}
else
{
status = ValueBlockInSectorWrite_PK(value, value_addr, sector_address, block_address, auth_key, PK_CRYPTO1_key);
}
status = ValueBlockInSectorWrite_PK(value, value_addr, sector_address, block_address, auth_key, PK_CRYPTO1_key);
break;
case 5:
status = ValueBlockInSectorWriteSamKey(value, value_addr, sector_address, block_address, auth_key, key_index);
......@@ -1400,14 +1196,7 @@ void operation_ValueBlockInSectorIncrement()
status = ValueBlockInSectorIncrement_AKM2(value, sector_address, block_address, auth_key);
break;
case 4:
if(isCardMifarePlus())
{
status = ValueBlockInSectorIncrement_PK(value, sector_address, block_address, auth_key_aes, PK_AES_key);
}
else
{
status = ValueBlockInSectorIncrement_PK(value, sector_address, block_address, auth_key, PK_CRYPTO1_key);
}
status = ValueBlockInSectorIncrement_PK(value, sector_address, block_address, auth_key, PK_CRYPTO1_key);
break;
case 5:
status = ValueBlockInSectorIncrementSamKey(value, sector_address, block_address, auth_key, key_index);
......@@ -1462,14 +1251,7 @@ void operation_ValueBlockInSectorDecrement()
status = ValueBlockInSectorDecrement_AKM2(value, sector_address, block_address, auth_key);
break;
case 4:
if(isCardMifarePlus())
{
status = ValueBlockInSectorDecrement_PK(value, sector_address, block_address, auth_key_aes, PK_AES_key);
}
else
{
status = ValueBlockInSectorDecrement_PK(value, sector_address, block_address, auth_key, PK_CRYPTO1_key);
}
status = ValueBlockInSectorDecrement_PK(value, sector_address, block_address, auth_key, PK_CRYPTO1_key);
break;
case 5:
status = ValueBlockInSectorDecrementSamKey(value, sector_address, block_address, auth_key, key_index);
......@@ -1580,16 +1362,8 @@ void operation_SectorTrailerWrite()
new_key_B, auth_key);
break;
case 4:
if(isCardMifarePlus())
{
status = SectorTrailerWrite_PK(addressing_mode, address, new_key_A, block0_access_bits, block1_access_bits, block2_access_bits, sector_trailer_access_bits, sector_trailer_byte9,
new_key_B, auth_key, PK_AES_key);
}
else
{
status = SectorTrailerWrite_PK(addressing_mode, address, new_key_A, block0_access_bits, block1_access_bits, block2_access_bits, sector_trailer_access_bits, sector_trailer_byte9,
status = SectorTrailerWrite_PK(addressing_mode, address, new_key_A, block0_access_bits, block1_access_bits, block2_access_bits, sector_trailer_access_bits, sector_trailer_byte9,
new_key_B, auth_key, PK_CRYPTO1_key);
}
break;
case 5:
status = SectorTrailerWriteSamKey(addressing_mode, address, new_key_A, block0_access_bits, block1_access_bits, block2_access_bits, sector_trailer_access_bits, sector_trailer_byte9,
......
......@@ -26,7 +26,6 @@ void operation_LinearRead(void);
void operation_LinearWrite(void);
void operation_ReaderKeyWrite(void);
void operation_ReaderKeyWriteAes(void);
bool isCardMifarePlus(void);
void operation_SamKeyWrite(void);
void operation_ValueBlockRead(void);
void operation_ValueBlockWrite(void);
......
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