radius.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. /*
  2. * RADIUS message processing
  3. * Copyright (c) 2002-2009, 2012, 2014-2015, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #ifndef RADIUS_H
  9. #define RADIUS_H
  10. /* RFC 2865 - RADIUS */
  11. #ifdef _MSC_VER
  12. #pragma pack(push, 1)
  13. #endif /* _MSC_VER */
  14. struct radius_hdr {
  15. u8 code;
  16. u8 identifier;
  17. be16 length; /* including this header */
  18. u8 authenticator[16];
  19. /* followed by length-20 octets of attributes */
  20. } STRUCT_PACKED;
  21. enum { RADIUS_CODE_ACCESS_REQUEST = 1,
  22. RADIUS_CODE_ACCESS_ACCEPT = 2,
  23. RADIUS_CODE_ACCESS_REJECT = 3,
  24. RADIUS_CODE_ACCOUNTING_REQUEST = 4,
  25. RADIUS_CODE_ACCOUNTING_RESPONSE = 5,
  26. RADIUS_CODE_ACCESS_CHALLENGE = 11,
  27. RADIUS_CODE_STATUS_SERVER = 12,
  28. RADIUS_CODE_STATUS_CLIENT = 13,
  29. RADIUS_CODE_DISCONNECT_REQUEST = 40,
  30. RADIUS_CODE_DISCONNECT_ACK = 41,
  31. RADIUS_CODE_DISCONNECT_NAK = 42,
  32. RADIUS_CODE_COA_REQUEST = 43,
  33. RADIUS_CODE_COA_ACK = 44,
  34. RADIUS_CODE_COA_NAK = 45,
  35. RADIUS_CODE_RESERVED = 255
  36. };
  37. struct radius_attr_hdr {
  38. u8 type;
  39. u8 length; /* including this header */
  40. /* followed by length-2 octets of attribute value */
  41. } STRUCT_PACKED;
  42. #define RADIUS_MAX_ATTR_LEN (255 - sizeof(struct radius_attr_hdr))
  43. enum { RADIUS_ATTR_USER_NAME = 1,
  44. RADIUS_ATTR_USER_PASSWORD = 2,
  45. RADIUS_ATTR_NAS_IP_ADDRESS = 4,
  46. RADIUS_ATTR_NAS_PORT = 5,
  47. RADIUS_ATTR_SERVICE_TYPE = 6,
  48. RADIUS_ATTR_FRAMED_IP_ADDRESS = 8,
  49. RADIUS_ATTR_FRAMED_MTU = 12,
  50. RADIUS_ATTR_REPLY_MESSAGE = 18,
  51. RADIUS_ATTR_STATE = 24,
  52. RADIUS_ATTR_CLASS = 25,
  53. RADIUS_ATTR_VENDOR_SPECIFIC = 26,
  54. RADIUS_ATTR_SESSION_TIMEOUT = 27,
  55. RADIUS_ATTR_IDLE_TIMEOUT = 28,
  56. RADIUS_ATTR_TERMINATION_ACTION = 29,
  57. RADIUS_ATTR_CALLED_STATION_ID = 30,
  58. RADIUS_ATTR_CALLING_STATION_ID = 31,
  59. RADIUS_ATTR_NAS_IDENTIFIER = 32,
  60. RADIUS_ATTR_PROXY_STATE = 33,
  61. RADIUS_ATTR_ACCT_STATUS_TYPE = 40,
  62. RADIUS_ATTR_ACCT_DELAY_TIME = 41,
  63. RADIUS_ATTR_ACCT_INPUT_OCTETS = 42,
  64. RADIUS_ATTR_ACCT_OUTPUT_OCTETS = 43,
  65. RADIUS_ATTR_ACCT_SESSION_ID = 44,
  66. RADIUS_ATTR_ACCT_AUTHENTIC = 45,
  67. RADIUS_ATTR_ACCT_SESSION_TIME = 46,
  68. RADIUS_ATTR_ACCT_INPUT_PACKETS = 47,
  69. RADIUS_ATTR_ACCT_OUTPUT_PACKETS = 48,
  70. RADIUS_ATTR_ACCT_TERMINATE_CAUSE = 49,
  71. RADIUS_ATTR_ACCT_MULTI_SESSION_ID = 50,
  72. RADIUS_ATTR_ACCT_LINK_COUNT = 51,
  73. RADIUS_ATTR_ACCT_INPUT_GIGAWORDS = 52,
  74. RADIUS_ATTR_ACCT_OUTPUT_GIGAWORDS = 53,
  75. RADIUS_ATTR_EVENT_TIMESTAMP = 55,
  76. RADIUS_ATTR_EGRESS_VLANID = 56,
  77. RADIUS_ATTR_NAS_PORT_TYPE = 61,
  78. RADIUS_ATTR_TUNNEL_TYPE = 64,
  79. RADIUS_ATTR_TUNNEL_MEDIUM_TYPE = 65,
  80. RADIUS_ATTR_TUNNEL_PASSWORD = 69,
  81. RADIUS_ATTR_CONNECT_INFO = 77,
  82. RADIUS_ATTR_EAP_MESSAGE = 79,
  83. RADIUS_ATTR_MESSAGE_AUTHENTICATOR = 80,
  84. RADIUS_ATTR_TUNNEL_PRIVATE_GROUP_ID = 81,
  85. RADIUS_ATTR_ACCT_INTERIM_INTERVAL = 85,
  86. RADIUS_ATTR_CHARGEABLE_USER_IDENTITY = 89,
  87. RADIUS_ATTR_NAS_IPV6_ADDRESS = 95,
  88. RADIUS_ATTR_ERROR_CAUSE = 101,
  89. RADIUS_ATTR_EAP_KEY_NAME = 102,
  90. RADIUS_ATTR_OPERATOR_NAME = 126,
  91. RADIUS_ATTR_LOCATION_INFO = 127,
  92. RADIUS_ATTR_LOCATION_DATA = 128,
  93. RADIUS_ATTR_BASIC_LOCATION_POLICY_RULES = 129,
  94. RADIUS_ATTR_EXTENDED_LOCATION_POLICY_RULES = 130,
  95. RADIUS_ATTR_LOCATION_CAPABLE = 131,
  96. RADIUS_ATTR_REQUESTED_LOCATION_INFO = 132,
  97. RADIUS_ATTR_GSS_ACCEPTOR_SERVICE_NAME = 164,
  98. RADIUS_ATTR_GSS_ACCEPTOR_HOST_NAME = 165,
  99. RADIUS_ATTR_GSS_ACCEPTOR_SERVICE_SPECIFICS = 166,
  100. RADIUS_ATTR_GSS_ACCEPTOR_REALM_NAME = 167,
  101. RADIUS_ATTR_MOBILITY_DOMAIN_ID = 177,
  102. RADIUS_ATTR_WLAN_HESSID = 181,
  103. RADIUS_ATTR_WLAN_REASON_CODE = 185,
  104. RADIUS_ATTR_WLAN_PAIRWISE_CIPHER = 186,
  105. RADIUS_ATTR_WLAN_GROUP_CIPHER = 187,
  106. RADIUS_ATTR_WLAN_AKM_SUITE = 188,
  107. RADIUS_ATTR_WLAN_GROUP_MGMT_CIPHER = 189,
  108. };
  109. /* Service-Type values (RFC 2865, 5.6) */
  110. #define RADIUS_SERVICE_TYPE_FRAMED 2
  111. /* Termination-Action */
  112. #define RADIUS_TERMINATION_ACTION_DEFAULT 0
  113. #define RADIUS_TERMINATION_ACTION_RADIUS_REQUEST 1
  114. /* NAS-Port-Type */
  115. #define RADIUS_NAS_PORT_TYPE_IEEE_802_11 19
  116. /* Acct-Status-Type */
  117. #define RADIUS_ACCT_STATUS_TYPE_START 1
  118. #define RADIUS_ACCT_STATUS_TYPE_STOP 2
  119. #define RADIUS_ACCT_STATUS_TYPE_INTERIM_UPDATE 3
  120. #define RADIUS_ACCT_STATUS_TYPE_ACCOUNTING_ON 7
  121. #define RADIUS_ACCT_STATUS_TYPE_ACCOUNTING_OFF 8
  122. /* Acct-Authentic */
  123. #define RADIUS_ACCT_AUTHENTIC_RADIUS 1
  124. #define RADIUS_ACCT_AUTHENTIC_LOCAL 2
  125. #define RADIUS_ACCT_AUTHENTIC_REMOTE 3
  126. /* Acct-Terminate-Cause */
  127. #define RADIUS_ACCT_TERMINATE_CAUSE_USER_REQUEST 1
  128. #define RADIUS_ACCT_TERMINATE_CAUSE_LOST_CARRIER 2
  129. #define RADIUS_ACCT_TERMINATE_CAUSE_LOST_SERVICE 3
  130. #define RADIUS_ACCT_TERMINATE_CAUSE_IDLE_TIMEOUT 4
  131. #define RADIUS_ACCT_TERMINATE_CAUSE_SESSION_TIMEOUT 5
  132. #define RADIUS_ACCT_TERMINATE_CAUSE_ADMIN_RESET 6
  133. #define RADIUS_ACCT_TERMINATE_CAUSE_ADMIN_REBOOT 7
  134. #define RADIUS_ACCT_TERMINATE_CAUSE_PORT_ERROR 8
  135. #define RADIUS_ACCT_TERMINATE_CAUSE_NAS_ERROR 9
  136. #define RADIUS_ACCT_TERMINATE_CAUSE_NAS_REQUEST 10
  137. #define RADIUS_ACCT_TERMINATE_CAUSE_NAS_REBOOT 11
  138. #define RADIUS_ACCT_TERMINATE_CAUSE_PORT_UNNEEDED 12
  139. #define RADIUS_ACCT_TERMINATE_CAUSE_PORT_PREEMPTED 13
  140. #define RADIUS_ACCT_TERMINATE_CAUSE_PORT_SUSPENDED 14
  141. #define RADIUS_ACCT_TERMINATE_CAUSE_SERVICE_UNAVAILABLE 15
  142. #define RADIUS_ACCT_TERMINATE_CAUSE_CALLBACK 16
  143. #define RADIUS_ACCT_TERMINATE_CAUSE_USER_ERROR 17
  144. #define RADIUS_ACCT_TERMINATE_CAUSE_HOST_REQUEST 18
  145. #define RADIUS_TUNNEL_TAGS 32
  146. /* Tunnel-Type */
  147. #define RADIUS_TUNNEL_TYPE_PPTP 1
  148. #define RADIUS_TUNNEL_TYPE_L2TP 3
  149. #define RADIUS_TUNNEL_TYPE_IPIP 7
  150. #define RADIUS_TUNNEL_TYPE_GRE 10
  151. #define RADIUS_TUNNEL_TYPE_VLAN 13
  152. /* Tunnel-Medium-Type */
  153. #define RADIUS_TUNNEL_MEDIUM_TYPE_IPV4 1
  154. #define RADIUS_TUNNEL_MEDIUM_TYPE_IPV6 2
  155. #define RADIUS_TUNNEL_MEDIUM_TYPE_802 6
  156. struct radius_attr_vendor {
  157. u8 vendor_type;
  158. u8 vendor_length;
  159. } STRUCT_PACKED;
  160. #define RADIUS_VENDOR_ID_CISCO 9
  161. #define RADIUS_CISCO_AV_PAIR 1
  162. /* RFC 2548 - Microsoft Vendor-specific RADIUS Attributes */
  163. #define RADIUS_VENDOR_ID_MICROSOFT 311
  164. enum { RADIUS_VENDOR_ATTR_MS_MPPE_SEND_KEY = 16,
  165. RADIUS_VENDOR_ATTR_MS_MPPE_RECV_KEY = 17
  166. };
  167. /* Hotspot 2.0 - WFA Vendor-specific RADIUS Attributes */
  168. #define RADIUS_VENDOR_ID_WFA 40808
  169. enum {
  170. RADIUS_VENDOR_ATTR_WFA_HS20_SUBSCR_REMEDIATION = 1,
  171. RADIUS_VENDOR_ATTR_WFA_HS20_AP_VERSION = 2,
  172. RADIUS_VENDOR_ATTR_WFA_HS20_STA_VERSION = 3,
  173. RADIUS_VENDOR_ATTR_WFA_HS20_DEAUTH_REQ = 4,
  174. RADIUS_VENDOR_ATTR_WFA_HS20_SESSION_INFO_URL = 5,
  175. };
  176. #ifdef _MSC_VER
  177. #pragma pack(pop)
  178. #endif /* _MSC_VER */
  179. struct radius_ms_mppe_keys {
  180. u8 *send;
  181. size_t send_len;
  182. u8 *recv;
  183. size_t recv_len;
  184. };
  185. struct radius_msg;
  186. /* Default size to be allocated for new RADIUS messages */
  187. #define RADIUS_DEFAULT_MSG_SIZE 1024
  188. /* Default size to be allocated for attribute array */
  189. #define RADIUS_DEFAULT_ATTR_COUNT 16
  190. /* MAC address ASCII format for IEEE 802.1X use
  191. * (draft-congdon-radius-8021x-20.txt) */
  192. #define RADIUS_802_1X_ADDR_FORMAT "%02X-%02X-%02X-%02X-%02X-%02X"
  193. /* MAC address ASCII format for non-802.1X use */
  194. #define RADIUS_ADDR_FORMAT "%02x%02x%02x%02x%02x%02x"
  195. struct radius_hdr * radius_msg_get_hdr(struct radius_msg *msg);
  196. struct wpabuf * radius_msg_get_buf(struct radius_msg *msg);
  197. struct radius_msg * radius_msg_new(u8 code, u8 identifier);
  198. void radius_msg_free(struct radius_msg *msg);
  199. void radius_msg_dump(struct radius_msg *msg);
  200. int radius_msg_finish(struct radius_msg *msg, const u8 *secret,
  201. size_t secret_len);
  202. int radius_msg_finish_srv(struct radius_msg *msg, const u8 *secret,
  203. size_t secret_len, const u8 *req_authenticator);
  204. int radius_msg_finish_das_resp(struct radius_msg *msg, const u8 *secret,
  205. size_t secret_len,
  206. const struct radius_hdr *req_hdr);
  207. void radius_msg_finish_acct(struct radius_msg *msg, const u8 *secret,
  208. size_t secret_len);
  209. void radius_msg_finish_acct_resp(struct radius_msg *msg, const u8 *secret,
  210. size_t secret_len,
  211. const u8 *req_authenticator);
  212. int radius_msg_verify_acct_req(struct radius_msg *msg, const u8 *secret,
  213. size_t secret_len);
  214. int radius_msg_verify_das_req(struct radius_msg *msg, const u8 *secret,
  215. size_t secret_len,
  216. int require_message_authenticator);
  217. struct radius_attr_hdr * radius_msg_add_attr(struct radius_msg *msg, u8 type,
  218. const u8 *data, size_t data_len);
  219. struct radius_msg * radius_msg_parse(const u8 *data, size_t len);
  220. int radius_msg_add_eap(struct radius_msg *msg, const u8 *data,
  221. size_t data_len);
  222. struct wpabuf * radius_msg_get_eap(struct radius_msg *msg);
  223. int radius_msg_verify(struct radius_msg *msg, const u8 *secret,
  224. size_t secret_len, struct radius_msg *sent_msg,
  225. int auth);
  226. int radius_msg_verify_msg_auth(struct radius_msg *msg, const u8 *secret,
  227. size_t secret_len, const u8 *req_auth);
  228. int radius_msg_copy_attr(struct radius_msg *dst, struct radius_msg *src,
  229. u8 type);
  230. int radius_msg_make_authenticator(struct radius_msg *msg);
  231. struct radius_ms_mppe_keys *
  232. radius_msg_get_ms_keys(struct radius_msg *msg, struct radius_msg *sent_msg,
  233. const u8 *secret, size_t secret_len);
  234. struct radius_ms_mppe_keys *
  235. radius_msg_get_cisco_keys(struct radius_msg *msg, struct radius_msg *sent_msg,
  236. const u8 *secret, size_t secret_len);
  237. int radius_msg_add_mppe_keys(struct radius_msg *msg,
  238. const u8 *req_authenticator,
  239. const u8 *secret, size_t secret_len,
  240. const u8 *send_key, size_t send_key_len,
  241. const u8 *recv_key, size_t recv_key_len);
  242. int radius_msg_add_wfa(struct radius_msg *msg, u8 subtype, const u8 *data,
  243. size_t len);
  244. int radius_user_password_hide(struct radius_msg *msg,
  245. const u8 *data, size_t data_len,
  246. const u8 *secret, size_t secret_len,
  247. u8 *buf, size_t buf_len);
  248. struct radius_attr_hdr *
  249. radius_msg_add_attr_user_password(struct radius_msg *msg,
  250. const u8 *data, size_t data_len,
  251. const u8 *secret, size_t secret_len);
  252. int radius_msg_get_attr(struct radius_msg *msg, u8 type, u8 *buf, size_t len);
  253. int radius_msg_get_vlanid(struct radius_msg *msg, int *untagged, int numtagged,
  254. int *tagged);
  255. char * radius_msg_get_tunnel_password(struct radius_msg *msg, int *keylen,
  256. const u8 *secret, size_t secret_len,
  257. struct radius_msg *sent_msg, size_t n);
  258. static inline int radius_msg_add_attr_int32(struct radius_msg *msg, u8 type,
  259. u32 value)
  260. {
  261. u32 val = htonl(value);
  262. return radius_msg_add_attr(msg, type, (u8 *) &val, 4) != NULL;
  263. }
  264. static inline int radius_msg_get_attr_int32(struct radius_msg *msg, u8 type,
  265. u32 *value)
  266. {
  267. u32 val;
  268. int res;
  269. res = radius_msg_get_attr(msg, type, (u8 *) &val, 4);
  270. if (res != 4)
  271. return -1;
  272. *value = ntohl(val);
  273. return 0;
  274. }
  275. int radius_msg_get_attr_ptr(struct radius_msg *msg, u8 type, u8 **buf,
  276. size_t *len, const u8 *start);
  277. int radius_msg_count_attr(struct radius_msg *msg, u8 type, int min_len);
  278. struct radius_attr_data {
  279. u8 *data;
  280. size_t len;
  281. };
  282. struct radius_class_data {
  283. struct radius_attr_data *attr;
  284. size_t count;
  285. };
  286. void radius_free_class(struct radius_class_data *c);
  287. int radius_copy_class(struct radius_class_data *dst,
  288. const struct radius_class_data *src);
  289. u8 radius_msg_find_unlisted_attr(struct radius_msg *msg, u8 *attrs);
  290. int radius_gen_session_id(u8 *id, size_t len);
  291. #endif /* RADIUS_H */