Improved debugging log in SIM triplet lookup
[strongswan.git] / src / charon / plugins / eap_sim_file / eap_sim_file_card.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_card.h"
17
18 #include <daemon.h>
19
20 typedef struct private_eap_sim_file_card_t private_eap_sim_file_card_t;
21
22 /**
23 * Private data of an eap_sim_file_card_t object.
24 */
25 struct private_eap_sim_file_card_t {
26
27 /**
28 * Public eap_sim_file_card_t interface.
29 */
30 eap_sim_file_card_t public;
31
32 /**
33 * source of triplets
34 */
35 eap_sim_file_triplets_t *triplets;
36 };
37
38 /**
39 * Implementation of sim_card_t.get_triplet
40 */
41 static bool get_triplet(private_eap_sim_file_card_t *this,
42 identification_t *imsi, char *rand, char *sres, char *kc)
43 {
44 enumerator_t *enumerator;
45 identification_t *id;
46 char *c_rand, *c_sres, *c_kc;
47
48 DBG2(DBG_CFG, "looking for triplet: %Y rand %b", imsi, rand, SIM_RAND_LEN);
49
50 enumerator = this->triplets->create_enumerator(this->triplets);
51 while (enumerator->enumerate(enumerator, &id, &c_rand, &c_sres, &c_kc))
52 {
53 DBG2(DBG_CFG, "got a triplet: %Y rand %b\nsres %b\n kc %b", id,
54 c_rand, SIM_RAND_LEN, c_sres, SIM_SRES_LEN, c_kc, SIM_KC_LEN);
55 if (imsi->matches(imsi, id))
56 {
57 if (memeq(c_rand, rand, SIM_RAND_LEN))
58 {
59 DBG2(DBG_CFG, " => triplet matches");
60 memcpy(sres, c_sres, SIM_SRES_LEN);
61 memcpy(kc, c_kc, SIM_KC_LEN);
62 enumerator->destroy(enumerator);
63 return TRUE;
64 }
65 }
66 }
67 enumerator->destroy(enumerator);
68 return FALSE;
69 }
70
71 /**
72 * Implementation of sim_card_t.get_quintuplet
73 */
74 static bool get_quintuplet()
75 {
76 return NOT_SUPPORTED;
77 }
78
79 /**
80 * Implementation of eap_sim_file_card_t.destroy.
81 */
82 static void destroy(private_eap_sim_file_card_t *this)
83 {
84 free(this);
85 }
86
87 /**
88 * See header
89 */
90 eap_sim_file_card_t *eap_sim_file_card_create(eap_sim_file_triplets_t *triplets)
91 {
92 private_eap_sim_file_card_t *this = malloc_thing(private_eap_sim_file_card_t);
93
94 this->public.card.get_triplet = (bool(*)(sim_card_t*, identification_t *imsi, char rand[SIM_RAND_LEN], char sres[SIM_SRES_LEN], char kc[SIM_KC_LEN]))get_triplet;
95 this->public.card.get_quintuplet = (status_t(*)(sim_card_t*, identification_t *imsi, char rand[AKA_RAND_LEN], char autn[AKA_AUTN_LEN], char ck[AKA_CK_LEN], char ik[AKA_IK_LEN], char res[AKA_RES_LEN]))get_quintuplet;
96 this->public.card.resync = (bool(*)(sim_card_t*, identification_t *imsi, char rand[AKA_RAND_LEN], char auts[AKA_AUTS_LEN]))return_false;
97 this->public.destroy = (void(*)(eap_sim_file_card_t*))destroy;
98
99 this->triplets = triplets;
100
101 return &this->public;
102 }
103