eapol/eapol_framework/eapol_common/type/securid/core/eap_type_securid_server.cpp
changeset 0 c8830336c852
child 2 1c7bc153c08e
equal deleted inserted replaced
-1:000000000000 0:c8830336c852
       
     1 /*
       
     2 * Copyright (c) 2001-2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  EAP and WLAN authentication protocols.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // This is enumeration of EAPOL source code.
       
    20 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    21 	#undef EAP_FILE_NUMBER_ENUM
       
    22 	#define EAP_FILE_NUMBER_ENUM 116 
       
    23 	#undef EAP_FILE_NUMBER_DATE 
       
    24 	#define EAP_FILE_NUMBER_DATE 1127594498 
       
    25 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    26 
       
    27 
       
    28 // INCLUDE FILES
       
    29 
       
    30 #include "eap_am_memory.h"
       
    31 #include "eap_state_notification.h"
       
    32 #include "eap_type_securid.h"
       
    33 #include "eap_type_securid_types.h"
       
    34 #include "eap_buffer.h"
       
    35 
       
    36 static const u8_t EAP_SECURID_PASSCODE_STRING[] = "passcode";
       
    37 
       
    38 
       
    39 #ifdef EAP_SECURID_SERVER
       
    40 
       
    41 eap_status_e eap_type_securid_c::server_packet_process(
       
    42 	eap_header_wr_c * const received_eap,
       
    43 	const u32_t eap_packet_length)
       
    44 {	
       
    45 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    46 	eap_status_e status = eap_status_header_corrupted;
       
    47 
       
    48 	if (eap_packet_length < received_eap->get_length())
       
    49 	{
       
    50 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    51 		return EAP_STATUS_RETURN(m_am_tools, eap_status_drop_packet_quietly);
       
    52 	}
       
    53 
       
    54 	if (received_eap->get_type() == eap_type_identity)
       
    55 	{
       
    56 		m_identifier = static_cast<u8_t> (received_eap->get_identifier() + 1);
       
    57 
       
    58 		// Send request
       
    59 
       
    60 		const u8_t * const message = EAP_SECURID_PASSCODE_STRING;
       
    61 		u32_t message_length = m_am_tools->strlen(reinterpret_cast<eap_const_string>(message));
       
    62 
       
    63 		u32_t packet_length = eap_header_base_c::get_type_data_start_offset(m_use_eap_expanded_type)
       
    64 			+ message_length; // Remove null termination
       
    65 
       
    66 		eap_buf_chain_wr_c * packet = create_send_packet(packet_length);
       
    67 		if (!packet)
       
    68 		{
       
    69 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    70 			return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
    71 		}
       
    72 
       
    73 		eap_header_base_c eap_header(
       
    74 			m_am_tools,
       
    75 			packet->get_data_offset(m_offset, packet_length),
       
    76 			packet_length);
       
    77 		if (eap_header.get_is_valid() == false)
       
    78 		{
       
    79 			delete packet;
       
    80 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    81 			return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_parameter);
       
    82 		}
       
    83 		eap_header.set_code(eap_code_request);
       
    84 		eap_header.set_identifier(++m_identifier);
       
    85 		eap_header.set_length(
       
    86 			static_cast<u16_t>(packet_length),
       
    87 			m_use_eap_expanded_type);
       
    88 		eap_header.set_type(
       
    89 			m_eap_type,
       
    90 			m_use_eap_expanded_type);
       
    91 
       
    92 		u8_t * type_data = const_cast<u8_t *> (eap_header.get_type_data_offset(0, eap_header.get_type_data_length()));
       
    93 		if (type_data == 0)
       
    94 		{
       
    95 			delete packet;
       
    96 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    97 			return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
    98 		}
       
    99 
       
   100 		m_am_tools->memmove(type_data, message, message_length);
       
   101 
       
   102 		eap_status_e status = packet_send(packet, packet_length);
       
   103 		delete packet;
       
   104 
       
   105 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   106 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   107 	}
       
   108 	else if (received_eap->get_type() == eap_type_securid)
       
   109 	{
       
   110 		// Verify passcode response.
       
   111 		u8_t * type_data = const_cast<u8_t *>(received_eap->get_type_data(received_eap->get_type_data_length()));
       
   112 		if (type_data == 0)
       
   113 		{
       
   114 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   115 			return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   116 		}
       
   117 
       
   118 		if (received_eap->get_type_data_length() != m_pincode.get_data_length()
       
   119 			|| m_am_tools->memcmp(
       
   120 				type_data,
       
   121 				m_pincode.get_data(m_pincode.get_data_length()),
       
   122 				m_pincode.get_data_length()) != 0)
       
   123 		{
       
   124 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   125 			return EAP_STATUS_RETURN(m_am_tools, eap_status_authentication_failure);
       
   126 		}
       
   127 	}
       
   128 	else if (received_eap->get_type() == eap_type_generic_token_card)
       
   129 	{
       
   130 		// Verify passcode response.
       
   131 		u8_t * type_data = const_cast<u8_t *>(received_eap->get_type_data(received_eap->get_type_data_length()));
       
   132 		if (type_data == 0)
       
   133 		{
       
   134 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   135 			return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   136 		}
       
   137 
       
   138 #if defined(USE_FAST_EAP_TYPE)
       
   139 		if (m_use_EAP_FAST_response == true)
       
   140 		{
       
   141 			const u32_t passcode_offset(EAP_FAST_EAP_GTC_RESPONSE_PREFIX_LENGTH + m_identity.get_data_length() + EAP_FAST_EAP_GTC_RESPONSE_SEPARATOR_LENGTH);
       
   142 
       
   143 			if (received_eap->get_type_data_length() < passcode_offset+m_passcode.get_data_length())
       
   144 			{
       
   145 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   146 				return EAP_STATUS_RETURN(m_am_tools, eap_status_too_short_message);
       
   147 			}
       
   148 
       
   149 			type_data += passcode_offset;
       
   150 
       
   151 			if (m_am_tools->memcmp(
       
   152 					type_data,
       
   153 					m_passcode.get_data(m_passcode.get_data_length()),
       
   154 					m_passcode.get_data_length()) != 0)
       
   155 			{
       
   156 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   157 				return EAP_STATUS_RETURN(m_am_tools, eap_status_authentication_failure);
       
   158 			}
       
   159 		}
       
   160 		else
       
   161 #endif //#if defined(USE_FAST_EAP_TYPE)
       
   162 		{
       
   163 			if (received_eap->get_type_data_length() != m_passcode.get_data_length()
       
   164 				|| m_am_tools->memcmp(
       
   165 					type_data,
       
   166 					m_passcode.get_data(m_passcode.get_data_length()),
       
   167 					m_passcode.get_data_length()) != 0)
       
   168 			{
       
   169 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   170 				return EAP_STATUS_RETURN(m_am_tools, eap_status_authentication_failure);
       
   171 			}
       
   172 		}
       
   173 	}
       
   174 	else
       
   175 	{
       
   176 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   177 		return EAP_STATUS_RETURN(m_am_tools, eap_status_authentication_failure);
       
   178 	}
       
   179 
       
   180 	m_identifier++;
       
   181 
       
   182 	status = finish_successful_authentication();
       
   183 
       
   184 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   185 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   186 
       
   187 }
       
   188 
       
   189 #endif //#ifdef EAP_SECURID_SERVER
       
   190 
       
   191 //--------------------------------------------------
       
   192 
       
   193 
       
   194 // End.