eapol/eapol_framework/wapi_common/src/ec_cs_compare_reference_issuer_name.cpp
changeset 17 8840d3e38314
equal deleted inserted replaced
2:1c7bc153c08e 17:8840d3e38314
       
     1 /*
       
     2 * ============================================================================
       
     3 *  Name        : ./accesssec/eapol/eapol_framework/wapi_common/src/ec_cs_compare_reference_issuer_name.cpp
       
     4 *  Part of     : WAPI / WAPI       *** Info from the SWAD
       
     5 *  Description : WAPI authentication
       
     6 *  Version     : %version: 5 % << Don't touch! Updated by Synergy at check-out.
       
     7 *
       
     8 *  Copyright © 2001-2009 Nokia.  All rights reserved.
       
     9 *  This material, including documentation and any related computer
       
    10 *  programs, is protected by copyright controlled by Nokia.  All
       
    11 *  rights are reserved.  Copying, including reproducing, storing,
       
    12 *  adapting or translating, any or all of this material requires the
       
    13 *  prior written consent of Nokia.  This material also contains
       
    14 *  confidential information which may not be disclosed to others
       
    15 *  without the prior written consent of Nokia.
       
    16 * ============================================================================
       
    17 * Template version: 4.1.1
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 // This is enumeration of WAPI source code.
       
    23 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    24 	#undef EAP_FILE_NUMBER_ENUM
       
    25 	#define EAP_FILE_NUMBER_ENUM 700 
       
    26 	#undef EAP_FILE_NUMBER_DATE 
       
    27 	#define EAP_FILE_NUMBER_DATE 1127594498 
       
    28 #endif //#if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
       
    29 
       
    30 
       
    31 #if defined(USE_WAPI_CORE)
       
    32 
       
    33 #include "eap_automatic_variable.h"
       
    34 #include "ec_cs_types.h"
       
    35 #include "ec_cs_data.h"
       
    36 #include "ec_cs_compare_reference_issuer_name.h"
       
    37 #include "wapi_certificate_asn1_der_parser.h"
       
    38 #include "wapi_asn1_der_parser.h"
       
    39 #include "ec_cs_tlv_header.h"
       
    40 #include "ec_cs_tlv_payloads.h"
       
    41 
       
    42 //----------------------------------------------------------------------------
       
    43 
       
    44 EAP_FUNC_EXPORT ec_cs_compare_reference_issuer_name_c::~ec_cs_compare_reference_issuer_name_c()
       
    45 {
       
    46 }
       
    47 
       
    48 //----------------------------------------------------------------------------
       
    49 
       
    50 EAP_FUNC_EXPORT ec_cs_compare_reference_issuer_name_c::ec_cs_compare_reference_issuer_name_c(
       
    51 	abs_eap_am_tools_c * const tools)
       
    52 	: m_am_tools(tools)
       
    53 {
       
    54 }
       
    55 
       
    56 //----------------------------------------------------------------------------
       
    57 
       
    58 EAP_FUNC_EXPORT i32_t ec_cs_compare_reference_issuer_name_c::compare(
       
    59 	const ec_cs_data_c * const reference_tlv_from_array,
       
    60 	const ec_cs_data_c * const in_issuer_name) const
       
    61 {
       
    62 	// reference_tlv_from_array includes ID-Reference TLV which includes ASU-ID TLV and Certificate-reference TLV.
       
    63 	// certificate_identity includes issuer name of certificate in ASN.1/DER encoded.
       
    64 
       
    65 	EAP_TRACE_DATA_DEBUG(
       
    66 		m_am_tools, 
       
    67 		TRACE_FLAGS_DEFAULT, 
       
    68 		(EAPL("ec_cs_compare_reference_issuer_name_c::compare(): reference_tlv_from_array"),
       
    69 		 reference_tlv_from_array->get_data()->get_data(),
       
    70 		 reference_tlv_from_array->get_data()->get_data_length()));
       
    71 
       
    72 	EAP_TRACE_DATA_DEBUG(
       
    73 		m_am_tools, 
       
    74 		TRACE_FLAGS_DEFAULT, 
       
    75 		(EAPL("ec_cs_compare_reference_issuer_name_c::compare(): in_issuer_name"),
       
    76 		 in_issuer_name->get_data()->get_data(),
       
    77 		 in_issuer_name->get_data()->get_data_length()));
       
    78 
       
    79 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
    80 
       
    81 	eap_variable_data_c reference_issuer_name(m_am_tools);
       
    82 	if (reference_issuer_name.get_is_valid() == false)
       
    83 	{
       
    84 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    85 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
    86 	}
       
    87 
       
    88 	ec_cs_tlv_header_c id_reference_tlv(
       
    89 		m_am_tools,
       
    90 		reference_tlv_from_array->get_data()->get_data(),
       
    91 		reference_tlv_from_array->get_data()->get_data_length());
       
    92 	if (id_reference_tlv.get_is_valid() == false)
       
    93 	{
       
    94 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    95 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
    96 	}
       
    97 
       
    98 
       
    99 	{
       
   100 		ec_cs_tlv_payloads_c parser(
       
   101 			m_am_tools,
       
   102 			true);
       
   103 		if (parser.get_is_valid() == false)
       
   104 		{
       
   105 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   106 			return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   107 		}
       
   108 
       
   109 		u32_t length(id_reference_tlv.get_data_length());
       
   110 		u32_t padding_length(0ul);
       
   111 
       
   112 		eap_status_e status = parser.parse_ec_cs_payloads(
       
   113 			id_reference_tlv.get_data(length), ///< This is the start of the message buffer.
       
   114 			&length, ///< This is the length of the buffer. This must match with the length of all payloads.
       
   115 			&padding_length ///< Length of possible padding is set to this variable.
       
   116 			);
       
   117 		if (status != eap_status_ok)
       
   118 		{
       
   119 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   120 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   121 		}
       
   122 
       
   123 		const ec_cs_variable_data_c * const asu_id = parser.get_tlv_pointer(ec_cs_tlv_type_CS_ASU_ID);
       
   124 		if (asu_id == 0)
       
   125 		{
       
   126 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   127 			return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_parameter);
       
   128 		}
       
   129 
       
   130 		{
       
   131 			wapi_asn1_der_parser_c parser(m_am_tools);
       
   132 			if (parser.get_is_valid() == false)
       
   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 			eap_variable_data_c id_data(
       
   139 				m_am_tools,
       
   140 				asu_id->get_data(asu_id->get_data_length()),
       
   141 				asu_id->get_data_length(),
       
   142 				false,
       
   143 				false);
       
   144 			if (id_data.get_is_valid() == false)
       
   145 			{
       
   146 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   147 				return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   148 			}
       
   149 
       
   150 			eap_status_e status = parser.decode(&id_data);
       
   151 			if (status != eap_status_ok)
       
   152 			{
       
   153 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   154 				return EAP_STATUS_RETURN(m_am_tools, status);
       
   155 			}
       
   156 
       
   157 			eap_variable_data_c certificate_subject_name(m_am_tools);
       
   158 			eap_variable_data_c certificate_sequence_number(m_am_tools);
       
   159 
       
   160 			status = parser.get_wapi_identity(
       
   161 				&certificate_subject_name,
       
   162 				&reference_issuer_name,
       
   163 				&certificate_sequence_number);
       
   164 			if (status != eap_status_ok)
       
   165 			{
       
   166 				EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   167 				return EAP_STATUS_RETURN(m_am_tools, status);
       
   168 			}
       
   169 		}
       
   170 	}
       
   171 
       
   172 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
   173 
       
   174 	return reference_issuer_name.compare(in_issuer_name->get_data());
       
   175 }
       
   176 
       
   177 //----------------------------------------------------------------------------------
       
   178 
       
   179 #endif //#if defined(USE_WAPI_CORE)
       
   180 
       
   181 // End.