I am currently working on a project where I have implemented a RADIUS server in Python using the pyrad library. The goal is to handle authentication requests from ocserv, and I have set up radcli to facilitate communication between ocserv and my Python program.
I am encountering an issue where my Python RADIUS server, utilizing the following code, is not receiving any requests:
from pyrad.server import Server
from pyrad.dictionary import Dictionary
from pyrad import packet
def auth_callback(req, *args, **kwargs):
print('ok')
username = req.get_user_name()
try:
password = req.PwDecrypt(kwargs["secret"])
except Exception as e:
print(f"Error decrypting password: {e}")
req.reply(packet.AccessReject)
return
if username == "1" and password == "2":
req.reply(packet.AccessAccept)
else:
req.reply(packet.AccessReject)
def callback_wrapper(req, *args, **kwargs):
auth_callback(req, *args, **kwargs)
def main():
dict_obj = Dictionary()
server = Server(dict=dict_obj)
server.hosts["0.0.0.0"] = callback_wrapper
server.hosts["0.0.0.0"].kwargs = {"secret": b"testing123"}
server.Run()
if __name__ == "__main__":
main()
I have ensured that the necessary dependencies are installed, and the code appears to be correct. However, no requests are being processed. If anyone has experience with integrating pyrad and radcli for ocserv authentication in Python or can provide guidance on debugging and resolving this issue, I would greatly appreciate your assistance.
Thank you!