?? eap_sim_common.c
字號:
break; case EAP_SIM_AT_AUTS: wpa_printf(MSG_DEBUG, "EAP-AKA: AT_AUTS"); if (!aka) { wpa_printf(MSG_DEBUG, "EAP-SIM: " "Unexpected AT_AUTS"); return -1; } if (alen != EAP_AKA_AUTS_LEN) { wpa_printf(MSG_INFO, "EAP-AKA: Invalid AT_AUTS" " (len %lu)", (unsigned long) alen); return -1; } attr->auts = apos; break; case EAP_SIM_AT_CHECKCODE: wpa_printf(MSG_DEBUG, "EAP-AKA: AT_CHECKCODE"); if (!aka) { wpa_printf(MSG_DEBUG, "EAP-SIM: " "Unexpected AT_CHECKCODE"); return -1; } apos += 2; alen -= 2; if (alen != 0 && alen != EAP_AKA_CHECKCODE_LEN && alen != EAP_AKA_PRIME_CHECKCODE_LEN) { wpa_printf(MSG_INFO, "EAP-AKA: Invalid " "AT_CHECKCODE (len %lu)", (unsigned long) alen); return -1; } attr->checkcode = apos; attr->checkcode_len = alen; break; case EAP_SIM_AT_RESULT_IND: if (encr) { wpa_printf(MSG_ERROR, "EAP-SIM: Encrypted " "AT_RESULT_IND"); return -1; } if (alen != 2) { wpa_printf(MSG_INFO, "EAP-SIM: Invalid " "AT_RESULT_IND (alen=%lu)", (unsigned long) alen); return -1; } wpa_printf(MSG_DEBUG, "EAP-SIM: AT_RESULT_IND"); attr->result_ind = 1; break;#ifdef EAP_AKA_PRIME case EAP_SIM_AT_KDF_INPUT: if (aka != 2) { wpa_printf(MSG_INFO, "EAP-AKA: Unexpected " "AT_KDF_INPUT"); return -1; } wpa_printf(MSG_DEBUG, "EAP-AKA: AT_KDF_INPUT"); plen = WPA_GET_BE16(apos); apos += 2; alen -= 2; if (plen > alen) { wpa_printf(MSG_INFO, "EAP-AKA': Invalid " "AT_KDF_INPUT (Actual Length %lu, " "remaining length %lu)", (unsigned long) plen, (unsigned long) alen); return -1; } attr->kdf_input = apos; attr->kdf_input_len = plen; break; case EAP_SIM_AT_KDF: if (aka != 2) { wpa_printf(MSG_INFO, "EAP-AKA: Unexpected " "AT_KDF"); return -1; } wpa_printf(MSG_DEBUG, "EAP-AKA: AT_KDF"); if (alen != 2) { wpa_printf(MSG_INFO, "EAP-AKA': Invalid " "AT_KDF (len %lu)", (unsigned long) alen); return -1; } if (attr->kdf_count == EAP_AKA_PRIME_KDF_MAX) { wpa_printf(MSG_DEBUG, "EAP-AKA': Too many " "AT_KDF attributes - ignore this"); continue; } attr->kdf[attr->kdf_count] = WPA_GET_BE16(apos); attr->kdf_count++; break; case EAP_SIM_AT_BIDDING: wpa_printf(MSG_DEBUG, "EAP-AKA: AT_BIDDING"); if (alen != 2) { wpa_printf(MSG_INFO, "EAP-AKA: Invalid " "AT_BIDDING (len %lu)", (unsigned long) alen); return -1; } attr->bidding = apos; break;#endif /* EAP_AKA_PRIME */ default: if (pos[0] < 128) { wpa_printf(MSG_INFO, "EAP-SIM: Unrecognized " "non-skippable attribute %d", pos[0]); return -1; } wpa_printf(MSG_DEBUG, "EAP-SIM: Unrecognized skippable" " attribute %d ignored", pos[0]); break; } pos += pos[1] * 4; } wpa_printf(MSG_DEBUG, "EAP-SIM: Attributes parsed successfully " "(aka=%d encr=%d)", aka, encr); return 0;}u8 * eap_sim_parse_encr(const u8 *k_encr, const u8 *encr_data, size_t encr_data_len, const u8 *iv, struct eap_sim_attrs *attr, int aka){ u8 *decrypted; if (!iv) { wpa_printf(MSG_INFO, "EAP-SIM: Encrypted data, but no IV"); return NULL; } decrypted = os_malloc(encr_data_len); if (decrypted == NULL) return NULL; os_memcpy(decrypted, encr_data, encr_data_len); if (aes_128_cbc_decrypt(k_encr, iv, decrypted, encr_data_len)) { os_free(decrypted); return NULL; } wpa_hexdump(MSG_MSGDUMP, "EAP-SIM: Decrypted AT_ENCR_DATA", decrypted, encr_data_len); if (eap_sim_parse_attr(decrypted, decrypted + encr_data_len, attr, aka, 1)) { wpa_printf(MSG_INFO, "EAP-SIM: (encr) Failed to parse " "decrypted AT_ENCR_DATA"); os_free(decrypted); return NULL; } return decrypted;}#define EAP_SIM_INIT_LEN 128struct eap_sim_msg { struct wpabuf *buf; size_t mac, iv, encr; /* index from buf */ int type;};struct eap_sim_msg * eap_sim_msg_init(int code, int id, int type, int subtype){ struct eap_sim_msg *msg; struct eap_hdr *eap; u8 *pos; msg = os_zalloc(sizeof(*msg)); if (msg == NULL) return NULL; msg->type = type; msg->buf = wpabuf_alloc(EAP_SIM_INIT_LEN); if (msg->buf == NULL) { os_free(msg); return NULL; } eap = wpabuf_put(msg->buf, sizeof(*eap)); eap->code = code; eap->identifier = id; pos = wpabuf_put(msg->buf, 4); *pos++ = type; *pos++ = subtype; *pos++ = 0; /* Reserved */ *pos++ = 0; /* Reserved */ return msg;}struct wpabuf * eap_sim_msg_finish(struct eap_sim_msg *msg, const u8 *k_aut, const u8 *extra, size_t extra_len){ struct eap_hdr *eap; struct wpabuf *buf; if (msg == NULL) return NULL; eap = wpabuf_mhead(msg->buf); eap->length = host_to_be16(wpabuf_len(msg->buf));#ifdef EAP_AKA_PRIME if (k_aut && msg->mac && msg->type == EAP_TYPE_AKA_PRIME) { eap_sim_add_mac_sha256(k_aut, (u8 *) wpabuf_head(msg->buf), wpabuf_len(msg->buf), (u8 *) wpabuf_mhead(msg->buf) + msg->mac, extra, extra_len); } else#endif /* EAP_AKA_PRIME */ if (k_aut && msg->mac) { eap_sim_add_mac(k_aut, (u8 *) wpabuf_head(msg->buf), wpabuf_len(msg->buf), (u8 *) wpabuf_mhead(msg->buf) + msg->mac, extra, extra_len); } buf = msg->buf; os_free(msg); return buf;}void eap_sim_msg_free(struct eap_sim_msg *msg){ if (msg) { wpabuf_free(msg->buf); os_free(msg); }}u8 * eap_sim_msg_add_full(struct eap_sim_msg *msg, u8 attr, const u8 *data, size_t len){ int attr_len = 2 + len; int pad_len; u8 *start; if (msg == NULL) return NULL; pad_len = (4 - attr_len % 4) % 4; attr_len += pad_len; if (wpabuf_resize(&msg->buf, attr_len)) return NULL; start = wpabuf_put(msg->buf, 0); wpabuf_put_u8(msg->buf, attr); wpabuf_put_u8(msg->buf, attr_len / 4); wpabuf_put_data(msg->buf, data, len); if (pad_len) os_memset(wpabuf_put(msg->buf, pad_len), 0, pad_len); return start;}u8 * eap_sim_msg_add(struct eap_sim_msg *msg, u8 attr, u16 value, const u8 *data, size_t len){ int attr_len = 4 + len; int pad_len; u8 *start; if (msg == NULL) return NULL; pad_len = (4 - attr_len % 4) % 4; attr_len += pad_len; if (wpabuf_resize(&msg->buf, attr_len)) return NULL; start = wpabuf_put(msg->buf, 0); wpabuf_put_u8(msg->buf, attr); wpabuf_put_u8(msg->buf, attr_len / 4); wpabuf_put_be16(msg->buf, value); if (data) wpabuf_put_data(msg->buf, data, len); else wpabuf_put(msg->buf, len); if (pad_len) os_memset(wpabuf_put(msg->buf, pad_len), 0, pad_len); return start;}u8 * eap_sim_msg_add_mac(struct eap_sim_msg *msg, u8 attr){ u8 *pos = eap_sim_msg_add(msg, attr, 0, NULL, EAP_SIM_MAC_LEN); if (pos) msg->mac = (pos - wpabuf_head_u8(msg->buf)) + 4; return pos;}int eap_sim_msg_add_encr_start(struct eap_sim_msg *msg, u8 attr_iv, u8 attr_encr){ u8 *pos = eap_sim_msg_add(msg, attr_iv, 0, NULL, EAP_SIM_IV_LEN); if (pos == NULL) return -1; msg->iv = (pos - wpabuf_head_u8(msg->buf)) + 4; if (os_get_random(wpabuf_mhead_u8(msg->buf) + msg->iv, EAP_SIM_IV_LEN)) { msg->iv = 0; return -1; } pos = eap_sim_msg_add(msg, attr_encr, 0, NULL, 0); if (pos == NULL) { msg->iv = 0; return -1; } msg->encr = pos - wpabuf_head_u8(msg->buf); return 0;}int eap_sim_msg_add_encr_end(struct eap_sim_msg *msg, u8 *k_encr, int attr_pad){ size_t encr_len; if (msg == NULL || k_encr == NULL || msg->iv == 0 || msg->encr == 0) return -1; encr_len = wpabuf_len(msg->buf) - msg->encr - 4; if (encr_len % 16) { u8 *pos; int pad_len = 16 - (encr_len % 16); if (pad_len < 4) { wpa_printf(MSG_WARNING, "EAP-SIM: " "eap_sim_msg_add_encr_end - invalid pad_len" " %d", pad_len); return -1; } wpa_printf(MSG_DEBUG, " *AT_PADDING"); pos = eap_sim_msg_add(msg, attr_pad, 0, NULL, pad_len - 4); if (pos == NULL) return -1; os_memset(pos + 4, 0, pad_len - 4); encr_len += pad_len; } wpa_printf(MSG_DEBUG, " (AT_ENCR_DATA data len %lu)", (unsigned long) encr_len); wpabuf_mhead_u8(msg->buf)[msg->encr + 1] = encr_len / 4 + 1; return aes_128_cbc_encrypt(k_encr, wpabuf_head_u8(msg->buf) + msg->iv, wpabuf_mhead_u8(msg->buf) + msg->encr + 4, encr_len);}void eap_sim_report_notification(void *msg_ctx, int notification, int aka){#ifndef CONFIG_NO_STDOUT_DEBUG const char *type = aka ? "AKA" : "SIM";#endif /* CONFIG_NO_STDOUT_DEBUG */ switch (notification) { case EAP_SIM_GENERAL_FAILURE_AFTER_AUTH: wpa_printf(MSG_WARNING, "EAP-%s: General failure " "notification (after authentication)", type); break; case EAP_SIM_TEMPORARILY_DENIED: wpa_printf(MSG_WARNING, "EAP-%s: Failure notification: " "User has been temporarily denied access to the " "requested service", type); break; case EAP_SIM_NOT_SUBSCRIBED: wpa_printf(MSG_WARNING, "EAP-%s: Failure notification: " "User has not subscribed to the requested service", type); break; case EAP_SIM_GENERAL_FAILURE_BEFORE_AUTH: wpa_printf(MSG_WARNING, "EAP-%s: General failure " "notification (before authentication)", type); break; case EAP_SIM_SUCCESS: wpa_printf(MSG_INFO, "EAP-%s: Successful authentication " "notification", type); break; default: if (notification >= 32768) { wpa_printf(MSG_INFO, "EAP-%s: Unrecognized " "non-failure notification %d", type, notification); } else { wpa_printf(MSG_WARNING, "EAP-%s: Unrecognized " "failure notification %d", type, notification); } }}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -