The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Macros | Functions | Variables
encode.c File Reference

Code common to EAP-SIM/AKA/AKA' clients and servers. More...

#include <freeradius-devel/io/test_point.h>
#include <freeradius-devel/server/module.h>
#include <freeradius-devel/tls/base.h>
#include <freeradius-devel/tls/strerror.h>
#include <freeradius-devel/util/dbuff.h>
#include <freeradius-devel/util/rand.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/sha1.h>
#include <freeradius-devel/eap/types.h>
#include "base.h"
#include "attrs.h"
#include "crypto_priv.h"
+ Include dependency graph for encode.c:

Go to the source code of this file.

Macros

#define SIM_MAX_ATTRIBUTE_VALUE_LEN   ((255 * 4) - 2) /* max length field value less Type + Length fields */
 

Functions

static int _test_ctx_free (UNUSED fr_aka_sim_ctx_t *ctx)
 
static ssize_t encode_array (fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, int depth, fr_dcursor_t *cursor, void *encode_ctx)
 Encodes the data portion of an attribute. More...
 
static ssize_t encode_encrypted_value (fr_dbuff_t *dbuff, uint8_t const *in, size_t inlen, void *encode_ctx)
 encrypt a value with AES-CBC-128 More...
 
static ssize_t encode_iv (fr_dbuff_t *dbuff, void *encode_ctx)
 Add an IV to a packet. More...
 
static ssize_t encode_rfc (fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, unsigned int depth, fr_dcursor_t *cursor, void *encode_ctx)
 Encode an RFC format attribute header. More...
 
static int encode_test_ctx_aka (void **out, TALLOC_CTX *ctx)
 
static int encode_test_ctx_sim (void **out, TALLOC_CTX *ctx)
 
static int encode_test_ctx_sim_rfc4186 (void **out, TALLOC_CTX *ctx)
 
static ssize_t encode_tlv (fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, unsigned int depth, fr_dcursor_t *cursor, void *encode_ctx)
 
static ssize_t encode_tlv_internal (fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, unsigned int depth, fr_dcursor_t *cursor, void *encode_ctx)
 
static ssize_t encode_value (fr_dbuff_t *dbuff, fr_da_stack_t *da_stack, int depth, fr_dcursor_t *cursor, void *encode_ctx)
 Encodes the data portion of an attribute. More...
 
ssize_t fr_aka_sim_encode (request_t *request, fr_pair_list_t *to_encode, void *encode_ctx)
 
ssize_t fr_aka_sim_encode_pair (fr_dbuff_t *dbuff, fr_dcursor_t *cursor, void *encode_ctx)
 
static bool is_eap_aka_encodable (void const *item, UNUSED void const *uctx)
 Evaluation function for EAP-AKA-encodability. More...
 
static fr_aka_sim_ctx_ttest_ctx_init (TALLOC_CTX *ctx, uint8_t const *k_encr, size_t k_encr_len)
 

Variables

fr_test_point_pair_encode_t aka_tp_encode
 
fr_test_point_pair_encode_t sim_tp_encode
 
fr_test_point_pair_encode_t sim_tp_encode_rfc4186
 

Detailed Description

Code common to EAP-SIM/AKA/AKA' clients and servers.

Definition in file encode.c.

Macro Definition Documentation

◆ SIM_MAX_ATTRIBUTE_VALUE_LEN

#define SIM_MAX_ATTRIBUTE_VALUE_LEN   ((255 * 4) - 2) /* max length field value less Type + Length fields */

Definition at line 40 of file encode.c.

Function Documentation

◆ _test_ctx_free()

static int _test_ctx_free ( UNUSED fr_aka_sim_ctx_t ctx)
static

Definition at line 989 of file encode.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encode_array()

static ssize_t encode_array ( fr_dbuff_t dbuff,
fr_da_stack_t da_stack,
int  depth,
fr_dcursor_t cursor,
void *  encode_ctx 
)
static

Encodes the data portion of an attribute.

       0                   1                   2                   3
       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       | AT_VERSION_L..| Length        | Actual Version List Length    |
       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       |  Supported Version 1          |  Supported Version 2          |
       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       .                                                               .
       .                                                               .
       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       | Supported Version N           |     Padding                   |
       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Definition at line 516 of file encode.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encode_encrypted_value()

static ssize_t encode_encrypted_value ( fr_dbuff_t dbuff,
uint8_t const *  in,
size_t  inlen,
void *  encode_ctx 
)
static

encrypt a value with AES-CBC-128

encrypts a value using AES-CBC-128, padding the value with AT_PADDING attributes until it matches the block length of the cipher (16).

May also write out an AT_IV attribute if this is the first encrypted value being encoded.

       1                   2                   3
       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       | AT_ENCR_DATA  | Length        |           Reserved            |
       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       |                                                               |
       .                    Encrypted Data                             .
       .                                                               .
       |                                                               |
       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Definition at line 155 of file encode.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encode_iv()

static ssize_t encode_iv ( fr_dbuff_t dbuff,
void *  encode_ctx 
)
static

Add an IV to a packet.

       0                   1                   2                   3
       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       |     AT_IV     | Length = 5    |           Reserved            |
       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       |                                                               |
       |                 Initialization Vector                         |
       |                                                               |
       |                                                               |
       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Definition at line 104 of file encode.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encode_rfc()

static ssize_t encode_rfc ( fr_dbuff_t dbuff,
fr_da_stack_t da_stack,
unsigned int  depth,
fr_dcursor_t cursor,
void *  encode_ctx 
)
static

Encode an RFC format attribute header.

This could be a standard attribute, or a TLV data type. If it's a standard attribute, then vp->da->attr == attribute. Otherwise, attribute may be something else.

Definition at line 587 of file encode.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encode_test_ctx_aka()

static int encode_test_ctx_aka ( void **  out,
TALLOC_CTX *  ctx 
)
static

Definition at line 1034 of file encode.c.

+ Here is the call graph for this function:

◆ encode_test_ctx_sim()

static int encode_test_ctx_sim ( void **  out,
TALLOC_CTX *  ctx 
)
static

Definition at line 1018 of file encode.c.

+ Here is the call graph for this function:

◆ encode_test_ctx_sim_rfc4186()

static int encode_test_ctx_sim_rfc4186 ( void **  out,
TALLOC_CTX *  ctx 
)
static

Definition at line 1050 of file encode.c.

+ Here is the call graph for this function:

◆ encode_tlv()

static ssize_t encode_tlv ( fr_dbuff_t dbuff,
fr_da_stack_t da_stack,
unsigned int  depth,
fr_dcursor_t cursor,
void *  encode_ctx 
)
static

Definition at line 736 of file encode.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encode_tlv_internal()

static ssize_t encode_tlv_internal ( fr_dbuff_t dbuff,
fr_da_stack_t da_stack,
unsigned int  depth,
fr_dcursor_t cursor,
void *  encode_ctx 
)
inlinestatic

Definition at line 652 of file encode.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ encode_value()

static ssize_t encode_value ( fr_dbuff_t dbuff,
fr_da_stack_t da_stack,
int  depth,
fr_dcursor_t cursor,
void *  encode_ctx 
)
static

Encodes the data portion of an attribute.

Returns
> 0, Length of the data portion. = 0, we could not encode anything, skip this attribute (and don't encode the header) < 0, failure.

Definition at line 272 of file encode.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_aka_sim_encode()

ssize_t fr_aka_sim_encode ( request_t request,
fr_pair_list_t to_encode,
void *  encode_ctx 
)

Definition at line 867 of file encode.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ fr_aka_sim_encode_pair()

ssize_t fr_aka_sim_encode_pair ( fr_dbuff_t dbuff,
fr_dcursor_t cursor,
void *  encode_ctx 
)

Definition at line 808 of file encode.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ is_eap_aka_encodable()

static bool is_eap_aka_encodable ( void const *  item,
UNUSED void const *  uctx 
)
static

Evaluation function for EAP-AKA-encodability.

Parameters
itempointer to a fr_pair_t
uctxcontext
Returns
true if the underlying fr_pair_t is EAP_AKA encodable, false otherwise

Definition at line 71 of file encode.c.

+ Here is the caller graph for this function:

◆ test_ctx_init()

static fr_aka_sim_ctx_t* test_ctx_init ( TALLOC_CTX *  ctx,
uint8_t const *  k_encr,
size_t  k_encr_len 
)
static

Definition at line 996 of file encode.c.

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ aka_tp_encode

Initial value:
= {
.test_ctx = encode_test_ctx_aka,
}
ssize_t fr_aka_sim_encode_pair(fr_dbuff_t *dbuff, fr_dcursor_t *cursor, void *encode_ctx)
Definition: encode.c:808
static int encode_test_ctx_aka(void **out, TALLOC_CTX *ctx)
Definition: encode.c:1034

Definition at line 1074 of file encode.c.

◆ sim_tp_encode

Initial value:
= {
.test_ctx = encode_test_ctx_sim,
}
static int encode_test_ctx_sim(void **out, TALLOC_CTX *ctx)
Definition: encode.c:1018

Definition at line 1068 of file encode.c.

◆ sim_tp_encode_rfc4186

fr_test_point_pair_encode_t sim_tp_encode_rfc4186
Initial value:
= {
}
static int encode_test_ctx_sim_rfc4186(void **out, TALLOC_CTX *ctx)
Definition: encode.c:1050

Definition at line 1080 of file encode.c.