Skip to content

Commit

Permalink
fix(sa_keylen): Correctly import UDSErrorCodes, make linters happy
Browse files Browse the repository at this point in the history
  • Loading branch information
emedav authored and rumpelsepp committed Aug 6, 2024
1 parent 9b2a655 commit e44030c
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/gallia/commands/scan/uds/sa_keylen.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from gallia.config import Config
from gallia.log import get_logger
from gallia.services.uds import NegativeResponse, UDSRequestConfig
from gallia.services.uds.core.service import SecurityAccessResponse, UDSErrorCodes
from gallia.services.uds.core.constants import UDSErrorCodes
from gallia.services.uds.core.service import SecurityAccessResponse
from gallia.services.uds.core.utils import g_repr
from gallia.utils import auto_int

Expand Down Expand Up @@ -97,9 +98,9 @@ async def main(self, args: Namespace) -> None:
session = args.session
logger.info(f"scanning in session: {g_repr(session)}")

resp = await self.ecu.set_session(session)
if isinstance(resp, NegativeResponse):
logger.critical(f"could not change to session: {resp}")
sess_resp = await self.ecu.set_session(session)
if isinstance(sess_resp, NegativeResponse):
logger.critical(f"could not change to session: {sess_resp}")
return

key = bytes([0x00])
Expand All @@ -124,21 +125,22 @@ async def main(self, args: Namespace) -> None:
logger.critical(f"Error while requesting seed: {g_repr(e)}")
sys.exit(1)

resp = await self.ecu.security_access_send_key(
key_resp = await self.ecu.security_access_send_key(
args.level + 1, key, config=UDSRequestConfig(tags=["ANALYZE"])
)
if isinstance(resp, SecurityAccessResponse):
if isinstance(key_resp, SecurityAccessResponse):
logger.result(
f"That's unexpected: Unlocked SA level {g_repr(args.level)} with all-zero key of length {len(key)}."
)
length_identified = True
break
elif isinstance(resp, NegativeResponse):
elif isinstance(key_resp, NegativeResponse):
if (
not args.request_seed
and resp.response_code == UDSErrorCodes.requestSequenceError
and key_resp.response_code == UDSErrorCodes.requestSequenceError
) or (
args.request_seed and resp.response_code == UDSErrorCodes.conditionsNotCorrect
args.request_seed
and key_resp.response_code == UDSErrorCodes.conditionsNotCorrect
):
logger.result(f"The ECU seems to be expecting keys of length {len(key)}.")
length_identified = True
Expand Down

0 comments on commit e44030c

Please sign in to comment.