29 RCSIDH(sim_h,
"$Id: 580ba78df839b1f446bb8671e18bc34a259696b1 $")
33 #include <freeradius-devel/tls/openssl_user_macros.h>
34 #include <openssl/evp.h>
35 #include <freeradius-devel/eap/compose.h>
36 #include <freeradius-devel/eap/types.h>
40 #define AKA_SIM_MAX_STRING_LENGTH 1016U
41 #define AKA_SIM_IV_SIZE 16U
42 #define AKA_SIM_MAC_DIGEST_SIZE 16U
43 #define AKA_SIM_MAC_SIZE 20U
44 #define AKA_SIM_AUTH_SIZE 16U
45 #define AKA_SIM_SQN_AK_SIZE 6U
46 #define AKA_SIM_NONCE_S_SIZE 16U
48 #define AKA_SIM_KI_SIZE 16U
49 #define AKA_SIM_OP_SIZE 16U
50 #define AKA_SIM_OPC_SIZE 16U
52 #define AKA_SIM_MK_MAX_SIZE 208U
54 #define AKA_SIM_MK_SIZE 20U
55 #define AKA_PRIME_MK_SIZE 208U
57 #define AKA_PRIME_MK_REAUTH_SIZE 80U
61 #define AKA_SIM_K_RE_SIZE 32U
63 #define AKA_SIM_SKIPPABLE_MAX 127U
65 #define AKA_SIM_VECTOR_GSM_RAND_SIZE 16U
66 #define AKA_SIM_VECTOR_GSM_SRES_SIZE 4U
67 #define AKA_SIM_VECTOR_GSM_KC_SIZE 8U
69 #define AKA_SIM_VECTOR_UMTS_AUTN_SIZE 16U
70 #define AKA_SIM_VECTOR_UMTS_CK_SIZE 16U
71 #define AKA_SIM_VECTOR_UMTS_IK_SIZE 16U
72 #define AKA_SIM_VECTOR_UMTS_AK_SIZE 6U
73 #define AKA_SIM_VECTOR_UMTS_RAND_SIZE 16U
74 #define AKA_SIM_VECTOR_UMTS_XRES_MAX_SIZE 16U
76 #define EAP_SIM_VERSION 1U
77 #define EAP_SIM_NONCE_MT_SIZE 16U
79 #define EAP_AKA_SIM_AUTH_SIZE 16U
82 #define EAP_AKA_AUTS_SIZE 14U
84 #define EAP_AKA_AUTH_SIZE 16U
85 #define EAP_AKA_PRIME_AUTH_SIZE 32U
270 #define fr_aka_sim_flag_encrypted(_da) fr_aka_sim_attr_flags(_da)->encrypt
276 uint8_t const *
data,
size_t data_len,
void *decode_ctx);
311 EVP_MD
const *md,
uint8_t const *key,
size_t const key_len,
312 uint8_t const *hmac_extra,
size_t const hmac_extra_len);
Structure to hold EAP data.
@ FR_DICT_ATTR_EXT_PROTOCOL_SPECIFIC
Protocol specific extensions.
static void * fr_dict_attr_ext(fr_dict_attr_t const *da, fr_dict_attr_ext_t ext)
uint8_t * identity
Identity from AT_IDENTITY.
int fr_aka_sim_crypto_umts_kdf_0(fr_aka_sim_keys_t *keys)
Key Derivation Function as described in RFC4187 (EAP-AKA) section 7.
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.
int fr_aka_sim_crypto_umts_kdf_1_reauth(fr_aka_sim_keys_t *keys)
Key Derivation Function (Fast-Reauthentication) as described in RFC 5448 (EAP-AKA') section 3....
#define AKA_SIM_MK_MAX_SIZE
Master key size, 20 for EAP-SIM/EAP-AKA.
size_t fr_aka_sim_attr_len(fr_pair_t const *vp)
Return the on-the-wire length of an attribute value.
#define AKA_SIM_VECTOR_UMTS_RAND_SIZE
#define AKA_SIM_VECTOR_GSM_RAND_SIZE
Length of RAND in GSM triplet.
ssize_t fr_aka_sim_crypto_sign_packet(uint8_t out[static AKA_SIM_MAC_DIGEST_SIZE], eap_packet_t *eap_packet, bool zero_mac, EVP_MD const *md, uint8_t const *key, size_t const key_len, uint8_t const *hmac_extra, size_t const hmac_extra_len)
Calculate the digest value for a packet.
#define EAP_SIM_NONCE_MT_SIZE
Length of challenge from SIM client.
#define AKA_SIM_IV_SIZE
Length of the IV used when processing AT_ENCR.
#define AKA_SIM_VECTOR_UMTS_AK_SIZE
void fr_aka_sim_free(void)
uint8_t * network
Network name (EAP-AKA-Prime only).
void fr_aka_sim_fips186_2prf(uint8_t out[static 160], uint8_t mk[static 20])
Implement the FIPS-186-2 PRF to derive keying material from the MK.
int fr_aka_sim_xlat_func_register(void)
void fr_aka_sim_crypto_keys_log(request_t *request, fr_aka_sim_keys_t *keys)
Dump the current state of all keys associated with the EAP SIM session.
#define AKA_SIM_VECTOR_GSM_SRES_SIZE
Length of SRES in GSM triplet.
size_t network_len
Length of the network name (EAP-AKA-Prime only).
#define AKA_SIM_NONCE_S_SIZE
Length of re-authentication nonce.
void fr_aka_sim_crypto_keys_init_umts_kdf_1_reauth(fr_aka_sim_keys_t *keys, uint8_t const mk[static AKA_PRIME_MK_REAUTH_SIZE], uint16_t counter)
Initialise fr_aka_sim_keys_t with EAP-AKA['] reauthentication data.
ssize_t fr_aka_sim_encode_pair(fr_dbuff_t *dbuff, fr_dcursor_t *cursor, void *encode_ctx)
uint64_t sqn
Sequence number.
size_t xres_len
Length of res (it's variable).
int fr_aka_sim_crypto_kdf_0_reauth(fr_aka_sim_keys_t *keys)
Key Derivation Function (Fast-Reauthentication) as described in RFC4186/7 (EAP-SIM/AKA) section 7.
int fr_aka_sim_init(void)
size_t fr_aka_sim_octets_prefix_len(fr_dict_attr_t const *da)
Return the number of bytes before the octets value.
int fr_aka_sim_vector_gsm_umts_kdf_0_reauth_from_attrs(request_t *request, fr_pair_list_t *vps, fr_aka_sim_keys_t *keys)
Populate a fr_aka_sim_keys_t structure from attributes in the session-state list.
bool have_iv
Whether we found the IV already.
uint8_t const * k_aut
The authentication key used for signing.
#define AKA_PRIME_MK_REAUTH_SIZE
The portion of the MK used for re-auth.
fr_aka_sim_attr_flags_encrypt_t
@ AKA_SIM_FLAG_ENCRYPT_AES_CBC
Encrypt attribute RFC 2865 style.
@ AKA_SIM_FLAG_ENCRYPT_NONE
No encryption.
@ AKA_SIM_FLAG_ENCRYPT_INVALID
Invalid encryption flag.
#define AKA_SIM_K_RE_SIZE
Reauthentication key size.
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.
ssize_t fr_aka_sim_crypto_finalise_checkcode(TALLOC_CTX *ctx, uint8_t **out, fr_aka_sim_checkcode_t *checkcode)
Write out the final checkcode value.
void fr_aka_sim_vector_umts_reauth_clear(fr_aka_sim_keys_t *keys)
Clear reauth data if reauthentication failed.
fr_aka_sim_vector_src_t
Where to get EAP-SIM vectors from.
@ AKA_SIM_VECTOR_SRC_REAUTH
Not a vector.
@ AKA_SIM_VECTOR_SRC_AUTO
Discover where to get Triplets from automatically.
@ AKA_SIM_VECTOR_SRC_QUINTUPLETS
Source of triplets is derived from EAP-AKA-* quintuplets.
@ AKA_SIM_VECTOR_SRC_KI
Should generate triplets locally using a Ki.
@ AKA_SIM_VECTOR_SRC_TRIPLETS
Source of triplets is EAP-SIM-* attributes.
int fr_aka_sim_crypto_gsm_kdf_0(fr_aka_sim_keys_t *keys)
Key Derivation Function as described in RFC4186 (EAP-SIM) section 7.
static fr_aka_sim_attr_flags_t const * fr_aka_sim_attr_flags(fr_dict_attr_t const *da)
#define AKA_SIM_KI_SIZE
Length of secret data shared between SIM and AuC.
EVP_MD const * hmac_md
HMAC digest algorithm, usually EVP_sha1().
#define AKA_SIM_VECTOR_UMTS_XRES_MAX_SIZE
eap_packet_t * eap_packet
Needed for validating AT_MAC.
#define AKA_SIM_VECTOR_UMTS_CK_SIZE
size_t identity_len
Length of the identity.
void fr_aka_sim_crypto_keys_init_kdf_0_reauth(fr_aka_sim_keys_t *keys, uint8_t const mk[static AKA_SIM_MK_SIZE], uint16_t counter)
Initialise fr_aka_sim_keys_t with EAP-SIM reauthentication data.
EVP_MD const * checkcode_md
HMAC we use for calculating the checkcode.
uint8_t const * k_encr
The encryption key used for encrypting.
#define AKA_SIM_VECTOR_GSM_KC_SIZE
Length of Kc in GSM triplet.
size_t k_aut_len
Length of k_aut. 16 for AKA/SIM, 32 for AKA'.
fr_aka_sim_attr_flags_encrypt_t encrypt
Attribute has a tag and is encrypted.
uint8_t const * hmac_extra
Extra data for the HMAC function.
#define AKA_SIM_MAC_DIGEST_SIZE
Length of MAC used to prevent packet modification.
int fr_aka_sim_crypto_umts_kdf_1(fr_aka_sim_keys_t *keys)
Key Derivation Function as described in RFC 5448 (EAP-AKA') section 3.3.
#define AKA_SIM_VECTOR_UMTS_IK_SIZE
int fr_aka_sim_crypto_update_checkcode(fr_aka_sim_checkcode_t *checkcode, eap_packet_t *eap_packet)
Digest a packet, updating the checkcode.
int fr_aka_sim_vector_gsm_from_attrs(request_t *request, fr_pair_list_t *vps, int idx, fr_aka_sim_keys_t *keys, fr_aka_sim_vector_src_t *src)
Retrieve GSM triplets from sets of attributes.
ssize_t fr_aka_sim_encode(request_t *request, fr_pair_list_t *to_encode, void *encode_ctx)
#define AKA_SIM_VECTOR_UMTS_AUTN_SIZE
int fr_aka_sim_vector_umts_kdf_1_reauth_from_attrs(request_t *request, fr_pair_list_t *vps, fr_aka_sim_keys_t *keys)
Populate a fr_aka_sim_keys_t structure from attributes in the session-state list.
#define AKA_SIM_OPC_SIZE
Length of modified Operator Algorithm Configuration.
EVP_MD_CTX * md_ctx
Context to hold state of digest as we consume packets.
fr_aka_sim_vector_type_t
The type of auth vector held by a fr_aka_sim_keys_t.
@ AKA_SIM_VECTOR_GSM
Vector is GSM triplets.
@ AKA_SIM_VECTOR_UMTS_REAUTH_KDF_1_REAUTH
@ AKA_SIM_VECTOR_UMTS
Vector is UMTS quintuplets.
@ AKA_SIM_VECTOR_UMTS_REAUTH_KDF_0_REAUTH
int fr_aka_sim_crypto_init_checkcode(TALLOC_CTX *ctx, fr_aka_sim_checkcode_t **checkcode, EVP_MD const *md)
Initialise checkcode message digest.
int fr_aka_sim_umts_resync_from_attrs(uint64_t *new_sqn, request_t *request, fr_pair_t *auts_vp, fr_aka_sim_keys_t *keys)
Perform milenage AUTS validation and resynchronisation.
int fr_aka_sim_vector_umts_from_attrs(request_t *request, fr_pair_list_t *vps, fr_aka_sim_keys_t *keys, fr_aka_sim_vector_src_t *src)
Retrieve UMTS quintuplets from sets of attributes.
void fr_aka_sim_xlat_func_unregister(void)
size_t const fr_aka_sim_attr_sizes[FR_TYPE_MAX+1][2]
SIM AT on-the-wire format attribute sizes.
Stores our checkcode state.
Master key state struct for all SIMlike EAP protocols.
@ FR_TYPE_MAX
Number of defined data types.
static fr_internal_encode_ctx_t encode_ctx
RADIUS bio handlers for tracking 8-bit IDs.
Stores an attribute, a value and various bits of other data.
#define FR_MAX_STRING_LEN
static size_t char ** out