Annotation of embedaddon/strongswan/src/libcharon/plugins/eap_simaka_pseudonym/eap_simaka_pseudonym_card.c, revision 1.1.1.1
1.1 misho 1: /*
2: * Copyright (C) 2016 Tobias Brunner
3: * Copyright (C) 2009 Martin Willi
4: * HSR Hochschule fuer Technik Rapperswil
5: *
6: * This program is free software; you can redistribute it and/or modify it
7: * under the terms of the GNU General Public License as published by the
8: * Free Software Foundation; either version 2 of the License, or (at your
9: * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14: * for more details.
15: */
16:
17: #include "eap_simaka_pseudonym_card.h"
18:
19: #include <daemon.h>
20: #include <collections/hashtable.h>
21:
22: typedef struct private_eap_simaka_pseudonym_card_t private_eap_simaka_pseudonym_card_t;
23:
24: /**
25: * Private data of an eap_simaka_pseudonym_card_t object.
26: */
27: struct private_eap_simaka_pseudonym_card_t {
28:
29: /**
30: * Public eap_simaka_pseudonym_card_t interface.
31: */
32: eap_simaka_pseudonym_card_t public;
33:
34: /**
35: * Permanent -> pseudonym mappings (entry_t*)
36: */
37: hashtable_t *pseudonym;
38: };
39:
40: /**
41: * Mapping between real and pseudonym identity
42: */
43: typedef struct {
44:
45: /** Real identity */
46: identification_t *id;
47:
48: /** Pseudonym */
49: identification_t *pseudonym;
50:
51: } entry_t;
52:
53: static void destroy_entry(entry_t *this)
54: {
55: this->id->destroy(this->id);
56: this->pseudonym->destroy(this->pseudonym);
57: free(this);
58: }
59:
60: /**
61: * hashtable hash function
62: */
63: static u_int hash(identification_t *key)
64: {
65: return chunk_hash(key->get_encoding(key));
66: }
67:
68: /**
69: * hashtable equals function
70: */
71: static bool equals(identification_t *key1, identification_t *key2)
72: {
73: return key1->equals(key1, key2);
74: }
75:
76: METHOD(simaka_card_t, get_pseudonym, identification_t*,
77: private_eap_simaka_pseudonym_card_t *this, identification_t *id)
78: {
79: entry_t *entry;
80:
81: entry = this->pseudonym->get(this->pseudonym, id);
82: if (entry)
83: {
84: return entry->pseudonym->clone(entry->pseudonym);
85: }
86: return NULL;
87: }
88:
89: METHOD(simaka_card_t, set_pseudonym, void,
90: private_eap_simaka_pseudonym_card_t *this, identification_t *id,
91: identification_t *pseudonym)
92: {
93: entry_t *entry;
94:
95: INIT(entry,
96: .id = id->clone(id),
97: .pseudonym = pseudonym->clone(pseudonym),
98: );
99: entry = this->pseudonym->put(this->pseudonym, entry->id, entry);
100: if (entry)
101: {
102: destroy_entry(entry);
103: }
104: }
105:
106: METHOD(simaka_card_t, get_quintuplet, status_t,
107: private_eap_simaka_pseudonym_card_t *this, identification_t *id,
108: char rand[AKA_RAND_LEN], char autn[AKA_AUTN_LEN], char ck[AKA_CK_LEN],
109: char ik[AKA_IK_LEN], char res[AKA_RES_MAX], int *res_len)
110: {
111: return NOT_SUPPORTED;
112: }
113:
114: METHOD(eap_simaka_pseudonym_card_t, destroy, void,
115: private_eap_simaka_pseudonym_card_t *this)
116: {
117: this->pseudonym->destroy_function(this->pseudonym, (void*)destroy_entry);
118: free(this);
119: }
120:
121: /**
122: * See header
123: */
124: eap_simaka_pseudonym_card_t *eap_simaka_pseudonym_card_create()
125: {
126: private_eap_simaka_pseudonym_card_t *this;
127:
128: INIT(this,
129: .public = {
130: .card = {
131: .get_triplet = (void*)return_false,
132: .get_quintuplet = _get_quintuplet,
133: .resync = (void*)return_false,
134: .get_pseudonym = _get_pseudonym,
135: .set_pseudonym = _set_pseudonym,
136: .get_reauth = (void*)return_null,
137: .set_reauth = (void*)nop,
138: },
139: .destroy = _destroy,
140: },
141: .pseudonym = hashtable_create((void*)hash, (void*)equals, 0),
142: );
143: return &this->public;
144: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>