⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 eap.c

📁 WLAN无线网络管理的最新程序
💻 C
📖 第 1 页 / 共 4 页
字号:
	/* Re-send any pending requests for user data since a new control	 * interface was added. This handles cases where the EAP authentication	 * starts immediately after system startup when the user interface is	 * not yet running. */	if (config->pending_req_identity)		eap_sm_request_identity(sm);	if (config->pending_req_password)		eap_sm_request_password(sm);	if (config->pending_req_new_password)		eap_sm_request_new_password(sm);	if (config->pending_req_otp)		eap_sm_request_otp(sm, NULL, 0);	if (config->pending_req_pin)		eap_sm_request_pin(sm);	if (config->pending_req_passphrase)		eap_sm_request_passphrase(sm);}static int eap_allowed_phase2_type(int vendor, int type){	if (vendor != EAP_VENDOR_IETF)		return 0;	return type != EAP_TYPE_PEAP && type != EAP_TYPE_TTLS &&		type != EAP_TYPE_FAST;}/** * eap_get_phase2_type - Get EAP type for the given EAP phase 2 method name * @name: EAP method name, e.g., MD5 * @vendor: Buffer for returning EAP Vendor-Id * Returns: EAP method type or %EAP_TYPE_NONE if not found * * This function maps EAP type names into EAP type numbers that are allowed for * Phase 2, i.e., for tunneled authentication. Phase 2 is used, e.g., with * EAP-PEAP, EAP-TTLS, and EAP-FAST. */u32 eap_get_phase2_type(const char *name, int *vendor){	int v;	u8 type = eap_get_type(name, &v);	if (eap_allowed_phase2_type(v, type)) {		*vendor = v;		return type;	}	*vendor = EAP_VENDOR_IETF;	return EAP_TYPE_NONE;}/** * eap_get_phase2_types - Get list of allowed EAP phase 2 types * @config: Pointer to a network configuration * @count: Pointer to a variable to be filled with number of returned EAP types * Returns: Pointer to allocated type list or %NULL on failure * * This function generates an array of allowed EAP phase 2 (tunneled) types for * the given network configuration. */struct eap_method_type * eap_get_phase2_types(struct wpa_ssid *config,					      size_t *count){	struct eap_method_type *buf;	u32 method;	int vendor;	size_t mcount;	const struct eap_method *methods, *m;	methods = eap_peer_get_methods(&mcount);	if (methods == NULL)		return NULL;	*count = 0;	buf = os_malloc(mcount * sizeof(struct eap_method_type));	if (buf == NULL)		return NULL;	for (m = methods; m; m = m->next) {		vendor = m->vendor;		method = m->method;		if (eap_allowed_phase2_type(vendor, method)) {			if (vendor == EAP_VENDOR_IETF &&			    method == EAP_TYPE_TLS && config &&			    config->private_key2 == NULL)				continue;			buf[*count].vendor = vendor;			buf[*count].method = method;			(*count)++;		}	}	return buf;}/** * eap_set_fast_reauth - Update fast_reauth setting * @sm: Pointer to EAP state machine allocated with eap_sm_init() * @enabled: 1 = Fast reauthentication is enabled, 0 = Disabled */void eap_set_fast_reauth(struct eap_sm *sm, int enabled){	sm->fast_reauth = enabled;}/** * eap_set_workaround - Update EAP workarounds setting * @sm: Pointer to EAP state machine allocated with eap_sm_init() * @workaround: 1 = Enable EAP workarounds, 0 = Disable EAP workarounds */void eap_set_workaround(struct eap_sm *sm, unsigned int workaround){	sm->workaround = workaround;}/** * eap_get_config - Get current network configuration * @sm: Pointer to EAP state machine allocated with eap_sm_init() * Returns: Pointer to the current network configuration or %NULL if not found * * EAP peer methods should avoid using this function if they can use other * access functions, like eap_get_config_identity() and * eap_get_config_password(), that do not require direct access to * struct wpa_ssid. */struct wpa_ssid * eap_get_config(struct eap_sm *sm){	return sm->eapol_cb->get_config(sm->eapol_ctx);}/** * eap_get_config_password - Get identity from the network configuration * @sm: Pointer to EAP state machine allocated with eap_sm_init() * @len: Buffer for the length of the identity * Returns: Pointer to the identity or %NULL if not found */const u8 * eap_get_config_identity(struct eap_sm *sm, size_t *len){	struct wpa_ssid *config = eap_get_config(sm);	if (config == NULL)		return NULL;	*len = config->identity_len;	return config->identity;}/** * eap_get_config_password - Get password from the network configuration * @sm: Pointer to EAP state machine allocated with eap_sm_init() * @len: Buffer for the length of the password * Returns: Pointer to the password or %NULL if not found */const u8 * eap_get_config_password(struct eap_sm *sm, size_t *len){	struct wpa_ssid *config = eap_get_config(sm);	if (config == NULL)		return NULL;	*len = config->password_len;	return config->password;}/** * eap_get_config_new_password - Get new password from network configuration * @sm: Pointer to EAP state machine allocated with eap_sm_init() * @len: Buffer for the length of the new password * Returns: Pointer to the new password or %NULL if not found */const u8 * eap_get_config_new_password(struct eap_sm *sm, size_t *len){	struct wpa_ssid *config = eap_get_config(sm);	if (config == NULL)		return NULL;	*len = config->new_password_len;	return config->new_password;}/** * eap_get_config_otp - Get one-time password from the network configuration * @sm: Pointer to EAP state machine allocated with eap_sm_init() * @len: Buffer for the length of the one-time password * Returns: Pointer to the one-time password or %NULL if not found */const u8 * eap_get_config_otp(struct eap_sm *sm, size_t *len){	struct wpa_ssid *config = eap_get_config(sm);	if (config == NULL)		return NULL;	*len = config->otp_len;	return config->otp;}/** * eap_clear_config_otp - Clear used one-time password * @sm: Pointer to EAP state machine allocated with eap_sm_init() * * This function clears a used one-time password (OTP) from the current network * configuration. This should be called when the OTP has been used and is not * needed anymore. */void eap_clear_config_otp(struct eap_sm *sm){	struct wpa_ssid *config = eap_get_config(sm);	if (config == NULL)		return;	os_memset(config->otp, 0, config->otp_len);	os_free(config->otp);	config->otp = NULL;	config->otp_len = 0;}/** * eap_key_available - Get key availability (eapKeyAvailable variable) * @sm: Pointer to EAP state machine allocated with eap_sm_init() * Returns: 1 if EAP keying material is available, 0 if not */int eap_key_available(struct eap_sm *sm){	return sm ? sm->eapKeyAvailable : 0;}/** * eap_notify_success - Notify EAP state machine about external success trigger * @sm: Pointer to EAP state machine allocated with eap_sm_init() * * This function is called when external event, e.g., successful completion of * WPA-PSK key handshake, is indicating that EAP state machine should move to * success state. This is mainly used with security modes that do not use EAP * state machine (e.g., WPA-PSK). */void eap_notify_success(struct eap_sm *sm){	if (sm) {		sm->decision = DECISION_COND_SUCC;		sm->EAP_state = EAP_SUCCESS;	}}/** * eap_notify_lower_layer_success - Notification of lower layer success * @sm: Pointer to EAP state machine allocated with eap_sm_init() * * Notify EAP state machines that a lower layer has detected a successful * authentication. This is used to recover from dropped EAP-Success messages. */void eap_notify_lower_layer_success(struct eap_sm *sm){	if (sm == NULL)		return;	if (eapol_get_bool(sm, EAPOL_eapSuccess) ||	    sm->decision == DECISION_FAIL ||	    (sm->methodState != METHOD_MAY_CONT &&	     sm->methodState != METHOD_DONE))		return;	if (sm->eapKeyData != NULL)		sm->eapKeyAvailable = TRUE;	eapol_set_bool(sm, EAPOL_eapSuccess, TRUE);	wpa_msg(sm->msg_ctx, MSG_INFO, WPA_EVENT_EAP_SUCCESS		"EAP authentication completed successfully (based on lower "		"layer success)");}/** * eap_get_eapKeyData - Get master session key (MSK) from EAP state machine * @sm: Pointer to EAP state machine allocated with eap_sm_init() * @len: Pointer to variable that will be set to number of bytes in the key * Returns: Pointer to the EAP keying data or %NULL on failure * * Fetch EAP keying material (MSK, eapKeyData) from the EAP state machine. The * key is available only after a successful authentication. EAP state machine * continues to manage the key data and the caller must not change or free the * returned data. */const u8 * eap_get_eapKeyData(struct eap_sm *sm, size_t *len){	if (sm == NULL || sm->eapKeyData == NULL) {		*len = 0;		return NULL;	}	*len = sm->eapKeyDataLen;	return sm->eapKeyData;}/** * eap_get_eapKeyData - Get EAP response data * @sm: Pointer to EAP state machine allocated with eap_sm_init() * @len: Pointer to variable that will be set to the length of the response * Returns: Pointer to the EAP response (eapRespData) or %NULL on failure * * Fetch EAP response (eapRespData) from the EAP state machine. This data is * available when EAP state machine has processed an incoming EAP request. The * EAP state machine does not maintain a reference to the response after this * function is called and the caller is responsible for freeing the data. */u8 * eap_get_eapRespData(struct eap_sm *sm, size_t *len){	u8 *resp;	if (sm == NULL || sm->eapRespData == NULL) {		*len = 0;		return NULL;	}	resp = sm->eapRespData;	*len = sm->eapRespDataLen;	sm->eapRespData = NULL;	sm->eapRespDataLen = 0;	return resp;}/** * eap_sm_register_scard_ctx - Notification of smart card context * @sm: Pointer to EAP state machine allocated with eap_sm_init() * @ctx: Context data for smart card operations * * Notify EAP state machines of context data for smart card operations. This * context data will be used as a parameter for scard_*() functions. */void eap_register_scard_ctx(struct eap_sm *sm, void *ctx){	if (sm)		sm->scard_ctx = ctx;}/** * eap_hdr_validate - Validate EAP header * @vendor: Expected EAP Vendor-Id (0 = IETF) * @eap_type: Expected EAP type number * @msg: EAP frame (starting with EAP header) * @msglen: Length of msg * @plen: Pointer to variable to contain the returned payload length * Returns: Pointer to EAP payload (after type field), or %NULL on failure * * This is a helper function for EAP method implementations. This is usually * called in the beginning of struct eap_method::process() function to verify * that the received EAP request packet has a valid header. This function is * able to process both legacy and expanded EAP headers and in most cases, the * caller can just use the returned payload pointer (into *plen) for processing * the payload regardless of whether the packet used the expanded EAP header or * not. */const u8 * eap_hdr_validate(int vendor, EapType eap_type,			    const u8 *msg, size_t msglen, size_t *plen){	const struct eap_hdr *hdr;	const u8 *pos;	size_t len;	hdr = (const struct eap_hdr *) msg;	if (msglen < sizeof(*hdr)) {		wpa_printf(MSG_INFO, "EAP: Too short EAP frame");		return NULL;	}	len = be_to_host16(hdr->length);	if (len < sizeof(*hdr) + 1 || len > msglen) {		wpa_printf(MSG_INFO, "EAP: Invalid EAP length");		return NULL;	}	pos = (const u8 *) (hdr + 1);	if (*pos == EAP_TYPE_EXPANDED) {		int exp_vendor;		u32 exp_type;		if (len < sizeof(*hdr) + 8) {			wpa_printf(MSG_INFO, "EAP: Invalid expanded EAP "				   "length");			return NULL;		}		pos++;		exp_vendor = WPA_GET_BE24(pos);		pos += 3;		exp_type = WPA_GET_BE32(pos);		pos += 4;		if (exp_vendor != vendor || exp_type != (u32) eap_type) {			wpa_printf(MSG_INFO, "EAP: Invalid expanded frame "				   "type");			return NULL;		}		*plen = len - sizeof(*hdr) - 8;		return pos;	} else {		if (vendor != EAP_VENDOR_IETF || *pos != eap_type) {			wpa_printf(MSG_INFO, "EAP: Invalid frame type");			return NULL;		}		*plen = len - sizeof(*hdr) - 1;		return pos + 1;	}}/** * eap_set_config_blob - Set or add a named configuration blob * @sm: Pointer to EAP state machine allocated with eap_sm_init() * @blob: New value for the blob * * Adds a new configuration blob or replaces the current value of an existing * blob. */void eap_set_config_blob(struct eap_sm *sm, struct wpa_config_blob *blob){	sm->eapol_cb->set_config_blob(sm->eapol_ctx, blob);}/** * eap_get_config_blob - Get a named configuration blob * @sm: Pointer to EAP state machine allocated with eap_sm_init() * @name: Name of the blob * Returns: Pointer to blob data or %NULL if not found */const struct wpa_config_blob * eap_get_config_blob(struct eap_sm *sm,						   const char *name){	return sm->eapol_cb->get_config_blob(sm->eapol_ctx, name);}/** * eap_set_force_disabled - Set force_disabled flag * @sm: Pointer to EAP state machine allocated with eap_sm_init() * @disabled: 1 = EAP disabled, 0 = EAP enabled * * This function is used to force EAP state machine to be disabled when it is * not in use (e.g., with WPA-PSK or plaintext connections). */void eap_set_force_disabled(struct eap_sm *sm, int disabled){	sm->force_disabled = disabled;}/** * eap_msg_alloc - Allocate a buffer for an EAP message * @vendor: Vendor-Id (0 = IETF) * @type: EAP type * @len: Buffer for returning message length * @payload_len: Payload length in bytes (data after Type) * @code: Message Code (EAP_CODE_*) * @identifier: Identifier * @payload: Pointer to payload pointer that will be set to point to the * beginning of the payload or %NULL if payload pointer is not needed * Returns: Pointer to the allocated message buffer or %NULL on error * * This function can be used to allocate a buffer for an EAP message and fill * in the EAP header. This function is automatically using expanded EAP header * if the selected Vendor-Id is not IETF. In other words, most EAP methods do * not need to separately select which header type to use when using this * function to allocate the message buffers. */struct eap_hdr * eap_msg_alloc(int vendor, EapType type, size_t *len,			       size_t payload_len, u8 code, u8 identifier,			       u8 **payload){	struct eap_hdr *hdr;	u8 *pos;	*len = sizeof(struct eap_hdr) + (vendor == EAP_VENDOR_IETF ? 1 : 8) +		payload_len;	hdr = os_malloc(*len);	if (hdr) {		hdr->code = code;		hdr->identifier = identifier;		hdr->length = host_to_be16(*len);		pos = (u8 *) (hdr + 1);		if (vendor == EAP_VENDOR_IETF) {			*pos++ = type;		} else {			*pos++ = EAP_TYPE_EXPANDED;			WPA_PUT_BE24(pos, vendor);			pos += 3;			WPA_PUT_BE32(pos, type);			pos += 4;		}		if (payload)			*payload = pos;	}	return hdr;} /** * eap_notify_pending - Notify that EAP method is ready to re-process a request * @sm: Pointer to EAP state machine allocated with eap_sm_init() * * An EAP method can perform a pending operation (e.g., to get a response from * an external process). Once the response is available, this function can be * used to request EAPOL state machine to retry delivering the previously * received (and still unanswered) EAP request to EAP state machine. */void eap_notify_pending(struct eap_sm *sm){	sm->eapol_cb->notify_pending(sm->eapol_ctx);}/** * eap_invalidate_cached_session - Mark cached session data invalid * @sm: Pointer to EAP state machine allocated with eap_sm_init() */void eap_invalidate_cached_session(struct eap_sm *sm){	if (sm)		eap_deinit_prev_method(sm, "invalidate");}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -