Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b98e65a41
|
@@ -133,4 +133,4 @@ def checkAccess(key: str, db: Session):
|
|||||||
logger.info("No more auths found")
|
logger.info("No more auths found")
|
||||||
return False
|
return False
|
||||||
except exc.NoResultFound:
|
except exc.NoResultFound:
|
||||||
raise Exception("No Access with that key found, this might be a db error")
|
raise Exception("No AccessAuth with that key found!")
|
||||||
|
|||||||
+14
-17
@@ -77,7 +77,7 @@ def readFileOnCard(desfire: DESFire):
|
|||||||
assert len(applications) == 1
|
assert len(applications) == 1
|
||||||
assert applications[0] == get_list(MIFARE_APP_ID)
|
assert applications[0] == get_list(MIFARE_APP_ID)
|
||||||
except AssertionError:
|
except AssertionError:
|
||||||
logger.error("No application found!")
|
logger.error("No application found! The card must be registered first!")
|
||||||
time.sleep(4)
|
time.sleep(4)
|
||||||
return
|
return
|
||||||
# Then use the key derivation with that uid, the appid, the sysid
|
# Then use the key derivation with that uid, the appid, the sysid
|
||||||
@@ -125,23 +125,13 @@ def DeleteCard():
|
|||||||
aes_null_key = DESFireKey(aes_keysettings, "00" * 16)
|
aes_null_key = DESFireKey(aes_keysettings, "00" * 16)
|
||||||
|
|
||||||
desfire.select_application(0x0)
|
desfire.select_application(0x0)
|
||||||
|
desfire.authenticate(0x0, desKey)
|
||||||
try:
|
|
||||||
try:
|
|
||||||
logger.debug("Auth1")
|
|
||||||
desfire.authenticate(0x0, aes_master_key)
|
|
||||||
except:
|
|
||||||
logger.debug("Auth2")
|
|
||||||
desfire.authenticate(0x0, aes_null_key)
|
|
||||||
except:
|
|
||||||
logger.debug("Auth3")
|
|
||||||
desfire.authenticate(0x0, desKey)
|
|
||||||
|
|
||||||
applications = desfire.get_application_ids()
|
applications = desfire.get_application_ids()
|
||||||
logger.debug(f"Applications: {applications}")
|
logger.debug(f"Applications: {applications}")
|
||||||
if len(applications) == 0:
|
if len(applications) == 0:
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_410_GONE, detail="No applications on card"
|
status_code=status.HTTP_410_GONE, detail="Card is empty."
|
||||||
)
|
)
|
||||||
|
|
||||||
desfire.select_application(MIFARE_APP_ID)
|
desfire.select_application(MIFARE_APP_ID)
|
||||||
@@ -185,6 +175,13 @@ def WriteNewCard():
|
|||||||
# get uid
|
# get uid
|
||||||
uid = desfire.get_real_uid()
|
uid = desfire.get_real_uid()
|
||||||
|
|
||||||
|
applications = desfire.get_application_ids()
|
||||||
|
logger.debug(f"Applications: {applications}")
|
||||||
|
if len(applications) >= 1:
|
||||||
|
raise HTTPException(
|
||||||
|
status_code=status.HTTP_409_CONFLICT, detail="This Card already has a key!"
|
||||||
|
)
|
||||||
|
|
||||||
# Set default key
|
# Set default key
|
||||||
logger.debug("Setting default key...")
|
logger.debug("Setting default key...")
|
||||||
desfire.change_default_key(aes_null_key, 0x0)
|
desfire.change_default_key(aes_null_key, 0x0)
|
||||||
@@ -270,12 +267,12 @@ def WriteNewCard():
|
|||||||
return key, to_hex_string(data=uid, separator=":")
|
return key, to_hex_string(data=uid, separator=":")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error in write function: {e}", exc_info=True)
|
logger.error(f"Error in write function: {e}", exc_info=False)
|
||||||
|
scannerThread.start()
|
||||||
raise HTTPException(
|
raise HTTPException(
|
||||||
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Error: {e}"
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=f"Error: {e}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class BackgroundScanner:
|
class BackgroundScanner:
|
||||||
def __init__(self, db):
|
def __init__(self, db):
|
||||||
self.db = db
|
self.db = db
|
||||||
@@ -310,7 +307,7 @@ class BackgroundScanner:
|
|||||||
logger.debug("READY after timout")
|
logger.debug("READY after timout")
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"Error in scan function: {e}", exc_info=True)
|
logger.error(f"Error in function _scan_loop: {e}", exc_info=False)
|
||||||
time.sleep(6)
|
time.sleep(6)
|
||||||
|
|
||||||
def _read_card(self):
|
def _read_card(self):
|
||||||
@@ -326,7 +323,7 @@ class BackgroundScanner:
|
|||||||
rdata = readFileOnCard(desfire=desfire)
|
rdata = readFileOnCard(desfire=desfire)
|
||||||
return rdata
|
return rdata
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"something went wrong: {e}")
|
logger.error(f"Error in function _read_card: {e}", exc_info=False)
|
||||||
time.sleep(5)
|
time.sleep(5)
|
||||||
|
|
||||||
def _check_db(self, key):
|
def _check_db(self, key):
|
||||||
|
|||||||
Reference in New Issue
Block a user