pyrad.curved – Twisted integration
Twisted integration code.
RADIUS servers built on Twisted: RADIUSAccess for authentication
and RADIUSAccounting for accounting requests, to be passed to
reactor.listenUDP. Twisted is not a dependency of pyrad and has to be
installed to use this module.
- class pyrad.curved.RADIUS(hosts=None, dict=None, enforce_ma=False, enable_pkt_verify=True)[source]
Base class of the Twisted RADIUS servers.
Receives and decodes packets, checks that they come from a known host, verifies them and passes them to
processPacket(). UseRADIUSAccessorRADIUSAccountingand overrideprocessPacket().Before
processPacket()is called,pkt.secretis set to the secret of the host andpkt.sourceto its(host, port). The Message-Authenticator of an Access-Request has been verified (and withenforce_marequired), and withenable_pkt_verifythe Request Authenticator of an Accounting-Request.- Parameters:
hosts (dict[str, pyrad.server.RemoteHost or bytes]) – hosts allowed to send packets, mapping their IP address to a
pyrad.server.RemoteHostor to the secret. IPv4 clients of a socket bound to'::'are looked up by their IPv4 address. Unlikepyrad.server.Server, there is no'0.0.0.0'entry for all other hosts: packets from other hosts are dropped.dict (pyrad.dictionary.Dictionary) – RADIUS dictionary used to decode the packets, by default an empty dictionary
enforce_ma (bool) – drop Access-Requests without a Message-Authenticator (an invalid Message-Authenticator is always dropped)
enable_pkt_verify (bool) – drop Accounting-Requests with an invalid Request Authenticator
- createPacket(**kwargs)[source]
Create the packet object for a received datagram.
RADIUSAccesscreates apyrad.packet.AuthPacketandRADIUSAccountingapyrad.packet.AcctPacket. The base method raisesNotImplementedError; a class that doesn’t override it receives genericpyrad.packet.Packetobjects.- Parameters:
kwargs – arguments for the packet class, e.g.
packet- Returns:
the packet
- Return type:
- processPacket(pkt)[source]
Process a received packet.
Override it and call the base method first, which raises
PacketErrorfor packets of the wrong type inRADIUSAccessandRADIUSAccounting. To answer, create a reply withpkt.CreateReply()and send it withself.transport.write(reply.ReplyPacket(), pkt.source). If no reply is sent, the request is dropped. RaisePacketErrorto drop the packet with a one-line log message; other exceptions are logged with a traceback.- Parameters:
pkt (pyrad.packet.Packet) – received packet
- class pyrad.curved.RADIUSAccess(*args: Any, **kwargs: Any)[source]
Bases:
RADIUSTwisted RADIUS authentication server.
Override
processPacket()and call the base method first, which drops all packets except Access-Requests. The User-Password is not verified: decrypt it withpkt.PwDecrypt.- Parameters:
hosts (dict[str, pyrad.server.RemoteHost or bytes]) – hosts allowed to send packets, mapping their IP address to a
pyrad.server.RemoteHostor to the secret. IPv4 clients of a socket bound to'::'are looked up by their IPv4 address. Unlikepyrad.server.Server, there is no'0.0.0.0'entry for all other hosts: packets from other hosts are dropped.dict (pyrad.dictionary.Dictionary) – RADIUS dictionary used to decode the packets, by default an empty dictionary
enforce_ma (bool) – drop Access-Requests without a Message-Authenticator (an invalid Message-Authenticator is always dropped)
enable_pkt_verify (bool) – drop Accounting-Requests with an invalid Request Authenticator
- createPacket(**kwargs)[source]
Create the packet object for a received datagram.
RADIUSAccesscreates apyrad.packet.AuthPacketandRADIUSAccountingapyrad.packet.AcctPacket. The base method raisesNotImplementedError; a class that doesn’t override it receives genericpyrad.packet.Packetobjects.- Parameters:
kwargs – arguments for the packet class, e.g.
packet- Returns:
the packet
- Return type:
- processPacket(pkt)[source]
Process a received packet.
Override it and call the base method first, which raises
PacketErrorfor packets of the wrong type inRADIUSAccessandRADIUSAccounting. To answer, create a reply withpkt.CreateReply()and send it withself.transport.write(reply.ReplyPacket(), pkt.source). If no reply is sent, the request is dropped. RaisePacketErrorto drop the packet with a one-line log message; other exceptions are logged with a traceback.- Parameters:
pkt (pyrad.packet.Packet) – received packet
- class pyrad.curved.RADIUSAccounting(*args: Any, **kwargs: Any)[source]
Bases:
RADIUSTwisted RADIUS accounting server.
Override
processPacket()and call the base method first, which drops all packets except Accounting-Requests.- Parameters:
hosts (dict[str, pyrad.server.RemoteHost or bytes]) – hosts allowed to send packets, mapping their IP address to a
pyrad.server.RemoteHostor to the secret. IPv4 clients of a socket bound to'::'are looked up by their IPv4 address. Unlikepyrad.server.Server, there is no'0.0.0.0'entry for all other hosts: packets from other hosts are dropped.dict (pyrad.dictionary.Dictionary) – RADIUS dictionary used to decode the packets, by default an empty dictionary
enforce_ma (bool) – drop Access-Requests without a Message-Authenticator (an invalid Message-Authenticator is always dropped)
enable_pkt_verify (bool) – drop Accounting-Requests with an invalid Request Authenticator
- createPacket(**kwargs)[source]
Create the packet object for a received datagram.
RADIUSAccesscreates apyrad.packet.AuthPacketandRADIUSAccountingapyrad.packet.AcctPacket. The base method raisesNotImplementedError; a class that doesn’t override it receives genericpyrad.packet.Packetobjects.- Parameters:
kwargs – arguments for the packet class, e.g.
packet- Returns:
the packet
- Return type:
- processPacket(pkt)[source]
Process a received packet.
Override it and call the base method first, which raises
PacketErrorfor packets of the wrong type inRADIUSAccessandRADIUSAccounting. To answer, create a reply withpkt.CreateReply()and send it withself.transport.write(reply.ReplyPacket(), pkt.source). If no reply is sent, the request is dropped. RaisePacketErrorto drop the packet with a one-line log message; other exceptions are logged with a traceback.- Parameters:
pkt (pyrad.packet.Packet) – received packet
- class pyrad.curved.PacketError[source]
A received packet is dropped.
Raised by
RADIUSAccess.processPacket()andRADIUSAccounting.processPacket()for packets of the wrong type. AprocessPacket()override may raise it to drop a packet: the drop is logged as one line instead of a traceback.This is not
pyrad.packet.PacketError, which it shadows in this module; packet handlers may raise either, orpyrad.server.ServerPacketError.