Update PKCS#11 references in template wpa_supplicant.conf
[mech_eap.git] / wpa_supplicant / mesh_rsn.c
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
9 #include "utils/includes.h"
10
11 #include "utils/common.h"
12 #include "utils/eloop.h"
13 #include "crypto/sha256.h"
14 #include "crypto/random.h"
15 #include "crypto/aes.h"
16 #include "crypto/aes_siv.h"
17 #include "rsn_supp/wpa.h"
18 #include "ap/hostapd.h"
19 #include "ap/wpa_auth.h"
20 #include "ap/sta_info.h"
21 #include "ap/ieee802_11.h"
22 #include "wpa_supplicant_i.h"
23 #include "driver_i.h"
24 #include "wpas_glue.h"
25 #include "mesh_mpm.h"
26 #include "mesh_rsn.h"
27
28 #define MESH_AUTH_TIMEOUT 10
29 #define MESH_AUTH_RETRY 3
30
31 void mesh_auth_timer(void *eloop_ctx, void *user_data)
32 {
33         struct wpa_supplicant *wpa_s = eloop_ctx;
34         struct sta_info *sta = user_data;
35         struct hostapd_data *hapd;
36
37         if (sta->sae->state != SAE_ACCEPTED) {
38                 wpa_printf(MSG_DEBUG, "AUTH: Re-authenticate with " MACSTR
39                            " (attempt %d) ",
40                            MAC2STR(sta->addr), sta->sae_auth_retry);
41                 wpa_msg(wpa_s, MSG_INFO, MESH_SAE_AUTH_FAILURE "addr=" MACSTR,
42                         MAC2STR(sta->addr));
43                 if (sta->sae_auth_retry < MESH_AUTH_RETRY) {
44                         mesh_rsn_auth_sae_sta(wpa_s, sta);
45                 } else {
46                         hapd = wpa_s->ifmsh->bss[0];
47
48                         if (sta->sae_auth_retry > MESH_AUTH_RETRY) {
49                                 ap_free_sta(hapd, sta);
50                                 return;
51                         }
52
53                         /* block the STA if exceeded the number of attempts */
54                         wpa_mesh_set_plink_state(wpa_s, sta, PLINK_BLOCKED);
55                         sta->sae->state = SAE_NOTHING;
56                         wpa_msg(wpa_s, MSG_INFO, MESH_SAE_AUTH_BLOCKED "addr="
57                                 MACSTR " duration=%d",
58                                 MAC2STR(sta->addr),
59                                 hapd->conf->ap_max_inactivity);
60                 }
61                 sta->sae_auth_retry++;
62         }
63 }
64
65
66 static void auth_logger(void *ctx, const u8 *addr, logger_level level,
67                         const char *txt)
68 {
69         if (addr)
70                 wpa_printf(MSG_DEBUG, "AUTH: " MACSTR " - %s",
71                            MAC2STR(addr), txt);
72         else
73                 wpa_printf(MSG_DEBUG, "AUTH: %s", txt);
74 }
75
76
77 static const u8 *auth_get_psk(void *ctx, const u8 *addr,
78                               const u8 *p2p_dev_addr, const u8 *prev_psk)
79 {
80         struct mesh_rsn *mesh_rsn = ctx;
81         struct hostapd_data *hapd = mesh_rsn->wpa_s->ifmsh->bss[0];
82         struct sta_info *sta = ap_get_sta(hapd, addr);
83
84         wpa_printf(MSG_DEBUG, "AUTH: %s (addr=" MACSTR " prev_psk=%p)",
85                    __func__, MAC2STR(addr), prev_psk);
86
87         if (sta && sta->auth_alg == WLAN_AUTH_SAE) {
88                 if (!sta->sae || prev_psk)
89                         return NULL;
90                 return sta->sae->pmk;
91         }
92
93         return NULL;
94 }
95
96
97 static int auth_set_key(void *ctx, int vlan_id, enum wpa_alg alg,
98                         const u8 *addr, int idx, u8 *key, size_t key_len)
99 {
100         struct mesh_rsn *mesh_rsn = ctx;
101         u8 seq[6];
102
103         os_memset(seq, 0, sizeof(seq));
104
105         if (addr) {
106                 wpa_printf(MSG_DEBUG, "AUTH: %s(alg=%d addr=" MACSTR
107                            " key_idx=%d)",
108                            __func__, alg, MAC2STR(addr), idx);
109         } else {
110                 wpa_printf(MSG_DEBUG, "AUTH: %s(alg=%d key_idx=%d)",
111                            __func__, alg, idx);
112         }
113         wpa_hexdump_key(MSG_DEBUG, "AUTH: set_key - key", key, key_len);
114
115         return wpa_drv_set_key(mesh_rsn->wpa_s, alg, addr, idx,
116                                1, seq, 6, key, key_len);
117 }
118
119
120 static int auth_start_ampe(void *ctx, const u8 *addr)
121 {
122         struct mesh_rsn *mesh_rsn = ctx;
123         struct hostapd_data *hapd;
124         struct sta_info *sta;
125
126         if (mesh_rsn->wpa_s->current_ssid->mode != WPAS_MODE_MESH)
127                 return -1;
128
129         hapd = mesh_rsn->wpa_s->ifmsh->bss[0];
130         sta = ap_get_sta(hapd, addr);
131         if (sta)
132                 eloop_cancel_timeout(mesh_auth_timer, mesh_rsn->wpa_s, sta);
133
134         mesh_mpm_auth_peer(mesh_rsn->wpa_s, addr);
135         return 0;
136 }
137
138
139 static int __mesh_rsn_auth_init(struct mesh_rsn *rsn, const u8 *addr)
140 {
141         struct wpa_auth_config conf;
142         struct wpa_auth_callbacks cb;
143         u8 seq[6] = {};
144
145         wpa_printf(MSG_DEBUG, "AUTH: Initializing group state machine");
146
147         os_memset(&conf, 0, sizeof(conf));
148         conf.wpa = 2;
149         conf.wpa_key_mgmt = WPA_KEY_MGMT_SAE;
150         conf.wpa_pairwise = WPA_CIPHER_CCMP;
151         conf.rsn_pairwise = WPA_CIPHER_CCMP;
152         conf.wpa_group = WPA_CIPHER_CCMP;
153         conf.eapol_version = 0;
154         conf.wpa_group_rekey = -1;
155
156         os_memset(&cb, 0, sizeof(cb));
157         cb.ctx = rsn;
158         cb.logger = auth_logger;
159         cb.get_psk = auth_get_psk;
160         cb.set_key = auth_set_key;
161         cb.start_ampe = auth_start_ampe;
162
163         rsn->auth = wpa_init(addr, &conf, &cb);
164         if (rsn->auth == NULL) {
165                 wpa_printf(MSG_DEBUG, "AUTH: wpa_init() failed");
166                 return -1;
167         }
168
169         /* TODO: support rekeying */
170         if (random_get_bytes(rsn->mgtk, 16) < 0)
171                 return -1;
172
173         /* group mgmt */
174         wpa_drv_set_key(rsn->wpa_s, WPA_ALG_IGTK, NULL, 4, 1,
175                         seq, sizeof(seq), rsn->mgtk, sizeof(rsn->mgtk));
176
177         /* group privacy / data frames */
178         wpa_drv_set_key(rsn->wpa_s, WPA_ALG_CCMP, NULL, 1, 1,
179                         seq, sizeof(seq), rsn->mgtk, sizeof(rsn->mgtk));
180
181         return 0;
182 }
183
184
185 static void mesh_rsn_deinit(struct mesh_rsn *rsn)
186 {
187         os_memset(rsn->mgtk, 0, sizeof(rsn->mgtk));
188         if (rsn->auth)
189                 wpa_deinit(rsn->auth);
190 }
191
192
193 struct mesh_rsn *mesh_rsn_auth_init(struct wpa_supplicant *wpa_s,
194                                     struct mesh_conf *conf)
195 {
196         struct mesh_rsn *mesh_rsn;
197         struct hostapd_data *bss = wpa_s->ifmsh->bss[0];
198         const u8 *ie;
199         size_t ie_len;
200
201         mesh_rsn = os_zalloc(sizeof(*mesh_rsn));
202         if (mesh_rsn == NULL)
203                 return NULL;
204         mesh_rsn->wpa_s = wpa_s;
205
206         if (__mesh_rsn_auth_init(mesh_rsn, wpa_s->own_addr) < 0) {
207                 mesh_rsn_deinit(mesh_rsn);
208                 os_free(mesh_rsn);
209                 return NULL;
210         }
211
212         bss->wpa_auth = mesh_rsn->auth;
213
214         ie = wpa_auth_get_wpa_ie(mesh_rsn->auth, &ie_len);
215         conf->rsn_ie = (u8 *) ie;
216         conf->rsn_ie_len = ie_len;
217
218         wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
219
220         return mesh_rsn;
221 }
222
223
224 static int index_within_array(const int *array, int idx)
225 {
226         int i;
227
228         for (i = 0; i < idx; i++) {
229                 if (array[i] == -1)
230                         return 0;
231         }
232
233         return 1;
234 }
235
236
237 static int mesh_rsn_sae_group(struct wpa_supplicant *wpa_s,
238                               struct sae_data *sae)
239 {
240         int *groups = wpa_s->ifmsh->bss[0]->conf->sae_groups;
241
242         /* Configuration may have changed, so validate current index */
243         if (!index_within_array(groups, wpa_s->mesh_rsn->sae_group_index))
244                 return -1;
245
246         for (;;) {
247                 int group = groups[wpa_s->mesh_rsn->sae_group_index];
248
249                 if (group <= 0)
250                         break;
251                 if (sae_set_group(sae, group) == 0) {
252                         wpa_dbg(wpa_s, MSG_DEBUG, "SME: Selected SAE group %d",
253                                 sae->group);
254                         return 0;
255                 }
256                 wpa_s->mesh_rsn->sae_group_index++;
257         }
258
259         return -1;
260 }
261
262
263 static int mesh_rsn_build_sae_commit(struct wpa_supplicant *wpa_s,
264                                      struct wpa_ssid *ssid,
265                                      struct sta_info *sta)
266 {
267         if (ssid->passphrase == NULL) {
268                 wpa_msg(wpa_s, MSG_DEBUG, "SAE: No password available");
269                 return -1;
270         }
271
272         if (mesh_rsn_sae_group(wpa_s, sta->sae) < 0) {
273                 wpa_msg(wpa_s, MSG_DEBUG, "SAE: Failed to select group");
274                 return -1;
275         }
276
277         return sae_prepare_commit(wpa_s->own_addr, sta->addr,
278                                   (u8 *) ssid->passphrase,
279                                   os_strlen(ssid->passphrase), sta->sae);
280 }
281
282
283 /* initiate new SAE authentication with sta */
284 int mesh_rsn_auth_sae_sta(struct wpa_supplicant *wpa_s,
285                           struct sta_info *sta)
286 {
287         struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
288         struct wpa_ssid *ssid = wpa_s->current_ssid;
289         struct rsn_pmksa_cache_entry *pmksa;
290         unsigned int rnd;
291         int ret;
292
293         if (!ssid) {
294                 wpa_msg(wpa_s, MSG_DEBUG,
295                         "AUTH: No current_ssid known to initiate new SAE");
296                 return -1;
297         }
298
299         if (!sta->sae) {
300                 sta->sae = os_zalloc(sizeof(*sta->sae));
301                 if (sta->sae == NULL)
302                         return -1;
303         }
304
305         pmksa = wpa_auth_pmksa_get(hapd->wpa_auth, sta->addr);
306         if (pmksa) {
307                 if (!sta->wpa_sm)
308                         sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
309                                                         sta->addr, NULL);
310                 if (!sta->wpa_sm) {
311                         wpa_printf(MSG_ERROR,
312                                    "mesh: Failed to initialize RSN state machine");
313                         return -1;
314                 }
315
316                 wpa_printf(MSG_DEBUG,
317                            "AUTH: Mesh PMKSA cache entry found for " MACSTR
318                            " - try to use PMKSA caching instead of new SAE authentication",
319                            MAC2STR(sta->addr));
320                 wpa_auth_pmksa_set_to_sm(pmksa, sta->wpa_sm, hapd->wpa_auth,
321                                          sta->sae->pmkid, sta->sae->pmk);
322                 sae_accept_sta(hapd, sta);
323                 sta->mesh_sae_pmksa_caching = 1;
324                 return 0;
325         }
326         sta->mesh_sae_pmksa_caching = 0;
327
328         if (mesh_rsn_build_sae_commit(wpa_s, ssid, sta))
329                 return -1;
330
331         wpa_msg(wpa_s, MSG_DEBUG,
332                 "AUTH: started authentication with SAE peer: " MACSTR,
333                 MAC2STR(sta->addr));
334
335         wpa_supplicant_set_state(wpa_s, WPA_AUTHENTICATING);
336         ret = auth_sae_init_committed(hapd, sta);
337         if (ret)
338                 return ret;
339
340         eloop_cancel_timeout(mesh_auth_timer, wpa_s, sta);
341         rnd = rand() % MESH_AUTH_TIMEOUT;
342         eloop_register_timeout(MESH_AUTH_TIMEOUT + rnd, 0, mesh_auth_timer,
343                                wpa_s, sta);
344         return 0;
345 }
346
347
348 void mesh_rsn_get_pmkid(struct mesh_rsn *rsn, struct sta_info *sta, u8 *pmkid)
349 {
350         os_memcpy(pmkid, sta->sae->pmkid, SAE_PMKID_LEN);
351 }
352
353
354 static void
355 mesh_rsn_derive_aek(struct mesh_rsn *rsn, struct sta_info *sta)
356 {
357         u8 *myaddr = rsn->wpa_s->own_addr;
358         u8 *peer = sta->addr;
359         u8 *addr1 = peer, *addr2 = myaddr;
360         u8 context[AES_BLOCK_SIZE];
361
362         /* SAE */
363         RSN_SELECTOR_PUT(context, wpa_cipher_to_suite(0, WPA_CIPHER_GCMP));
364
365         if (os_memcmp(myaddr, peer, ETH_ALEN) < 0) {
366                 addr1 = myaddr;
367                 addr2 = peer;
368         }
369         os_memcpy(context + 4, addr1, ETH_ALEN);
370         os_memcpy(context + 10, addr2, ETH_ALEN);
371
372         sha256_prf(sta->sae->pmk, sizeof(sta->sae->pmk), "AEK Derivation",
373                    context, sizeof(context), sta->aek, sizeof(sta->aek));
374 }
375
376
377 /* derive mesh temporal key from pmk */
378 int mesh_rsn_derive_mtk(struct wpa_supplicant *wpa_s, struct sta_info *sta)
379 {
380         u8 *ptr;
381         u8 *min, *max;
382         u16 min_lid, max_lid;
383         size_t nonce_len = sizeof(sta->my_nonce);
384         size_t lid_len = sizeof(sta->my_lid);
385         u8 *myaddr = wpa_s->own_addr;
386         u8 *peer = sta->addr;
387         /* 2 nonces, 2 linkids, akm suite, 2 mac addrs */
388         u8 context[64 + 4 + 4 + 12];
389
390         ptr = context;
391         if (os_memcmp(sta->my_nonce, sta->peer_nonce, nonce_len) < 0) {
392                 min = sta->my_nonce;
393                 max = sta->peer_nonce;
394         } else {
395                 min = sta->peer_nonce;
396                 max = sta->my_nonce;
397         }
398         os_memcpy(ptr, min, nonce_len);
399         os_memcpy(ptr + nonce_len, max, nonce_len);
400         ptr += 2 * nonce_len;
401
402         if (sta->my_lid < sta->peer_lid) {
403                 min_lid = host_to_le16(sta->my_lid);
404                 max_lid = host_to_le16(sta->peer_lid);
405         } else {
406                 min_lid = host_to_le16(sta->peer_lid);
407                 max_lid = host_to_le16(sta->my_lid);
408         }
409         os_memcpy(ptr, &min_lid, lid_len);
410         os_memcpy(ptr + lid_len, &max_lid, lid_len);
411         ptr += 2 * lid_len;
412
413         /* SAE */
414         RSN_SELECTOR_PUT(ptr, wpa_cipher_to_suite(0, WPA_CIPHER_GCMP));
415         ptr += 4;
416
417         if (os_memcmp(myaddr, peer, ETH_ALEN) < 0) {
418                 min = myaddr;
419                 max = peer;
420         } else {
421                 min = peer;
422                 max = myaddr;
423         }
424         os_memcpy(ptr, min, ETH_ALEN);
425         os_memcpy(ptr + ETH_ALEN, max, ETH_ALEN);
426
427         sha256_prf(sta->sae->pmk, sizeof(sta->sae->pmk),
428                    "Temporal Key Derivation", context, sizeof(context),
429                    sta->mtk, sizeof(sta->mtk));
430         return 0;
431 }
432
433
434 void mesh_rsn_init_ampe_sta(struct wpa_supplicant *wpa_s, struct sta_info *sta)
435 {
436         if (random_get_bytes(sta->my_nonce, 32) < 0) {
437                 wpa_printf(MSG_INFO, "mesh: Failed to derive random nonce");
438                 /* TODO: How to handle this more cleanly? */
439         }
440         os_memset(sta->peer_nonce, 0, 32);
441         mesh_rsn_derive_aek(wpa_s->mesh_rsn, sta);
442 }
443
444
445 /* insert AMPE and encrypted MIC at @ie.
446  * @mesh_rsn: mesh RSN context
447  * @sta: STA we're sending to
448  * @cat: pointer to category code in frame header.
449  * @buf: wpabuf to add encrypted AMPE and MIC to.
450  * */
451 int mesh_rsn_protect_frame(struct mesh_rsn *rsn, struct sta_info *sta,
452                            const u8 *cat, struct wpabuf *buf)
453 {
454         struct ieee80211_ampe_ie *ampe;
455         u8 const *ie = wpabuf_head_u8(buf) + wpabuf_len(buf);
456         u8 *ampe_ie = NULL, *mic_ie = NULL, *mic_payload;
457         const u8 *aad[] = { rsn->wpa_s->own_addr, sta->addr, cat };
458         const size_t aad_len[] = { ETH_ALEN, ETH_ALEN, ie - cat };
459         int ret = 0;
460
461         if (AES_BLOCK_SIZE + 2 + sizeof(*ampe) + 2 > wpabuf_tailroom(buf)) {
462                 wpa_printf(MSG_ERROR, "protect frame: buffer too small");
463                 return -EINVAL;
464         }
465
466         ampe_ie = os_zalloc(2 + sizeof(*ampe));
467         if (!ampe_ie) {
468                 wpa_printf(MSG_ERROR, "protect frame: out of memory");
469                 return -ENOMEM;
470         }
471
472         mic_ie = os_zalloc(2 + AES_BLOCK_SIZE);
473         if (!mic_ie) {
474                 wpa_printf(MSG_ERROR, "protect frame: out of memory");
475                 ret = -ENOMEM;
476                 goto free;
477         }
478
479         /*  IE: AMPE */
480         ampe_ie[0] = WLAN_EID_AMPE;
481         ampe_ie[1] = sizeof(*ampe);
482         ampe = (struct ieee80211_ampe_ie *) (ampe_ie + 2);
483
484         RSN_SELECTOR_PUT(ampe->selected_pairwise_suite,
485                      wpa_cipher_to_suite(WPA_PROTO_RSN, WPA_CIPHER_CCMP));
486         os_memcpy(ampe->local_nonce, sta->my_nonce, 32);
487         os_memcpy(ampe->peer_nonce, sta->peer_nonce, 32);
488         /* incomplete: see 13.5.4 */
489         /* TODO: static mgtk for now since we don't support rekeying! */
490         os_memcpy(ampe->mgtk, rsn->mgtk, 16);
491         /*  TODO: Populate Key RSC */
492         /*  expire in 13 decades or so */
493         os_memset(ampe->key_expiration, 0xff, 4);
494
495         /* IE: MIC */
496         mic_ie[0] = WLAN_EID_MIC;
497         mic_ie[1] = AES_BLOCK_SIZE;
498         wpabuf_put_data(buf, mic_ie, 2);
499         /* MIC field is output ciphertext */
500
501         /* encrypt after MIC */
502         mic_payload = (u8 *) wpabuf_put(buf, 2 + sizeof(*ampe) +
503                                         AES_BLOCK_SIZE);
504
505         if (aes_siv_encrypt(sta->aek, ampe_ie, 2 + sizeof(*ampe), 3,
506                             aad, aad_len, mic_payload)) {
507                 wpa_printf(MSG_ERROR, "protect frame: failed to encrypt");
508                 ret = -ENOMEM;
509                 goto free;
510         }
511
512 free:
513         os_free(ampe_ie);
514         os_free(mic_ie);
515
516         return ret;
517 }
518
519
520 int mesh_rsn_process_ampe(struct wpa_supplicant *wpa_s, struct sta_info *sta,
521                           struct ieee802_11_elems *elems, const u8 *cat,
522                           const u8 *chosen_pmk,
523                           const u8 *start, size_t elems_len)
524 {
525         int ret = 0;
526         struct ieee80211_ampe_ie *ampe;
527         u8 null_nonce[32] = {};
528         u8 ampe_eid;
529         u8 ampe_ie_len;
530         u8 *ampe_buf, *crypt = NULL;
531         size_t crypt_len;
532         const u8 *aad[] = { sta->addr, wpa_s->own_addr, cat };
533         const size_t aad_len[] = { ETH_ALEN, ETH_ALEN,
534                                    (elems->mic - 2) - cat };
535
536         if (!sta->sae) {
537                 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
538
539                 if (!wpa_auth_pmksa_get(hapd->wpa_auth, sta->addr)) {
540                         wpa_printf(MSG_INFO,
541                                    "Mesh RSN: SAE is not prepared yet");
542                         return -1;
543                 }
544                 mesh_rsn_auth_sae_sta(wpa_s, sta);
545         }
546
547         if (chosen_pmk && os_memcmp(chosen_pmk, sta->sae->pmkid, PMKID_LEN)) {
548                 wpa_msg(wpa_s, MSG_DEBUG,
549                         "Mesh RSN: Invalid PMKID (Chosen PMK did not match calculated PMKID)");
550                 return -1;
551         }
552
553         if (!elems->mic || elems->mic_len < AES_BLOCK_SIZE) {
554                 wpa_msg(wpa_s, MSG_DEBUG, "Mesh RSN: missing mic ie");
555                 return -1;
556         }
557
558         ampe_buf = (u8 *) elems->mic + elems->mic_len;
559         if ((int) elems_len < ampe_buf - start)
560                 return -1;
561
562         crypt_len = elems_len - (elems->mic - start);
563         if (crypt_len < 2) {
564                 wpa_msg(wpa_s, MSG_DEBUG, "Mesh RSN: missing ampe ie");
565                 return -1;
566         }
567
568         /* crypt is modified by siv_decrypt */
569         crypt = os_zalloc(crypt_len);
570         if (!crypt) {
571                 wpa_printf(MSG_ERROR, "Mesh RSN: out of memory");
572                 ret = -ENOMEM;
573                 goto free;
574         }
575
576         os_memcpy(crypt, elems->mic, crypt_len);
577
578         if (aes_siv_decrypt(sta->aek, crypt, crypt_len, 3,
579                             aad, aad_len, ampe_buf)) {
580                 wpa_printf(MSG_ERROR, "Mesh RSN: frame verification failed!");
581                 ret = -1;
582                 goto free;
583         }
584
585         ampe_eid = *ampe_buf++;
586         ampe_ie_len = *ampe_buf++;
587
588         if (ampe_eid != WLAN_EID_AMPE ||
589             ampe_ie_len < sizeof(struct ieee80211_ampe_ie)) {
590                 wpa_msg(wpa_s, MSG_DEBUG, "Mesh RSN: invalid ampe ie");
591                 ret = -1;
592                 goto free;
593         }
594
595         ampe = (struct ieee80211_ampe_ie *) ampe_buf;
596         if (os_memcmp(ampe->peer_nonce, null_nonce, 32) != 0 &&
597             os_memcmp(ampe->peer_nonce, sta->my_nonce, 32) != 0) {
598                 wpa_msg(wpa_s, MSG_DEBUG, "Mesh RSN: invalid peer nonce");
599                 ret = -1;
600                 goto free;
601         }
602         os_memcpy(sta->peer_nonce, ampe->local_nonce,
603                   sizeof(ampe->local_nonce));
604         os_memcpy(sta->mgtk, ampe->mgtk, sizeof(ampe->mgtk));
605
606         /* todo parse mgtk expiration */
607 free:
608         os_free(crypt);
609         return ret;
610 }