2 * Copyright (C) 2009 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_message simaka_message
18 * @{ @ingroup libsimaka
21 #ifndef SIMAKA_MESSAGE_H_
22 #define SIMAKA_MESSAGE_H_
27 #include "simaka_crypto.h"
29 typedef struct simaka_message_t simaka_message_t
;
30 typedef enum simaka_attribute_t simaka_attribute_t
;
31 typedef enum simaka_subtype_t simaka_subtype_t
;
34 * Subtypes of EAP-SIM/AKA messages
36 enum simaka_subtype_t
{
38 AKA_AUTHENTICATION_REJECT
= 2,
39 AKA_SYNCHRONIZATION_FAILURE
= 4,
43 SIM_NOTIFICATION
= 12,
44 AKA_NOTIFICATION
= 12,
45 SIM_REAUTHENTICATION
= 13,
46 AKA_REAUTHENTICATION
= 13,
47 SIM_CLIENT_ERROR
= 14,
48 AKA_CLIENT_ERROR
= 14,
52 * Enum names for simaka_subtype_t
54 extern enum_name_t
*simaka_subtype_names
;
57 * Attributes in EAP-SIM/AKA messages
59 enum simaka_attribute_t
{
66 AT_PERMANENT_ID_REQ
= 10,
72 AT_SELECTED_VERSION
= 16,
73 AT_FULLAUTH_ID_REQ
= 17,
75 AT_COUNTER_TOO_SMALL
= 20,
77 AT_CLIENT_ERROR_CODE
= 22,
80 AT_NEXT_PSEUDONYM
= 132,
81 AT_NEXT_REAUTH_ID
= 133,
87 * Enum names for simaka_attribute_t
89 extern enum_name_t
*simaka_attribute_names
;
92 * EAP-SIM and EAP-AKA message abstraction.
94 * Messages for EAP-SIM and EAP-AKA share a common format, this class
95 * abstracts such a message and provides encoding/encryption/signing
98 struct simaka_message_t
{
101 * Check if the given message is a request or response.
103 * @return TRUE if request, FALSE if response
105 bool (*is_request
)(simaka_message_t
*this);
108 * Get the EAP message identifier.
110 * @return EAP message identifier
112 u_int8_t (*get_identifier
)(simaka_message_t
*this);
115 * Get the EAP type of the message.
117 * @return EAP type: EAP-SIM or EAP-AKA
119 eap_type_t (*get_type
)(simaka_message_t
*this);
122 * Get the subtype of an EAP-SIM message.
124 * @return subtype of message
126 simaka_subtype_t (*get_subtype
)(simaka_message_t
*this);
129 * Create an enumerator over message attributes.
131 * @return enumerator over (simaka_attribute_t, chunk_t)
133 enumerator_t
* (*create_attribute_enumerator
)(simaka_message_t
*this);
136 * Append an attribute to the EAP-SIM message.
138 * Make sure to pass only data of correct length for the given attribute.
140 * @param type type of attribute to add to message
141 * @param data unpadded attribute data to add
143 void (*add_attribute
)(simaka_message_t
*this, simaka_attribute_t type
,
147 * Parse a message, with optional attribute decryption.
149 * This method does not verify message integrity, as the key is available
150 * only after the payload has been parsed.
152 * @param crypto EAP-SIM/AKA crypto helper
153 * @return TRUE if message parsed successfully
155 bool (*parse
)(simaka_message_t
*this, simaka_crypto_t
*crypto
);
158 * Verify the message integrity of a parsed message.
160 * @param crypto EAP-SIM/AKA crypto helper
161 * @param sigdata additional data to include in signature, if any
162 * @return TRUE if message integrity check successful
164 bool (*verify
)(simaka_message_t
*this, simaka_crypto_t
*crypto
,
168 * Generate a message, optionally encrypt attributes and create a MAC.
170 * @param crypto EAP-SIM/AKA crypto helper
171 * @param sigdata additional data to include in signature, if any
172 * @return generated eap payload, NULL if failed
174 eap_payload_t
* (*generate
)(simaka_message_t
*this, simaka_crypto_t
*crypto
,
178 * Destroy a simaka_message_t.
180 void (*destroy
)(simaka_message_t
*this);
184 * Create an empty simaka_message.
186 * @param request TRUE for a request message, FALSE for a response
187 * @param identifier EAP message identifier
188 * @param type EAP subtype of the message
189 * @return empty message of requested kind, NULL on error
191 simaka_message_t
*simaka_message_create(bool request
, u_int8_t identifier
,
192 eap_type_t type
, simaka_subtype_t subtype
);
195 * Create an simaka_message from a chunk of data.
197 * @param payload payload to create message from
198 * @return EAP message, NULL on error
200 simaka_message_t
*simaka_message_create_from_payload(eap_payload_t
*payload
);
202 #endif /* SIMAKA_MESSAGE_H_ @}*/