simaka_message.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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. * @defgroup libsimaka libsimaka
  17. *
  18. * @addtogroup libsimaka
  19. * Library providing functions shared between EAP-SIM and EAP-AKA plugins.
  20. *
  21. * @defgroup simaka_message simaka_message
  22. * @{ @ingroup libsimaka
  23. */
  24. #ifndef SIMAKA_MESSAGE_H_
  25. #define SIMAKA_MESSAGE_H_
  26. #include <utils/utils.h>
  27. #include <eap/eap.h>
  28. #include "simaka_crypto.h"
  29. typedef enum simaka_attribute_t simaka_attribute_t;
  30. typedef enum simaka_subtype_t simaka_subtype_t;
  31. typedef enum simaka_notification_t simaka_notification_t;
  32. typedef enum simaka_client_error_t simaka_client_error_t;
  33. typedef struct simaka_message_t simaka_message_t;
  34. /**
  35. * Subtypes of EAP-SIM/AKA messages
  36. */
  37. enum simaka_subtype_t {
  38. AKA_CHALLENGE = 1,
  39. AKA_AUTHENTICATION_REJECT = 2,
  40. AKA_SYNCHRONIZATION_FAILURE = 4,
  41. AKA_IDENTITY = 5,
  42. SIM_START = 10,
  43. SIM_CHALLENGE = 11,
  44. SIM_NOTIFICATION = 12,
  45. AKA_NOTIFICATION = 12,
  46. SIM_REAUTHENTICATION = 13,
  47. AKA_REAUTHENTICATION = 13,
  48. SIM_CLIENT_ERROR = 14,
  49. AKA_CLIENT_ERROR = 14,
  50. };
  51. /**
  52. * Enum names for simaka_subtype_t
  53. */
  54. extern enum_name_t *simaka_subtype_names;
  55. /**
  56. * Attributes in EAP-SIM/AKA messages
  57. */
  58. enum simaka_attribute_t {
  59. AT_RAND = 1,
  60. AT_AUTN = 2,
  61. AT_RES = 3,
  62. AT_AUTS = 4,
  63. AT_PADDING = 6,
  64. AT_NONCE_MT = 7,
  65. AT_PERMANENT_ID_REQ = 10,
  66. AT_MAC = 11,
  67. AT_NOTIFICATION = 12,
  68. AT_ANY_ID_REQ = 13,
  69. AT_IDENTITY = 14,
  70. AT_VERSION_LIST = 15,
  71. AT_SELECTED_VERSION = 16,
  72. AT_FULLAUTH_ID_REQ = 17,
  73. AT_COUNTER = 19,
  74. AT_COUNTER_TOO_SMALL = 20,
  75. AT_NONCE_S = 21,
  76. AT_CLIENT_ERROR_CODE = 22,
  77. AT_IV = 129,
  78. AT_ENCR_DATA = 130,
  79. AT_NEXT_PSEUDONYM = 132,
  80. AT_NEXT_REAUTH_ID = 133,
  81. AT_CHECKCODE = 134,
  82. AT_RESULT_IND = 135,
  83. };
  84. /**
  85. * Enum names for simaka_attribute_t
  86. */
  87. extern enum_name_t *simaka_attribute_names;
  88. /**
  89. * Notification codes used within AT_NOTIFICATION attribute.
  90. */
  91. enum simaka_notification_t {
  92. /** SIM General failure after authentication. (Implies failure) */
  93. SIM_GENERAL_FAILURE_AA = 0,
  94. /** AKA General failure after authentication. (Implies failure) */
  95. AKA_GENERAL_FAILURE_AA = 0,
  96. /** SIM General failure. (Implies failure, used before authentication) */
  97. SIM_GENERAL_FAILURE = 16384,
  98. /** AKA General failure. (Implies failure, used before authentication) */
  99. AKA_GENERAL_FAILURE = 16384,
  100. /** SIM User has been temporarily denied access to the requested service. */
  101. SIM_TEMP_DENIED = 1026,
  102. /** AKA User has been temporarily denied access to the requested service. */
  103. AKA_TEMP_DENIED = 1026,
  104. /** SIM User has not subscribed to the requested service. */
  105. SIM_NOT_SUBSCRIBED = 1031,
  106. /** AKA User has not subscribed to the requested service. */
  107. AKA_NOT_SUBSCRIBED = 1031,
  108. /** SIM Success. User has been successfully authenticated. */
  109. SIM_SUCCESS = 32768,
  110. /** AKA Success. User has been successfully authenticated. */
  111. AKA_SUCCESS = 32768,
  112. };
  113. /**
  114. * Enum names for simaka_notification_t
  115. */
  116. extern enum_name_t *simaka_notification_names;
  117. /**
  118. * Error codes sent in AT_CLIENT_ERROR_CODE attribute
  119. */
  120. enum simaka_client_error_t {
  121. /** AKA unable to process packet */
  122. AKA_UNABLE_TO_PROCESS = 0,
  123. /** SIM unable to process packet */
  124. SIM_UNABLE_TO_PROCESS = 0,
  125. /** SIM unsupported version */
  126. SIM_UNSUPPORTED_VERSION = 1,
  127. /** SIM insufficient number of challenges */
  128. SIM_INSUFFICIENT_CHALLENGES = 2,
  129. /** SIM RANDs are not fresh */
  130. SIM_RANDS_NOT_FRESH = 3,
  131. };
  132. /**
  133. * Enum names for simaka_client_error_t
  134. */
  135. extern enum_name_t *simaka_client_error_names;
  136. /**
  137. * Check if an EAP-SIM/AKA attribute is "skippable".
  138. *
  139. * @param attribute attribute to check
  140. * @return TRUE if attribute skippable, FALSE if non-skippable
  141. */
  142. bool simaka_attribute_skippable(simaka_attribute_t attribute);
  143. /**
  144. * EAP-SIM and EAP-AKA message abstraction.
  145. *
  146. * Messages for EAP-SIM and EAP-AKA share a common format, this class
  147. * abstracts such a message and provides encoding/encryption/signing
  148. * functionality.
  149. */
  150. struct simaka_message_t {
  151. /**
  152. * Check if the given message is a request or response.
  153. *
  154. * @return TRUE if request, FALSE if response
  155. */
  156. bool (*is_request)(simaka_message_t *this);
  157. /**
  158. * Get the EAP message identifier.
  159. *
  160. * @return EAP message identifier
  161. */
  162. uint8_t (*get_identifier)(simaka_message_t *this);
  163. /**
  164. * Get the EAP type of the message.
  165. *
  166. * @return EAP type: EAP-SIM or EAP-AKA
  167. */
  168. eap_type_t (*get_type)(simaka_message_t *this);
  169. /**
  170. * Get the subtype of an EAP-SIM message.
  171. *
  172. * @return subtype of message
  173. */
  174. simaka_subtype_t (*get_subtype)(simaka_message_t *this);
  175. /**
  176. * Create an enumerator over message attributes.
  177. *
  178. * @return enumerator over (simaka_attribute_t, chunk_t)
  179. */
  180. enumerator_t* (*create_attribute_enumerator)(simaka_message_t *this);
  181. /**
  182. * Append an attribute to the EAP-SIM message.
  183. *
  184. * Make sure to pass only data of correct length for the given attribute.
  185. *
  186. * @param type type of attribute to add to message
  187. * @param data unpadded attribute data to add
  188. */
  189. void (*add_attribute)(simaka_message_t *this, simaka_attribute_t type,
  190. chunk_t data);
  191. /**
  192. * Parse a message, with optional attribute decryption.
  193. *
  194. * This method does not verify message integrity, as the key is available
  195. * only after the payload has been parsed. It might be necessary to call
  196. * parse twice, as key derivation data in EAP-SIM/AKA is in the same
  197. * packet as encrypted data.
  198. *
  199. * @param crypto EAP-SIM/AKA crypto helper
  200. * @return TRUE if message parsed successfully
  201. */
  202. bool (*parse)(simaka_message_t *this);
  203. /**
  204. * Verify the message integrity of a parsed message.
  205. *
  206. * @param crypto EAP-SIM/AKA crypto helper
  207. * @param sigdata additional data to include in signature, if any
  208. * @return TRUE if message integrity check successful
  209. */
  210. bool (*verify)(simaka_message_t *this, chunk_t sigdata);
  211. /**
  212. * Generate a message, optionally encrypt attributes and create a MAC.
  213. *
  214. * @param sigdata additional data to include in signature, if any
  215. * @param gen allocated generated data, if successful
  216. * @return TRUE if successful
  217. */
  218. bool (*generate)(simaka_message_t *this, chunk_t sigdata, chunk_t *gen);
  219. /**
  220. * Destroy a simaka_message_t.
  221. */
  222. void (*destroy)(simaka_message_t *this);
  223. };
  224. /**
  225. * Create an empty simaka_message.
  226. *
  227. * @param request TRUE for a request message, FALSE for a response
  228. * @param identifier EAP message identifier
  229. * @param type EAP type: EAP-SIM or EAP-AKA
  230. * @param subtype subtype of the EAP message
  231. * @param crypto EAP-SIM/AKA crypto helper
  232. * @return empty message of requested kind, NULL on error
  233. */
  234. simaka_message_t *simaka_message_create(bool request, uint8_t identifier,
  235. eap_type_t type, simaka_subtype_t subtype,
  236. simaka_crypto_t *crypto);
  237. /**
  238. * Create an simaka_message from a chunk of data.
  239. *
  240. * @param data message data to parse
  241. * @param crypto EAP-SIM/AKA crypto helper
  242. * @return EAP message, NULL on error
  243. */
  244. simaka_message_t *simaka_message_create_from_payload(chunk_t data,
  245. simaka_crypto_t *crypto);
  246. #endif /** SIMAKA_MESSAGE_H_ @}*/