radius.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. """Remote Authentication Dial-In User Service."""
  2. from pypacker import pypacker
  3. # http://www.untruth.org/~josh/security/radius/radius-auth.html
  4. # RFC 2865
  5. class Radius(pypacker.Packet):
  6. __hdr__ = (
  7. ("code", "B", 0),
  8. ("id", "B", 0),
  9. ("len", "H", 4),
  10. ("auth", "16s", b"")
  11. )
  12. # TODO: dead code
  13. @staticmethod
  14. def parse_attrs(buf):
  15. """
  16. Parse attributes buffer into a list of (type, data) tuples.
  17. """
  18. attrs = []
  19. while buf:
  20. t = ord(buf[0])
  21. l = ord(buf[1])
  22. if l < 2:
  23. break
  24. d, buf = buf[2:l], buf[l:]
  25. attrs.append((t, d))
  26. return attrs
  27. # Codes
  28. RADIUS_ACCESS_REQUEST = 1
  29. RADIUS_ACCESS_ACCEPT = 2
  30. RADIUS_ACCESS_REJECT = 3
  31. RADIUS_ACCT_REQUEST = 4
  32. RADIUS_ACCT_RESPONSE = 5
  33. RADIUS_ACCT_STATUS = 6
  34. RADIUS_ACCESS_CHALLENGE = 11
  35. # Attributes
  36. RADIUS_USER_NAME = 1
  37. RADIUS_USER_PASSWORD = 2
  38. RADIUS_CHAP_PASSWORD = 3
  39. RADIUS_NAS_IP_ADDR = 4
  40. RADIUS_NAS_PORT = 5
  41. RADIUS_SERVICE_TYPE = 6
  42. RADIUS_FRAMED_PROTOCOL = 7
  43. RADIUS_FRAMED_IP_ADDR = 8
  44. RADIUS_FRAMED_IP_NETMASK = 9
  45. RADIUS_FRAMED_ROUTING = 10
  46. RADIUS_FILTER_ID = 11
  47. RADIUS_FRAMED_MTU = 12
  48. RADIUS_FRAMED_COMPRESSION = 13
  49. RADIUS_LOGIN_IP_HOST = 14
  50. RADIUS_LOGIN_SERVICE = 15
  51. RADIUS_LOGIN_TCP_PORT = 16
  52. # unassigned
  53. RADIUS_REPLY_MESSAGE = 18
  54. RADIUS_CALLBACK_NUMBER = 19
  55. RADIUS_CALLBACK_ID = 20
  56. # unassigned
  57. RADIUS_FRAMED_ROUTE = 22
  58. RADIUS_FRAMED_IPX_NETWORK = 23
  59. RADIUS_STATE = 24
  60. RADIUS_CLASS = 25
  61. RADIUS_VENDOR_SPECIFIC = 26
  62. RADIUS_SESSION_TIMEOUT = 27
  63. RADIUS_IDLE_TIMEOUT = 28
  64. RADIUS_TERMINATION_ACTION = 29
  65. RADIUS_CALLED_STATION_ID = 30
  66. RADIUS_CALLING_STATION_ID = 31
  67. RADIUS_NAS_ID = 32
  68. RADIUS_PROXY_STATE = 33
  69. RADIUS_LOGIN_LAT_SERVICE = 34
  70. RADIUS_LOGIN_LAT_NODE = 35
  71. RADIUS_LOGIN_LAT_GROUP = 36
  72. RADIUS_FRAMED_ATALK_LINK = 37
  73. RADIUS_FRAMED_ATALK_NETWORK = 38
  74. RADIUS_FRAMED_ATALK_ZONE = 39
  75. # 40-59 reserved for accounting
  76. RADIUS_CHAP_CHALLENGE = 60
  77. RADIUS_NAS_PORT_TYPE = 61
  78. RADIUS_PORT_LIMIT = 62
  79. RADIUS_LOGIN_LAT_PORT = 63