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

📄 testradeap.c

📁 Radius PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
字号:
/* This sample test program demonstrates how to use EAP MD5 Method within *//* WindNet RADIUS Client												  *//* Copyright 1984 - 2006 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history____________________	10jan06,snd Fix for SPR 113557, In radius_send_eap_authentication_request(),            we are calling a procedure, radius_server_get_ip_address() to             display the IP address using the server handle10jan06,snd Changed radius_MD_string() to cciHashBlock() from Network            Security libraries->CCI Routines*/    /************************************************************************//*	Copyright (C) 1993 - 1999 RouterWare, Inc.   						*//*	Unpublished - rights reserved under the Copyright Laws of the		*//*	United States.  Use, duplication, or disclosure by the 				*//*	Government is subject to restrictions as set forth in 				*//*	subparagraph (c)(1)(ii) of the Rights in Technical Data and 		*//*	Computer Software clause at 252.227-7013.							*//*	RouterWare, Inc., 3961 MacArthur Suite 212 Newport Beach, CA 92660	*//************************************************************************/#define __EAP__#include "testradeap.h"#include <wrn/radius/radius_utils.h>#include <wrn/radius/radius_interface.h>#include <wrn/cci/cci.h>#include <netinet/in.h>#include <logLib.h>#include <sysLib.h>static void radius_eap_fake_response (RADIUS_REQUEST_HANDLE radius_request_handle, 				enum RADIUS_CODE code, 				RADIUS_ATTRIBUTE_LIST_HANDLE attribute_list_handle);static void radius_eap_fake_error_callback (RADIUS_REQUEST_HANDLE radius_request_handle, 					enum RADIUS_ERROR_CALLBACK_CODE error_code);/**********************************************************************************************************/void radius_send_test_eap_authentication_request (RADIUS_ATTRIBUTE_LIST_HANDLE attribute_list_handle,												RADIUS_REQUEST_CALLBACKS *p_callbacks){	BYTE* bp_nas_address;	USER_HANDLE *p_user_handle = (USER_HANDLE *) malloc (sizeof(USER_HANDLE));	BYTE * eap_packet = (BYTE *)malloc(strlen (username) + 5);	ULONG nas_address = htonl(0xC0A8FE78);		USHORT len = strlen(username) + 5;		USHORT len1;	char * server;	/* add username */	radius_add_attribute_to_list (attribute_list_handle, RADIUS_USER_NAME, strlen (username), (BYTE*)username);	bp_nas_address = (BYTE*)(&nas_address);	/* add NAS IP address */	radius_add_attribute_to_list (attribute_list_handle, RADIUS_NAS_IP_ADDRESS, 4, bp_nas_address);	/* display the server IP address */	server = radius_server_get_ip_address (serverHandle);	printf ("Sending authentication request to server %s\n", server);	free(server);	/* hardcode the PPP EAP packet */	eap_packet[0] = EAP_RESPONSE;	eap_packet[1] = 1; 	len1 = radius_swap(len);	memcpy(&(eap_packet[2]), &len1, 2);	eap_packet[4] = 1; 	memcpy (&(eap_packet[5]),username,strlen(username));	/* add EAP encapsulated message */	radius_add_attribute_to_list (attribute_list_handle, RADIUS_EAP_MESSAGE, 10, (BYTE *)eap_packet);	free (eap_packet);	/* store user handles */	p_user_handle->p_callbacks = p_callbacks;	p_user_handle->attribute_list_handle = attribute_list_handle;	/* send the request */    radius_server_request (serverHandle, (UINT)p_user_handle, p_callbacks, RADIUS_ACCESS_REQUEST, attribute_list_handle);}/************************************************************************//* Process challenge response by adding RADIUS_STATE to the original    *//* request handle.  Using MD5 Message Digest to calculate the challenge *//* response.  Send the Challenge Response.                              *//************************************************************************/static void radius_eap_access_challenge_response (UINT user_handle, enum RADIUS_CODE code, RADIUS_ATTRIBUTE_LIST_HANDLE response_attr_handle){	enum RADIUS_ATTRIBUTE_TYPE type;	UINT length;	BYTE *bp_chap_challenge;	USHORT len = strlen(username) + 22;	BYTE * eap_packet = (BYTE *)malloc(len);	unsigned char	nas_id = 2;	BYTE* bp_nas_id = (BYTE*) (&nas_id);	BYTE *bp_chap = (BYTE *)calloc (1, 16);	char valueString[RADIUS_MAX_ATTRIBUTE_LEN];	USHORT len1,i,mylen;	RADIUS_ATTRIBUTE_LIST_HANDLE attribute_list_handle;	USER_HANDLE* p_user_handle = (USER_HANDLE*)user_handle;	BYTE* bp_user_password = (BYTE *)user_password;	BYTE* bp_username = (BYTE *)username;	cci_t md5_result_length = MD5_RESULT_LENGTH;	attribute_list_handle = p_user_handle->attribute_list_handle;    	bp_chap_challenge = (BYTE *) calloc (1, 1 + strlen ((char *)bp_user_password) + 16);        	printf ("bp_chap_challenge memory allocation\n");	if (bp_chap_challenge == NULL)		{		return;		}	memset(bp_chap_challenge,0,sizeof(bp_chap_challenge));	memcpy (bp_chap_challenge, bp_nas_id, 1);	memcpy ((bp_chap_challenge + 1), (char *)bp_user_password, strlen ((char *)bp_user_password));	memset(bp_chap,0,sizeof(bp_chap));	printf ("before checking response attribute\n");	if (radius_attribute_list_goto_first_attribute(response_attr_handle) == false)		{		return;		}	do		{		type   = radius_attribute_list_get_attribute_type(response_attr_handle);		length = radius_attribute_list_get_attribute_length(response_attr_handle);		switch (type)			{			case RADIUS_STATE:				radius_attribute_list_get_attribute_value (response_attr_handle, 				  (void *) valueString, length);				radius_add_attribute_to_list (attribute_list_handle, type, length, (BYTE *)&valueString[0]);				break;			case RADIUS_EAP_MESSAGE:				radius_attribute_list_get_attribute_value (response_attr_handle, 				  (void *) valueString, length);				printf ("The value string is %s\n", valueString);				mylen = 1 + strlen((char *)bp_user_password);				memcpy (bp_chap_challenge + mylen, (BYTE *)&valueString[6], 16);				break;			default:            				break;			}		}		while (radius_attribute_list_goto_next_attribute(response_attr_handle));	/* encode */	cciHashBlock( CCI_DEF_PROVIDER_ID, CCI_HASH_MD5, (const cci_b*) bp_chap_challenge,(cci_t)(1 + strlen ((char *)bp_user_password) + 16), (cci_b*)bp_chap, &md5_result_length);	free((char *)bp_chap_challenge);	eap_packet[0] = EAP_RESPONSE;	eap_packet[1] = 0x02; 	len1 = radius_swap(len);	printf("The length is %x\n", len1);	memcpy(&(eap_packet[2]), &len1,2);	eap_packet[4] = 0x04; 	memset (&eap_packet[5],0x10,1);	memcpy (&eap_packet[6], (char *)bp_chap, 16);	memcpy (&eap_packet[22],(char *)bp_username,strlen((char *)bp_username));	printf("EAP challenge response packet is ");	for(i = 0; i < len; i++)		printf("%x \t", eap_packet[i]);	free((BYTE *) bp_chap);	/* remove old EAP-Message attribute */	radius_remove_attribute (attribute_list_handle, RADIUS_EAP_MESSAGE);	/* add the new EAP packet to the request handle */	radius_add_attribute_to_list (attribute_list_handle, RADIUS_EAP_MESSAGE, len, (BYTE *)eap_packet);	free ((BYTE *)eap_packet); 	printf ("sending Auth req again\n");	/* send the request */	radius_server_request (serverHandle, (UINT)p_user_handle, p_user_handle->p_callbacks, RADIUS_ACCESS_REQUEST, attribute_list_handle);}/************************************************************************/static void radius_eap_fake_response (RADIUS_REQUEST_HANDLE request_handle, enum RADIUS_CODE code, RADIUS_ATTRIBUTE_LIST_HANDLE response_attr_handle){	USER_HANDLE *p_user_handle = (USER_HANDLE *) request_handle;	switch (code)	{	case RADIUS_ACCESS_ACCEPT:		{		printf ("\n\n\n\n\n*************ACCESS ACCEPTED*************\n\n\n\n");				free (p_user_handle->p_callbacks);		radius_delete_attribute_list (p_user_handle->attribute_list_handle);		free ((void *)request_handle);		}		break;	case RADIUS_ACCESS_REJECT:		{		printf ("\n\n\n\n\n*************ACCESS REJECTED*************\n\n\n\n");				free (p_user_handle->p_callbacks);		radius_delete_attribute_list (p_user_handle->attribute_list_handle);		free ((void *)p_user_handle);		}		break;	case RADIUS_ACCOUNTING_RESPONSE:		{		printf ("\n\n\n\n\n*************ACCOUNTING RESPONSE*************\n\n\n\n");		}		break;	case RADIUS_ACCESS_CHALLENGE:		{		printf ("\n\n\n\n\n*************ACCESS CHALLENGE*************\n\n\n\n");		radius_eap_access_challenge_response (request_handle, code, response_attr_handle);		}		break;	default:		/* should not happen! */		break;	}}/************************************************************************/static void radius_eap_fake_error_callback (RADIUS_REQUEST_HANDLE request_handle, enum RADIUS_ERROR_CALLBACK_CODE error_code){	switch (error_code)	{	case RADIUS_ILLEGAL_ATTRIBUTE_LIST:		printf ("\n\n\n\n\n*************ILLEGAL ATTRIBUTE LIST*************\n\n\n\n");		break;	case RADIUS_UDP_SEND_ERROR:		printf ("\n\n\n\n\n*************UDP SEND ERROR*************\n\n\n\n");		break;	case RADIUS_MAXIMUM_NUMBER_OF_OUTSTANDING_REQUEST_REACHED:		printf ("\n\n\n\n\n*************MAX NO OF OUTSTANDING REQ REACHED*************\n\n\n\n");		break;	case RADIUS_RETRY_LIMIT_REACHED:		printf ("\n\n\n\n\n*************RETRY LIMIT REACHED*************\n\n\n\n");		break;	case RADIUS_INVALID_SERVER_SPECIFIED:		printf ("\n\n\n\n\n*************INVALID SERVER SPECIFIED*************\n\n\n\n");		break;	case RADIUS_SERVER_NOT_FOUND:		printf ("\n\n\n\n\n*************SERVER NOT FOUND*************\n\n\n\n");		break;	default:		/* should not happen! */		break;	}}/************************************************************************/void radius_eap (){			RADIUS_ATTRIBUTE_LIST_HANDLE attribute_list_handle;		RADIUS_REQUEST_CALLBACKS* p_callbacks;	attribute_list_handle = radius_create_attribute_list ();	p_callbacks = (RADIUS_REQUEST_CALLBACKS*) malloc (sizeof (RADIUS_REQUEST_CALLBACKS));	p_callbacks->fptr_radius_normal_callback = radius_eap_fake_response;		p_callbacks->fptr_radius_error_callback = radius_eap_fake_error_callback;	/* get server handle with ip = 192.168.254.85, port = 1812, and server type = Authentication */	serverHandle = radius_find_server_with_specified_parameters ("192.168.254.85", 1812, RADIUS_AUTHENTICATION_SERVER_TYPE);	if (serverHandle != INVALID_HANDLE)		{		radius_send_test_eap_authentication_request (attribute_list_handle, p_callbacks);		}	else		{		free (p_callbacks);		radius_delete_attribute_list (attribute_list_handle);		return;		}}

⌨️ 快捷键说明

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