From: Jouni Malinen Date: Sat, 6 Feb 2016 14:27:52 +0000 (+0200) Subject: RADIUS: Share a single function for generating session IDs X-Git-Tag: hostap_2_6~938 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1fc63fe2998c6d4218b503e90d6c6fe4075f05ba;p=thirdparty%2Fhostap.git RADIUS: Share a single function for generating session IDs There is no need to maintain three copies of this functionality even if it is currently implemented as a single function call. Signed-off-by: Jouni Malinen --- diff --git a/src/ap/accounting.c b/src/ap/accounting.c index 22684a68c..f3ce1215c 100644 --- a/src/ap/accounting.c +++ b/src/ap/accounting.c @@ -379,13 +379,8 @@ void accounting_sta_stop(struct hostapd_data *hapd, struct sta_info *sta) int accounting_sta_get_id(struct hostapd_data *hapd, struct sta_info *sta) { - /* - * Acct-Session-Id should be globally and temporarily unique. - * A high quality random number is required therefore. - * This could be be improved by switching to a GUID. - */ - return os_get_random((u8 *) &sta->acct_session_id, - sizeof(sta->acct_session_id)); + return radius_gen_session_id((u8 *) &sta->acct_session_id, + sizeof(sta->acct_session_id)); } @@ -454,13 +449,8 @@ static void accounting_report_state(struct hostapd_data *hapd, int on) */ int accounting_init(struct hostapd_data *hapd) { - /* - * Acct-Session-Id should be globally and temporarily unique. - * A high quality random number is required therefore. - * This could be be improved by switching to a GUID. - */ - if (os_get_random((u8 *) &hapd->acct_session_id, - sizeof(hapd->acct_session_id)) < 0) + if (radius_gen_session_id((u8 *) &hapd->acct_session_id, + sizeof(hapd->acct_session_id)) < 0) return -1; if (radius_client_register(hapd->radius, RADIUS_ACCT, diff --git a/src/eapol_auth/eapol_auth_sm.c b/src/eapol_auth/eapol_auth_sm.c index 62db368e7..ff673bb2e 100644 --- a/src/eapol_auth/eapol_auth_sm.c +++ b/src/eapol_auth/eapol_auth_sm.c @@ -866,16 +866,13 @@ eapol_auth_alloc(struct eapol_authenticator *eapol, const u8 *addr, sm->radius_cui = wpabuf_alloc_copy(radius_cui, os_strlen(radius_cui)); - /* - * Acct-Multi-Session-Id should be globally and temporarily unique. - * A high quality random number is required therefore. - * This could be be improved by switching to a GUID. - */ - if (os_get_random((u8 *) &sm->acct_multi_session_id, - sizeof(sm->acct_multi_session_id)) < 0) { +#ifndef CONFIG_NO_RADIUS + if (radius_gen_session_id((u8 *) &sm->acct_multi_session_id, + sizeof(sm->acct_multi_session_id)) < 0) { eapol_auth_free(sm); return NULL; } +#endif /* CONFIG_NO_RADIUS */ return sm; } diff --git a/src/radius/radius.c b/src/radius/radius.c index d48a4b54c..77f998074 100644 --- a/src/radius/radius.c +++ b/src/radius/radius.c @@ -1656,3 +1656,14 @@ u8 radius_msg_find_unlisted_attr(struct radius_msg *msg, u8 *attrs) return 0; } + + +int radius_gen_session_id(u8 *id, size_t len) +{ + /* + * Acct-Session-Id and Acct-Multi-Session-Id should be globally and + * temporarily unique. A high quality random number is required + * therefore. This could be be improved by switching to a GUID. + */ + return os_get_random(id, len); +} diff --git a/src/radius/radius.h b/src/radius/radius.h index 9218c94d4..313fc650f 100644 --- a/src/radius/radius.h +++ b/src/radius/radius.h @@ -319,4 +319,6 @@ int radius_copy_class(struct radius_class_data *dst, u8 radius_msg_find_unlisted_attr(struct radius_msg *msg, u8 *attrs); +int radius_gen_session_id(u8 *id, size_t len); + #endif /* RADIUS_H */