Functions to send/receive radius packets. More...
#include <freeradius-devel/libradius.h>
#include <freeradius-devel/md5.h>
#include <freeradius-devel/udp.h>
#include <fcntl.h>
#include <ctype.h>
Go to the source code of this file.
Data Structures | |
struct | radius_packet_t |
Macros | |
#define | FR_DEBUG_STRERROR_PRINTF if (fr_debug_lvl) fr_strerror_printf |
#define | MAX_PACKET_LEN 4096 |
Typedefs | |
typedef struct radius_packet_t | radius_packet_t |
Functions | |
static int | calc_acctdigest (RADIUS_PACKET *packet, char const *secret) |
Validates the requesting client NAS. More... | |
static int | calc_replydigest (RADIUS_PACKET *packet, RADIUS_PACKET *original, char const *secret) |
Validates the requesting client NAS. More... | |
void | fr_printf_log (char const *fmt,...) |
RADIUS_PACKET * | fr_radius_alloc (TALLOC_CTX *ctx, bool new_vector) |
Allocate a new RADIUS_PACKET. More... | |
RADIUS_PACKET * | fr_radius_alloc_reply (TALLOC_CTX *ctx, RADIUS_PACKET *packet) |
Allocate a new RADIUS_PACKET response. More... | |
RADIUS_PACKET * | fr_radius_copy (TALLOC_CTX *ctx, RADIUS_PACKET const *in) |
Duplicate a RADIUS_PACKET. More... | |
int | fr_radius_decode (RADIUS_PACKET *packet, RADIUS_PACKET *original, char const *secret) |
Calculate/check digest, and decode radius attributes. More... | |
int | fr_radius_digest_cmp (uint8_t const *a, uint8_t const *b, size_t length) |
Do a comparison of two authentication digests by comparing the FULL digest. More... | |
int | fr_radius_encode (RADIUS_PACKET *packet, RADIUS_PACKET const *original, char const *secret) |
Encode a packet. More... | |
void | fr_radius_free (RADIUS_PACKET **radius_packet_ptr) |
Free a RADIUS_PACKET. More... | |
ssize_t | fr_radius_len (uint8_t const *data, size_t data_len) |
See how big of a packet is in the buffer. More... | |
void | fr_radius_make_secret (uint8_t *digest, uint8_t const *vector, char const *secret, uint8_t const *value) |
Build an encrypted secret value to return in a reply packet. More... | |
bool | fr_radius_ok (RADIUS_PACKET *packet, int flags, decode_fail_t *reason) |
See if the data pointed to by PTR is a valid RADIUS packet. More... | |
void | fr_radius_print_hex (RADIUS_PACKET *packet) |
RADIUS_PACKET * | fr_radius_recv (TALLOC_CTX *ctx, int fd, int flags) |
Receive UDP client requests, and fill in the basics of a RADIUS_PACKET structure. More... | |
ssize_t | fr_radius_recv_header (int sockfd, fr_ipaddr_t *src_ipaddr, uint16_t *src_port, unsigned int *code) |
Basic validation of RADIUS packet header. More... | |
int | fr_radius_send (RADIUS_PACKET *packet, RADIUS_PACKET const *original, char const *secret) |
Reply to the request. More... | |
int | fr_radius_sign (RADIUS_PACKET *packet, RADIUS_PACKET const *original, char const *secret) |
Sign a previously encoded packet. More... | |
int | fr_radius_verify (RADIUS_PACKET *packet, RADIUS_PACKET *original, char const *secret) |
Verify the Request/Response Authenticator (and Message-Authenticator if present) of a packet. More... | |
uint32_t | fr_rand (void) |
Return a 32-bit random number. More... | |
void | fr_rand_seed (void const *data, size_t size) |
Seed the random number generator. More... | |
static void | print_hex_data (uint8_t const *ptr, int attrlen, int depth) |
static ssize_t | rad_recvfrom (int sockfd, RADIUS_PACKET *packet, int flags) |
Wrapper for recvfrom, which handles recvfromto, IPv6, and all possible combinations. More... | |
Variables | |
FILE * | fr_log_fp = NULL |
uint32_t | fr_max_attributes = 0 |
char const * | fr_packet_codes [FR_MAX_PACKET_CODE] |
static _fr_thread_local bool | fr_rand_initialized = false |
static _fr_thread_local fr_randctx | fr_rand_pool |
A pool of pre-generated random integers. More... | |
FR_NAME_NUMBER const | fr_request_types [] |
Functions to send/receive radius packets.
Functions to encode RADIUS attributes.
Functions to decode RADIUS attributes.
Definition in file radius.c.
struct radius_packet_t |
Data Fields | ||
---|---|---|
uint8_t | code | |
uint8_t | data[1] | |
uint8_t | id | |
uint8_t | length[2] | |
uint8_t | vector[AUTH_VECTOR_LEN] |
#define FR_DEBUG_STRERROR_PRINTF if (fr_debug_lvl) fr_strerror_printf |
typedef struct radius_packet_t radius_packet_t |
|
static |
|
static |
RADIUS_PACKET* fr_radius_alloc | ( | TALLOC_CTX * | ctx, |
bool | new_vector | ||
) |
Allocate a new RADIUS_PACKET.
ctx | the context in which the packet is allocated. May be NULL if the packet is not associated with a REQUEST. |
new_vector | if true a new request authenticator will be generated. |
Definition at line 1651 of file radius.c.
RADIUS_PACKET* fr_radius_alloc_reply | ( | TALLOC_CTX * | ctx, |
RADIUS_PACKET * | packet | ||
) |
Allocate a new RADIUS_PACKET response.
ctx | the context in which the packet is allocated. May be NULL if the packet is not associated with a REQUEST. |
packet | The request packet. |
Definition at line 1691 of file radius.c.
RADIUS_PACKET* fr_radius_copy | ( | TALLOC_CTX * | ctx, |
RADIUS_PACKET const * | in | ||
) |
Duplicate a RADIUS_PACKET.
ctx | the context in which the packet is allocated. May be NULL if the packet is not associated with a REQUEST. |
in | The packet to copy |
Definition at line 1751 of file radius.c.
int fr_radius_decode | ( | RADIUS_PACKET * | packet, |
RADIUS_PACKET * | original, | ||
char const * | secret | ||
) |
int fr_radius_digest_cmp | ( | uint8_t const * | a, |
uint8_t const * | b, | ||
size_t | length | ||
) |
Do a comparison of two authentication digests by comparing the FULL digest.
Otherwise, the server can be subject to timing attacks that allow attackers find a valid message authenticator.
http://www.cs.rice.edu/~dwallach/pub/crosby-timing2009.pdf
Definition at line 578 of file radius.c.
int fr_radius_encode | ( | RADIUS_PACKET * | packet, |
RADIUS_PACKET const * | original, | ||
char const * | secret | ||
) |
void fr_radius_free | ( | RADIUS_PACKET ** | radius_packet_ptr | ) |
ssize_t fr_radius_len | ( | uint8_t const * | data, |
size_t | data_len | ||
) |
See how big of a packet is in the buffer.
Packet is not 'const * const' because we may update data_len, if there's more data in the UDP packet than in the RADIUS packet.
data | pointer to the packet buffer |
data_len | length of the packet buffer |
void fr_radius_make_secret | ( | uint8_t * | digest, |
uint8_t const * | vector, | ||
char const * | secret, | ||
uint8_t const * | value | ||
) |
Build an encrypted secret value to return in a reply packet.
The secret is hidden by xoring with a MD5 digest created from the shared secret and the authentication vector. We put them into MD5 in the reverse order from that used when encrypting passwords to RADIUS.
Definition at line 272 of file radius.c.
bool fr_radius_ok | ( | RADIUS_PACKET * | packet, |
int | flags, | ||
decode_fail_t * | reason | ||
) |
See if the data pointed to by PTR is a valid RADIUS packet.
Packet is not 'const * const' because we may update data_len, if there's more data in the UDP packet than in the RADIUS packet.
packet | to check |
flags | to control decoding |
reason | if not NULL, will have the failure reason written to where it points. |
Definition at line 731 of file radius.c.
void fr_radius_print_hex | ( | RADIUS_PACKET * | packet | ) |
RADIUS_PACKET* fr_radius_recv | ( | TALLOC_CTX * | ctx, |
int | fd, | ||
int | flags | ||
) |
ssize_t fr_radius_recv_header | ( | int | sockfd, |
fr_ipaddr_t * | src_ipaddr, | ||
uint16_t * | src_port, | ||
unsigned int * | code | ||
) |
Basic validation of RADIUS packet header.
[in] | sockfd | we're reading from. |
[out] | src_ipaddr | of the packet. |
[out] | src_port | of the packet. |
[out] | code | Pointer to where to write the packet code. |
Definition at line 299 of file radius.c.
int fr_radius_send | ( | RADIUS_PACKET * | packet, |
RADIUS_PACKET const * | original, | ||
char const * | secret | ||
) |
int fr_radius_sign | ( | RADIUS_PACKET * | packet, |
RADIUS_PACKET const * | original, | ||
char const * | secret | ||
) |
int fr_radius_verify | ( | RADIUS_PACKET * | packet, |
RADIUS_PACKET * | original, | ||
char const * | secret | ||
) |
uint32_t fr_rand | ( | void | ) |
void fr_rand_seed | ( | void const * | data, |
size_t | size | ||
) |
|
static |
|
static |
char const* fr_packet_codes[FR_MAX_PACKET_CODE] |
|
static |
FR_NAME_NUMBER const fr_request_types[] |