def authorization_id_confirmation(auth_id, nonce_abf, key): cmd_id = 0x001E cmd_id = utils.pack_u16(cmd_id) auth_id = utils.pack_u32(auth_id) message = auth_id + nonce_abf auth_h = nacl.bindings.crypto_auth_hmacsha256(message, key) message = cmd_id + auth_h + auth_id return message
def lock_action(auth_id, lock_action, bridge_id, flags, nonce_k): cmd_id = 0x000D cmd_id = utils.pack_u16(cmd_id) lock_action = utils.pack_u8(lock_action) bridge_id = utils.pack_u32(bridge_id) flags = utils.pack_u8(flags) message = cmd_id + lock_action + bridge_id + flags + nonce_k return message
def _inject_error_encrypted(self, error_id, cmd_id=0xFFFF, auth_id=0xFFFFFFFF): error = error_id cmd_id = cmd_id message = cmd.error_bridge(error, cmd_id) decrypted = utils.pack_u32(auth_id) + message decrypted = utils.add_crc(decrypted) return auth_id, message, decrypted
def encrypt_tx(auth_id, message, key, nonce=''): auth_id = utils.pack_u32(auth_id) pdata = auth_id + message pdata = utils.add_crc(pdata) encrypted = encrypt(pdata, key, nonce) nonce = encrypted[:24] pdata = encrypted[24:] length = len(pdata) length = utils.pack_u16(length) message = nonce + auth_id + length + pdata return message
def authorization_data(id_type, bridge_id, name, nonce_abf, nonce_k, key): cmd_id = 0x0006 cmd_id = utils.pack_u16(cmd_id) id_type = utils.pack_u8(id_type) bridge_id = utils.pack_u32(bridge_id) z_fill = a2b_hex('0000000000000000000000000000000000000000000000000000000000000000') name = a2b_hex(hexlify(name))[:15] + z_fill name = name[:32] message = id_type + bridge_id + name + nonce_abf + nonce_k auth_h = nacl.bindings.crypto_auth_hmacsha256(message, key) message = cmd_id + auth_h + id_type + bridge_id + name + nonce_abf return message