xref: /freebsd/contrib/wpa/src/radius/radius_client.h (revision a90b9d0159070121c221b966469c3e36d912bf82)
139beb93cSSam Leffler /*
2e28a4053SRui Paulo  * RADIUS client
3*a90b9d01SCy Schubert  * Copyright (c) 2002-2024, Jouni Malinen <j@w1.fi>
439beb93cSSam Leffler  *
5f05cddf9SRui Paulo  * This software may be distributed under the terms of the BSD license.
6f05cddf9SRui Paulo  * See README for more details.
739beb93cSSam Leffler  */
839beb93cSSam Leffler 
939beb93cSSam Leffler #ifndef RADIUS_CLIENT_H
1039beb93cSSam Leffler #define RADIUS_CLIENT_H
1139beb93cSSam Leffler 
1239beb93cSSam Leffler #include "ip_addr.h"
1339beb93cSSam Leffler 
1439beb93cSSam Leffler struct radius_msg;
1539beb93cSSam Leffler 
16e28a4053SRui Paulo /**
17e28a4053SRui Paulo  * struct hostapd_radius_server - RADIUS server information for RADIUS client
18e28a4053SRui Paulo  *
19e28a4053SRui Paulo  * This structure contains information about a RADIUS server. The values are
20e28a4053SRui Paulo  * mainly for MIB information. The MIB variable prefix (radiusAuth or
21e28a4053SRui Paulo  * radiusAcc) depends on whether this is an authentication or accounting
22e28a4053SRui Paulo  * server.
23e28a4053SRui Paulo  *
24e28a4053SRui Paulo  * radiusAuthClientPendingRequests (or radiusAccClientPendingRequests) is the
25e28a4053SRui Paulo  * number struct radius_client_data::msgs for matching msg_type.
26e28a4053SRui Paulo  */
2739beb93cSSam Leffler struct hostapd_radius_server {
28e28a4053SRui Paulo 	/**
29e28a4053SRui Paulo 	 * addr - radiusAuthServerAddress or radiusAccServerAddress
30e28a4053SRui Paulo 	 */
31e28a4053SRui Paulo 	struct hostapd_ip_addr addr;
32e28a4053SRui Paulo 
33e28a4053SRui Paulo 	/**
34e28a4053SRui Paulo 	 * port - radiusAuthClientServerPortNumber or radiusAccClientServerPortNumber
35e28a4053SRui Paulo 	 */
36e28a4053SRui Paulo 	int port;
37e28a4053SRui Paulo 
38e28a4053SRui Paulo 	/**
39*a90b9d01SCy Schubert 	 * tls - Whether to use RADIUS/TLS instead of RADIUS/UDP
40*a90b9d01SCy Schubert 	 */
41*a90b9d01SCy Schubert 	bool tls;
42*a90b9d01SCy Schubert 
43*a90b9d01SCy Schubert 	/**
44e28a4053SRui Paulo 	 * shared_secret - Shared secret for authenticating RADIUS messages
45e28a4053SRui Paulo 	 */
4639beb93cSSam Leffler 	u8 *shared_secret;
47e28a4053SRui Paulo 
48e28a4053SRui Paulo 	/**
49e28a4053SRui Paulo 	 * shared_secret_len - Length of shared_secret in octets
50e28a4053SRui Paulo 	 */
5139beb93cSSam Leffler 	size_t shared_secret_len;
5239beb93cSSam Leffler 
53*a90b9d01SCy Schubert 	/**
54*a90b9d01SCy Schubert 	 * ca_cert - Path to trusted CA certificate(s) for RADIUS/TLS
55*a90b9d01SCy Schubert 	 */
56*a90b9d01SCy Schubert 	char *ca_cert;
57*a90b9d01SCy Schubert 
58*a90b9d01SCy Schubert 	/**
59*a90b9d01SCy Schubert 	 * client_cert - Path to client certificate for RADIUS/TLS
60*a90b9d01SCy Schubert 	 */
61*a90b9d01SCy Schubert 	char *client_cert;
62*a90b9d01SCy Schubert 
63*a90b9d01SCy Schubert 	/**
64*a90b9d01SCy Schubert 	 * private_key - Path to clienbt private key for RADIUS/TLS
65*a90b9d01SCy Schubert 	 */
66*a90b9d01SCy Schubert 	char *private_key;
67*a90b9d01SCy Schubert 
68*a90b9d01SCy Schubert 	/**
69*a90b9d01SCy Schubert 	 * private_key_passwd - Password for the private key for RADIUS/TLS
70*a90b9d01SCy Schubert 	 */
71*a90b9d01SCy Schubert 	char *private_key_passwd;
72*a90b9d01SCy Schubert 
7339beb93cSSam Leffler 	/* Dynamic (not from configuration file) MIB data */
74e28a4053SRui Paulo 
75e28a4053SRui Paulo 	/**
76e28a4053SRui Paulo 	 * index - radiusAuthServerIndex or radiusAccServerIndex
77e28a4053SRui Paulo 	 */
78e28a4053SRui Paulo 	int index;
79e28a4053SRui Paulo 
80e28a4053SRui Paulo 	/**
81e28a4053SRui Paulo 	 * round_trip_time - radiusAuthClientRoundTripTime or radiusAccClientRoundTripTime
82e28a4053SRui Paulo 	 * Round-trip time in hundredths of a second.
83e28a4053SRui Paulo 	 */
84e28a4053SRui Paulo 	int round_trip_time;
85e28a4053SRui Paulo 
86e28a4053SRui Paulo 	/**
87e28a4053SRui Paulo 	 * requests - radiusAuthClientAccessRequests or radiusAccClientRequests
88e28a4053SRui Paulo 	 */
89e28a4053SRui Paulo 	u32 requests;
90e28a4053SRui Paulo 
91e28a4053SRui Paulo 	/**
92e28a4053SRui Paulo 	 * retransmissions - radiusAuthClientAccessRetransmissions or radiusAccClientRetransmissions
93e28a4053SRui Paulo 	 */
94e28a4053SRui Paulo 	u32 retransmissions;
95e28a4053SRui Paulo 
96e28a4053SRui Paulo 	/**
97e28a4053SRui Paulo 	 * access_accepts - radiusAuthClientAccessAccepts
98e28a4053SRui Paulo 	 */
99e28a4053SRui Paulo 	u32 access_accepts;
100e28a4053SRui Paulo 
101e28a4053SRui Paulo 	/**
102e28a4053SRui Paulo 	 * access_rejects - radiusAuthClientAccessRejects
103e28a4053SRui Paulo 	 */
104e28a4053SRui Paulo 	u32 access_rejects;
105e28a4053SRui Paulo 
106e28a4053SRui Paulo 	/**
107e28a4053SRui Paulo 	 * access_challenges - radiusAuthClientAccessChallenges
108e28a4053SRui Paulo 	 */
109e28a4053SRui Paulo 	u32 access_challenges;
110e28a4053SRui Paulo 
111e28a4053SRui Paulo 	/**
112e28a4053SRui Paulo 	 * responses - radiusAccClientResponses
113e28a4053SRui Paulo 	 */
114e28a4053SRui Paulo 	u32 responses;
115e28a4053SRui Paulo 
116e28a4053SRui Paulo 	/**
117e28a4053SRui Paulo 	 * malformed_responses - radiusAuthClientMalformedAccessResponses or radiusAccClientMalformedResponses
118e28a4053SRui Paulo 	 */
119e28a4053SRui Paulo 	u32 malformed_responses;
120e28a4053SRui Paulo 
121e28a4053SRui Paulo 	/**
122e28a4053SRui Paulo 	 * bad_authenticators - radiusAuthClientBadAuthenticators or radiusAccClientBadAuthenticators
123e28a4053SRui Paulo 	 */
124e28a4053SRui Paulo 	u32 bad_authenticators;
125e28a4053SRui Paulo 
126e28a4053SRui Paulo 	/**
127e28a4053SRui Paulo 	 * timeouts - radiusAuthClientTimeouts or radiusAccClientTimeouts
128e28a4053SRui Paulo 	 */
129e28a4053SRui Paulo 	u32 timeouts;
130e28a4053SRui Paulo 
131e28a4053SRui Paulo 	/**
132e28a4053SRui Paulo 	 * unknown_types - radiusAuthClientUnknownTypes or radiusAccClientUnknownTypes
133e28a4053SRui Paulo 	 */
134e28a4053SRui Paulo 	u32 unknown_types;
135e28a4053SRui Paulo 
136e28a4053SRui Paulo 	/**
137e28a4053SRui Paulo 	 * packets_dropped - radiusAuthClientPacketsDropped or radiusAccClientPacketsDropped
138e28a4053SRui Paulo 	 */
139e28a4053SRui Paulo 	u32 packets_dropped;
14039beb93cSSam Leffler };
14139beb93cSSam Leffler 
142e28a4053SRui Paulo /**
143e28a4053SRui Paulo  * struct hostapd_radius_servers - RADIUS servers for RADIUS client
144e28a4053SRui Paulo  */
14539beb93cSSam Leffler struct hostapd_radius_servers {
146e28a4053SRui Paulo 	/**
147e28a4053SRui Paulo 	 * auth_servers - RADIUS Authentication servers in priority order
148e28a4053SRui Paulo 	 */
149e28a4053SRui Paulo 	struct hostapd_radius_server *auth_servers;
150e28a4053SRui Paulo 
151e28a4053SRui Paulo 	/**
152e28a4053SRui Paulo 	 * num_auth_servers - Number of auth_servers entries
153e28a4053SRui Paulo 	 */
15439beb93cSSam Leffler 	int num_auth_servers;
155e28a4053SRui Paulo 
156e28a4053SRui Paulo 	/**
157e28a4053SRui Paulo 	 * auth_server - The current Authentication server
158e28a4053SRui Paulo 	 */
159e28a4053SRui Paulo 	struct hostapd_radius_server *auth_server;
160e28a4053SRui Paulo 
161e28a4053SRui Paulo 	/**
162e28a4053SRui Paulo 	 * acct_servers - RADIUS Accounting servers in priority order
163e28a4053SRui Paulo 	 */
164e28a4053SRui Paulo 	struct hostapd_radius_server *acct_servers;
165e28a4053SRui Paulo 
166e28a4053SRui Paulo 	/**
167e28a4053SRui Paulo 	 * num_acct_servers - Number of acct_servers entries
168e28a4053SRui Paulo 	 */
16939beb93cSSam Leffler 	int num_acct_servers;
17039beb93cSSam Leffler 
171e28a4053SRui Paulo 	/**
172e28a4053SRui Paulo 	 * acct_server - The current Accounting server
173e28a4053SRui Paulo 	 */
174e28a4053SRui Paulo 	struct hostapd_radius_server *acct_server;
17539beb93cSSam Leffler 
176e28a4053SRui Paulo 	/**
177e28a4053SRui Paulo 	 * retry_primary_interval - Retry interval for trying primary server
178e28a4053SRui Paulo 	 *
179e28a4053SRui Paulo 	 * This specifies a retry interval in sexconds for trying to return to
180e28a4053SRui Paulo 	 * the primary RADIUS server. RADIUS client code will automatically try
181e28a4053SRui Paulo 	 * to use the next server when the current server is not replying to
182e28a4053SRui Paulo 	 * requests. If this interval is set (non-zero), the primary server
183e28a4053SRui Paulo 	 * will be retried after the specified number of seconds has passed
184e28a4053SRui Paulo 	 * even if the current used secondary server is still working.
185e28a4053SRui Paulo 	 */
186e28a4053SRui Paulo 	int retry_primary_interval;
187e28a4053SRui Paulo 
188e28a4053SRui Paulo 	/**
189e28a4053SRui Paulo 	 * msg_dumps - Whether RADIUS message details are shown in stdout
190e28a4053SRui Paulo 	 */
19139beb93cSSam Leffler 	int msg_dumps;
19239beb93cSSam Leffler 
193e28a4053SRui Paulo 	/**
194e28a4053SRui Paulo 	 * client_addr - Client (local) address to use if force_client_addr
195e28a4053SRui Paulo 	 */
19639beb93cSSam Leffler 	struct hostapd_ip_addr client_addr;
197e28a4053SRui Paulo 
198e28a4053SRui Paulo 	/**
199e28a4053SRui Paulo 	 * force_client_addr - Whether to force client (local) address
200e28a4053SRui Paulo 	 */
20139beb93cSSam Leffler 	int force_client_addr;
202c1d255d3SCy Schubert 
203c1d255d3SCy Schubert 	/**
204c1d255d3SCy Schubert 	 * force_client_dev - Bind the socket to a specified interface, if set
205c1d255d3SCy Schubert 	 */
206c1d255d3SCy Schubert 	char *force_client_dev;
20739beb93cSSam Leffler };
20839beb93cSSam Leffler 
20939beb93cSSam Leffler 
210e28a4053SRui Paulo /**
211e28a4053SRui Paulo  * RadiusType - RADIUS server type for RADIUS client
212e28a4053SRui Paulo  */
21339beb93cSSam Leffler typedef enum {
214e28a4053SRui Paulo 	/**
215e28a4053SRui Paulo 	 * RADIUS authentication
216e28a4053SRui Paulo 	 */
21739beb93cSSam Leffler 	RADIUS_AUTH,
218e28a4053SRui Paulo 
219e28a4053SRui Paulo 	/**
220e28a4053SRui Paulo 	 * RADIUS_ACCT - RADIUS accounting
221e28a4053SRui Paulo 	 */
22239beb93cSSam Leffler 	RADIUS_ACCT,
223e28a4053SRui Paulo 
224e28a4053SRui Paulo 	/**
225e28a4053SRui Paulo 	 * RADIUS_ACCT_INTERIM - RADIUS interim accounting message
226e28a4053SRui Paulo 	 *
227e28a4053SRui Paulo 	 * Used only with radius_client_send(). This behaves just like
228e28a4053SRui Paulo 	 * RADIUS_ACCT, but removes any pending interim RADIUS Accounting
229e28a4053SRui Paulo 	 * messages for the same STA before sending the new interim update.
230e28a4053SRui Paulo 	 */
231e28a4053SRui Paulo 	RADIUS_ACCT_INTERIM
23239beb93cSSam Leffler } RadiusType;
23339beb93cSSam Leffler 
234e28a4053SRui Paulo /**
235e28a4053SRui Paulo  * RadiusRxResult - RADIUS client RX handler result
236e28a4053SRui Paulo  */
23739beb93cSSam Leffler typedef enum {
238e28a4053SRui Paulo 	/**
239e28a4053SRui Paulo 	 * RADIUS_RX_PROCESSED - Message processed
240e28a4053SRui Paulo 	 *
241e28a4053SRui Paulo 	 * This stops handler calls and frees the message.
242e28a4053SRui Paulo 	 */
24339beb93cSSam Leffler 	RADIUS_RX_PROCESSED,
244e28a4053SRui Paulo 
245e28a4053SRui Paulo 	/**
246e28a4053SRui Paulo 	 * RADIUS_RX_QUEUED - Message has been queued
247e28a4053SRui Paulo 	 *
248e28a4053SRui Paulo 	 * This stops handler calls, but does not free the message; the handler
249e28a4053SRui Paulo 	 * that returned this is responsible for eventually freeing the
250e28a4053SRui Paulo 	 * message.
251e28a4053SRui Paulo 	 */
25239beb93cSSam Leffler 	RADIUS_RX_QUEUED,
253e28a4053SRui Paulo 
254e28a4053SRui Paulo 	/**
255e28a4053SRui Paulo 	 * RADIUS_RX_UNKNOWN - Message is not for this handler
256e28a4053SRui Paulo 	 */
25739beb93cSSam Leffler 	RADIUS_RX_UNKNOWN,
258e28a4053SRui Paulo 
259e28a4053SRui Paulo 	/**
260e28a4053SRui Paulo 	 * RADIUS_RX_INVALID_AUTHENTICATOR - Message has invalid Authenticator
261e28a4053SRui Paulo 	 */
26239beb93cSSam Leffler 	RADIUS_RX_INVALID_AUTHENTICATOR
26339beb93cSSam Leffler } RadiusRxResult;
26439beb93cSSam Leffler 
26539beb93cSSam Leffler struct radius_client_data;
26639beb93cSSam Leffler 
26739beb93cSSam Leffler int radius_client_register(struct radius_client_data *radius,
26839beb93cSSam Leffler 			   RadiusType msg_type,
26939beb93cSSam Leffler 			   RadiusRxResult (*handler)
27039beb93cSSam Leffler 			   (struct radius_msg *msg, struct radius_msg *req,
27139beb93cSSam Leffler 			    const u8 *shared_secret, size_t shared_secret_len,
27239beb93cSSam Leffler 			    void *data),
27339beb93cSSam Leffler 			   void *data);
274780fb4a2SCy Schubert void radius_client_set_interim_error_cb(struct radius_client_data *radius,
275780fb4a2SCy Schubert 					void (*cb)(const u8 *addr, void *ctx),
276780fb4a2SCy Schubert 					void *ctx);
27739beb93cSSam Leffler int radius_client_send(struct radius_client_data *radius,
27839beb93cSSam Leffler 		       struct radius_msg *msg,
27939beb93cSSam Leffler 		       RadiusType msg_type, const u8 *addr);
28039beb93cSSam Leffler u8 radius_client_get_id(struct radius_client_data *radius);
28139beb93cSSam Leffler void radius_client_flush(struct radius_client_data *radius, int only_auth);
28239beb93cSSam Leffler struct radius_client_data *
28339beb93cSSam Leffler radius_client_init(void *ctx, struct hostapd_radius_servers *conf);
28439beb93cSSam Leffler void radius_client_deinit(struct radius_client_data *radius);
285e28a4053SRui Paulo void radius_client_flush_auth(struct radius_client_data *radius,
286e28a4053SRui Paulo 			      const u8 *addr);
28739beb93cSSam Leffler int radius_client_get_mib(struct radius_client_data *radius, char *buf,
28839beb93cSSam Leffler 			  size_t buflen);
289f05cddf9SRui Paulo void radius_client_reconfig(struct radius_client_data *radius,
290f05cddf9SRui Paulo 			    struct hostapd_radius_servers *conf);
29139beb93cSSam Leffler 
29239beb93cSSam Leffler #endif /* RADIUS_CLIENT_H */
293