Ejemplo n.º 1
0
 def testerPresent(self, *args):
     try:
         with Client(self.conn,
                     request_timeout=1,
                     config={'exception_on_unexpected_response':
                             False}) as client:  # noqa: F841
             self.conn.send(b'\x10\x03')
             self.termPrint('Request', b'\x10\x03')
             payload = self.conn.wait_frame(timeout=1)
             response = Response.\
                 from_payload(payload)  # noqa: F841, E501
             response = str(response).split('<')
             response = (response[1].split('-'))[0]
             self.termPrint(response)
             self.conn.send(b'\x27\x63')
             self.termPrint('Request', b'\x27\x63')
             payload = self.conn.wait_frame(timeout=1)
             response = Response.from_payload(payload)
             seed = (response.data.hex()[2:])
             sA = sec.securityAlgo(seed, 'series')
             sleep(.1)
             key = b'\x27\x64' + sA.calculatedKey
             response = str(response).split('<')
             response = (response[1].split('-'))[0]
             self.conn.send(key)
             payload = self.conn.wait_frame(timeout=1)
             response = Response.from_payload(payload)
             response = str(response).split('<')
             response = (response[1].split('-'))[0]
             self.termPrint(response)
         self.tpTime += 4
         service = (self.begServicesList[self.begService.get()])[0]
         while self.commStatus and service == 'Write Data':
             if time() - self.tpTime >= 4:
                 self.tpTime = time()
                 with Client(
                         self.conn,
                         request_timeout=1,
                         config={'exception_on_unexpected_response':
                                 False}) as client:  # noqa: F841
                     msg = b'\x3E\x00'
                     self.conn.send(msg)
                     self.termPrint('Request', msg)
                     '''payload = self.conn.wait_frame(timeout=1)
                     response = Response.\
                         from_payload(payload)  # noqa: F841, E501
                     self.termPrint('Response', response.data)'''
             service = (self.begServicesList[self.begService.get()])[0]
         self.begService.set(0)
     except Exception as e:
         messagebox.showinfo('Function unavailable', e)
         self.begService.set(0)
Ejemplo n.º 2
0
 def test_from_payload_custom_data_negative(self):
     payload = b'\x7F\x3E\x10\x12\x34\x56\x78'  # 0x3E = TesterPresent, 0x10 = General Reject
     response = Response.from_payload(payload)
     self.assertTrue(response.valid)
     self.assertEqual(response.service.response_id(), 0x7E)
     self.assertEqual(response.code, 0x10)
     self.assertEqual(response.data, b'\x12\x34\x56\x78')
Ejemplo n.º 3
0
 def test_from_payload_custom_data_positive(self):
     payload = b'\x7E\x01\x12\x34\x56\x78'  # 0x3E = TesterPresent
     response = Response.from_payload(payload)
     self.assertTrue(response.valid)
     self.assertTrue(response.positive)
     self.assertEqual(response.service.response_id(), 0x7E)
     self.assertEqual(response.data, b'\x01\x12\x34\x56\x78')
Ejemplo n.º 4
0
 def test_from_payload_basic_negative(self):
     payload = b'\x7F\x3E\x10'  # 0x3e = TesterPresent, 0x10 = General Reject
     response = Response.from_payload(payload)
     self.assertTrue(response.valid)
     self.assertFalse(response.positive)
     self.assertEqual(response.service.response_id(), 0x7E)
     self.assertEqual(response.code, 0x10)
Ejemplo n.º 5
0
 def test_from_payload_basic_positive(self):
     payload = b'\x7E\x00'  # 0x7e = TesterPresent
     response = Response.from_payload(payload)
     self.assertTrue(response.valid)
     self.assertTrue(response.positive)
     self.assertEqual(response.service.response_id(), 0x7E)
     self.assertEqual(response.code, 0)
Ejemplo n.º 6
0
    def __getSeed(self):
        req = Request(SecurityAccess, subfunction=self.ACCESS_LEVEL)
        self.client.send(req.get_payload())
        payload = self.client.wait_frame(timeout=self.timeout)
        response = Response.from_payload(payload)

        if response.service == SecurityAccess and response.code == Response.Code.PositiveResponse:
            return response.data[1:]
        else:
            return None
Ejemplo n.º 7
0
    def __sendKeyAndMesureTime(self, keyLevel, data):
        req = Request(SecurityAccess, subfunction=keyLevel, data=data)
        self.client.send(req.get_payload())

        startTime = time.time()
        payload = self.client.wait_frame(timeout=self.timeout)
        endTime = time.time()

        progressTime = endTime - startTime

        response = Response.from_payload(payload)

        return response, progressTime
Ejemplo n.º 8
0
    def send_request(self, request, timeout=-1):
        if timeout is not None and timeout < 0:
            timeout = self.request_timeout
        self.conn.empty_rxqueue()
        self.logger.debug("Sending request to server")
        self.conn.send(request)

        if not request.suppress_positive_response:
            self.logger.debug("Waiting for server response")
            try:
                payload = self.conn.wait_frame(timeout=timeout, exception=True)
            except Exception as e:
                raise e

            response = Response.from_payload(payload)
            self.last_response = response
            self.logger.debug("Received response from server")

            if not response.valid:
                raise InvalidResponseException(
                    response, 'Received response is invalid.')

            if response.service.response_id() != request.service.response_id():
                msg = "Response gotten from server has a service ID different than the one of the request. Received=0x%02x, Expected=0x%02x" % (
                    response.service.response_id(),
                    request.service.response_id())
                raise UnexpectedResponseException(response, msg)

            if not response.positive:
                if not request.service.is_supported_negative_response(
                        response.code):
                    self.logger.warning(
                        "Given response (%s) is not a supported negative response code according to UDS standard."
                        % response.code_name)
                raise NegativeResponseException(response)

            self.logger.info('Received positive response from server.')
            return response
Ejemplo n.º 9
0
import securityAlgo as sec
from time import sleep

tp_addr = isotp.Address(isotp.AddressingMode.Normal_29bits,
                        txid=0x18DA2AF1,
                        rxid=0x18DAFA2A)
bus = Bus(bustype='pcan', channel='PCAN_USBBUS1', bitrate=500000)
stack = isotp.CanStack(bus=bus, address=tp_addr)
conn = PythonIsoTpConnection(stack)
with Client(conn,
            request_timeout=1,
            config={'exception_on_unexpected_response': False}) as client:
    try:
        conn.send(b'\x10\x03')
        payload = conn.wait_frame(timeout=1)
        response = Response.from_payload(payload)
        print(response)
        conn.send(b'\x27\x63')
        payload = conn.wait_frame(timeout=1)
        response = Response.from_payload(payload)
        print('key: ' + response.data.hex()[2:])
        seed = (response.data.hex()[2:])
        sA = sec.securityAlgo(seed, 'series')
        sleep(.1)
        print('calculated key: ' + (sA.calculatedKey).hex())
        conn.send(b'\x27\x64' + sA.calculatedKey)
        payload = conn.wait_frame(timeout=1)
        response = Response.from_payload(payload)
        response = str(response).split('<')
        response = (response[1].split('-'))[0]
        print(response)
Ejemplo n.º 10
0
 def test_from_empty_payload(self):
     payload = b''
     response = Response.from_payload(payload)
     self.assertFalse(response.valid)
     self.assertIsNone(response.service)
     self.assertEqual(b'', response.data)
Ejemplo n.º 11
0
 def test_from_bad_payload(self):
     payload = '\xFF\xFF'
     response = Response.from_payload(payload)
     self.assertFalse(response.valid)
     self.assertIsNone(response.service)
     self.assertEqual('', response.data)