Use new identity constructor in EAP-SIM

This commit is contained in:
Martin Willi
2009-11-12 10:34:01 +01:00
parent 324528700d
commit 947b03fd09
3 changed files with 23 additions and 42 deletions
+17 -38
View File
@@ -94,37 +94,6 @@ struct private_eap_sim_peer_t {
/* version of SIM protocol we speak */ /* version of SIM protocol we speak */
static chunk_t version = chunk_from_chars(0x00,0x01); static chunk_t version = chunk_from_chars(0x00,0x01);
/**
* Store received next fast reauthentication identity, along with mk/counter
*/
static void set_reauth(private_eap_sim_peer_t *this, chunk_t data)
{
identification_t *reauth;
char buf[data.len + 1];
snprintf(buf, sizeof(buf), "%.*s", data.len, data.ptr);
reauth = identification_create_from_string(buf);
DBG1(DBG_IKE, "received next reauthentication identity '%Y'", reauth);
charon->sim->card_set_reauth(charon->sim, this->permanent, reauth,
this->mk, this->counter);
reauth->destroy(reauth);
}
/**
* Store a pseudonym in a SIM card
*/
static void set_pseudonym(private_eap_sim_peer_t *this, chunk_t data)
{
identification_t *pseudonym;
char buf[data.len + 1];
snprintf(buf, sizeof(buf), "%.*s", data.len, data.ptr);
pseudonym = identification_create_from_string(buf);
DBG1(DBG_IKE, "received pseudonym '%Y' for next authentication", pseudonym);
charon->sim->card_set_pseudonym(charon->sim, this->permanent, pseudonym);
pseudonym->destroy(pseudonym);
}
/** /**
* Create a SIM_CLIENT_ERROR * Create a SIM_CLIENT_ERROR
*/ */
@@ -272,7 +241,7 @@ static status_t process_challenge(private_eap_sim_peer_t *this,
enumerator_t *enumerator; enumerator_t *enumerator;
simaka_attribute_t type; simaka_attribute_t type;
chunk_t data, rands = chunk_empty, kcs, kc, sreses, sres, mk; chunk_t data, rands = chunk_empty, kcs, kc, sreses, sres, mk;
identification_t *peer; identification_t *id;
if (this->tries-- <= 0) if (this->tries-- <= 0)
{ {
@@ -332,14 +301,14 @@ static status_t process_challenge(private_eap_sim_peer_t *this,
rands = chunk_skip(rands, SIM_RAND_LEN); rands = chunk_skip(rands, SIM_RAND_LEN);
} }
peer = this->permanent; id = this->permanent;
if (this->pseudonym) if (this->pseudonym)
{ {
peer = this->pseudonym; id = this->pseudonym;
} }
data = chunk_cata("cccc", kcs, this->nonce, this->version_list, version); data = chunk_cata("cccc", kcs, this->nonce, this->version_list, version);
free(this->msk.ptr); free(this->msk.ptr);
this->msk = this->crypto->derive_keys_full(this->crypto, peer, data, &mk); this->msk = this->crypto->derive_keys_full(this->crypto, id, data, &mk);
memcpy(this->mk, mk.ptr, mk.len); memcpy(this->mk, mk.ptr, mk.len);
free(mk.ptr); free(mk.ptr);
@@ -359,10 +328,15 @@ static status_t process_challenge(private_eap_sim_peer_t *this,
{ {
case AT_NEXT_REAUTH_ID: case AT_NEXT_REAUTH_ID:
this->counter = 0; this->counter = 0;
set_reauth(this, data); id = identification_create_from_data(data);
charon->sim->card_set_reauth(charon->sim, this->permanent, id,
this->mk, this->counter);
id->destroy(id);
break; break;
case AT_NEXT_PSEUDONYM: case AT_NEXT_PSEUDONYM:
set_pseudonym(this, data); id = identification_create_from_data(data);
charon->sim->card_set_pseudonym(charon->sim, this->permanent, id);
id->destroy(id);
break; break;
default: default:
break; break;
@@ -477,7 +451,12 @@ static status_t process_reauthentication(private_eap_sim_peer_t *this,
chunk_create(this->mk, HASH_SIZE_SHA1)); chunk_create(this->mk, HASH_SIZE_SHA1));
if (id.len) if (id.len)
{ {
set_reauth(this, id); identification_t *reauth;
reauth = identification_create_from_data(data);
charon->sim->card_set_reauth(charon->sim, this->permanent, reauth,
this->mk, this->counter);
reauth->destroy(reauth);
} }
} }
message->add_attribute(message, AT_COUNTER, counter); message->add_attribute(message, AT_COUNTER, counter);
+1 -4
View File
@@ -294,11 +294,8 @@ static status_t process_start(private_eap_sim_server_t *this,
if (identity.len) if (identity.len)
{ {
identification_t *permanent; identification_t *permanent;
char buf[identity.len + 1];
snprintf(buf, sizeof(buf), "%.*s", identity.len, identity.ptr);
id = identification_create_from_string(buf);
id = identification_create_from_data(identity);
if (this->use_reauth && !nonce.len) if (this->use_reauth && !nonce.len)
{ {
char mk[HASH_SIZE_SHA1]; char mk[HASH_SIZE_SHA1];
@@ -145,6 +145,8 @@ static void card_set_pseudonym(private_sim_manager_t *this,
enumerator_t *enumerator; enumerator_t *enumerator;
sim_card_t *card; sim_card_t *card;
DBG1(DBG_IKE, "storing pseudonym '%Y' for '%Y'", pseudonym, id);
enumerator = this->cards->create_enumerator(this->cards); enumerator = this->cards->create_enumerator(this->cards);
while (enumerator->enumerate(enumerator, &card)) while (enumerator->enumerate(enumerator, &card))
{ {
@@ -188,6 +190,9 @@ static void card_set_reauth(private_sim_manager_t *this, identification_t *id,
enumerator_t *enumerator; enumerator_t *enumerator;
sim_card_t *card; sim_card_t *card;
DBG1(DBG_IKE, "storing next reauthentication identity '%Y' for '%Y'",
next, id);
enumerator = this->cards->create_enumerator(this->cards); enumerator = this->cards->create_enumerator(this->cards);
while (enumerator->enumerate(enumerator, &card)) while (enumerator->enumerate(enumerator, &card))
{ {