radius_das.py 960 B

1234567891011121314151617181920212223242526272829
  1. #!/usr/bin/python
  2. #
  3. # RADIUS DAS extensions to pyrad
  4. # Copyright (c) 2014, Jouni Malinen <j@w1.fi>
  5. #
  6. # This software may be distributed under the terms of the BSD license.
  7. # See README for more details.
  8. import hashlib
  9. import random
  10. import struct
  11. import pyrad.packet
  12. class DisconnectPacket(pyrad.packet.Packet):
  13. def __init__(self, code=pyrad.packet.DisconnectRequest, id=None,
  14. secret=None, authenticator=None, **attributes):
  15. pyrad.packet.Packet.__init__(self, code, id, secret, authenticator,
  16. **attributes)
  17. def RequestPacket(self):
  18. attr = self._PktEncodeAttributes()
  19. if self.id is None:
  20. self.id = random.randrange(0, 256)
  21. header = struct.pack('!BBH', self.code, self.id, (20 + len(attr)))
  22. self.authenticator = hashlib.md5(header[0:4] + 16 * b'\x00' + attr
  23. + self.secret).digest()
  24. return header + self.authenticator + attr