pyrad.client – basic client
Blocking RADIUS client.
- class pyrad.client.Timeout[source]
Raised by
Client.SendPacket()when no valid reply was received.pyrad.client_async.ClientAsyncfails its futures withTimeoutErrorinstead.
- class pyrad.client.Client(server, authport=1812, acctport=1813, coaport=3799, secret=b'', dict=None, retries=3, timeout=5, enforce_ma=False)[source]
Basic blocking RADIUS client.
Sends requests to one RADIUS server, retransmits them if no reply is received and verifies the replies. Packets are created with
CreateAuthPacket(),CreateAcctPacket()andCreateCoAPacket()and sent withSendPacket().- Variables:
server – hostname or IP address of the RADIUS server
secret – RADIUS secret shared with the server
retries – maximum number of times a request is sent in total (
0never sends it and raisesTimeout)timeout – number of seconds to wait for a reply after each send
enforce_ma – require a Message-Authenticator in replies to Access-Request and Status-Server packets
- Parameters:
server (str) – hostname or IP address of the RADIUS server
authport (int) – server port for authentication packets
acctport (int) – server port for accounting packets
coaport (int) – server port for CoA and Disconnect packets
secret (bytes) – RADIUS secret
dict (pyrad.dictionary.Dictionary) – RADIUS dictionary
retries (int) – maximum number of times a request is sent in total
timeout (float) – number of seconds to wait for a reply after each send
enforce_ma (bool) – require a Message-Authenticator in replies to Access-Request and Status-Server packets (a Message-Authenticator in a reply is always verified)
- CreateAcctPacket(**args)[source]
Create an accounting packet for the server of this client.
The packet has the dictionary and secret of the client. The keyword arguments are passed to
pyrad.packet.AcctPacket: packet arguments (code,id,authenticator,message_authenticator,packet) and attributes to add, with-in the attribute names replaced by_. The default code is Accounting-Request;code=pyrad.packet.StatusServercreates a Status-Server packet to the accounting port.- Returns:
a new packet
- Return type:
- CreateAuthPacket(**args)[source]
Create an authentication packet for the server of this client.
The packet has the dictionary and secret of the client. The keyword arguments are passed to
pyrad.packet.AuthPacket: packet arguments (code,id,authenticator,auth_type,message_authenticator,packet) and attributes to add, with-in the attribute names replaced by_. The default code is Access-Request, usecode=pyrad.packet.StatusServerfor a Status-Server packet to the authentication port.A Message-Authenticator is added when the packet is encoded, as countermeasure against the BlastRADIUS attack (CVE-2024-3596); disable it with
message_authenticator=False.For PAP the password must be encrypted:
pkt['User-Password'] = pkt.PwCrypt(password). For EAP-MD5 passauth_type='eap-md5'and set the cleartext password as User-Password, seeSendPacket().- Returns:
a new packet
- Return type:
- CreateCoAPacket(**args)[source]
Create a CoA-Request or Disconnect-Request for this client’s server.
The packet has the dictionary and secret of the client. The keyword arguments are passed to
pyrad.packet.CoAPacket: packet arguments (code,id,authenticator,message_authenticator,packet) and attributes to add, with-in the attribute names replaced by_. The default code is CoA-Request, passcode=pyrad.packet.DisconnectRequestfor a Disconnect-Request.- Returns:
a new packet
- Return type:
- SendPacket(pkt)[source]
Send a request to the RADIUS server and wait for a valid reply.
The port depends on the packet class: an
AuthPacket(also a Status-Server created withCreateAuthPacket()) is sent toauthport, aCoAPackettocoaportand any other packet (also a Status-ServerAcctPacket) toacctport.The request is sent at most
retriestimes, waitingtimeoutseconds for a reply after each send. Invalid replies are ignored: a wrong Response Authenticator or Message-Authenticator, a Proxy-State that was not sent, or a missing Message-Authenticator withenforce_ma. Before an Accounting-Request is sent again, its Acct-Delay-Time is increased bytimeout(this modifiespkt).With
auth_type='eap-md5'the client authenticates with EAP-MD5 (RFC 3748, RFC 3579): the EAP-Response/Identity carries the User-Name, and User-Password holds the cleartext password, which is used for the MD5 response but not sent. The Access-Challenge of the server is answered automatically, sopktends up with an EAP-Message, the State of the challenge and a new id.- Parameters:
pkt (pyrad.packet.Packet) – the request to send
- Returns:
the reply; check
reply.code, e.g. Access-Accept or Access-Reject- Return type:
- Raises:
Timeout – no valid reply was received
ValueError –
auth_type='eap-md5'without User-Name or User-Password, or an attribute value that cannot be encodedOSError – the socket fails, e.g. the server name cannot be resolved