root / src / charon / plugins / eap_simaka_pseudonym / eap_simaka_pseudonym_card.c @ 832f28315044abe4c2523ce28e46dc60ecb45a98
History | View | Annotate | Download (4.4 KB)
| 1 | /*
|
|---|---|
| 2 | * Copyright (C) 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_simaka_pseudonym_card.h" |
| 17 | |
| 18 | #include <daemon.h> |
| 19 | #include <utils/hashtable.h> |
| 20 | |
| 21 | typedef struct private_eap_simaka_pseudonym_card_t private_eap_simaka_pseudonym_card_t; |
| 22 | |
| 23 | /**
|
| 24 | * Private data of an eap_simaka_pseudonym_card_t object. |
| 25 | */ |
| 26 | struct private_eap_simaka_pseudonym_card_t {
|
| 27 | |
| 28 | /**
|
| 29 | * Public eap_simaka_pseudonym_card_t interface. |
| 30 | */ |
| 31 | eap_simaka_pseudonym_card_t public; |
| 32 | |
| 33 | /**
|
| 34 | * Permanent -> pseudonym mappings |
| 35 | */ |
| 36 | hashtable_t *pseudonym; |
| 37 | |
| 38 | /**
|
| 39 | * Reverse pseudonym -> permanent mappings |
| 40 | */ |
| 41 | hashtable_t *permanent; |
| 42 | }; |
| 43 | |
| 44 | /**
|
| 45 | * hashtable hash function |
| 46 | */ |
| 47 | static u_int hash(identification_t *key)
|
| 48 | {
|
| 49 | return chunk_hash(key->get_encoding(key));
|
| 50 | } |
| 51 | |
| 52 | /**
|
| 53 | * hashtable equals function |
| 54 | */ |
| 55 | static bool equals(identification_t *key1, identification_t *key2) |
| 56 | {
|
| 57 | return key1->equals(key1, key2);
|
| 58 | } |
| 59 | |
| 60 | /**
|
| 61 | * Implementation of sim_card_t.get_pseudonym |
| 62 | */ |
| 63 | static identification_t *get_pseudonym(private_eap_simaka_pseudonym_card_t *this,
|
| 64 | identification_t *id) |
| 65 | {
|
| 66 | identification_t *pseudonym; |
| 67 | |
| 68 | pseudonym = this->pseudonym->get(this->pseudonym, id); |
| 69 | if (pseudonym)
|
| 70 | {
|
| 71 | return pseudonym->clone(pseudonym);
|
| 72 | } |
| 73 | return NULL; |
| 74 | } |
| 75 | |
| 76 | /**
|
| 77 | * Implementation of sim_card_t.set_pseudonym |
| 78 | */ |
| 79 | static void set_pseudonym(private_eap_simaka_pseudonym_card_t *this, |
| 80 | identification_t *id, identification_t *pseudonym) |
| 81 | {
|
| 82 | identification_t *permanent; |
| 83 | |
| 84 | /* create new entries */
|
| 85 | id = id->clone(id); |
| 86 | pseudonym = pseudonym->clone(pseudonym); |
| 87 | permanent = this->permanent->put(this->permanent, pseudonym, id); |
| 88 | pseudonym = this->pseudonym->put(this->pseudonym, id, pseudonym); |
| 89 | |
| 90 | /* delete old entries */
|
| 91 | DESTROY_IF(permanent); |
| 92 | DESTROY_IF(pseudonym); |
| 93 | } |
| 94 | |
| 95 | /**
|
| 96 | * Implementation of sim_card_t.get_quintuplet |
| 97 | */ |
| 98 | static status_t get_quintuplet()
|
| 99 | {
|
| 100 | return NOT_SUPPORTED;
|
| 101 | } |
| 102 | |
| 103 | /**
|
| 104 | * Implementation of eap_simaka_pseudonym_card_t.destroy. |
| 105 | */ |
| 106 | static void destroy(private_eap_simaka_pseudonym_card_t *this) |
| 107 | {
|
| 108 | enumerator_t *enumerator; |
| 109 | identification_t *id; |
| 110 | void *key;
|
| 111 | |
| 112 | enumerator = this->pseudonym->create_enumerator(this->pseudonym); |
| 113 | while (enumerator->enumerate(enumerator, &key, &id))
|
| 114 | {
|
| 115 | id->destroy(id); |
| 116 | } |
| 117 | enumerator->destroy(enumerator); |
| 118 | |
| 119 | enumerator = this->permanent->create_enumerator(this->permanent); |
| 120 | while (enumerator->enumerate(enumerator, &key, &id))
|
| 121 | {
|
| 122 | id->destroy(id); |
| 123 | } |
| 124 | enumerator->destroy(enumerator); |
| 125 | |
| 126 | this->pseudonym->destroy(this->pseudonym); |
| 127 | this->permanent->destroy(this->permanent); |
| 128 | free(this); |
| 129 | } |
| 130 | |
| 131 | /**
|
| 132 | * See header |
| 133 | */ |
| 134 | eap_simaka_pseudonym_card_t *eap_simaka_pseudonym_card_create() |
| 135 | {
|
| 136 | private_eap_simaka_pseudonym_card_t *this; |
| 137 | |
| 138 | this = malloc_thing(private_eap_simaka_pseudonym_card_t); |
| 139 | |
| 140 | this->public.card.get_triplet = (bool(*)(sim_card_t*, identification_t *id, char rand[SIM_RAND_LEN], char sres[SIM_SRES_LEN], char kc[SIM_KC_LEN]))return_false; |
| 141 | this->public.card.get_quintuplet = (status_t(*)(sim_card_t*, identification_t *id, char rand[AKA_RAND_LEN], char autn[AKA_AUTN_LEN], char ck[AKA_CK_LEN], char ik[AKA_IK_LEN], char res[AKA_RES_MAX], int *res_len))get_quintuplet; |
| 142 | this->public.card.resync = (bool(*)(sim_card_t*, identification_t *id, char rand[AKA_RAND_LEN], char auts[AKA_AUTS_LEN]))return_false; |
| 143 | this->public.card.get_pseudonym = (identification_t*(*)(sim_card_t*, identification_t *perm))get_pseudonym; |
| 144 | this->public.card.set_pseudonym = (void(*)(sim_card_t*, identification_t *id, identification_t *pseudonym))set_pseudonym;
|
| 145 | this->public.card.get_reauth = (identification_t*(*)(sim_card_t*, identification_t *id, char mk[HASH_SIZE_SHA1], u_int16_t *counter))return_null;
|
| 146 | this->public.card.set_reauth = (void(*)(sim_card_t*, identification_t *id, identification_t* next, char mk[HASH_SIZE_SHA1], u_int16_t counter))nop; |
| 147 | this->public.destroy = (void(*)(eap_simaka_pseudonym_card_t*))destroy;
|
| 148 | |
| 149 | this->pseudonym = hashtable_create((void*)hash, (void*)equals, 0); |
| 150 | this->permanent = hashtable_create((void*)hash, (void*)equals, 0); |
| 151 | |
| 152 | return &this->public;
|
| 153 | } |
| 154 |