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

📄 eap.c

📁 WPA在Linux下实现的原代码 WPA在Linux下实现的原代码
💻 C
📖 第 1 页 / 共 4 页
字号:
 */void eap_sm_request_identity(struct eap_sm *sm, struct wpa_ssid *config){	eap_sm_request(sm, config, TYPE_IDENTITY, NULL, 0);}/** * eap_sm_request_password - Request password from user (ctrl_iface) * @sm: Pointer to EAP state machine allocated with eap_sm_init() * @config: Pointer to the current network configuration * * EAP methods can call this function to request password information for the * current network. This is normally called when the password is not included * in the network configuration. The request will be sent to monitor programs * through the control interface. */void eap_sm_request_password(struct eap_sm *sm, struct wpa_ssid *config){	eap_sm_request(sm, config, TYPE_PASSWORD, NULL, 0);}/** * eap_sm_request_new_password - Request new password from user (ctrl_iface) * @sm: Pointer to EAP state machine allocated with eap_sm_init() * @config: Pointer to the current network configuration * * EAP methods can call this function to request new password information for * the current network. This is normally called when the EAP method indicates * that the current password has expired and password change is required. The * request will be sent to monitor programs through the control interface. */void eap_sm_request_new_password(struct eap_sm *sm, struct wpa_ssid *config){	eap_sm_request(sm, config, TYPE_NEW_PASSWORD, NULL, 0);}/** * eap_sm_request_pin - Request SIM or smart card PIN from user (ctrl_iface) * @sm: Pointer to EAP state machine allocated with eap_sm_init() * @config: Pointer to the current network configuration * * EAP methods can call this function to request SIM or smart card PIN * information for the current network. This is normally called when the PIN is * not included in the network configuration. The request will be sent to * monitor programs through the control interface. */void eap_sm_request_pin(struct eap_sm *sm, struct wpa_ssid *config){	eap_sm_request(sm, config, TYPE_PIN, NULL, 0);}/** * eap_sm_request_otp - Request one time password from user (ctrl_iface) * @sm: Pointer to EAP state machine allocated with eap_sm_init() * @config: Pointer to the current network configuration * @msg: Message to be displayed to the user when asking for OTP * @msg_len: Length of the user displayable message * * EAP methods can call this function to request open time password (OTP) for * the current network. The request will be sent to monitor programs through * the control interface. */void eap_sm_request_otp(struct eap_sm *sm, struct wpa_ssid *config,			const char *msg, size_t msg_len){	eap_sm_request(sm, config, TYPE_OTP, msg, msg_len);}/** * eap_sm_request_passphrase - Request passphrase from user (ctrl_iface) * @sm: Pointer to EAP state machine allocated with eap_sm_init() * @config: Pointer to the current network configuration * * EAP methods can call this function to request passphrase for a private key * for the current network. This is normally called when the passphrase is not * included in the network configuration. The request will be sent to monitor * programs through the control interface. */void eap_sm_request_passphrase(struct eap_sm *sm, struct wpa_ssid *config){	eap_sm_request(sm, config, TYPE_PASSPHRASE, NULL, 0);}/** * eap_sm_notify_ctrl_attached - Notification of attached monitor * @sm: Pointer to EAP state machine allocated with eap_sm_init() * * Notify EAP state machines that a monitor was attached to the control * interface to trigger re-sending of pending requests for user input. */void eap_sm_notify_ctrl_attached(struct eap_sm *sm){	struct wpa_ssid *config = eap_get_config(sm);	if (config == NULL)		return;	/* 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, config);	if (config->pending_req_password)		eap_sm_request_password(sm, config);	if (config->pending_req_new_password)		eap_sm_request_new_password(sm, config);	if (config->pending_req_otp)		eap_sm_request_otp(sm, config, NULL, 0);	if (config->pending_req_pin)		eap_sm_request_pin(sm, config);	if (config->pending_req_passphrase)		eap_sm_request_passphrase(sm, config);}/** * eap_get_type - Get EAP type for the given EAP method name * @name: EAP method name, e.g., TLS * Returns: EAP method type or %EAP_TYPE_NONE if not found * * This function maps EAP type names into EAP type numbers based on the list of * EAP methods included in the build. */u8 eap_get_type(const char *name){	int i;	for (i = 0; i < NUM_EAP_METHODS; i++) {		if (strcmp(eap_methods[i]->name, name) == 0)			return eap_methods[i]->method;	}	return EAP_TYPE_NONE;}/** * eap_get_name - Get EAP method name for the given EAP type * @type: EAP method type * Returns: EAP method name, e.g., TLS, or %NULL if not found * * This function maps EAP type numbers into EAP type names based on the list of * EAP methods included in the build. */const char * eap_get_name(EapType type){	int i;	for (i = 0; i < NUM_EAP_METHODS; i++) {		if (eap_methods[i]->method == type)			return eap_methods[i]->name;	}	return NULL;}/** * eap_get_names - Get space separated list of names for supported EAP methods * @buf: Buffer for names * @buflen: Buffer length * Returns: Number of characters written into buf (not including nul * termination) */size_t eap_get_names(char *buf, size_t buflen){	char *pos, *end;	int i;	pos = buf;	end = pos + buflen;	for (i = 0; i < NUM_EAP_METHODS; i++) {		pos += snprintf(pos, end - pos, "%s%s",				i == 0 ? "" : " ", eap_methods[i]->name);	}	return pos - buf;}static int eap_allowed_phase2_type(int type){	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 * 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. */u8 eap_get_phase2_type(const char *name){	u8 type = eap_get_type(name);	if (eap_allowed_phase2_type(type))		return type;	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. */u8 *eap_get_phase2_types(struct wpa_ssid *config, size_t *count){	u8 *buf, method;	int i;	*count = 0;	buf = malloc(NUM_EAP_METHODS);	if (buf == NULL)		return NULL;	for (i = 0; i < NUM_EAP_METHODS; i++) {		method = eap_methods[i]->method;		if (eap_allowed_phase2_type(method)) {			if (method == EAP_TYPE_TLS && config &&			    config->private_key2 == NULL)				continue;			buf[*count] = 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 */struct wpa_ssid * eap_get_config(struct eap_sm *sm){	return sm->eapol_cb->get_config(sm->eapol_ctx);}/** * 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 * @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. */const u8 * eap_hdr_validate(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;	pos = (const u8 *) (hdr + 1);	if (msglen < sizeof(*hdr) + 1 || *pos != eap_type) {		wpa_printf(MSG_INFO, "EAP: Invalid frame type");		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;	}	*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_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 + -