Lines Matching +full:mic +full:- +full:pos

2  * WPA Supplicant - Mesh RSN routines
3 * Copyright (c) 2013-2014, cozybit, Inc. All rights reserved.
37 if (sta->sae->state != SAE_ACCEPTED) {
38 wpa_printf(MSG_DEBUG, "AUTH: Re-authenticate with " MACSTR
40 MAC2STR(sta->addr), sta->sae_auth_retry);
42 MAC2STR(sta->addr));
43 if (sta->sae_auth_retry < MESH_AUTH_RETRY) {
46 hapd = wpa_s->ifmsh->bss[0];
48 if (sta->sae_auth_retry > MESH_AUTH_RETRY) {
55 sta->sae->state = SAE_NOTHING;
58 MAC2STR(sta->addr),
59 hapd->conf->ap_max_inactivity);
61 sta->sae_auth_retry++;
70 wpa_printf(MSG_DEBUG, "AUTH: " MACSTR " - %s",
82 struct hostapd_data *hapd = mesh_rsn->wpa_s->ifmsh->bss[0];
92 if (sta && sta->auth_alg == WLAN_AUTH_SAE) {
93 if (!sta->sae || prev_psk)
95 return sta->sae->pmk;
119 wpa_hexdump_key(MSG_DEBUG, "AUTH: set_key - key", key, key_len);
121 return wpa_drv_set_key(mesh_rsn->wpa_s, -1, alg, addr, idx,
132 if (mesh_rsn->wpa_s->current_ssid->mode != WPAS_MODE_MESH)
133 return -1;
135 hapd = mesh_rsn->wpa_s->ifmsh->bss[0];
138 eloop_cancel_timeout(mesh_auth_timer, mesh_rsn->wpa_s, sta);
140 mesh_mpm_auth_peer(mesh_rsn->wpa_s, addr);
153 hapd = rsn->wpa_s->ifmsh->bss[0];
154 for (sta = hapd->sta_list; sta; sta = sta->next) {
155 if (sta->wpa_sm && cb(sta->wpa_sm, cb_ctx))
180 conf.wpa_pairwise = rsn->pairwise_cipher;
181 conf.rsn_pairwise = rsn->pairwise_cipher;
182 conf.wpa_group = rsn->group_cipher;
184 conf.wpa_group_rekey = -1;
189 conf.group_mgmt_cipher = rsn->mgmt_group_cipher;
194 rsn->auth = wpa_init(addr, &conf, &cb, rsn);
195 if (rsn->auth == NULL) {
197 return -1;
201 rsn->mgtk_len = wpa_cipher_key_len(conf.wpa_group);
202 if (random_get_bytes(rsn->mgtk, rsn->mgtk_len) < 0)
203 return -1;
204 rsn->mgtk_key_id = 1;
207 rsn->igtk_len = wpa_cipher_key_len(conf.group_mgmt_cipher);
208 if (random_get_bytes(rsn->igtk, rsn->igtk_len) < 0)
209 return -1;
210 rsn->igtk_key_id = 4;
214 rsn->igtk, rsn->igtk_len);
215 wpa_drv_set_key(rsn->wpa_s, -1,
216 wpa_cipher_to_alg(rsn->mgmt_group_cipher),
218 rsn->igtk_key_id, 1,
219 seq, sizeof(seq), rsn->igtk, rsn->igtk_len,
225 rsn->mgtk, rsn->mgtk_len);
226 wpa_drv_set_key(rsn->wpa_s, -1, wpa_cipher_to_alg(rsn->group_cipher),
228 rsn->mgtk_key_id, 1, seq, sizeof(seq),
229 rsn->mgtk, rsn->mgtk_len, KEY_FLAG_GROUP_TX_DEFAULT);
237 os_memset(rsn->mgtk, 0, sizeof(rsn->mgtk));
238 rsn->mgtk_len = 0;
239 os_memset(rsn->igtk, 0, sizeof(rsn->igtk));
240 rsn->igtk_len = 0;
241 if (rsn->auth)
242 wpa_deinit(rsn->auth);
250 struct hostapd_data *bss = wpa_s->ifmsh->bss[0];
260 mesh_rsn->wpa_s = wpa_s;
261 mesh_rsn->pairwise_cipher = conf->pairwise_cipher;
262 mesh_rsn->group_cipher = conf->group_cipher;
263 mesh_rsn->mgmt_group_cipher = conf->mgmt_group_cipher;
265 if (__mesh_rsn_auth_init(mesh_rsn, wpa_s->own_addr,
266 conf->ieee80211w, conf->ocv) < 0) {
272 bss->wpa_auth = mesh_rsn->auth;
275 while ((entry = dl_list_last(&wpa_s->mesh_external_pmksa_cache,
280 ret = wpa_auth_pmksa_add_entry(bss->wpa_auth,
281 entry->pmksa_cache);
282 dl_list_del(&entry->list);
290 ie = wpa_auth_get_wpa_ie(mesh_rsn->auth, &ie_len);
291 conf->rsn_ie = (u8 *) ie;
292 conf->rsn_ie_len = ie_len;
294 wpa_supplicant_rsn_supp_set_config(wpa_s, wpa_s->current_ssid);
305 if (array[i] == -1)
316 int *groups = wpa_s->ifmsh->bss[0]->conf->sae_groups;
319 if (!index_within_array(groups, wpa_s->mesh_rsn->sae_group_index))
320 return -1;
323 int group = groups[wpa_s->mesh_rsn->sae_group_index];
329 sae->group);
332 wpa_s->mesh_rsn->sae_group_index++;
335 return -1;
345 password = ssid->sae_password;
347 password = ssid->passphrase;
350 return -1;
353 if (mesh_rsn_sae_group(wpa_s, sta->sae) < 0) {
355 return -1;
358 if (sta->sae->tmp && !sta->sae->tmp->pw_id && ssid->sae_password_id) {
359 sta->sae->tmp->pw_id = os_strdup(ssid->sae_password_id);
360 if (!sta->sae->tmp->pw_id)
361 return -1;
363 return sae_prepare_commit(wpa_s->own_addr, sta->addr,
365 sta->sae);
373 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
374 struct wpa_ssid *ssid = wpa_s->current_ssid;
382 return -1;
385 if (!sta->sae) {
386 sta->sae = os_zalloc(sizeof(*sta->sae));
387 if (sta->sae == NULL)
388 return -1;
391 pmksa = wpa_auth_pmksa_get(hapd->wpa_auth, sta->addr, NULL);
393 if (!sta->wpa_sm)
394 sta->wpa_sm = wpa_auth_sta_init(hapd->wpa_auth,
395 sta->addr, NULL);
396 if (!sta->wpa_sm) {
399 return -1;
404 " - try to use PMKSA caching instead of new SAE authentication",
405 MAC2STR(sta->addr));
406 wpa_auth_pmksa_set_to_sm(pmksa, sta->wpa_sm, hapd->wpa_auth,
407 sta->sae->pmkid, sta->sae->pmk,
408 &sta->sae->pmk_len);
410 sta->mesh_sae_pmksa_caching = 1;
413 sta->mesh_sae_pmksa_caching = 0;
416 return -1;
420 MAC2STR(sta->addr));
436 os_memcpy(pmkid, sta->sae->pmkid, SAE_PMKID_LEN);
443 u8 *myaddr = rsn->wpa_s->own_addr;
444 u8 *peer = sta->addr;
449 * AEK = KDF-Hash-256(PMK, "AEK Derivation", Selected AKM Suite ||
467 sha256_prf(sta->sae->pmk, sizeof(sta->sae->pmk), "AEK Derivation",
468 context, sizeof(context), sta->aek, sizeof(sta->aek));
477 u8 *myaddr = wpa_s->own_addr;
478 u8 *peer = sta->addr;
482 * MTK = KDF-Hash-Length(PMK, "Temporal Key Derivation", min(localNonce,
488 if (os_memcmp(sta->my_nonce, sta->peer_nonce, WPA_NONCE_LEN) < 0) {
489 min = sta->my_nonce;
490 max = sta->peer_nonce;
492 min = sta->peer_nonce;
493 max = sta->my_nonce;
500 if (sta->my_lid < sta->peer_lid) {
501 WPA_PUT_LE16(ptr, sta->my_lid);
503 WPA_PUT_LE16(ptr, sta->peer_lid);
506 WPA_PUT_LE16(ptr, sta->peer_lid);
508 WPA_PUT_LE16(ptr, sta->my_lid);
527 sta->mtk_len = wpa_cipher_key_len(wpa_s->mesh_rsn->pairwise_cipher);
528 sha256_prf(sta->sae->pmk, SAE_PMK_LEN,
530 sta->mtk, sta->mtk_len);
537 if (random_get_bytes(sta->my_nonce, WPA_NONCE_LEN) < 0) {
541 os_memset(sta->peer_nonce, 0, WPA_NONCE_LEN);
542 mesh_rsn_derive_aek(wpa_s->mesh_rsn, sta);
546 /* insert AMPE and encrypted MIC at @ie.
550 * @buf: wpabuf to add encrypted AMPE and MIC to.
557 u8 *ampe_ie, *pos, *mic_payload;
558 const u8 *aad[] = { rsn->wpa_s->own_addr, sta->addr, cat };
559 const size_t aad_len[] = { ETH_ALEN, ETH_ALEN, ie - cat };
565 len += rsn->mgtk_len + WPA_KEY_RSC_LEN + 4;
566 if (cat[1] == PLINK_OPEN && rsn->igtk_len)
567 len += 2 + 6 + rsn->igtk_len;
571 return -EINVAL;
577 return -ENOMEM;
585 RSN_SELECTOR_PUT(ampe->selected_pairwise_suite,
587 os_memcpy(ampe->local_nonce, sta->my_nonce, WPA_NONCE_LEN);
588 os_memcpy(ampe->peer_nonce, sta->peer_nonce, WPA_NONCE_LEN);
590 pos = (u8 *) (ampe + 1);
602 os_memcpy(pos, rsn->mgtk, rsn->mgtk_len);
603 pos += rsn->mgtk_len;
604 wpa_drv_get_seqnum(rsn->wpa_s, NULL, rsn->mgtk_key_id, pos);
605 pos += WPA_KEY_RSC_LEN;
607 WPA_PUT_LE32(pos, 0xffffffff);
608 pos += 4;
614 if (rsn->igtk_len) {
615 WPA_PUT_LE16(pos, rsn->igtk_key_id);
616 pos += 2;
617 wpa_drv_get_seqnum(rsn->wpa_s, NULL, rsn->igtk_key_id, pos);
618 pos += 6;
619 os_memcpy(pos, rsn->igtk, rsn->igtk_len);
626 /* IE: MIC */
629 /* MIC field is output ciphertext */
631 /* encrypt after MIC */
634 if (aes_siv_encrypt(sta->aek, sizeof(sta->aek), ampe_ie, 2 + len, 3,
637 ret = -ENOMEM;
656 u8 *ampe_buf, *crypt = NULL, *pos, *end;
658 const u8 *aad[] = { sta->addr, wpa_s->own_addr, cat };
660 elems->mic ? (elems->mic - 2) - cat : 0 };
663 if (!sta->sae) {
664 struct hostapd_data *hapd = wpa_s->ifmsh->bss[0];
666 if (!wpa_auth_pmksa_get(hapd->wpa_auth, sta->addr, NULL)) {
669 return -1;
675 (!sta->sae ||
676 os_memcmp(chosen_pmk, sta->sae->pmkid, PMKID_LEN) != 0)) {
679 return -1;
682 if (!elems->mic || elems->mic_len < AES_BLOCK_SIZE) {
683 wpa_msg(wpa_s, MSG_DEBUG, "Mesh RSN: missing mic ie");
684 return -1;
687 ampe_buf = (u8 *) elems->mic + elems->mic_len;
688 if ((int) elems_len < ampe_buf - start)
689 return -1;
691 crypt_len = elems_len - (elems->mic - start);
694 return -1;
701 ret = -ENOMEM;
705 os_memcpy(crypt, elems->mic, crypt_len);
707 if (aes_siv_decrypt(sta->aek, sizeof(sta->aek), crypt, crypt_len, 3,
710 ret = -2;
714 crypt_len -= AES_BLOCK_SIZE;
725 ret = -1;
730 pos = (u8 *) (ampe + 1);
732 if (os_memcmp(ampe->peer_nonce, null_nonce, WPA_NONCE_LEN) != 0 &&
733 os_memcmp(ampe->peer_nonce, sta->my_nonce, WPA_NONCE_LEN) != 0) {
735 ret = -1;
738 os_memcpy(sta->peer_nonce, ampe->local_nonce,
739 sizeof(ampe->local_nonce));
758 if (end > pos) {
761 pos, end - pos);
770 sta->mgtk_key_id = 1; /* FIX: Where to get Key ID? */
771 key_len = wpa_cipher_key_len(wpa_s->mesh_rsn->group_cipher);
772 if ((int) key_len + WPA_KEY_RSC_LEN + 4 > end - pos) {
774 ret = -1;
777 sta->mgtk_len = key_len;
778 os_memcpy(sta->mgtk, pos, sta->mgtk_len);
779 wpa_hexdump_key(MSG_DEBUG, "mesh: GTKdata - MGTK",
780 sta->mgtk, sta->mgtk_len);
781 pos += sta->mgtk_len;
782 wpa_hexdump(MSG_DEBUG, "mesh: GTKdata - MGTK - Key RSC",
783 pos, WPA_KEY_RSC_LEN);
784 os_memcpy(sta->mgtk_rsc, pos, sizeof(sta->mgtk_rsc));
785 pos += WPA_KEY_RSC_LEN;
787 "mesh: GTKdata - MGTK - GTKExpirationTime: %u seconds",
788 WPA_GET_LE32(pos));
789 pos += 4;
795 key_len = wpa_cipher_key_len(wpa_s->mesh_rsn->mgmt_group_cipher);
796 if (end - pos >= (int) (2 + 6 + key_len)) {
797 sta->igtk_key_id = WPA_GET_LE16(pos);
798 wpa_printf(MSG_DEBUG, "mesh: IGTKdata - Key ID %u",
799 sta->igtk_key_id);
800 pos += 2;
801 os_memcpy(sta->igtk_rsc, pos, sizeof(sta->igtk_rsc));
802 wpa_hexdump(MSG_DEBUG, "mesh: IGTKdata - IPN",
803 sta->igtk_rsc, sizeof(sta->igtk_rsc));
804 pos += 6;
805 os_memcpy(sta->igtk, pos, key_len);
806 sta->igtk_len = key_len;
807 wpa_hexdump_key(MSG_DEBUG, "mesh: IGTKdata - IGTK",
808 sta->igtk, sta->igtk_len);