📄 testradeap.c
字号:
/* This sample test program demonstrates how to use EAP MD5 Method within *//* WindNet RADIUS Client *//* Copyright 1984 - 2000 Wind River Systems, Inc. */#include "copyright_wrs.h"/************************************************************************//* 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 *//************************************************************************/#include <netinet\in.h>#include <logLib.h>#include "radius.h"#include "testradeap.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; ULONG value; RW_CONTAINER_ITERATOR server_iterator; RADIUS_SERVER *p_server; USER_HANDLE *p_user_handle = (USER_HANDLE *) malloc (sizeof(USER_HANDLE)); struct in_addr inetAddr; EAP_PACKET* eap_packet = (EAP_PACKET *)malloc(10); ULONG nas_address = swap_long(0xC0A8FE78); unsigned char nas_id = 1; BYTE* bp_nas_id = (BYTE*) (&nas_id); BYTE* ip_string = (BYTE *)malloc(18); /* add username */ radius_add_attribute_to_list (attribute_list_handle, RADIUS_USER_NAME, strlen (username), 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_iterator = (RW_CONTAINER_ITERATOR) serverHandle; p_server = (RADIUS_SERVER*) rw_container_at (server_iterator); radius_util_serialize_ulong(p_server->ip_address, (BYTE *)&value); inetAddr.s_addr = value; inet_ntoa_b(inetAddr, ip_string); printf ("Sending authentication request to server %s\n", ip_string); free(ip_string); /* hardcode the PPP EAP packet */ eap_packet->code = EAP_RESPONSE; eap_packet->identifier = 0x01; eap_packet->length = swap(0xa); eap_packet->type = 0x01; memcpy (&eap_packet->data[0],"user1",strlen("user1")); /* 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 (RADIUS_REQUEST_HANDLE request_handle, enum RADIUS_CODE code, RADIUS_ATTRIBUTE_LIST_HANDLE response_attr_handle){ enum RADIUS_ATTRIBUTE_TYPE type; UINT length; RADIUS_ATTRIBUTE_ENTRY* p_attribute; RW_CONTAINER_ITERATOR attribute_iterator; BYTE *bp_chap_challenge; EAP_PACKET* eap_packet = (EAP_PACKET *)malloc(27); unsigned char nas_id = 2; BYTE* bp_nas_id = (BYTE*) (&nas_id); BYTE *bp_chap = (BYTE *)calloc (1, 16); char valueString[80]; USER_HANDLE *p_user_handle = (USER_HANDLE *) request_handle; RADIUS_ATTRIBUTE_LIST_HANDLE attribute_list_handle = p_user_handle->attribute_list_handle; bp_chap_challenge = (BYTE *) calloc (1, 1 + strlen (user_password) + 16); 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), user_password, strlen (user_password)); memset(bp_chap,0,sizeof(bp_chap)); 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); memcpy ((bp_chap_challenge + 1 + strlen (user_password)), (BYTE *)&valueString[6], 16); break; default: break; } } while (radius_attribute_list_goto_next_attribute(response_attr_handle)); /* encode */ MD_string( bp_chap_challenge, (1 + strlen (user_password) + 16), bp_chap, 0x05); free(bp_chap_challenge); /* hardcode the PPP EAP packet */ eap_packet->code = EAP_RESPONSE; eap_packet->identifier = 0x02; eap_packet->length = swap(0x1b); eap_packet->type = 0x04; memset (&eap_packet->data[0],0x10,1); memcpy (&eap_packet->data[1], bp_chap, 16); memcpy (&eap_packet->data[17],"user1",strlen("user1")); free(bp_chap); /* remove old EAP-Message attribute */ radius_remove_attribute (attribute_list_handle, RADIUS_EAP_MESSAGE); /* add the new PPP EAP packet to the request handle */ radius_add_attribute_to_list (attribute_list_handle, RADIUS_EAP_MESSAGE, 27, (BYTE *)eap_packet); free (eap_packet); /* send the request */ radius_server_request (serverHandle, request_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_REQUEST_CALLBACKS *p_callbacks; RADIUS_ATTRIBUTE_LIST_HANDLE attribute_list_handle; 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 + -