Annotation of embedaddon/strongswan/src/libcharon/plugins/eap_simaka_reauth/eap_simaka_reauth_card.c, revision 1.1.1.1
1.1 misho 1: /*
2: * Copyright (C) 2009 Martin Willi
3: * HSR 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_reauth_card.h"
17:
18: #include <daemon.h>
19: #include <collections/hashtable.h>
20:
21: typedef struct private_eap_simaka_reauth_card_t private_eap_simaka_reauth_card_t;
22:
23: /**
24: * Private data of an eap_simaka_reauth_card_t object.
25: */
26: struct private_eap_simaka_reauth_card_t {
27:
28: /**
29: * Public eap_simaka_reauth_card_t interface.
30: */
31: eap_simaka_reauth_card_t public;
32:
33: /**
34: * Permanent -> reauth_data_t mappings
35: */
36: hashtable_t *reauth;
37: };
38:
39: /**
40: * Data associated to a reauthentication identity
41: */
42: typedef struct {
43: /** currently used reauthentication identity */
44: identification_t *id;
45: /** associated permanent identity */
46: identification_t *permanent;
47: /** counter value */
48: uint16_t counter;
49: /** master key */
50: char mk[HASH_SIZE_SHA1];
51: } reauth_data_t;
52:
53: /**
54: * hashtable hash function
55: */
56: static u_int hash(identification_t *key)
57: {
58: return chunk_hash(key->get_encoding(key));
59: }
60:
61: /**
62: * hashtable equals function
63: */
64: static bool equals(identification_t *key1, identification_t *key2)
65: {
66: return key1->equals(key1, key2);
67: }
68:
69: METHOD(simaka_card_t, get_reauth, identification_t*,
70: private_eap_simaka_reauth_card_t *this, identification_t *id,
71: char mk[HASH_SIZE_SHA1], uint16_t *counter)
72: {
73: reauth_data_t *data;
74: identification_t *reauth;
75:
76: /* look up reauthentication data */
77: data = this->reauth->remove(this->reauth, id);
78: if (!data)
79: {
80: return NULL;
81: }
82: *counter = ++data->counter;
83: memcpy(mk, data->mk, HASH_SIZE_SHA1);
84: reauth = data->id;
85: data->permanent->destroy(data->permanent);
86: free(data);
87: return reauth;
88: }
89:
90: METHOD(simaka_card_t, set_reauth, void,
91: private_eap_simaka_reauth_card_t *this, identification_t *id,
92: identification_t* next, char mk[HASH_SIZE_SHA1], uint16_t counter)
93: {
94: reauth_data_t *data;
95:
96: data = this->reauth->get(this->reauth, id);
97: if (data)
98: {
99: data->id->destroy(data->id);
100: }
101: else
102: {
103: data = malloc_thing(reauth_data_t);
104: data->permanent = id->clone(id);
105: this->reauth->put(this->reauth, data->permanent, data);
106: }
107: data->counter = counter;
108: data->id = next->clone(next);
109: memcpy(data->mk, mk, HASH_SIZE_SHA1);
110: }
111:
112: METHOD(simaka_card_t, get_quintuplet, status_t,
113: private_eap_simaka_reauth_card_t *this, identification_t *id,
114: char rand[AKA_RAND_LEN], char autn[AKA_AUTN_LEN], char ck[AKA_CK_LEN],
115: char ik[AKA_IK_LEN], char res[AKA_RES_MAX], int *res_len)
116: {
117: return NOT_SUPPORTED;
118: }
119:
120: METHOD(eap_simaka_reauth_card_t, destroy, void,
121: private_eap_simaka_reauth_card_t *this)
122: {
123: enumerator_t *enumerator;
124: reauth_data_t *data;
125: void *key;
126:
127: enumerator = this->reauth->create_enumerator(this->reauth);
128: while (enumerator->enumerate(enumerator, &key, &data))
129: {
130: data->id->destroy(data->id);
131: data->permanent->destroy(data->permanent);
132: free(data);
133: }
134: enumerator->destroy(enumerator);
135:
136: this->reauth->destroy(this->reauth);
137: free(this);
138: }
139:
140: /**
141: * See header
142: */
143: eap_simaka_reauth_card_t *eap_simaka_reauth_card_create()
144: {
145: private_eap_simaka_reauth_card_t *this;
146:
147: INIT(this,
148: .public = {
149: .card = {
150: .get_triplet = (void*)return_null,
151: .get_quintuplet = _get_quintuplet,
152: .resync = (void*)return_false,
153: .get_pseudonym = (void*)return_null,
154: .set_pseudonym = (void*)nop,
155: .get_reauth = _get_reauth,
156: .set_reauth = _set_reauth,
157: },
158: .destroy = _destroy,
159: },
160: .reauth = hashtable_create((void*)hash, (void*)equals, 0),
161: );
162:
163: return &this->public;
164: }
165:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>