ieee802_1x_kay.h 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /*
  2. * IEEE 802.1X-2010 Key Agree Protocol of PAE state machine
  3. * Copyright (c) 2013, Qualcomm Atheros, Inc.
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #ifndef IEEE802_1X_KAY_H
  9. #define IEEE802_1X_KAY_H
  10. #include "utils/list.h"
  11. #include "common/defs.h"
  12. #include "common/ieee802_1x_defs.h"
  13. struct macsec_init_params;
  14. #define MI_LEN 12 /* 96-bit Member Identifier */
  15. #define MAX_KEY_LEN 32 /* 32 bytes, 256 bits */
  16. #define MAX_CKN_LEN 32 /* 32 bytes, 256 bits */
  17. /* MKA timer, unit: millisecond */
  18. #define MKA_HELLO_TIME 2000
  19. #define MKA_LIFE_TIME 6000
  20. #define MKA_SAK_RETIRE_TIME 3000
  21. /**
  22. * struct ieee802_1x_mka_ki - Key Identifier (KI)
  23. * @mi: Key Server's Member Identifier
  24. * @kn: Key Number, assigned by the Key Server
  25. * IEEE 802.1X-2010 9.8 SAK generation, distribution, and selection
  26. */
  27. struct ieee802_1x_mka_ki {
  28. u8 mi[MI_LEN];
  29. u32 kn;
  30. };
  31. struct ieee802_1x_mka_sci {
  32. u8 addr[ETH_ALEN];
  33. be16 port;
  34. };
  35. struct mka_key {
  36. u8 key[MAX_KEY_LEN];
  37. size_t len;
  38. };
  39. struct mka_key_name {
  40. u8 name[MAX_CKN_LEN];
  41. size_t len;
  42. };
  43. enum mka_created_mode {
  44. PSK,
  45. EAP_EXCHANGE,
  46. };
  47. struct data_key {
  48. u8 *key;
  49. int key_len;
  50. struct ieee802_1x_mka_ki key_identifier;
  51. enum confidentiality_offset confidentiality_offset;
  52. u8 an;
  53. Boolean transmits;
  54. Boolean receives;
  55. struct os_time created_time;
  56. u32 next_pn;
  57. /* not defined data */
  58. Boolean rx_latest;
  59. Boolean tx_latest;
  60. int user;
  61. struct dl_list list;
  62. };
  63. /* TransmitSC in IEEE Std 802.1AE-2006, Figure 10-6 */
  64. struct transmit_sc {
  65. struct ieee802_1x_mka_sci sci; /* const SCI sci */
  66. Boolean transmitting; /* bool transmitting (read only) */
  67. struct os_time created_time; /* Time createdTime */
  68. u8 encoding_sa; /* AN encodingSA (read only) */
  69. u8 enciphering_sa; /* AN encipheringSA (read only) */
  70. /* not defined data */
  71. struct dl_list list;
  72. struct dl_list sa_list;
  73. };
  74. /* TransmitSA in IEEE Std 802.1AE-2006, Figure 10-6 */
  75. struct transmit_sa {
  76. Boolean in_use; /* bool inUse (read only) */
  77. u32 next_pn; /* PN nextPN (read only) */
  78. struct os_time created_time; /* Time createdTime */
  79. Boolean enable_transmit; /* bool EnableTransmit */
  80. u8 an;
  81. Boolean confidentiality;
  82. struct data_key *pkey;
  83. struct transmit_sc *sc;
  84. struct dl_list list; /* list entry in struct transmit_sc::sa_list */
  85. };
  86. /* ReceiveSC in IEEE Std 802.1AE-2006, Figure 10-6 */
  87. struct receive_sc {
  88. struct ieee802_1x_mka_sci sci; /* const SCI sci */
  89. Boolean receiving; /* bool receiving (read only) */
  90. struct os_time created_time; /* Time createdTime */
  91. struct dl_list list;
  92. struct dl_list sa_list;
  93. };
  94. /* ReceiveSA in IEEE Std 802.1AE-2006, Figure 10-6 */
  95. struct receive_sa {
  96. Boolean enable_receive; /* bool enableReceive */
  97. Boolean in_use; /* bool inUse (read only) */
  98. u32 next_pn; /* PN nextPN (read only) */
  99. u32 lowest_pn; /* PN lowestPN (read only) */
  100. u8 an;
  101. struct os_time created_time;
  102. struct data_key *pkey;
  103. struct receive_sc *sc; /* list entry in struct receive_sc::sa_list */
  104. struct dl_list list;
  105. };
  106. struct ieee802_1x_kay_ctx {
  107. /* pointer to arbitrary upper level context */
  108. void *ctx;
  109. /* abstract wpa driver interface */
  110. int (*macsec_init)(void *ctx, struct macsec_init_params *params);
  111. int (*macsec_deinit)(void *ctx);
  112. int (*macsec_get_capability)(void *priv, enum macsec_cap *cap);
  113. int (*enable_protect_frames)(void *ctx, Boolean enabled);
  114. int (*enable_encrypt)(void *ctx, Boolean enabled);
  115. int (*set_replay_protect)(void *ctx, Boolean enabled, u32 window);
  116. int (*set_current_cipher_suite)(void *ctx, u64 cs);
  117. int (*enable_controlled_port)(void *ctx, Boolean enabled);
  118. int (*get_receive_lowest_pn)(void *ctx, struct receive_sa *sa);
  119. int (*get_transmit_next_pn)(void *ctx, struct transmit_sa *sa);
  120. int (*set_transmit_next_pn)(void *ctx, struct transmit_sa *sa);
  121. int (*create_receive_sc)(void *ctx, struct receive_sc *sc,
  122. enum validate_frames vf,
  123. enum confidentiality_offset co);
  124. int (*delete_receive_sc)(void *ctx, struct receive_sc *sc);
  125. int (*create_receive_sa)(void *ctx, struct receive_sa *sa);
  126. int (*delete_receive_sa)(void *ctx, struct receive_sa *sa);
  127. int (*enable_receive_sa)(void *ctx, struct receive_sa *sa);
  128. int (*disable_receive_sa)(void *ctx, struct receive_sa *sa);
  129. int (*create_transmit_sc)(void *ctx, struct transmit_sc *sc,
  130. enum confidentiality_offset co);
  131. int (*delete_transmit_sc)(void *ctx, struct transmit_sc *sc);
  132. int (*create_transmit_sa)(void *ctx, struct transmit_sa *sa);
  133. int (*delete_transmit_sa)(void *ctx, struct transmit_sa *sa);
  134. int (*enable_transmit_sa)(void *ctx, struct transmit_sa *sa);
  135. int (*disable_transmit_sa)(void *ctx, struct transmit_sa *sa);
  136. };
  137. struct ieee802_1x_kay {
  138. Boolean enable;
  139. Boolean active;
  140. Boolean authenticated;
  141. Boolean secured;
  142. Boolean failed;
  143. struct ieee802_1x_mka_sci actor_sci;
  144. u8 actor_priority;
  145. struct ieee802_1x_mka_sci key_server_sci;
  146. u8 key_server_priority;
  147. enum macsec_cap macsec_capable;
  148. Boolean macsec_desired;
  149. Boolean macsec_protect;
  150. Boolean macsec_encrypt;
  151. Boolean macsec_replay_protect;
  152. u32 macsec_replay_window;
  153. enum validate_frames macsec_validate;
  154. enum confidentiality_offset macsec_confidentiality;
  155. u32 ltx_kn;
  156. u8 ltx_an;
  157. u32 lrx_kn;
  158. u8 lrx_an;
  159. u32 otx_kn;
  160. u8 otx_an;
  161. u32 orx_kn;
  162. u8 orx_an;
  163. /* not defined in IEEE802.1X */
  164. struct ieee802_1x_kay_ctx *ctx;
  165. Boolean is_key_server;
  166. Boolean is_obliged_key_server;
  167. char if_name[IFNAMSIZ];
  168. unsigned int macsec_csindex; /* MACsec cipher suite table index */
  169. int mka_algindex; /* MKA alg table index */
  170. u32 dist_kn;
  171. u32 rcvd_keys;
  172. u8 dist_an;
  173. time_t dist_time;
  174. u8 mka_version;
  175. u8 algo_agility[4];
  176. u32 pn_exhaustion;
  177. Boolean port_enable;
  178. Boolean rx_enable;
  179. Boolean tx_enable;
  180. struct dl_list participant_list;
  181. enum macsec_policy policy;
  182. struct ieee802_1x_cp_sm *cp;
  183. struct l2_packet_data *l2_mka;
  184. enum validate_frames vf;
  185. enum confidentiality_offset co;
  186. };
  187. u64 mka_sci_u64(struct ieee802_1x_mka_sci *sci);
  188. struct ieee802_1x_kay *
  189. ieee802_1x_kay_init(struct ieee802_1x_kay_ctx *ctx, enum macsec_policy policy,
  190. u16 port, u8 priority, const char *ifname, const u8 *addr);
  191. void ieee802_1x_kay_deinit(struct ieee802_1x_kay *kay);
  192. struct ieee802_1x_mka_participant *
  193. ieee802_1x_kay_create_mka(struct ieee802_1x_kay *kay,
  194. struct mka_key_name *ckn, struct mka_key *cak,
  195. u32 life, enum mka_created_mode mode,
  196. Boolean is_authenticator);
  197. void ieee802_1x_kay_delete_mka(struct ieee802_1x_kay *kay,
  198. struct mka_key_name *ckn);
  199. void ieee802_1x_kay_mka_participate(struct ieee802_1x_kay *kay,
  200. struct mka_key_name *ckn,
  201. Boolean status);
  202. int ieee802_1x_kay_new_sak(struct ieee802_1x_kay *kay);
  203. int ieee802_1x_kay_change_cipher_suite(struct ieee802_1x_kay *kay,
  204. unsigned int cs_index);
  205. int ieee802_1x_kay_set_latest_sa_attr(struct ieee802_1x_kay *kay,
  206. struct ieee802_1x_mka_ki *lki, u8 lan,
  207. Boolean ltx, Boolean lrx);
  208. int ieee802_1x_kay_set_old_sa_attr(struct ieee802_1x_kay *kay,
  209. struct ieee802_1x_mka_ki *oki,
  210. u8 oan, Boolean otx, Boolean orx);
  211. int ieee802_1x_kay_create_sas(struct ieee802_1x_kay *kay,
  212. struct ieee802_1x_mka_ki *lki);
  213. int ieee802_1x_kay_delete_sas(struct ieee802_1x_kay *kay,
  214. struct ieee802_1x_mka_ki *ki);
  215. int ieee802_1x_kay_enable_tx_sas(struct ieee802_1x_kay *kay,
  216. struct ieee802_1x_mka_ki *lki);
  217. int ieee802_1x_kay_enable_rx_sas(struct ieee802_1x_kay *kay,
  218. struct ieee802_1x_mka_ki *lki);
  219. int ieee802_1x_kay_enable_new_info(struct ieee802_1x_kay *kay);
  220. int ieee802_1x_kay_get_status(struct ieee802_1x_kay *kay, char *buf,
  221. size_t buflen);
  222. #endif /* IEEE802_1X_KAY_H */