The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
Functions | Variables
decode.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/strerror.h>
#include <freeradius-devel/util/debug.h>
#include <freeradius-devel/util/sha1.h>
#include <freeradius-devel/util/decode.h>
#include <freeradius-devel/eap/types.h>
#include "attrs.h"
#include "base.h"
#include "crypto_priv.h"
+ Include dependency graph for decode.c:

Go to the source code of this file.

Functions

static int _test_ctx_free (UNUSED fr_aka_sim_ctx_t *ctx)
 
static int decode_test_ctx_aka (void **out, TALLOC_CTX *ctx)
 
static int decode_test_ctx_sim (void **out, TALLOC_CTX *ctx)
 
static int decode_test_ctx_sim_rfc4186 (void **out, TALLOC_CTX *ctx)
 
int fr_aka_sim_decode (TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_t const *dict, uint8_t const *data, size_t data_len, fr_aka_sim_ctx_t *decode_ctx)
 Decode SIM/AKA/AKA' specific packet data. More...
 
ssize_t fr_aka_sim_decode_pair (TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len, void *decode_ctx)
 Decode SIM/AKA/AKA' attributes. More...
 
static int sim_array_members (size_t *out, size_t len, fr_dict_attr_t const *da)
 Returns the number of array members for arrays with fixed element sizes. More...
 
static ssize_t sim_decode_array (TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t const attr_len, UNUSED size_t data_len, void *decode_ctx)
 
static ssize_t sim_decode_pair_internal (TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len, void *decode_ctx)
 Decode SIM/AKA/AKA' attributes. More...
 
static ssize_t sim_decode_pair_value (TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t const attr_len, size_t const data_len, void *decode_ctx)
 Create any kind of VP from the attribute contents. More...
 
static ssize_t sim_decode_tlv (TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t const attr_len, size_t data_len, void *decode_ctx)
 Break apart a TLV attribute into individual attributes. More...
 
static int sim_iv_extract (uint8_t out[AKA_SIM_IV_SIZE], uint8_t const *in, size_t in_len)
 Extract the IV value from an AT_IV attribute. More...
 
static ssize_t sim_value_decrypt (TALLOC_CTX *ctx, uint8_t **out, uint8_t const *data, size_t const attr_len, size_t const data_len, void *decode_ctx)
 Decrypt an AES-128-CBC encrypted attribute. 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_decode_t aka_tp_decode
 
fr_test_point_pair_decode_t sim_tp_decode
 
fr_test_point_pair_decode_t sim_tp_decode_rfc4186
 

Detailed Description

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

The development of the EAP-SIM support was funded by Internet Foundation Austria (http://www.nic.at/ipa).

Definition in file decode.c.

Function Documentation

◆ _test_ctx_free()

static int _test_ctx_free ( UNUSED fr_aka_sim_ctx_t ctx)
static

Definition at line 1004 of file decode.c.

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

◆ decode_test_ctx_aka()

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

Definition at line 1043 of file decode.c.

+ Here is the call graph for this function:

◆ decode_test_ctx_sim()

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

Definition at line 1026 of file decode.c.

+ Here is the call graph for this function:

◆ decode_test_ctx_sim_rfc4186()

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

Definition at line 1059 of file decode.c.

+ Here is the call graph for this function:

◆ fr_aka_sim_decode()

int fr_aka_sim_decode ( TALLOC_CTX *  ctx,
fr_pair_list_t out,
fr_dict_t const *  dict,
uint8_t const *  data,
size_t  data_len,
fr_aka_sim_ctx_t decode_ctx 
)

Decode SIM/AKA/AKA' specific packet data.

Note
data should point to the subtype field in the EAP packet.

Extracts the SUBTYPE and adds it an attribute, then decodes any TLVs in the SIM/AKA/AKA' 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 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Code | Identifier | Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Type | Subtype | Reserved | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

The first byte of the data pointer should be the subtype.

Parameters
[in]ctxwhere to allocate the pairs.
[in]outwhere to write out attributes.
[in]dictfor looking up attributes.
[in]datato convert to pairs.
[in]data_lenlength of data to convert.
[in]decode_ctxholds the state of the decoder.
Returns
  • 0 on success.
  • -1 on failure.

Definition at line 942 of file decode.c.

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

◆ fr_aka_sim_decode_pair()

ssize_t fr_aka_sim_decode_pair ( TALLOC_CTX *  ctx,
fr_pair_list_t out,
fr_dict_attr_t const *  parent,
uint8_t const *  data,
size_t  data_len,
void *  decode_ctx 
)

Decode SIM/AKA/AKA' attributes.

Parameters
[in]ctxto allocate attributes in.
[in]outwhere to insert the attributes.
[in]parentfor looking up attributes.
[in]datadata to parse.
[in]data_lenlength of data. For top level attributes packet_ctx must be the length of the packet (so we can hunt for AT_IV), for Sub-TLVs it should be the length of the container value.
[in]decode_ctxextra context to pass to the decoder.
Returns
  • The number of bytes parsed.
  • -1 on error.

Definition at line 909 of file decode.c.

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

◆ sim_array_members()

static int sim_array_members ( size_t out,
size_t  len,
fr_dict_attr_t const *  da 
)
static

Returns the number of array members for arrays with fixed element sizes.

Parameters
[out]outThe element length.
[in]lenthe total length of the array.
[in]dathe specifying the array type.
Returns
  • The number of elements in the array on success.
  • < 0 on error (array length not a multiple of element size).

Definition at line 250 of file decode.c.

+ Here is the caller graph for this function:

◆ sim_decode_array()

static ssize_t sim_decode_array ( TALLOC_CTX *  ctx,
fr_pair_list_t out,
fr_dict_attr_t const *  parent,
uint8_t const *  data,
size_t const  attr_len,
UNUSED size_t  data_len,
void *  decode_ctx 
)
static

Definition at line 297 of file decode.c.

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

◆ sim_decode_pair_internal()

static ssize_t sim_decode_pair_internal ( TALLOC_CTX *  ctx,
fr_pair_list_t out,
fr_dict_attr_t const *  parent,
uint8_t const *  data,
size_t  data_len,
void *  decode_ctx 
)
static

Decode SIM/AKA/AKA' attributes.

Parameters
[in]ctxto allocate attributes in.
[in]outwhere to insert the attributes.
[in]parentof current attribute being decoded.
[in]datadata to parse.
[in]data_lenlength of data. For top level attributes packet_ctx must be the length of the packet (so we can hunt for AT_IV), for Sub-TLVs it should be the length of the container value.
[in]decode_ctxextra context to pass to the decoder.
Returns
  • The number of bytes parsed.
  • -1 on error.

Definition at line 831 of file decode.c.

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

◆ sim_decode_pair_value()

static ssize_t sim_decode_pair_value ( TALLOC_CTX *  ctx,
fr_pair_list_t out,
fr_dict_attr_t const *  parent,
uint8_t const *  data,
size_t const  attr_len,
size_t const  data_len,
void *  decode_ctx 
)
static

Create any kind of VP from the attribute contents.

Parameters
[in]ctxto allocate new attributes in.
[in]outto add new attributes to.
[in]parentthe current attribute we're processing.
[in]datato parse. Points to the data field of the attribute.
[in]attr_lenlength of the attribute being parsed.
[in]data_lenlength of the remaining data in the packet.
[in]decode_ctxIVs, keys etc...
Returns
  • Length on success.
  • -1 on failure.

Definition at line 525 of file decode.c.

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

◆ sim_decode_tlv()

static ssize_t sim_decode_tlv ( TALLOC_CTX *  ctx,
fr_pair_list_t out,
fr_dict_attr_t const *  parent,
uint8_t const *  data,
size_t const  attr_len,
size_t  data_len,
void *  decode_ctx 
)
static

Break apart a TLV attribute into individual attributes.

Parameters
[in]ctxto allocate new attributes in.
[in]outto add new attributes to.
[in]parentthe current attribute TLV attribute we're processing.
[in]datato parse. Points to the data field of the attribute.
[in]attr_lenlength of the TLV attribute.
[in]data_lenremaining data in the packet.
[in]decode_ctxIVs, keys etc...
Returns
  • Length on success.
  • < 0 on malformed attribute.

Definition at line 368 of file decode.c.

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

◆ sim_iv_extract()

static int sim_iv_extract ( uint8_t  out[AKA_SIM_IV_SIZE],
uint8_t const *  in,
size_t  in_len 
)
inlinestatic

Extract the IV value from an AT_IV attribute.

SIM uses padding at the start of the attribute to make it a multiple of 4. We need to strip packet_ctx and check that it was set to zero.

Parameters
[out]outWhere to write IV.
[in]invalue of AT_IV attribute.
[in]in_lenthe length of the AT_IV attribute (should be 18).
Returns
  • 0 on success.
  • < 0 on failure (bad IV).

Definition at line 79 of file decode.c.

+ Here is the caller graph for this function:

◆ sim_value_decrypt()

static ssize_t sim_value_decrypt ( TALLOC_CTX *  ctx,
uint8_t **  out,
uint8_t const *  data,
size_t const  attr_len,
size_t const  data_len,
void *  decode_ctx 
)
static

Decrypt an AES-128-CBC encrypted attribute.

Parameters
[in]ctxto allocate decr buffer in.
[out]outwhere to write pointer to decr buffer.
[in]datato decrypt.
[in]attr_lenlength of encrypted data.
[in]data_lenlength of data remaining in the packet.
[in]decode_ctxcontaining keys, and the IV (if we already found it).
Returns
  • Number of decr bytes decrypted on success.
  • < 0 on failure.

Definition at line 115 of file decode.c.

+ Here is the call graph for this function:
+ 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 1011 of file decode.c.

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

Variable Documentation

◆ aka_tp_decode

Initial value:
= {
.test_ctx = decode_test_ctx_aka,
}
ssize_t fr_aka_sim_decode_pair(TALLOC_CTX *ctx, fr_pair_list_t *out, fr_dict_attr_t const *parent, uint8_t const *data, size_t data_len, void *decode_ctx)
Decode SIM/AKA/AKA' attributes.
Definition: decode.c:909
static int decode_test_ctx_aka(void **out, TALLOC_CTX *ctx)
Definition: decode.c:1043

Definition at line 1089 of file decode.c.

◆ sim_tp_decode

Initial value:
= {
.test_ctx = decode_test_ctx_sim,
}
static int decode_test_ctx_sim(void **out, TALLOC_CTX *ctx)
Definition: decode.c:1026

Definition at line 1077 of file decode.c.

◆ sim_tp_decode_rfc4186

fr_test_point_pair_decode_t sim_tp_decode_rfc4186
Initial value:
= {
}
static int decode_test_ctx_sim_rfc4186(void **out, TALLOC_CTX *ctx)
Definition: decode.c:1059

Definition at line 1083 of file decode.c.