Skip to content

Commit

Permalink
temp changes to mfc, will need to update menu navigation further
Browse files Browse the repository at this point in the history
  • Loading branch information
doomwastaken committed Oct 16, 2023
1 parent 2a26c1d commit b4b00b7
Showing 1 changed file with 51 additions and 28 deletions.
79 changes: 51 additions & 28 deletions scripts/flippigator/nfc/test_emulate_mifare_classic.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,21 @@ class TestEmulateClassic:
@pytest.fixture(scope="function", autouse=True)
def add_4k7_manually(self, nav):
# Code below will run before each "function" (test)
nav.go_to_main_screen()

# Delete file if exists, needs to be added as picture sadly
nav.delete_file("NFC", "T_mfc_4k7")
# nav.delete_file("NFC", "T_mfc_4k7")
# Todo: return back to line above, after browser is fixed
nav.nfc.go_into()
nav.go_to("Saved")
nav.press_ok()
nav.go_to("T_mfc_4k7", direction="up")
menu_items = nav.get_menu_list()
if "T_mfc_4k7" in menu_items:
nav.press_ok()
nav.go_to("Delete", direction="up")
nav.press_ok()
nav.press_right()

nav.nfc.go_into()
nav.go_to("Add Manually")
nav.press_ok()
Expand All @@ -30,8 +41,19 @@ def add_4k7_manually(self, nav):
yield

# This code will run after each "function" (test)
nav.go_to_main_screen()
nav.delete_file("NFC", "T_mfc_4k7")
# nav.delete_file("NFC", "T_mfc_4k7")
# Todo: return back to line above, after browser is fixed
# Todo2: move to function
nav.nfc.go_into()
nav.go_to("Saved")
nav.press_ok()
nav.go_to("T_mfc_4k7", direction="up")
menu_items = nav.get_menu_list()
if "T_mfc_4k7" in menu_items:
nav.press_ok()
nav.go_to("Delete", direction="up")
nav.press_ok()
nav.press_right()

@pytest.fixture(scope="function")
def emulate_classic(self, nav):
Expand All @@ -53,9 +75,6 @@ def test_mfc_4k7_basic(self, px, emulate_classic):
# read 1 block
read1 = px.execute("hf mf rdbl --blk 1 -k ffffffffffff")
expected = "[=] 1 | FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF | ................ "
print("///////////////////////////////////")
print(expected in read1)
print("///////////////////////////////////")
assert expected in read1, "Incorrect block read"

# write 1 block
Expand All @@ -70,48 +89,52 @@ def test_mfc_4k7_basic(self, px, emulate_classic):

# set value block
set_value = px.execute("hf mf value --blk 1 -k ffffffffffff --set 1000")
expected = "[+] Update ... : success"
expected = "[=] set value to : 1000"
expected_status = "[+] Update ... : success"
assert expected in set_value, "Incorrect set value"
assert expected_status in set_value, "Update failed"

# increment value block
inc_value = px.execute("hf mf value --blk 1 -k ffffffffffff --inc 200")
expected = "[+] Update ... : success"
expected = "[=] Value incremented by : 200"
expected_status = "[+] Update ... : success"

# tests work up to this point
assert expected in inc_value, "Incorrect increment value"
assert expected_status in inc_value, "Update failed"

# decrement value block
dec_value = px.execute("hf mf value --blk 1 -k ffffffffffff --dec 10000")
assert dec_value[0] == "Decrement success, new value is -8800", "Incorrect decrement value"
expected = "[=] Value decremented by : 10000"
expected_status = "[+] Update ... : success"
assert expected in dec_value, "Incorrect decrement value"
assert expected_status in dec_value, "Update failed"

# change key A in 0 sector
change_key = px.execute("hf mf wrbl --blk 3 -k ffffffffffff -d a0a1a2a3a4a5ff078069ffffffffffff")
assert change_key[0] == "Block write OK", "Incorrect change key"
expected = "[=] data: A0 A1 A2 A3 A4 A5 FF 07 80 69 FF FF FF FF FF FF"
expected_status = "[+] Write ( ok )"
assert expected in change_key, "Incorrect change key"
assert expected_status in change_key, "Update failed"

# read 1 block with old key
read1 = px.execute("hf mf rdbl --blk 1 -k ffffffffffff")
assert read1[0] == "Auth error", "Incorrect block read"
expected_status = "[#] Auth error"
assert expected_status in read1, "Auth error not present"

# read 1 block with new key
read1 = px.execute("hf mf rdbl --blk 1 -k a0a1a2a3a4a5")
assert read1[0] == "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", "Incorrect block read"
expected = "[=] 1 | E8 03 00 00 17 FC FF FF E8 03 00 00 01 FE 01 FE | ................ "
assert expected in read1, "Incorrect block read"

# all tests below are non-functional, need help verifying them
# change key B in 0 sector
change_key = px.execute("hf mf wrbl --blk 3 -k ffffffffffff -d b0b1b2b3b4b5ff078069ffffffffffff")
assert change_key[0] == "Block write OK", "Incorrect change key"
# change_key = px.execute("hf mf wrbl --blk 3 -k ffffffffffff -d ffffffffffff078069b0b1b2b3b4b5ff")
# assert change_key[0] == "Block write OK", "Incorrect change key"

# read sector trailer with key A
trailer_a_key = px.execute("hf mf rdbl --blk 3 -k a0a1a2a3a4a5")
assert trailer_a_key[0] == "Key A not present, Access Bits present, Key B present in the output", "Incorrect trailer read"
# trailer_a_key = px.execute("hf mf rdbl --blk 3 -k a0a1a2a3a4a5")
# assert trailer_a_key[0] == "Key A not present, Access Bits present, Key B present in the output", "Incorrect trailer read"

# read sector trailer with key B
trailer_b_key = px.execute("hf mf rdbl --blk 3 -b -k b0b1b2b3b4b5")
assert trailer_b_key[0] == "Key A not present, Access Bits not present, Key B not present in the output", "Incorrect trailer read"



px_result = px.execute(command)
#
# result = px_result[0]

assert 1
# trailer_b_key = px.execute("hf mf rdbl --blk 3 -b -k b0b1b2b3b4b5")
# assert trailer_b_key[0] == "Key A not present, Access Bits not present, Key B not present in the output", "Incorrect trailer read"

0 comments on commit b4b00b7

Please sign in to comment.