aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Willi <martin@strongswan.org>2009-10-09 10:59:34 +0200
committerMartin Willi <martin@strongswan.org>2009-10-09 13:02:20 +0200
commit5d5e2853b6edde364bad4d49a44adbe2a1584dfc (patch)
tree1d9aa6d86c9abd50cdf6f86cc898d2da9578b5fc
parent31f5280cee50200993644cb25f0996abef51823c (diff)
downloadstrongswan-5d5e2853b6edde364bad4d49a44adbe2a1584dfc.tar.bz2
strongswan-5d5e2853b6edde364bad4d49a44adbe2a1584dfc.tar.xz
SIM card interface takes IMSI as parameter (same as in USIM)
-rw-r--r--src/charon/plugins/eap_sim/eap_sim.c20
-rw-r--r--src/charon/plugins/eap_sim_file/eap_sim_file_card.c44
-rw-r--r--src/charon/plugins/eap_sim_file/eap_sim_file_provider.c6
-rw-r--r--src/charon/plugins/eap_sim_file/eap_sim_file_provider.h2
-rw-r--r--src/charon/plugins/eap_sim_file/eap_sim_file_triplets.c16
-rw-r--r--src/charon/plugins/eap_sim_file/eap_sim_file_triplets.h18
-rw-r--r--src/charon/sa/authenticators/eap/sim_manager.h25
7 files changed, 44 insertions, 87 deletions
diff --git a/src/charon/plugins/eap_sim/eap_sim.c b/src/charon/plugins/eap_sim/eap_sim.c
index c83f051fb..874328db1 100644
--- a/src/charon/plugins/eap_sim/eap_sim.c
+++ b/src/charon/plugins/eap_sim/eap_sim.c
@@ -576,30 +576,22 @@ static bool get_card_triplet(private_eap_sim_t *this,
char *rand, char *sres, char *kc)
{
enumerator_t *enumerator;
- sim_card_t *card = NULL, *current;
- id_match_t match, best = ID_MATCH_NONE;
+ sim_card_t *card;
bool success = FALSE;
- /* find the best matching SIM */
enumerator = charon->sim->create_card_enumerator(charon->sim);
- while (enumerator->enumerate(enumerator, &current))
+ while (enumerator->enumerate(enumerator, &card))
{
- match = this->peer->matches(this->peer, current->get_imsi(current));
- if (match > best)
+ if (card->get_triplet(card, this->peer, rand, sres, kc))
{
- card = current;
- best = match;
+ success = TRUE;
break;
}
}
- if (card)
- {
- success = card->get_triplet(card, rand, sres, kc);
- }
enumerator->destroy(enumerator);
- if (!card)
+ if (!success)
{
- DBG1(DBG_IKE, "no SIM card found matching '%Y'", this->peer);
+ DBG1(DBG_IKE, "no SIM card found with triplets for '%Y'", this->peer);
}
return success;
}
diff --git a/src/charon/plugins/eap_sim_file/eap_sim_file_card.c b/src/charon/plugins/eap_sim_file/eap_sim_file_card.c
index 11efd5420..65e9f760a 100644
--- a/src/charon/plugins/eap_sim_file/eap_sim_file_card.c
+++ b/src/charon/plugins/eap_sim_file/eap_sim_file_card.c
@@ -15,6 +15,8 @@
#include "eap_sim_file_card.h"
+#include <daemon.h>
+
typedef struct private_eap_sim_file_card_t private_eap_sim_file_card_t;
/**
@@ -28,41 +30,37 @@ struct private_eap_sim_file_card_t {
eap_sim_file_card_t public;
/**
- * IMSI, is ID_ANY for file implementation
- */
- identification_t *imsi;
-
- /**
* source of triplets
*/
eap_sim_file_triplets_t *triplets;
};
-#include <daemon.h>
-
/**
* Implementation of sim_card_t.get_triplet
*/
static bool get_triplet(private_eap_sim_file_card_t *this,
- char *rand, char *sres, char *kc)
+ identification_t *imsi, char *rand, char *sres, char *kc)
{
enumerator_t *enumerator;
identification_t *id;
char *c_rand, *c_sres, *c_kc;
- DBG2(DBG_CFG, "looking for rand: %b", rand, RAND_LEN);
+ DBG2(DBG_CFG, "looking for rand: %b from %Y", rand, SIM_RAND_LEN, imsi);
enumerator = this->triplets->create_enumerator(this->triplets);
while (enumerator->enumerate(enumerator, &id, &c_rand, &c_sres, &c_kc))
{
- DBG2(DBG_CFG, "found triplet: rand %b\nsres %b\n kc %b",
- c_rand, RAND_LEN, c_sres, SRES_LEN, c_kc, KC_LEN);
- if (memeq(c_rand, rand, RAND_LEN))
+ if (imsi->matches(imsi, id))
{
- memcpy(sres, c_sres, SRES_LEN);
- memcpy(kc, c_kc, KC_LEN);
- enumerator->destroy(enumerator);
- return TRUE;
+ DBG2(DBG_CFG, "found triplet: rand %b\nsres %b\n kc %b",
+ c_rand, SIM_RAND_LEN, c_sres, SIM_SRES_LEN, c_kc, SIM_KC_LEN);
+ if (memeq(c_rand, rand, SIM_RAND_LEN))
+ {
+ memcpy(sres, c_sres, SIM_SRES_LEN);
+ memcpy(kc, c_kc, SIM_KC_LEN);
+ enumerator->destroy(enumerator);
+ return TRUE;
+ }
}
}
enumerator->destroy(enumerator);
@@ -70,19 +68,10 @@ static bool get_triplet(private_eap_sim_file_card_t *this,
}
/**
- * Implementation of sim_card_t.get_imsi
- */
-static identification_t* get_imsi(private_eap_sim_file_card_t *this)
-{
- return this->imsi;
-}
-
-/**
* Implementation of eap_sim_file_card_t.destroy.
*/
static void destroy(private_eap_sim_file_card_t *this)
{
- this->imsi->destroy(this->imsi);
free(this);
}
@@ -93,12 +82,9 @@ eap_sim_file_card_t *eap_sim_file_card_create(eap_sim_file_triplets_t *triplets)
{
private_eap_sim_file_card_t *this = malloc_thing(private_eap_sim_file_card_t);
- this->public.card.get_triplet = (bool(*)(sim_card_t*, char *rand, char *sres, char *kc))get_triplet;
- this->public.card.get_imsi = (identification_t*(*)(sim_card_t*))get_imsi;
+ this->public.card.get_triplet = (bool(*)(sim_card_t*, identification_t *imsi, char *rand, char *sres, char *kc))get_triplet;
this->public.destroy = (void(*)(eap_sim_file_card_t*))destroy;
- /* this SIM card implementation does not have an ID, serve ID_ANY */
- this->imsi = identification_create_from_encoding(ID_ANY, chunk_empty);
this->triplets = triplets;
return &this->public;
diff --git a/src/charon/plugins/eap_sim_file/eap_sim_file_provider.c b/src/charon/plugins/eap_sim_file/eap_sim_file_provider.c
index 3fec47bee..43fb1b840 100644
--- a/src/charon/plugins/eap_sim_file/eap_sim_file_provider.c
+++ b/src/charon/plugins/eap_sim_file/eap_sim_file_provider.c
@@ -49,9 +49,9 @@ static bool get_triplet(private_eap_sim_file_provider_t *this,
{
if (imsi->matches(imsi, id))
{
- memcpy(rand, c_rand, RAND_LEN);
- memcpy(sres, c_sres, SRES_LEN);
- memcpy(kc, c_kc, KC_LEN);
+ memcpy(rand, c_rand, SIM_RAND_LEN);
+ memcpy(sres, c_sres, SIM_SRES_LEN);
+ memcpy(kc, c_kc, SIM_KC_LEN);
enumerator->destroy(enumerator);
return TRUE;
}
diff --git a/src/charon/plugins/eap_sim_file/eap_sim_file_provider.h b/src/charon/plugins/eap_sim_file/eap_sim_file_provider.h
index 72f29d51f..245923b05 100644
--- a/src/charon/plugins/eap_sim_file/eap_sim_file_provider.h
+++ b/src/charon/plugins/eap_sim_file/eap_sim_file_provider.h
@@ -23,8 +23,6 @@
#include "eap_sim_file_triplets.h"
-#include <sa/authenticators/eap/sim_manager.h>
-
typedef struct eap_sim_file_provider_t eap_sim_file_provider_t;
/**
diff --git a/src/charon/plugins/eap_sim_file/eap_sim_file_triplets.c b/src/charon/plugins/eap_sim_file/eap_sim_file_triplets.c
index b4686bf8f..6b4d90736 100644
--- a/src/charon/plugins/eap_sim_file/eap_sim_file_triplets.c
+++ b/src/charon/plugins/eap_sim_file/eap_sim_file_triplets.c
@@ -50,9 +50,9 @@ struct private_eap_sim_file_triplets_t {
*/
typedef struct {
identification_t *imsi;
- char rand[RAND_LEN];
- char sres[SRES_LEN];
- char kc[KC_LEN];
+ char rand[SIM_RAND_LEN];
+ char sres[SIM_SRES_LEN];
+ char kc[SIM_KC_LEN];
} triplet_t;
/**
@@ -197,13 +197,13 @@ static void read_triplets(private_eap_sim_file_triplets_t *this, char *path)
triplet->imsi = identification_create_from_string(token);
continue;
case 1: /* rand */
- parse_token(triplet->rand, token, RAND_LEN);
+ parse_token(triplet->rand, token, SIM_RAND_LEN);
continue;
case 2: /* sres */
- parse_token(triplet->sres, token, SRES_LEN);
+ parse_token(triplet->sres, token, SIM_SRES_LEN);
continue;
case 3: /* kc */
- parse_token(triplet->kc, token, KC_LEN);
+ parse_token(triplet->kc, token, SIM_KC_LEN);
continue;
default:
break;;
@@ -219,8 +219,8 @@ static void read_triplets(private_eap_sim_file_triplets_t *this, char *path)
}
DBG2(DBG_CFG, "triplet: imsi %Y\nrand %b\nsres %b\nkc %b",
- triplet->imsi, triplet->rand, RAND_LEN,
- triplet->sres, SRES_LEN, triplet->kc, KC_LEN);
+ triplet->imsi, triplet->rand, SIM_RAND_LEN,
+ triplet->sres, SIM_SRES_LEN, triplet->kc, SIM_KC_LEN);
this->triplets->insert_last(this->triplets, triplet);
}
diff --git a/src/charon/plugins/eap_sim_file/eap_sim_file_triplets.h b/src/charon/plugins/eap_sim_file/eap_sim_file_triplets.h
index d4ff2a781..efa2bd33c 100644
--- a/src/charon/plugins/eap_sim_file/eap_sim_file_triplets.h
+++ b/src/charon/plugins/eap_sim_file/eap_sim_file_triplets.h
@@ -21,23 +21,7 @@
#ifndef EAP_SIM_FILE_TRIPLETS_H_
#define EAP_SIM_FILE_TRIPLETS_H_
-#include <utils/enumerator.h>
-#include <utils/identification.h>
-
-/**
- * size of RAND value
- */
-#define RAND_LEN 16
-
-/**
- * size of SRES value
- */
-#define SRES_LEN 4
-
-/**
- * size of KC value
- */
-#define KC_LEN 8
+#include <sa/authenticators/eap/sim_manager.h>
typedef struct eap_sim_file_triplets_t eap_sim_file_triplets_t;
diff --git a/src/charon/sa/authenticators/eap/sim_manager.h b/src/charon/sa/authenticators/eap/sim_manager.h
index 260e73038..bc77ad0d9 100644
--- a/src/charon/sa/authenticators/eap/sim_manager.h
+++ b/src/charon/sa/authenticators/eap/sim_manager.h
@@ -28,31 +28,27 @@ typedef struct sim_manager_t sim_manager_t;
typedef struct sim_card_t sim_card_t;
typedef struct sim_provider_t sim_provider_t;
+#define SIM_RAND_LEN 16
+#define SIM_SRES_LEN 4
+#define SIM_KC_LEN 8
+
/**
* Interface for a SIM card (used as EAP client).
*/
struct sim_card_t {
/**
- * Get the identity of a SIM card.
- *
- * The returned identity owned by the sim_card and not destroyed outside.
- * The SIM card may return ID_ANY if it does not support/use an IMSI.
- *
- * @return identity
- */
- identification_t* (*get_imsi)(sim_card_t *this);
-
- /**
* Calculate SRES/KC from a RAND.
*
+ * @param imsi identity to get a triplet for
* @param rand RAND input buffer, fixed size 16 bytes
* @param sres SRES output buffer, fixed size 4 byte
* @param kc KC output buffer, fixed size 8 bytes
- * @return TRUE if SRES/KC calculated, FALSE on error
+ * @return TRUE if SRES/KC calculated, FALSE on error/wrong identity
*/
- bool (*get_triplet)(sim_card_t *this,
- char rand[16], char sres[4], char kc[8]);
+ bool (*get_triplet)(sim_card_t *this, identification_t *imsi,
+ char rand[SIM_RAND_LEN], char sres[SIM_SRES_LEN],
+ char kc[SIM_KC_LEN]);
};
/**
@@ -70,7 +66,8 @@ struct sim_provider_t {
* @return TRUE if triplet received, FALSE otherwise
*/
bool (*get_triplet)(sim_provider_t *this, identification_t *imsi,
- char rand[16], char sres[4], char kc[8]);
+ char rand[SIM_RAND_LEN], char sres[SIM_SRES_LEN],
+ char kc[SIM_KC_LEN]);
};
/**