mesh_rsn.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574
  1. /*
  2. * WPA Supplicant - Mesh RSN routines
  3. * Copyright (c) 2013-2014, cozybit, Inc. All rights reserved.
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include "utils/includes.h"
  9. #include "utils/common.h"
  10. #include "utils/eloop.h"
  11. #include "crypto/sha256.h"
  12. #include "crypto/random.h"
  13. #include "crypto/aes.h"
  14. #include "crypto/aes_siv.h"
  15. #include "rsn_supp/wpa.h"
  16. #include "ap/hostapd.h"
  17. #include "ap/wpa_auth.h"
  18. #include "ap/sta_info.h"
  19. #include "ap/ieee802_11.h"
  20. #include "wpa_supplicant_i.h"
  21. #include "driver_i.h"
  22. #include "wpas_glue.h"
  23. #include "mesh_mpm.h"
  24. #include "mesh_rsn.h"
  25. #define MESH_AUTH_TIMEOUT 10
  26. #define MESH_AUTH_RETRY 3
  27. #define MESH_AUTH_BLOCK_DURATION 3600
  28. void mesh_auth_timer(void *eloop_ctx, void *user_data)
  29. {
  30. struct wpa_supplicant *wpa_s = eloop_ctx;
  31. struct sta_info *sta = user_data;
  32. if (sta->sae->state != SAE_ACCEPTED) {
  33. wpa_printf(MSG_DEBUG, "AUTH: Re-authenticate with " MACSTR
  34. " (attempt %d) ",
  35. MAC2STR(sta->addr), sta->sae_auth_retry);
  36. wpa_msg(wpa_s, MSG_INFO, MESH_SAE_AUTH_FAILURE "addr=" MACSTR,
  37. MAC2STR(sta->addr));
  38. if (sta->sae_auth_retry < MESH_AUTH_RETRY) {
  39. mesh_rsn_auth_sae_sta(wpa_s, sta);
  40. } else {
  41. if (sta->sae_auth_retry > MESH_AUTH_RETRY) {
  42. ap_free_sta(wpa_s->ifmsh->bss[0], sta);
  43. return;
  44. }
  45. /* block the STA if exceeded the number of attempts */
  46. wpa_mesh_set_plink_state(wpa_s, sta, PLINK_BLOCKED);
  47. sta->sae->state = SAE_NOTHING;
  48. if (wpa_s->mesh_auth_block_duration <
  49. MESH_AUTH_BLOCK_DURATION)
  50. wpa_s->mesh_auth_block_duration += 60;
  51. eloop_register_timeout(wpa_s->mesh_auth_block_duration,
  52. 0, mesh_auth_timer, wpa_s, sta);
  53. wpa_msg(wpa_s, MSG_INFO, MESH_SAE_AUTH_BLOCKED "addr="
  54. MACSTR " duration=%d",
  55. MAC2STR(sta->addr),
  56. wpa_s->mesh_auth_block_duration);
  57. }
  58. sta->sae_auth_retry++;
  59. }
  60. }
  61. static void auth_logger(void *ctx, const u8 *addr, logger_level level,
  62. const char *txt)
  63. {
  64. if (addr)
  65. wpa_printf(MSG_DEBUG, "AUTH: " MACSTR " - %s",
  66. MAC2STR(addr), txt);
  67. else
  68. wpa_printf(MSG_DEBUG, "AUTH: %s", txt);
  69. }
  70. static const u8 *auth_get_psk(void *ctx, const u8 *addr,
  71. const u8 *p2p_dev_addr, const u8 *prev_psk)
  72. {
  73. struct mesh_rsn *mesh_rsn = ctx;
  74. struct hostapd_data *hapd = mesh_rsn->wpa_s->ifmsh->bss[0];
  75. struct sta_info *sta = ap_get_sta(hapd, addr);
  76. wpa_printf(MSG_DEBUG, "AUTH: %s (addr=" MACSTR " prev_psk=%p)",
  77. __func__, MAC2STR(addr), prev_psk);
  78. if (sta && sta->auth_alg == WLAN_AUTH_SAE) {
  79. if (!sta->sae || prev_psk)
  80. return NULL;
  81. return sta->sae->pmk;
  82. }
  83. return NULL;
  84. }
  85. static int auth_set_key(void *ctx, int vlan_id, enum wpa_alg alg,
  86. const u8 *addr, int idx, u8 *key, size_t key_len)
  87. {
  88. struct mesh_rsn *mesh_rsn = ctx;
  89. u8 seq[6];
  90. os_memset(seq, 0, sizeof(seq));
  91. if (addr) {
  92. wpa_printf(MSG_DEBUG, "AUTH: %s(alg=%d addr=" MACSTR
  93. " key_idx=%d)",
  94. __func__, alg, MAC2STR(addr), idx);
  95. } else {
  96. wpa_printf(MSG_DEBUG, "AUTH: %s(alg=%d key_idx=%d)",
  97. __func__, alg, idx);
  98. }
  99. wpa_hexdump_key(MSG_DEBUG, "AUTH: set_key - key", key, key_len);
  100. return wpa_drv_set_key(mesh_rsn->wpa_s, alg, addr, idx,
  101. 1, seq, 6, key, key_len);
  102. }
  103. static int auth_start_ampe(void *ctx, const u8 *addr)
  104. {
  105. struct mesh_rsn *mesh_rsn = ctx;
  106. struct hostapd_data *hapd;
  107. struct sta_info *sta;
  108. if (mesh_rsn->wpa_s->current_ssid->mode != WPAS_MODE_MESH)
  109. return -1;
  110. hapd = mesh_rsn->wpa_s->ifmsh->bss[0];
  111. sta = ap_get_sta(hapd, addr);
  112. if (sta)
  113. eloop_cancel_timeout(mesh_auth_timer, mesh_rsn->wpa_s, sta);
  114. mesh_mpm_auth_peer(mesh_rsn->wpa_s, addr);
  115. return 0;
  116. }
  117. static int __mesh_rsn_auth_init(struct mesh_rsn *rsn, const u8 *addr)
  118. {
  119. struct wpa_auth_config conf;
  120. struct wpa_auth_callbacks cb;
  121. u8 seq[6] = {};
  122. wpa_printf(MSG_DEBUG, "AUTH: Initializing group state machine");
  123. os_memset(&conf, 0, sizeof(conf));
  124. conf.wpa = 2;
  125. conf.wpa_key_mgmt = WPA_KEY_MGMT_SAE;
  126. conf.wpa_pairwise = WPA_CIPHER_CCMP;
  127. conf.rsn_pairwise = WPA_CIPHER_CCMP;
  128. conf.wpa_group = WPA_CIPHER_CCMP;
  129. conf.eapol_version = 0;
  130. conf.wpa_group_rekey = -1;
  131. os_memset(&cb, 0, sizeof(cb));
  132. cb.ctx = rsn;
  133. cb.logger = auth_logger;
  134. cb.get_psk = auth_get_psk;
  135. cb.set_key = auth_set_key;
  136. cb.start_ampe = auth_start_ampe;
  137. rsn->auth = wpa_init(addr, &conf, &cb);
  138. if (rsn->auth == NULL) {
  139. wpa_printf(MSG_DEBUG, "AUTH: wpa_init() failed");
  140. return -1;
  141. }
  142. /* TODO: support rekeying */
  143. if (random_get_bytes(rsn->mgtk, 16) < 0) {
  144. wpa_deinit(rsn->auth);
  145. return -1;
  146. }
  147. /* group mgmt */
  148. wpa_drv_set_key(rsn->wpa_s, WPA_ALG_IGTK, NULL, 4, 1,
  149. seq, sizeof(seq), rsn->mgtk, sizeof(rsn->mgtk));
  150. /* group privacy / data frames */
  151. wpa_drv_set_key(rsn->wpa_s, WPA_ALG_CCMP, NULL, 1, 1,
  152. seq, sizeof(seq), rsn->mgtk, sizeof(rsn->mgtk));
  153. return 0;
  154. }
  155. static void mesh_rsn_deinit(struct mesh_rsn *rsn)
  156. {
  157. os_memset(rsn->mgtk, 0, sizeof(rsn->mgtk));
  158. wpa_deinit(rsn->auth);
  159. }
  160. struct mesh_rsn *mesh_rsn_auth_init(struct wpa_supplicant *wpa_s,
  161. struct mesh_conf *conf)
  162. {
  163. struct mesh_rsn *mesh_rsn;
  164. struct hostapd_data *bss = wpa_s->ifmsh->bss[0];
  165. const u8 *ie;
  166. size_t ie_len;
  167. mesh_rsn = os_zalloc(sizeof(*mesh_rsn));
  168. if (mesh_rsn == NULL)
  169. return NULL;
  170. mesh_rsn->wpa_s = wpa_s;
  171. if (__mesh_rsn_auth_init(mesh_rsn, wpa_s->own_addr) < 0) {
  172. mesh_rsn_deinit(mesh_rsn);
  173. return NULL;
  174. }
  175. bss->wpa_auth = mesh_rsn->auth;
  176. ie = wpa_auth_get_wpa_ie(mesh_rsn->auth, &ie_len);
  177. conf->ies = (u8 *) ie;
  178. conf->ie_len = ie_len;
  179. wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
  180. return mesh_rsn;
  181. }
  182. static int index_within_array(const int *array, int idx)
  183. {
  184. int i;
  185. for (i = 0; i < idx; i++) {
  186. if (array[i] == -1)
  187. return 0;
  188. }
  189. return 1;
  190. }
  191. static int mesh_rsn_sae_group(struct wpa_supplicant *wpa_s,
  192. struct sae_data *sae)
  193. {
  194. int *groups = wpa_s->ifmsh->bss[0]->conf->sae_groups;
  195. /* Configuration may have changed, so validate current index */
  196. if (!index_within_array(groups, wpa_s->mesh_rsn->sae_group_index))
  197. return -1;
  198. for (;;) {
  199. int group = groups[wpa_s->mesh_rsn->sae_group_index];
  200. if (group <= 0)
  201. break;
  202. if (sae_set_group(sae, group) == 0) {
  203. wpa_dbg(wpa_s, MSG_DEBUG, "SME: Selected SAE group %d",
  204. sae->group);
  205. return 0;
  206. }
  207. wpa_s->mesh_rsn->sae_group_index++;
  208. }
  209. return -1;
  210. }
  211. static int mesh_rsn_build_sae_commit(struct wpa_supplicant *wpa_s,
  212. struct wpa_ssid *ssid,
  213. struct sta_info *sta)
  214. {
  215. if (ssid->passphrase == NULL) {
  216. wpa_msg(wpa_s, MSG_DEBUG, "SAE: No password available");
  217. return -1;
  218. }
  219. if (mesh_rsn_sae_group(wpa_s, sta->sae) < 0) {
  220. wpa_msg(wpa_s, MSG_DEBUG, "SAE: Failed to select group");
  221. return -1;
  222. }
  223. return sae_prepare_commit(wpa_s->own_addr, sta->addr,
  224. (u8 *) ssid->passphrase,
  225. os_strlen(ssid->passphrase), sta->sae);
  226. }
  227. /* initiate new SAE authentication with sta */
  228. int mesh_rsn_auth_sae_sta(struct wpa_supplicant *wpa_s,
  229. struct sta_info *sta)
  230. {
  231. struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
  232. struct wpa_ssid *ssid = wpa_s->current_ssid;
  233. unsigned int rnd;
  234. int ret;
  235. if (!ssid) {
  236. wpa_msg(wpa_s, MSG_DEBUG,
  237. "AUTH: No current_ssid known to initiate new SAE");
  238. return -1;
  239. }
  240. if (!sta->sae) {
  241. sta->sae = os_zalloc(sizeof(*sta->sae));
  242. if (sta->sae == NULL)
  243. return -1;
  244. }
  245. if (mesh_rsn_build_sae_commit(wpa_s, ssid, sta))
  246. return -1;
  247. wpa_msg(wpa_s, MSG_DEBUG,
  248. "AUTH: started authentication with SAE peer: " MACSTR,
  249. MAC2STR(sta->addr));
  250. wpa_supplicant_set_state(wpa_s, WPA_AUTHENTICATING);
  251. ret = auth_sae_init_committed(hapd, sta);
  252. if (ret)
  253. return ret;
  254. eloop_cancel_timeout(mesh_auth_timer, wpa_s, sta);
  255. rnd = rand() % MESH_AUTH_TIMEOUT;
  256. eloop_register_timeout(MESH_AUTH_TIMEOUT + rnd, 0, mesh_auth_timer,
  257. wpa_s, sta);
  258. return 0;
  259. }
  260. void mesh_rsn_get_pmkid(struct mesh_rsn *rsn, struct sta_info *sta, u8 *pmkid)
  261. {
  262. /* don't expect wpa auth to cache the pmkid for now */
  263. rsn_pmkid(sta->sae->pmk, PMK_LEN, rsn->wpa_s->own_addr,
  264. sta->addr, pmkid,
  265. wpa_key_mgmt_sha256(wpa_auth_sta_key_mgmt(sta->wpa_sm)));
  266. }
  267. static void
  268. mesh_rsn_derive_aek(struct mesh_rsn *rsn, struct sta_info *sta)
  269. {
  270. u8 *myaddr = rsn->wpa_s->own_addr;
  271. u8 *peer = sta->addr;
  272. u8 *addr1 = peer, *addr2 = myaddr;
  273. u8 context[AES_BLOCK_SIZE];
  274. /* SAE */
  275. RSN_SELECTOR_PUT(context, wpa_cipher_to_suite(0, WPA_CIPHER_GCMP));
  276. if (os_memcmp(myaddr, peer, ETH_ALEN) < 0) {
  277. addr1 = myaddr;
  278. addr2 = peer;
  279. }
  280. os_memcpy(context + 4, addr1, ETH_ALEN);
  281. os_memcpy(context + 10, addr2, ETH_ALEN);
  282. sha256_prf(sta->sae->pmk, sizeof(sta->sae->pmk), "AEK Derivation",
  283. context, sizeof(context), sta->aek, sizeof(sta->aek));
  284. }
  285. /* derive mesh temporal key from pmk */
  286. int mesh_rsn_derive_mtk(struct wpa_supplicant *wpa_s, struct sta_info *sta)
  287. {
  288. u8 *ptr;
  289. u8 *min, *max;
  290. u16 min_lid, max_lid;
  291. size_t nonce_len = sizeof(sta->my_nonce);
  292. size_t lid_len = sizeof(sta->my_lid);
  293. u8 *myaddr = wpa_s->own_addr;
  294. u8 *peer = sta->addr;
  295. /* 2 nonces, 2 linkids, akm suite, 2 mac addrs */
  296. u8 context[64 + 4 + 4 + 12];
  297. ptr = context;
  298. if (os_memcmp(sta->my_nonce, sta->peer_nonce, nonce_len) < 0) {
  299. min = sta->my_nonce;
  300. max = sta->peer_nonce;
  301. } else {
  302. min = sta->peer_nonce;
  303. max = sta->my_nonce;
  304. }
  305. os_memcpy(ptr, min, nonce_len);
  306. os_memcpy(ptr + nonce_len, max, nonce_len);
  307. ptr += 2 * nonce_len;
  308. if (sta->my_lid < sta->peer_lid) {
  309. min_lid = host_to_le16(sta->my_lid);
  310. max_lid = host_to_le16(sta->peer_lid);
  311. } else {
  312. min_lid = host_to_le16(sta->peer_lid);
  313. max_lid = host_to_le16(sta->my_lid);
  314. }
  315. os_memcpy(ptr, &min_lid, lid_len);
  316. os_memcpy(ptr + lid_len, &max_lid, lid_len);
  317. ptr += 2 * lid_len;
  318. /* SAE */
  319. RSN_SELECTOR_PUT(ptr, wpa_cipher_to_suite(0, WPA_CIPHER_GCMP));
  320. ptr += 4;
  321. if (os_memcmp(myaddr, peer, ETH_ALEN) < 0) {
  322. min = myaddr;
  323. max = peer;
  324. } else {
  325. min = peer;
  326. max = myaddr;
  327. }
  328. os_memcpy(ptr, min, ETH_ALEN);
  329. os_memcpy(ptr + ETH_ALEN, max, ETH_ALEN);
  330. sha256_prf(sta->sae->pmk, sizeof(sta->sae->pmk),
  331. "Temporal Key Derivation", context, sizeof(context),
  332. sta->mtk, sizeof(sta->mtk));
  333. return 0;
  334. }
  335. void mesh_rsn_init_ampe_sta(struct wpa_supplicant *wpa_s, struct sta_info *sta)
  336. {
  337. if (random_get_bytes(sta->my_nonce, 32) < 0) {
  338. wpa_printf(MSG_INFO, "mesh: Failed to derive random nonce");
  339. /* TODO: How to handle this more cleanly? */
  340. }
  341. os_memset(sta->peer_nonce, 0, 32);
  342. mesh_rsn_derive_aek(wpa_s->mesh_rsn, sta);
  343. }
  344. /* insert AMPE and encrypted MIC at @ie.
  345. * @mesh_rsn: mesh RSN context
  346. * @sta: STA we're sending to
  347. * @cat: pointer to category code in frame header.
  348. * @buf: wpabuf to add encrypted AMPE and MIC to.
  349. * */
  350. int mesh_rsn_protect_frame(struct mesh_rsn *rsn, struct sta_info *sta,
  351. const u8 *cat, struct wpabuf *buf)
  352. {
  353. struct ieee80211_ampe_ie *ampe;
  354. u8 const *ie = wpabuf_head_u8(buf) + wpabuf_len(buf);
  355. u8 *ampe_ie = NULL, *mic_ie = NULL, *mic_payload;
  356. const u8 *aad[] = { rsn->wpa_s->own_addr, sta->addr, cat };
  357. const size_t aad_len[] = { ETH_ALEN, ETH_ALEN, ie - cat };
  358. int ret = 0;
  359. if (AES_BLOCK_SIZE + 2 + sizeof(*ampe) + 2 > wpabuf_tailroom(buf)) {
  360. wpa_printf(MSG_ERROR, "protect frame: buffer too small");
  361. return -EINVAL;
  362. }
  363. ampe_ie = os_zalloc(2 + sizeof(*ampe));
  364. if (!ampe_ie) {
  365. wpa_printf(MSG_ERROR, "protect frame: out of memory");
  366. return -ENOMEM;
  367. }
  368. mic_ie = os_zalloc(2 + AES_BLOCK_SIZE);
  369. if (!mic_ie) {
  370. wpa_printf(MSG_ERROR, "protect frame: out of memory");
  371. ret = -ENOMEM;
  372. goto free;
  373. }
  374. /* IE: AMPE */
  375. ampe_ie[0] = WLAN_EID_AMPE;
  376. ampe_ie[1] = sizeof(*ampe);
  377. ampe = (struct ieee80211_ampe_ie *) (ampe_ie + 2);
  378. RSN_SELECTOR_PUT(ampe->selected_pairwise_suite,
  379. wpa_cipher_to_suite(WPA_PROTO_RSN, WPA_CIPHER_CCMP));
  380. os_memcpy(ampe->local_nonce, sta->my_nonce, 32);
  381. os_memcpy(ampe->peer_nonce, sta->peer_nonce, 32);
  382. /* incomplete: see 13.5.4 */
  383. /* TODO: static mgtk for now since we don't support rekeying! */
  384. os_memcpy(ampe->mgtk, rsn->mgtk, 16);
  385. /* TODO: Populate Key RSC */
  386. /* expire in 13 decades or so */
  387. os_memset(ampe->key_expiration, 0xff, 4);
  388. /* IE: MIC */
  389. mic_ie[0] = WLAN_EID_MIC;
  390. mic_ie[1] = AES_BLOCK_SIZE;
  391. wpabuf_put_data(buf, mic_ie, 2);
  392. /* MIC field is output ciphertext */
  393. /* encrypt after MIC */
  394. mic_payload = (u8 *) wpabuf_put(buf, 2 + sizeof(*ampe) +
  395. AES_BLOCK_SIZE);
  396. if (aes_siv_encrypt(sta->aek, ampe_ie, 2 + sizeof(*ampe), 3,
  397. aad, aad_len, mic_payload)) {
  398. wpa_printf(MSG_ERROR, "protect frame: failed to encrypt");
  399. ret = -ENOMEM;
  400. goto free;
  401. }
  402. free:
  403. os_free(ampe_ie);
  404. os_free(mic_ie);
  405. return ret;
  406. }
  407. int mesh_rsn_process_ampe(struct wpa_supplicant *wpa_s, struct sta_info *sta,
  408. struct ieee802_11_elems *elems, const u8 *cat,
  409. const u8 *start, size_t elems_len)
  410. {
  411. int ret = 0;
  412. struct ieee80211_ampe_ie *ampe;
  413. u8 null_nonce[32] = {};
  414. u8 ampe_eid;
  415. u8 ampe_ie_len;
  416. u8 *ampe_buf, *crypt = NULL;
  417. size_t crypt_len;
  418. const u8 *aad[] = { sta->addr, wpa_s->own_addr, cat };
  419. const size_t aad_len[] = { ETH_ALEN, ETH_ALEN,
  420. (elems->mic - 2) - cat };
  421. if (!elems->mic || elems->mic_len < AES_BLOCK_SIZE) {
  422. wpa_msg(wpa_s, MSG_DEBUG, "Mesh RSN: missing mic ie");
  423. return -1;
  424. }
  425. ampe_buf = (u8 *) elems->mic + elems->mic_len;
  426. if ((int) elems_len < ampe_buf - start)
  427. return -1;
  428. crypt_len = elems_len - (elems->mic - start);
  429. if (crypt_len < 2) {
  430. wpa_msg(wpa_s, MSG_DEBUG, "Mesh RSN: missing ampe ie");
  431. return -1;
  432. }
  433. /* crypt is modified by siv_decrypt */
  434. crypt = os_zalloc(crypt_len);
  435. if (!crypt) {
  436. wpa_printf(MSG_ERROR, "Mesh RSN: out of memory");
  437. ret = -ENOMEM;
  438. goto free;
  439. }
  440. os_memcpy(crypt, elems->mic, crypt_len);
  441. if (aes_siv_decrypt(sta->aek, crypt, crypt_len, 3,
  442. aad, aad_len, ampe_buf)) {
  443. wpa_printf(MSG_ERROR, "Mesh RSN: frame verification failed!");
  444. ret = -1;
  445. goto free;
  446. }
  447. ampe_eid = *ampe_buf++;
  448. ampe_ie_len = *ampe_buf++;
  449. if (ampe_eid != WLAN_EID_AMPE ||
  450. ampe_ie_len < sizeof(struct ieee80211_ampe_ie)) {
  451. wpa_msg(wpa_s, MSG_DEBUG, "Mesh RSN: invalid ampe ie");
  452. ret = -1;
  453. goto free;
  454. }
  455. ampe = (struct ieee80211_ampe_ie *) ampe_buf;
  456. if (os_memcmp(ampe->peer_nonce, null_nonce, 32) != 0 &&
  457. os_memcmp(ampe->peer_nonce, sta->my_nonce, 32) != 0) {
  458. wpa_msg(wpa_s, MSG_DEBUG, "Mesh RSN: invalid peer nonce");
  459. ret = -1;
  460. goto free;
  461. }
  462. os_memcpy(sta->peer_nonce, ampe->local_nonce,
  463. sizeof(ampe->local_nonce));
  464. os_memcpy(sta->mgtk, ampe->mgtk, sizeof(ampe->mgtk));
  465. /* todo parse mgtk expiration */
  466. free:
  467. os_free(crypt);
  468. return ret;
  469. }