eapolutil.c (3489B)
1 /* 2 * 3 * Wireless daemon for Linux 4 * 5 * Copyright (C) 2013-2019 Intel Corporation. All rights reserved. 6 * 7 * This library is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU Lesser General Public 9 * License as published by the Free Software Foundation; either 10 * version 2.1 of the License, or (at your option) any later version. 11 * 12 * This library is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public 18 * License along with this library; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 20 * 21 */ 22 23 #ifdef HAVE_CONFIG_H 24 #include <config.h> 25 #endif 26 27 #include <stdio.h> 28 #include <errno.h> 29 #include <ell/ell.h> 30 31 #include "src/eapolutil.h" 32 #include "src/ie.h" 33 34 const struct eapol_key *eapol_key_validate(const uint8_t *frame, size_t len, 35 size_t mic_len) 36 { 37 const struct eapol_key *ek; 38 39 /* 40 * Since EAPOL_KEY_DATA_LEN actually gets the key data length bytes we 41 * have to check this first, otherwise we could potentially overrun the 42 * frame buffer 43 */ 44 if (len < EAPOL_FRAME_LEN(mic_len)) 45 return NULL; 46 47 ek = (const struct eapol_key *) frame; 48 49 if (len < EAPOL_FRAME_LEN(mic_len) + EAPOL_KEY_DATA_LEN(ek, mic_len)) 50 return NULL; 51 52 switch (ek->header.protocol_version) { 53 case EAPOL_PROTOCOL_VERSION_2001: 54 case EAPOL_PROTOCOL_VERSION_2004: 55 case EAPOL_PROTOCOL_VERSION_2010: 56 break; 57 default: 58 return NULL; 59 } 60 61 if (ek->header.packet_type != 3) 62 return NULL; 63 64 switch (ek->descriptor_type) { 65 case EAPOL_DESCRIPTOR_TYPE_RC4: 66 case EAPOL_DESCRIPTOR_TYPE_80211: 67 case EAPOL_DESCRIPTOR_TYPE_WPA: 68 break; 69 default: 70 return NULL; 71 } 72 73 switch (ek->key_descriptor_version) { 74 case EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4: 75 case EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_SHA1_AES: 76 case EAPOL_KEY_DESCRIPTOR_VERSION_AES_128_CMAC_AES: 77 case EAPOL_KEY_DESCRIPTOR_VERSION_AKM_DEFINED: 78 break; 79 default: 80 return NULL; 81 } 82 83 return ek; 84 } 85 86 int eapol_key_descriptor_version_from_akm(enum ie_rsn_akm_suite akm, 87 enum ie_rsn_cipher_suite pairwise, 88 uint8_t *outv) 89 { 90 /* 802.11-2020 Section 12.7.2 */ 91 switch (akm) { 92 case IE_RSN_AKM_SUITE_8021X: 93 case IE_RSN_AKM_SUITE_PSK: 94 if (pairwise == IE_RSN_CIPHER_SUITE_USE_GROUP_CIPHER || 95 pairwise == IE_RSN_CIPHER_SUITE_TKIP) 96 *outv = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_MD5_ARC4; 97 else 98 *outv = EAPOL_KEY_DESCRIPTOR_VERSION_HMAC_SHA1_AES; 99 100 return 0; 101 case IE_RSN_AKM_SUITE_FT_OVER_8021X: 102 case IE_RSN_AKM_SUITE_FT_USING_PSK: 103 case IE_RSN_AKM_SUITE_8021X_SHA256: 104 case IE_RSN_AKM_SUITE_PSK_SHA256: 105 *outv = EAPOL_KEY_DESCRIPTOR_VERSION_AES_128_CMAC_AES; 106 return 0; 107 case IE_RSN_AKM_SUITE_SAE_SHA256: 108 case IE_RSN_AKM_SUITE_FT_OVER_SAE_SHA256: 109 case IE_RSN_AKM_SUITE_8021X_SUITE_B_SHA256: 110 case IE_RSN_AKM_SUITE_8021X_SUITE_B_SHA384: 111 case IE_RSN_AKM_SUITE_FT_OVER_8021X_SHA384: 112 case IE_RSN_AKM_SUITE_FILS_SHA256: 113 case IE_RSN_AKM_SUITE_FILS_SHA384: 114 case IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA256: 115 case IE_RSN_AKM_SUITE_FT_OVER_FILS_SHA384: 116 case IE_RSN_AKM_SUITE_OWE: 117 case IE_RSN_AKM_SUITE_OSEN: 118 *outv = EAPOL_KEY_DESCRIPTOR_VERSION_AKM_DEFINED; 119 return 0; 120 case IE_RSN_AKM_SUITE_TDLS: 121 case IE_RSN_AKM_SUITE_AP_PEER_KEY_SHA256: 122 break; 123 } 124 125 return -ENOTSUP; 126 };