Пример #1
0
 def get_diagnostics_data(self):
     """
     Get response to NC command
     """
     response = OutgoingMessage(header=self.header)
     response.set_response_code('ND')
     response.set_error_code('00')
     response.set('LMK Check Value', key_CV(raw2B(self.LMK), 16))
     response.set('Firmware Version', str2bytes(self.firmware_version))
     return response
Пример #2
0
    def get_key_check_value(self, request):
        """
        Get response to BU command
        TODO: return different check values (length of 6 or length of 16)
        """
        response = OutgoingMessage(header=self.header)
        response.set_response_code('BV')
        response.set_error_code('00')

        key = request.get('Key')
        if key[0:1] in [b'U']:
            key = key[1:]
        response.set('Key Check Value', key_CV(key, 16))
        return response
Пример #3
0
    def generate_key_a0(self, request):
        """
        Get response to A0 command
        """
        response = OutgoingMessage(header=self.header)
        response.set_response_code('A1')
        response.set_error_code('00')

        new_clear_key = modify_key_parity(bytes(os.urandom(16)))
        self._debug_trace('Generated key: {}'.format(raw2str(new_clear_key)))
        new_key_under_lmk = self.cipher.encrypt(new_clear_key)
        response.set('Key under LMK', b'U' + raw2B(new_key_under_lmk))

        zmk_under_lmk = request.get('ZMK/TMK')[1:33]
        if zmk_under_lmk:
            clear_zmk = self.cipher.decrypt(B2raw(zmk_under_lmk))
            zmk_key_cipher = DES3.new(clear_zmk, DES3.MODE_ECB)
            new_key_under_zmk = zmk_key_cipher.encrypt(new_clear_key)

            response.set('Key under ZMK', b'U' + raw2B(new_key_under_zmk))
            response.set('Key Check Value', key_CV(raw2B(new_clear_key), 6))

        return response
Пример #4
0
    def translate_zpk(self, request):
        """
        Get response to FA command
        """
        response = OutgoingMessage(header=self.header)
        response.set_response_code('FB')
        response.set_error_code('00')

        zmk_under_lmk = request.get('ZMK')[1:33]
        if zmk_under_lmk:
            clear_zmk = self.cipher.decrypt(B2raw(zmk_under_lmk))
            self._debug_trace('Clear ZMK: {}'.format(raw2str(clear_zmk)))

            zmk_key_cipher = DES3.new(clear_zmk, DES3.MODE_ECB)

            zpk_under_zmk = request.get('ZPK')[1:33]
            if zpk_under_zmk:
                clear_zpk = zmk_key_cipher.decrypt(B2raw(zpk_under_zmk))
                self._debug_trace('Clear ZPK: {}'.format(raw2str(clear_zpk)))

                zpk_under_lmk = self.cipher.encrypt(clear_zpk)

                response.set('ZPK under LMK', b'U' + raw2B(zpk_under_lmk))
                response.set('Key Check Value', key_CV(raw2B(zpk_under_lmk),
                                                       6))
                response.set_error_code('00')

            else:
                self._debug_trace('ERROR: Invalid ZPK')
                response.set_error_code('01')

        else:
            self._debug_trace('ERROR: Invalid ZMK')
            response.set_error_code('01')

        return response
Пример #5
0
 def test_key_CV_16(self):
     self.assertEqual(key_CV(b'E6F1081FEA4C402CC192B65DE367EC3E', 16),
                      b'212CF9158251CDD3')
Пример #6
0
 def test_key_CV_6(self):
     self.assertEqual(key_CV(b'E6F1081FEA4C402CC192B65DE367EC3E', 6),
                      b'212CF9')
Пример #7
0
 def test_key_CV_default_kcv_length(self):
     self.assertEqual(key_CV(b'E6F1081FEA4C402CC192B65DE367EC3E'),
                      b'212CF9')