Use message instead of attributes in hook
This commit is contained in:
committed by
Martin Willi
parent
b3b74e479b
commit
ed5fc4cafe
@@ -450,27 +450,20 @@ static void remove_hooks(private_sim_manager_t *this, sim_hooks_t *hooks)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Implementation of sim_manager_t.attribute_hook
|
* Implementation of sim_manager_t.message_hook
|
||||||
*/
|
*/
|
||||||
static bool attribute_hook(private_sim_manager_t *this, eap_code_t code,
|
static void message_hook(private_sim_manager_t *this,
|
||||||
eap_type_t type, u_int8_t subtype,
|
simaka_message_t *message, bool inbound, bool decrypted)
|
||||||
u_int8_t attribute, chunk_t data)
|
|
||||||
{
|
{
|
||||||
enumerator_t *enumerator;
|
enumerator_t *enumerator;
|
||||||
sim_hooks_t *hooks;
|
sim_hooks_t *hooks;
|
||||||
bool filter = FALSE;
|
|
||||||
|
|
||||||
enumerator = this->hooks->create_enumerator(this->hooks);
|
enumerator = this->hooks->create_enumerator(this->hooks);
|
||||||
while (enumerator->enumerate(enumerator, &hooks))
|
while (enumerator->enumerate(enumerator, &hooks))
|
||||||
{
|
{
|
||||||
if (hooks->attribute(hooks, code, type, subtype, attribute, data))
|
hooks->message(hooks, message, inbound, decrypted);
|
||||||
{
|
|
||||||
filter = TRUE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
enumerator->destroy(enumerator);
|
enumerator->destroy(enumerator);
|
||||||
return filter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -528,7 +521,7 @@ sim_manager_t *sim_manager_create()
|
|||||||
this->public.provider_gen_reauth = (identification_t*(*)(sim_manager_t*, identification_t *id, char mk[HASH_SIZE_SHA1]))provider_gen_reauth;
|
this->public.provider_gen_reauth = (identification_t*(*)(sim_manager_t*, identification_t *id, char mk[HASH_SIZE_SHA1]))provider_gen_reauth;
|
||||||
this->public.add_hooks = (void(*)(sim_manager_t*, sim_hooks_t *hooks))add_hooks;
|
this->public.add_hooks = (void(*)(sim_manager_t*, sim_hooks_t *hooks))add_hooks;
|
||||||
this->public.remove_hooks = (void(*)(sim_manager_t*, sim_hooks_t *hooks))remove_hooks;
|
this->public.remove_hooks = (void(*)(sim_manager_t*, sim_hooks_t *hooks))remove_hooks;
|
||||||
this->public.attribute_hook = (bool(*)(sim_manager_t*, eap_code_t code, eap_type_t type, u_int8_t subtype, u_int8_t attribute, chunk_t data))attribute_hook;
|
this->public.message_hook = (void(*)(sim_manager_t*, simaka_message_t *message, bool inbound, bool decrypted))message_hook;
|
||||||
this->public.key_hook = (void(*)(sim_manager_t*, chunk_t k_encr, chunk_t k_auth))key_hook;
|
this->public.key_hook = (void(*)(sim_manager_t*, chunk_t k_encr, chunk_t k_auth))key_hook;
|
||||||
this->public.destroy = (void(*)(sim_manager_t*))destroy;
|
this->public.destroy = (void(*)(sim_manager_t*))destroy;
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ typedef struct sim_card_t sim_card_t;
|
|||||||
typedef struct sim_provider_t sim_provider_t;
|
typedef struct sim_provider_t sim_provider_t;
|
||||||
typedef struct sim_hooks_t sim_hooks_t;
|
typedef struct sim_hooks_t sim_hooks_t;
|
||||||
|
|
||||||
|
/** implemented in libsimaka, but we need it for the message hook */
|
||||||
|
typedef struct simaka_message_t simaka_message_t;
|
||||||
|
|
||||||
#define SIM_RAND_LEN 16
|
#define SIM_RAND_LEN 16
|
||||||
#define SIM_SRES_LEN 4
|
#define SIM_SRES_LEN 4
|
||||||
#define SIM_KC_LEN 8
|
#define SIM_KC_LEN 8
|
||||||
@@ -245,17 +248,17 @@ struct sim_provider_t {
|
|||||||
struct sim_hooks_t {
|
struct sim_hooks_t {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SIM/AKA attribute parsing hook.
|
* SIM/AKA message parsing.
|
||||||
*
|
*
|
||||||
* @param code code of EAP message the attribute was parsed from
|
* As a SIM/AKA optionally contains encrypted attributes, the hook
|
||||||
* @param type EAP method, SIM or AKA
|
* might get invoked twice, once before and once after decryption.
|
||||||
* @param subtye method specific subtype
|
*
|
||||||
* @param attribute parsed SIM/AKA attribute type
|
* @param message SIM/AKA message
|
||||||
* @param data attribute data
|
* @param inbound TRUE for incoming messages, FALSE for outgoing
|
||||||
* @return TRUE to filter out attribute from further processing
|
* @param decrypted TRUE if AT_ENCR_DATA has been decrypted
|
||||||
*/
|
*/
|
||||||
bool (*attribute)(sim_hooks_t *this, eap_code_t code, eap_type_t type,
|
void (*message)(sim_hooks_t *this, simaka_message_t *message,
|
||||||
u_int8_t subtype, u_int8_t attribute, chunk_t data);
|
bool inbound, bool decrypted);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SIM/AKA encryption/authentication key hooks.
|
* SIM/AKA encryption/authentication key hooks.
|
||||||
@@ -478,18 +481,14 @@ struct sim_manager_t {
|
|||||||
void (*remove_hooks)(sim_manager_t *this, sim_hooks_t *hooks);
|
void (*remove_hooks)(sim_manager_t *this, sim_hooks_t *hooks);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoke SIM/AKA attribute hook.
|
* Invoke SIM/AKA message hook.
|
||||||
*
|
*
|
||||||
* @param code EAP message code (Request/response/success/failed)
|
* @param message SIM message
|
||||||
* @param type EAP method type, EAP-SIM or AKA
|
* @param inbound TRUE for incoming messages, FALSE for outgoing
|
||||||
* @param subtype method specific message subtype
|
* @param decrypted TRUE if AT_ENCR_DATA has been decrypted
|
||||||
* @param attribute SIM/AKA attribute type
|
|
||||||
* @param data attribute data
|
|
||||||
* @return TRUE to filter out attribute from further processing
|
|
||||||
*/
|
*/
|
||||||
bool (*attribute_hook)(sim_manager_t *this, eap_code_t code,
|
void (*message_hook)(sim_manager_t *this, simaka_message_t *message,
|
||||||
eap_type_t type, u_int8_t subtype,
|
bool inbound, bool decrypted);
|
||||||
u_int8_t attribute, chunk_t data);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoke SIM/AKA key hook.
|
* Invoke SIM/AKA key hook.
|
||||||
|
|||||||
@@ -256,16 +256,12 @@ static void add_attribute(private_simaka_message_t *this,
|
|||||||
{
|
{
|
||||||
attr_t *attr;
|
attr_t *attr;
|
||||||
|
|
||||||
if (!charon->sim->attribute_hook(charon->sim, this->hdr->code,
|
attr = malloc(sizeof(attr_t) + data.len);
|
||||||
this->hdr->type, this->hdr->subtype, type, data))
|
attr->len = data.len;
|
||||||
{
|
attr->type = type;
|
||||||
attr = malloc(sizeof(attr_t) + data.len);
|
memcpy(attr->data, data.ptr, data.len);
|
||||||
attr->len = data.len;
|
|
||||||
attr->type = type;
|
|
||||||
memcpy(attr->data, data.ptr, data.len);
|
|
||||||
|
|
||||||
this->attributes->insert_last(this->attributes, attr);
|
this->attributes->insert_last(this->attributes, attr);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -463,6 +459,9 @@ static bool parse_attributes(private_simaka_message_t *this, chunk_t in)
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
charon->sim->message_hook(charon->sim, &this->public, TRUE, this->encrypted);
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -604,6 +603,8 @@ static eap_payload_t* generate(private_simaka_message_t *this, chunk_t sigdata)
|
|||||||
u_int16_t len;
|
u_int16_t len;
|
||||||
signer_t *signer;
|
signer_t *signer;
|
||||||
|
|
||||||
|
charon->sim->message_hook(charon->sim, &this->public, FALSE, TRUE);
|
||||||
|
|
||||||
out = chunk_create(out_buf, sizeof(out_buf));
|
out = chunk_create(out_buf, sizeof(out_buf));
|
||||||
encr = chunk_create(encr_buf, sizeof(encr_buf));
|
encr = chunk_create(encr_buf, sizeof(encr_buf));
|
||||||
|
|
||||||
@@ -814,6 +815,9 @@ static eap_payload_t* generate(private_simaka_message_t *this, chunk_t sigdata)
|
|||||||
data = chunk_cata("cc", out, sigdata);
|
data = chunk_cata("cc", out, sigdata);
|
||||||
signer->get_signature(signer, data, mac.ptr);
|
signer->get_signature(signer, data, mac.ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
charon->sim->message_hook(charon->sim, &this->public, FALSE, FALSE);
|
||||||
|
|
||||||
return eap_payload_create_data(out);
|
return eap_payload_create_data(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,6 @@
|
|||||||
|
|
||||||
#include "simaka_crypto.h"
|
#include "simaka_crypto.h"
|
||||||
|
|
||||||
typedef struct simaka_message_t simaka_message_t;
|
|
||||||
typedef enum simaka_attribute_t simaka_attribute_t;
|
typedef enum simaka_attribute_t simaka_attribute_t;
|
||||||
typedef enum simaka_subtype_t simaka_subtype_t;
|
typedef enum simaka_subtype_t simaka_subtype_t;
|
||||||
typedef enum simaka_notification_t simaka_notification_t;
|
typedef enum simaka_notification_t simaka_notification_t;
|
||||||
|
|||||||
Reference in New Issue
Block a user