sim_provider_t API gained support for pseudonym/fast reauthentication
[strongswan.git] / src / charon / plugins / eap_sim_file / eap_sim_file_provider.c
1 /*
2 * Copyright (C) 2008-2009 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include "eap_sim_file_provider.h"
17
18 typedef struct private_eap_sim_file_provider_t private_eap_sim_file_provider_t;
19
20 /**
21 * Private data of an eap_sim_file_provider_t object.
22 */
23 struct private_eap_sim_file_provider_t {
24
25 /**
26 * Public eap_sim_file_provider_t interface.
27 */
28 eap_sim_file_provider_t public;
29
30 /**
31 * source of triplets
32 */
33 eap_sim_file_triplets_t *triplets;
34 };
35
36 /**
37 * Implementation of sim_provider_t.get_triplet
38 */
39 static bool get_triplet(private_eap_sim_file_provider_t *this,
40 identification_t *imsi,
41 char *rand, char *sres, char *kc)
42 {
43 enumerator_t *enumerator;
44 identification_t *id;
45 char *c_rand, *c_sres, *c_kc;
46
47 enumerator = this->triplets->create_enumerator(this->triplets);
48 while (enumerator->enumerate(enumerator, &id, &c_rand, &c_sres, &c_kc))
49 {
50 if (imsi->matches(imsi, id))
51 {
52 memcpy(rand, c_rand, SIM_RAND_LEN);
53 memcpy(sres, c_sres, SIM_SRES_LEN);
54 memcpy(kc, c_kc, SIM_KC_LEN);
55 enumerator->destroy(enumerator);
56 return TRUE;
57 }
58 }
59 enumerator->destroy(enumerator);
60 return FALSE;
61 }
62
63 /**
64 * Implementation of eap_sim_file_provider_t.destroy.
65 */
66 static void destroy(private_eap_sim_file_provider_t *this)
67 {
68 free(this);
69 }
70
71 /**
72 * See header
73 */
74 eap_sim_file_provider_t *eap_sim_file_provider_create(
75 eap_sim_file_triplets_t *triplets)
76 {
77 private_eap_sim_file_provider_t *this = malloc_thing(private_eap_sim_file_provider_t);
78
79 this->public.provider.get_triplet = (bool(*)(sim_provider_t*, identification_t *imsi, char rand[SIM_RAND_LEN], char sres[SIM_SRES_LEN], char kc[SIM_KC_LEN]))get_triplet;
80 this->public.provider.get_quintuplet = (bool(*)(sim_provider_t*, identification_t *imsi, char rand[AKA_RAND_LEN], char xres[AKA_RES_LEN], char ck[AKA_CK_LEN], char ik[AKA_IK_LEN], char autn[AKA_AUTN_LEN]))return_false;
81 this->public.provider.resync = (bool(*)(sim_provider_t*, identification_t *imsi, char rand[AKA_RAND_LEN], char auts[AKA_AUTS_LEN]))return_false;
82 this->public.provider.gen_pseudonym = (identification_t*(*)(sim_provider_t*, identification_t *id))return_null;
83 this->public.provider.is_reauth = (bool(*)(sim_provider_t*, identification_t *id, char [HASH_SIZE_SHA1], u_int16_t *counter))return_false;
84 this->public.provider.gen_reauth = (identification_t*(*)(sim_provider_t*, identification_t *id, char mk[HASH_SIZE_SHA1]))return_null;
85 this->public.destroy = (void(*)(eap_sim_file_provider_t*))destroy;
86
87 this->triplets = triplets;
88
89 return &this->public;
90 }
91