eapol/eapol_framework/wapi_common/src/wapi_asn1_der_parser.cpp
changeset 17 8840d3e38314
equal deleted inserted replaced
2:1c7bc153c08e 17:8840d3e38314
       
     1 /*
       
     2 * ============================================================================
       
     3 *  Name        : ./accesssec/eapol/eapol_framework/wapi_common/src/wapi_asn1_der_parser.cpp
       
     4 *  Part of     : WAPI / WAPI       *** Info from the SWAD
       
     5 *  Description : WAPI authentication
       
     6 *  Version     : %version: 12 % << 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 #include "wapi_asn1_der_parser.h"
       
    21 #include "eap_automatic_variable.h"
       
    22 #include "wapi_types.h"
       
    23 
       
    24 //--------------------------------------------------------------------------------------------------
       
    25 
       
    26 EAP_FUNC_EXPORT wapi_asn1_der_parser_c::~wapi_asn1_der_parser_c()
       
    27 {
       
    28 }
       
    29 
       
    30 //--------------------------------------------------------------------------------------------------
       
    31 
       
    32 EAP_FUNC_EXPORT wapi_asn1_der_parser_c::wapi_asn1_der_parser_c(
       
    33 	abs_eap_am_tools_c * const tools)
       
    34 	: m_am_tools(tools)
       
    35 	, m_is_valid(false)
       
    36 	, m_objects(tools)
       
    37 {
       
    38 	m_is_valid = true;
       
    39 }
       
    40 
       
    41 //--------------------------------------------------------------------------------------------------
       
    42 
       
    43 EAP_FUNC_EXPORT bool wapi_asn1_der_parser_c::get_is_valid() const
       
    44 {
       
    45 	return m_is_valid;
       
    46 }
       
    47 
       
    48 //--------------------------------------------------------------------------------------------------
       
    49 
       
    50 EAP_FUNC_EXPORT eap_status_e wapi_asn1_der_parser_c::decode(const eap_variable_data_c * const asn1_der_data)
       
    51 {
       
    52 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    53 
       
    54 	ASN1_TYPE_TRACE_DEBUG(
       
    55 		m_am_tools,
       
    56 		TRACE_FLAGS_DEFAULT,
       
    57 		(EAPL("WAPI_Core: this = 0x%08x: wapi_asn1_der_parser_c::decode()\n"),
       
    58 		 this));
       
    59 
       
    60 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns: wapi_asn1_der_parser_c::decode()");
       
    61 
       
    62 	eap_status_e status(eap_status_process_general_error);
       
    63 
       
    64 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
    65 
       
    66 	bool data_continues(true);
       
    67 
       
    68 	status = m_objects.reset();
       
    69 	if (status != eap_status_ok)
       
    70 	{
       
    71 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    72 		return EAP_STATUS_RETURN(m_am_tools, status);
       
    73 	}
       
    74 
       
    75 	eap_variable_data_c input(m_am_tools);
       
    76 	if (input.get_is_valid() == false)
       
    77 	{
       
    78 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    79 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
    80 	}
       
    81 
       
    82 	u32_t input_offset(0ul);
       
    83 	const u32_t input_length(asn1_der_data->get_data_length());
       
    84 	u32_t input_remain_length(input_length);
       
    85 
       
    86 	while(data_continues == true)
       
    87 	{
       
    88 		asn1_der_type_c * const asn1_der_object = new asn1_der_type_c(m_am_tools);
       
    89 
       
    90 		eap_automatic_variable_c<asn1_der_type_c> automatic_asn1_der_object(m_am_tools, asn1_der_object);
       
    91 
       
    92 		if (asn1_der_object == 0
       
    93 			|| asn1_der_object->get_is_valid() == false)
       
    94 		{
       
    95 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
    96 			return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
    97 		}
       
    98 
       
    99 		status = input.set_buffer(
       
   100 			asn1_der_data->get_data_offset(input_offset, input_remain_length),
       
   101 			input_remain_length,
       
   102 			false,
       
   103 			false);
       
   104 
       
   105 		status = asn1_der_object->decode(&input);
       
   106 		if (status != eap_status_ok)
       
   107 		{
       
   108 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   109 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   110 		}
       
   111 
       
   112 		automatic_asn1_der_object.do_not_free_variable();
       
   113 
       
   114 		status = m_objects.add_object(asn1_der_object, true);
       
   115 		if (status != eap_status_ok)
       
   116 		{
       
   117 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   118 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   119 		}
       
   120 
       
   121 		input_offset += asn1_der_object->get_full_data_length();
       
   122 
       
   123 		if (input_remain_length < asn1_der_object->get_full_data_length())
       
   124 		{
       
   125 			data_continues = false;
       
   126 		}
       
   127 		else
       
   128 		{
       
   129 			input_remain_length -= asn1_der_object->get_full_data_length();
       
   130 
       
   131 			if (input_remain_length >= input_length
       
   132 				|| input_offset >= input_length)
       
   133 			{
       
   134 				data_continues = false;
       
   135 			}
       
   136 		}
       
   137 	}
       
   138 
       
   139 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
   140 
       
   141 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   142 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   143 }
       
   144 
       
   145 //--------------------------------------------------------------------------------------------------
       
   146 
       
   147 EAP_FUNC_EXPORT const asn1_der_type_c * wapi_asn1_der_parser_c::get_object(const u32_t index) const
       
   148 {
       
   149 	if (m_objects.get_object_count() <= index)
       
   150 	{
       
   151 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   152 		(void) EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_index);
       
   153 		return 0;
       
   154 	}
       
   155 
       
   156 	return m_objects.get_object(index);
       
   157 }
       
   158 
       
   159 //--------------------------------------------------------------------------------------------------
       
   160 
       
   161 EAP_FUNC_EXPORT u32_t wapi_asn1_der_parser_c::get_object_count() const
       
   162 {
       
   163 	return m_objects.get_object_count();
       
   164 }
       
   165 
       
   166 //--------------------------------------------------------------------------------------------------
       
   167 
       
   168 EAP_FUNC_EXPORT eap_status_e wapi_asn1_der_parser_c::get_wapi_identity(
       
   169 	eap_variable_data_c * const subject_name,
       
   170 	eap_variable_data_c * const issuer_name,
       
   171 	eap_variable_data_c * const sequence_number)
       
   172 {
       
   173 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   174 
       
   175 	ASN1_TYPE_TRACE_DEBUG(
       
   176 		m_am_tools,
       
   177 		TRACE_FLAGS_DEFAULT,
       
   178 		(EAPL("WAPI_Core: this = 0x%08x: wapi_asn1_der_parser_c::get_wapi_identity()\n"),
       
   179 		 this));
       
   180 
       
   181 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns: wapi_asn1_der_parser_c::get_wapi_identity()");
       
   182 
       
   183 	eap_status_e status(eap_status_process_general_error);
       
   184 
       
   185 	if (subject_name == 0
       
   186 		|| issuer_name == 0
       
   187 		|| sequence_number == 0
       
   188 		|| subject_name->get_is_valid() == false
       
   189 		|| issuer_name->get_is_valid() == false
       
   190 		|| sequence_number->get_is_valid() == false)
       
   191 	{
       
   192 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   193 		return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_parameter);
       
   194 	}
       
   195 
       
   196 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
   197 
       
   198 	const asn1_type_const_c type_object_identifier[] =
       
   199 		{
       
   200 			ASN1_TYPE_OBJECT(
       
   201 				asn1_der_type_c::asn1_class_universal,
       
   202 				asn1_der_type_c::asn1_tag_sequence,
       
   203 				0),										// Name ::= CHOICE { RDNSequence } 
       
   204 														// ::= RDNSequence 
       
   205 														// ::= SEQUENCE OF RelativeDistinguishedName
       
   206 														// ::= {organizationalUnitName[0], commonName[1]}
       
   207 			ASN1_TYPE_OBJECT(
       
   208 				asn1_der_type_c::asn1_class_universal,
       
   209 				asn1_der_type_c::asn1_tag_set,
       
   210 				1),										// commonName ::= SET OF AttributeTypeAndValue
       
   211 			ASN1_TYPE_OBJECT(
       
   212 				asn1_der_type_c::asn1_class_universal,
       
   213 				asn1_der_type_c::asn1_tag_sequence,
       
   214 				0),										// AttributeTypeAndValue ::= SEQUENCE {
       
   215 														//		type     AttributeType,
       
   216 														//		value    AttributeValue }
       
   217 			ASN1_TYPE_OBJECT(
       
   218 				asn1_der_type_c::asn1_class_universal,
       
   219 				asn1_der_type_c::asn1_tag_object_identifier,
       
   220 				0),										// AttributeType ::= OBJECT IDENTIFIER
       
   221 			ASN1_TYPE_OBJECT_TERMINATOR
       
   222 		};
       
   223 
       
   224 	u32_t index(0ul);
       
   225 
       
   226 	{
       
   227 		const asn1_der_type_c * const der_subject_name = get_object(index);
       
   228 
       
   229 		if (der_subject_name == 0
       
   230 			|| der_subject_name->get_is_valid() == false)
       
   231 		{
       
   232 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   233 			return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_index);
       
   234 		}
       
   235 
       
   236 		const asn1_der_type_c * const der_object_identifier = der_subject_name->get_sub_type(type_object_identifier);
       
   237 
       
   238 		if (der_object_identifier == 0
       
   239 			|| der_object_identifier->get_is_valid() == false)
       
   240 		{
       
   241 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   242 			return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_index);
       
   243 		}
       
   244 
       
   245 		if (der_object_identifier->get_full_data_length() != sizeof(WAPI_COMMON_NAME_OID_PARAMETER)
       
   246 			|| m_am_tools->memcmp(WAPI_COMMON_NAME_OID_PARAMETER,
       
   247 			der_object_identifier->get_full_data(),
       
   248 			sizeof(WAPI_COMMON_NAME_OID_PARAMETER)) != 0)
       
   249 		{
       
   250 			// ERROR: wrong payload.
       
   251 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   252 			return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_data_payload);
       
   253 		}
       
   254 
       
   255 		status = subject_name->set_copy_of_buffer(
       
   256 			der_subject_name->get_full_data(),
       
   257 			der_subject_name->get_full_data_length());
       
   258 		if (status != eap_status_ok)
       
   259 		{
       
   260 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   261 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   262 		}
       
   263 
       
   264 		EAP_TRACE_DATA_DEBUG(
       
   265 			m_am_tools,
       
   266 			TRACE_FLAGS_DEFAULT,
       
   267 			(EAPL("subject_name"),
       
   268 			subject_name->get_data(),
       
   269 			subject_name->get_data_length()));
       
   270 	}
       
   271 
       
   272 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
   273 
       
   274 	++index;
       
   275 
       
   276 	{
       
   277 		const asn1_der_type_c * const der_issuer_name = get_object(index);
       
   278 
       
   279 		if (der_issuer_name == 0
       
   280 			|| der_issuer_name->get_is_valid() == false)
       
   281 		{
       
   282 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   283 			return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_index);
       
   284 		}
       
   285 
       
   286 		const asn1_der_type_c * const der_object_identifier = der_issuer_name->get_sub_type(type_object_identifier);
       
   287 
       
   288 		if (der_object_identifier == 0
       
   289 			|| der_object_identifier->get_is_valid() == false)
       
   290 		{
       
   291 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   292 			return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_index);
       
   293 		}
       
   294 
       
   295 		if (der_object_identifier->get_full_data_length() != sizeof(WAPI_COMMON_NAME_OID_PARAMETER)
       
   296 			|| m_am_tools->memcmp(WAPI_COMMON_NAME_OID_PARAMETER,
       
   297 			der_object_identifier->get_full_data(),
       
   298 			sizeof(WAPI_COMMON_NAME_OID_PARAMETER)) != 0)
       
   299 		{
       
   300 			// ERROR: wrong payload.
       
   301 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   302 			return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_data_payload);
       
   303 		}
       
   304 
       
   305 		status = issuer_name->set_copy_of_buffer(
       
   306 			der_issuer_name->get_full_data(),
       
   307 			der_issuer_name->get_full_data_length());
       
   308 		if (status != eap_status_ok)
       
   309 		{
       
   310 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   311 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   312 		}
       
   313 
       
   314 		EAP_TRACE_DATA_DEBUG(
       
   315 			m_am_tools,
       
   316 			TRACE_FLAGS_DEFAULT,
       
   317 			(EAPL("issuer_name"),
       
   318 			issuer_name->get_data(),
       
   319 			issuer_name->get_data_length()));
       
   320 	}
       
   321 
       
   322 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
   323 
       
   324 	++index;
       
   325 
       
   326 	{
       
   327 		const asn1_der_type_c * const der_sequence_number = get_object(index);
       
   328 
       
   329 		if (der_sequence_number == 0
       
   330 			|| der_sequence_number->get_is_valid() == false)
       
   331 		{
       
   332 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   333 			return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_index);
       
   334 		}
       
   335 
       
   336 		switch(der_sequence_number->get_tag())
       
   337 		{
       
   338 		case asn1_der_type_c::asn1_tag_integer:
       
   339 			// OK
       
   340 			break;
       
   341 		default:
       
   342 			// ERROR: wrong payload.
       
   343 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   344 			return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_data_payload);
       
   345 		};
       
   346 
       
   347 		status = sequence_number->set_copy_of_buffer(
       
   348 			der_sequence_number->get_full_data(),
       
   349 			der_sequence_number->get_full_data_length());
       
   350 		if (status != eap_status_ok)
       
   351 		{
       
   352 			EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   353 			return EAP_STATUS_RETURN(m_am_tools, status);
       
   354 		}
       
   355 
       
   356 		EAP_TRACE_DATA_DEBUG(
       
   357 			m_am_tools,
       
   358 			TRACE_FLAGS_DEFAULT,
       
   359 			(EAPL("sequence_number"),
       
   360 			sequence_number->get_data(),
       
   361 			sequence_number->get_data_length()));
       
   362 	}
       
   363 
       
   364 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
   365 
       
   366 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   367 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   368 }
       
   369 
       
   370 //--------------------------------------------------------------------------------------------------
       
   371 
       
   372 EAP_FUNC_EXPORT eap_status_e wapi_asn1_der_parser_c::get_wapi_identity(
       
   373 	eap_variable_data_c * const wapi_identity)
       
   374 {
       
   375 	EAP_TRACE_BEGIN(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   376 
       
   377 	ASN1_TYPE_TRACE_DEBUG(
       
   378 		m_am_tools,
       
   379 		TRACE_FLAGS_DEFAULT,
       
   380 		(EAPL("WAPI_Core: this = 0x%08x: wapi_asn1_der_parser_c::get_wapi_identity()\n"),
       
   381 		 this));
       
   382 
       
   383 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns: wapi_asn1_der_parser_c::get_wapi_identity()");
       
   384 
       
   385 	eap_status_e status(eap_status_process_general_error);
       
   386 
       
   387 	if (wapi_identity == 0
       
   388 		|| wapi_identity->get_is_valid() == false)
       
   389 	{
       
   390 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   391 		return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_parameter);
       
   392 	}
       
   393 
       
   394 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
   395 
       
   396 	eap_variable_data_c subject_name(m_am_tools);
       
   397 	eap_variable_data_c issuer_name(m_am_tools);
       
   398 	eap_variable_data_c sequence_number(m_am_tools);
       
   399 
       
   400 	if (subject_name.get_is_valid() == false
       
   401 		|| issuer_name.get_is_valid() == false
       
   402 		|| sequence_number.get_is_valid() == false)
       
   403 	{
       
   404 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   405 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   406 	}
       
   407 
       
   408 	status = get_wapi_identity(
       
   409 		&subject_name,
       
   410 		&issuer_name,
       
   411 		&sequence_number);
       
   412 	if (status != eap_status_ok)
       
   413 	{
       
   414 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   415 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   416 	}
       
   417 
       
   418 	status = wapi_identity->set_copy_of_buffer(&subject_name);
       
   419 	if (status != eap_status_ok)
       
   420 	{
       
   421 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   422 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   423 	}
       
   424 
       
   425 	status = wapi_identity->add_data(&issuer_name);
       
   426 	if (status != eap_status_ok)
       
   427 	{
       
   428 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   429 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   430 	}
       
   431 
       
   432 	status = wapi_identity->add_data(&sequence_number);
       
   433 	if (status != eap_status_ok)
       
   434 	{
       
   435 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   436 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   437 	}
       
   438 
       
   439 	// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
       
   440 
       
   441 	EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   442 	return EAP_STATUS_RETURN(m_am_tools, status);
       
   443 }
       
   444 
       
   445 
       
   446 //--------------------------------------------------------------------------------------------------
       
   447 
       
   448 EAP_FUNC_EXPORT eap_status_e wapi_asn1_der_parser_c::get_decoded_subject_name(
       
   449     eap_variable_data_c * const identity_data,
       
   450     eap_variable_data_c * const decoded_data)
       
   451 {
       
   452     
       
   453     eap_status_e status = eap_status_ok;
       
   454     eap_variable_data_c subject_name(m_am_tools);
       
   455    
       
   456 	if ( subject_name.get_is_valid() == false )
       
   457 	{
       
   458 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   459 		return EAP_STATUS_RETURN(m_am_tools, eap_status_allocation_error);
       
   460 	}
       
   461     
       
   462     // The data is stored to this objects internal variables with decode
       
   463     status = decode(identity_data);
       
   464 	if (status != eap_status_ok)
       
   465 	{
       
   466 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   467 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   468 	}
       
   469     
       
   470 	const asn1_type_const_c type_name_sequence[] =
       
   471 		{
       
   472 			ASN1_TYPE_OBJECT(
       
   473 				asn1_der_type_c::asn1_class_universal,
       
   474 				asn1_der_type_c::asn1_tag_sequence,
       
   475 				0),										// Name ::= CHOICE { RDNSequence } 
       
   476 														// ::= RDNSequence 
       
   477 														// ::= SEQUENCE OF RelativeDistinguishedName
       
   478 														// ::= {organizationalUnitName[0], commonName[1]}
       
   479 			ASN1_TYPE_OBJECT(
       
   480 				asn1_der_type_c::asn1_class_universal,
       
   481 				asn1_der_type_c::asn1_tag_set,
       
   482 				1),										// commonName ::= SET OF AttributeTypeAndValue
       
   483 			ASN1_TYPE_OBJECT(
       
   484 				asn1_der_type_c::asn1_class_universal,
       
   485 				asn1_der_type_c::asn1_tag_sequence,
       
   486 				0),										// AttributeTypeAndValue ::= SEQUENCE {
       
   487 														//		type     AttributeType,
       
   488 														//		value    AttributeValue }
       
   489 #if 0
       
   490 			// This last object is variable type and it is handled later.
       
   491 			ASN1_TYPE_OBJECT(
       
   492 				asn1_der_type_c::asn1_class_universal,
       
   493 				asn1_der_type_c::asn1_tag_printable_string,
       
   494 				0),										// AttributeValue ::= ANY DEFINED BY AttributeType
       
   495 														// ::= DirectoryString ::= CHOICE {
       
   496 														// teletexString           TeletexString (SIZE (1..MAX)),
       
   497 														// printableString         PrintableString (SIZE (1..MAX)),
       
   498 														// universalString         UniversalString (SIZE (1..MAX)),
       
   499 														// utf8String              UTF8String (SIZE (1..MAX)),
       
   500 														// bmpString               BMPString (SIZE (1..MAX)) }
       
   501 #endif
       
   502 			ASN1_TYPE_OBJECT_TERMINATOR
       
   503 		};
       
   504 
       
   505 	if (get_object_count() == 0ul)
       
   506 	{
       
   507 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   508 		return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_index);
       
   509 	}
       
   510 
       
   511 	const asn1_der_type_c * const der_name_sequence = get_object(0ul)->get_sub_type(type_name_sequence);
       
   512 
       
   513 	if (der_name_sequence == 0
       
   514 		|| der_name_sequence->get_is_valid() == false)
       
   515 	{
       
   516 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   517 		return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_index);
       
   518 	}
       
   519 
       
   520 	// Second object (index 1) in SEQUENCE is AttributeValue.
       
   521 	const asn1_der_type_c * const der_name = der_name_sequence->get_sub_types()->get_object(1ul);
       
   522 
       
   523 	if (der_name == 0
       
   524 		|| der_name->get_is_valid() == false
       
   525 		|| (/* der_name->get_tag() != asn1_der_type_c::asn1_tag_teletex_string // This is not defined yet.
       
   526 			&& */
       
   527 			der_name->get_tag() != asn1_der_type_c::asn1_tag_printable_string
       
   528 			&& der_name->get_tag() != asn1_der_type_c::asn1_tag_universal_string
       
   529 			&& der_name->get_tag() != asn1_der_type_c::asn1_tag_utf8_string
       
   530 			&& der_name->get_tag() != asn1_der_type_c::asn1_tag_bmp_string
       
   531 			&& der_name->get_tag() != asn1_der_type_c::asn1_tag_t61_string))
       
   532 	{
       
   533 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   534 		return EAP_STATUS_RETURN(m_am_tools, eap_status_illegal_index);
       
   535 	}
       
   536 
       
   537     // Copy the decoded data into the returned parameter
       
   538     status = decoded_data->set_copy_of_buffer(
       
   539 		der_name->get_content(), 
       
   540 		der_name->get_content_length());
       
   541 	if (status != eap_status_ok)
       
   542 	{
       
   543 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   544 		return EAP_STATUS_RETURN(m_am_tools, status);
       
   545 	}
       
   546     
       
   547     EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
       
   548     return EAP_STATUS_RETURN(m_am_tools, status);
       
   549 }
       
   550 
       
   551 
       
   552 //--------------------------------------------------------------------------------------------------
       
   553 
       
   554 // End.