pyradius / pyrad

Python RADIUS Implementation
BSD 3-Clause "New" or "Revised" License
294 stars 185 forks source link

ClientAsync not able to validate reply #160

Closed mrfoxyfoxy closed 1 year ago

mrfoxyfoxy commented 2 years ago

Setup: Server: Freeradius Server 3.0 Client: pyrad with Python 3.5.3 debian stretch (tested with Python 3.9.2, debian buster, too)

I'm issuing a simple authentication request. With the synchronous client this works without problems. With the ClientAsync I get this log message (with different payloads per request):

[192.168.0.1:1812] Ignore invalid reply: b'\x02\x8c\x00\x14\x89\xc3\xa2\x1b\x00\xf7f\xc5(\xc6\xd1#\xb9\x86\xf2%'

I can observe that the server accepts a request with valid credentials and rejects one with invalid credentials. The log message stays the same. I tried the provided example code, too, but it had the same result. So I guess theres a problem with the encoding.

Sample code:

import pyrad.packet
from pyrad.client_async import ClientAsync
from pyrad.dictionary import Dictionary
import asyncio

class Settings:
    # sentinel class for settings
    pass

settings = Settings()
settings.server = "192.168.0.1"
settings.dictionary = "dictionary"
settings.radius_secret = "secret"

client = ClientAsync(server=settings.server,secret=bytes(settings.radius_secret, "utf-8"),timeout=4,dict=Dictionary(settings.dictionary))

username = "username"
password = "password"

async def check_radius(username, password, client):
    await client.initialize_transports(
        enable_auth=True,
        local_addr='192.168.0.2',
        local_auth_port=800,
        enable_acct=False,
        enable_coa=False
    )
    request = client.CreateAuthPacket(code=pyrad.packet.AccessRequest,User_Name=username,NAS_Identifier="localhost")
    request["User-Password"] = request.PwCrypt(password)
    response = await client.SendPacket(request)
    await client.deinitialize_transports()
    if response.code == pyrad.packet.AccessAccept:
        print("access accepted")
    else:
        print("access denied")

loop = asyncio.get_event_loop()
loop.run_until_complete(check_radius(username, password, client))
ValdikSS commented 2 years ago

Proposed fix in https://github.com/pyradius/pyrad/pull/169