2 * Copyright (C) 2008-2011 Martin Willi
3 * Hochschule fuer Technik Rapperswil
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>.
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
17 * @defgroup simaka_manager simaka_manager
18 * @{ @ingroup libsimaka
21 #ifndef SIMAKA_MANAGER_H_
22 #define SIMAKA_MANAGER_H_
24 #include <crypto/hashers/hasher.h>
25 #include <utils/identification.h>
26 #include <collections/enumerator.h>
27 #include <plugins/plugin.h>
29 typedef struct simaka_manager_t simaka_manager_t
;
31 #define SIM_RAND_LEN 16
32 #define SIM_SRES_LEN 4
35 #define AKA_RAND_LEN 16
36 #define AKA_RES_MAX 16
39 #define AKA_AUTN_LEN 16
40 #define AKA_AUTS_LEN 14
42 #include "simaka_card.h"
43 #include "simaka_provider.h"
44 #include "simaka_hooks.h"
47 * The SIM manager handles multiple (U)SIM cards/providers and hooks.
49 struct simaka_manager_t
{
52 * Register a SIM card (client) at the manager.
54 * @param card sim card to register
56 void (*add_card
)(simaka_manager_t
*this, simaka_card_t
*card
);
59 * Unregister a previously registered card from the manager.
61 * @param card sim card to unregister
63 void (*remove_card
)(simaka_manager_t
*this, simaka_card_t
*card
);
66 * Calculate SIM triplets on one of the registered SIM cards.
68 * @param id permanent identity to get a triplet for
69 * @param rand RAND input buffer, fixed size 16 bytes
70 * @param sres SRES output buffer, fixed size 4 byte
71 * @param kc KC output buffer, fixed size 8 bytes
72 * @return TRUE if calculated, FALSE if no matching card found
74 bool (*card_get_triplet
)(simaka_manager_t
*this, identification_t
*id
,
75 char rand
[SIM_RAND_LEN
], char sres
[SIM_SRES_LEN
],
79 * Calculate AKA quitpulets on one of the registered SIM cards.
81 * @param id permanent identity to request quintuplet for
82 * @param rand random value rand
83 * @param autn authentication token autn
84 * @param ck buffer receiving encryption key ck
85 * @param ik buffer receiving integrity key ik
86 * @param res buffer receiving authentication result res
87 * @param res_len number of bytes written to res buffer
88 * @return SUCCESS, FAILED, or INVALID_STATE if out of sync
90 status_t (*card_get_quintuplet
)(simaka_manager_t
*this, identification_t
*id
,
91 char rand
[AKA_RAND_LEN
], char autn
[AKA_AUTN_LEN
],
92 char ck
[AKA_CK_LEN
], char ik
[AKA_IK_LEN
],
93 char res
[AKA_RES_MAX
], int *res_len
);
96 * Calculate resynchronization data on one of the registered SIM cards.
98 * @param id permanent identity to request quintuplet for
99 * @param rand random value rand
100 * @param auts resynchronization parameter auts
101 * @return TRUE if calculated, FALSE if no matcing card found
103 bool (*card_resync
)(simaka_manager_t
*this, identification_t
*id
,
104 char rand
[AKA_RAND_LEN
], char auts
[AKA_AUTS_LEN
]);
107 * Store a received pseudonym on one of the registered SIM cards.
109 * @param id permanent identity of the peer
110 * @param pseudonym pseudonym identity received from the server
112 void (*card_set_pseudonym
)(simaka_manager_t
*this, identification_t
*id
,
113 identification_t
*pseudonym
);
116 * Get a stored pseudonym from one of the registered SIM cards.
118 * @param id permanent identity of the peer
119 * @return associated pseudonym identity, NULL if none found
121 identification_t
* (*card_get_pseudonym
)(simaka_manager_t
*this,
122 identification_t
*id
);
125 * Store fast reauthentication parameters on one of the registered cards.
127 * @param id permanent identity of the peer
128 * @param next next fast reauthentication identity to use
129 * @param mk master key MK to store for reauthentication
130 * @param counter counter value to store, host order
132 void (*card_set_reauth
)(simaka_manager_t
*this, identification_t
*id
,
133 identification_t
*next
, char mk
[HASH_SIZE_SHA1
],
137 * Retrieve fast reauthentication parameters from one of the registered cards.
139 * @param id permanent identity of the peer
140 * @param mk buffer receiving master key MK
141 * @param counter pointer receiving counter value, in host order
142 * @return fast reauthentication identity, NULL if none found
144 identification_t
* (*card_get_reauth
)(simaka_manager_t
*this,
145 identification_t
*id
, char mk
[HASH_SIZE_SHA1
],
149 * Register a triplet provider (server) at the manager.
151 * @param card sim card to register
153 void (*add_provider
)(simaka_manager_t
*this, simaka_provider_t
*provider
);
156 * Unregister a previously registered provider from the manager.
158 * @param card sim card to unregister
160 void (*remove_provider
)(simaka_manager_t
*this, simaka_provider_t
*provider
);
163 * Get a SIM triplet from one of the registered providers.
165 * @param id permanent identity of peer to gen triplet for
166 * @param rand RAND output buffer, fixed size 16 bytes
167 * @param sres SRES output buffer, fixed size 4 byte
168 * @param kc KC output buffer, fixed size 8 bytes
169 * @return TRUE if triplet received, FALSE if no match found
171 bool (*provider_get_triplet
)(simaka_manager_t
*this, identification_t
*id
,
172 char rand
[SIM_RAND_LEN
], char sres
[SIM_SRES_LEN
],
173 char kc
[SIM_KC_LEN
]);
176 * Get a AKA quintuplet from one of the registered providers.
178 * @param id permanent identity of peer to create challenge for
179 * @param rand buffer receiving random value rand
180 * @param xres buffer receiving expected authentication result xres
181 * @param ck buffer receiving encryption key ck
182 * @param ik buffer receiving integrity key ik
183 * @param autn authentication token autn
184 * @return TRUE if quintuplet received, FALSE if no match found
186 bool (*provider_get_quintuplet
)(simaka_manager_t
*this, identification_t
*id
,
187 char rand
[AKA_RAND_LEN
],
188 char xres
[AKA_RES_MAX
], int *xres_len
,
189 char ck
[AKA_CK_LEN
], char ik
[AKA_IK_LEN
],
190 char autn
[AKA_AUTN_LEN
]);
193 * Pass AKA resynchronization data to one of the registered providers.
195 * @param id permanent identity of peer requesting resynchronisation
196 * @param rand random value rand
197 * @param auts synchronization parameter auts
198 * @return TRUE if resynchronized, FALSE if not handled
200 bool (*provider_resync
)(simaka_manager_t
*this, identification_t
*id
,
201 char rand
[AKA_RAND_LEN
], char auts
[AKA_AUTS_LEN
]);
204 * Check if a peer uses a pseudonym using one of the registered providers.
206 * @param id pseudonym identity candidate
207 * @return permanent identity, NULL if id not a pseudonym
209 identification_t
* (*provider_is_pseudonym
)(simaka_manager_t
*this,
210 identification_t
*id
);
213 * Generate a new pseudonym using one of the registered providers.
215 * @param id permanent identity to generate a pseudonym for
216 * @return generated pseudonym, NULL to not use a pseudonym identity
218 identification_t
* (*provider_gen_pseudonym
)(simaka_manager_t
*this,
219 identification_t
*id
);
222 * Check if a peer uses a reauth id using one of the registered providers.
224 * @param id reauthentication identity (candidate)
225 * @param mk buffer receiving master key MK
226 * @param counter pointer receiving current counter value, host order
227 * @return permanent identity, NULL if not a known reauth identity
229 identification_t
* (*provider_is_reauth
)(simaka_manager_t
*this,
230 identification_t
*id
, char mk
[HASH_SIZE_SHA1
],
234 * Generate a fast reauth id using one of the registered providers.
236 * @param id permanent peer identity
237 * @param mk master key to store along with generated identity
238 * @return fast reauthentication identity, NULL to not use reauth
240 identification_t
* (*provider_gen_reauth
)(simaka_manager_t
*this,
241 identification_t
*id
, char mk
[HASH_SIZE_SHA1
]);
244 * Register a set of hooks to the manager.
246 * @param hooks hook interface implementation to register
248 void (*add_hooks
)(simaka_manager_t
*this, simaka_hooks_t
*hooks
);
251 * Unregister a set of hooks from the manager.
253 * @param hooks hook interface implementation to unregister
255 void (*remove_hooks
)(simaka_manager_t
*this, simaka_hooks_t
*hooks
);
258 * Invoke SIM/AKA message hook.
260 * @param message SIM message
261 * @param inbound TRUE for incoming messages, FALSE for outgoing
262 * @param decrypted TRUE if AT_ENCR_DATA has been decrypted
264 void (*message_hook
)(simaka_manager_t
*this, simaka_message_t
*message
,
265 bool inbound
, bool decrypted
);
268 * Invoke SIM/AKA key hook.
270 * @param k_encr SIM/AKA encryption key k_encr
271 * @param k_auth SIM/AKA authentication key k_auth
273 void (*key_hook
)(simaka_manager_t
*this, chunk_t k_encr
, chunk_t k_auth
);
276 * Destroy a manager instance.
278 void (*destroy
)(simaka_manager_t
*this);
282 * Create an SIM/AKA manager to handle multiple (U)SIM cards/providers.
284 * @return simaka_t object
286 simaka_manager_t
*simaka_manager_create();
289 * Callback for the simaka_manager_register_cb_t, provides backend to register.
291 * @param plugin plugin registering a backend (card or provider)
292 * @return a simaka_card_t* or simaka_provider_t*, NULL on failure
294 typedef void* (*simaka_manager_register_cb_t
)(plugin_t
*plugin
);
297 * Helper function to (un-)register SIM/AKA backend plugin features.
299 * This function is a plugin_feature_callback_t and can be used with the
300 * PLUGIN_CALLBACK macro to register a SIM/AKA backend.
302 * @param plugin plugin registering the SIM/AKA backend
303 * @param feature associated plugin feature
304 * @param reg TRUE to register, FALSE to unregister.
305 * @param data data passed to callback, an simaka_manager_register_cb_t
307 bool simaka_manager_register(plugin_t
*plugin
, plugin_feature_t
*feature
,
308 bool reg
, void *data
);
312 * @addtogroup libsimaka
315 * Dummy libsimaka initialization function needed for integrity test
317 void libsimaka_init(void);
319 #endif /** SIMAKA_MANAGER_H_ @}*/