[lint] lint + format tests
This commit is contained in:
41
test.py
41
test.py
@@ -15,21 +15,32 @@ It performs the following steps:
|
||||
import logging
|
||||
import os
|
||||
|
||||
from desfire import (
|
||||
DESFire,
|
||||
DESFireKey,
|
||||
PCSCDevice,
|
||||
diversify_key,
|
||||
get_list,
|
||||
to_hex_string,
|
||||
)
|
||||
from desfire.enums import (
|
||||
DESFireCommunicationMode,
|
||||
DESFireFileType,
|
||||
DESFireKeySettings,
|
||||
DESFireKeyType,
|
||||
)
|
||||
from desfire.schemas import FilePermissions, FileSettings, KeySettings
|
||||
from dotenv import load_dotenv
|
||||
from smartcard.CardRequest import CardRequest
|
||||
from smartcard.CardType import AnyCardType
|
||||
from smartcard.Exceptions import CardRequestTimeoutException
|
||||
|
||||
from desfire import DESFire, DESFireKey, PCSCDevice, diversify_key, get_list, to_hex_string
|
||||
from desfire.enums import DESFireCommunicationMode, DESFireFileType, DESFireKeySettings, DESFireKeyType
|
||||
from desfire.schemas import FilePermissions, FileSettings, KeySettings
|
||||
|
||||
from dotenv import load_dotenv
|
||||
# Please make sure to yet your own keys here before running this script
|
||||
load_dotenv()
|
||||
|
||||
MIFARE_APP_MASTER_KEY = os.getenv('MIFARE_APP_MASTER_KEY')
|
||||
MIFARE_ACL_READ_BASE_KEY = os.getenv('MIFARE_ACL_READ_BASE_KEY')
|
||||
MIFARE_ACL_WRITE_BASE_KEY = os.getenv('MIFARE_ACL_WRITE_BASE_KEY')
|
||||
MIFARE_APP_MASTER_KEY = os.getenv("MIFARE_APP_MASTER_KEY")
|
||||
MIFARE_ACL_READ_BASE_KEY = os.getenv("MIFARE_ACL_READ_BASE_KEY")
|
||||
MIFARE_ACL_WRITE_BASE_KEY = os.getenv("MIFARE_ACL_WRITE_BASE_KEY")
|
||||
|
||||
# Constants
|
||||
MIFARE_APP_ID = "DEAFFE" # 7 bytes
|
||||
@@ -118,8 +129,12 @@ desfire.authenticate(0x0, aes_app_mk)
|
||||
|
||||
# Change file read and write keys (diversified)
|
||||
diversification_data = [0x01] + uid + get_list(MIFARE_APP_ID) + get_list(MIFARE_SYS_ID)
|
||||
read_div_key_bytes = diversify_key(get_list(MIFARE_ACL_READ_BASE_KEY), diversification_data, pad_to_32=False)
|
||||
write_div_key_bytes = diversify_key(get_list(MIFARE_ACL_WRITE_BASE_KEY), diversification_data, pad_to_32=False)
|
||||
read_div_key_bytes = diversify_key(
|
||||
get_list(MIFARE_ACL_READ_BASE_KEY), diversification_data, pad_to_32=False
|
||||
)
|
||||
write_div_key_bytes = diversify_key(
|
||||
get_list(MIFARE_ACL_WRITE_BASE_KEY), diversification_data, pad_to_32=False
|
||||
)
|
||||
|
||||
print("Changing file read key...")
|
||||
aes_file_read_key = DESFireKey(aes_keysettings, read_div_key_bytes)
|
||||
@@ -154,11 +169,13 @@ print(" - File created successfully.")
|
||||
print("Writing UID to encrypted file...")
|
||||
data = [0x0] + uid
|
||||
assert len(data) == 8
|
||||
desfire.write_file_data(MIFARE_ENCRYPTED_FILE_ID, 0x0, file_data.encryption, get_list(data))
|
||||
desfire.write_file_data(
|
||||
MIFARE_ENCRYPTED_FILE_ID, 0x0, file_data.encryption, get_list(data)
|
||||
)
|
||||
|
||||
print("Reading from encrypted file...")
|
||||
rdata = desfire.read_file_data(MIFARE_ENCRYPTED_FILE_ID, file_data)
|
||||
assert rdata == data
|
||||
print(" - Data written successfully.")
|
||||
|
||||
print("Personalization finished.")
|
||||
print("Personalization finished.")
|
||||
|
||||
Reference in New Issue
Block a user