eapol/eapol_framework/eapol_common/type/mschapv2/core/eap_type_mschapv2.cpp
branchRCL_3
changeset 18 bad0cc58d154
parent 2 1c7bc153c08e
child 19 c74b3d9f6b9e
equal deleted inserted replaced
17:30e048a7b597 18:bad0cc58d154
    14 * Description:  EAP and WLAN authentication protocols.
    14 * Description:  EAP and WLAN authentication protocols.
    15 *
    15 *
    16 */
    16 */
    17 
    17 
    18 /*
    18 /*
    19 * %version: 40.1.2 %
    19 * %version: 46 %
    20 */
    20 */
    21 
    21 
    22 // This is enumeration of EAPOL source code.
    22 // This is enumeration of EAPOL source code.
    23 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
    23 #if defined(USE_EAP_MINIMUM_RELEASE_TRACES)
    24 	#undef EAP_FILE_NUMBER_ENUM
    24 	#undef EAP_FILE_NUMBER_ENUM
   728 	}
   728 	}
   729 #endif //#if defined(EAP_USE_TTLS_PLAIN_MS_CHAP_V2_HACK)
   729 #endif //#if defined(EAP_USE_TTLS_PLAIN_MS_CHAP_V2_HACK)
   730 
   730 
   731 	//----------------------------------------------------------
   731 	//----------------------------------------------------------
   732 
   732 
   733 #if defined(USE_EAP_EXPANDED_TYPES)
       
   734 	{
   733 	{
   735 		eap_variable_data_c use_eap_expanded_type(m_am_tools);
   734 		eap_variable_data_c use_eap_expanded_type(m_am_tools);
   736 
   735 
   737 		eap_status_e status = m_am_type_mschapv2->type_configure_read(
   736 		eap_status_e status = m_am_type_mschapv2->type_configure_read(
   738 			cf_str_EAP_MSCHAPV2_use_eap_expanded_type.get_field(),
   737 			cf_str_EAP_MSCHAPV2_use_eap_expanded_type.get_field(),
   762 					m_use_eap_expanded_type = false;
   761 					m_use_eap_expanded_type = false;
   763 				}
   762 				}
   764 			}
   763 			}
   765 		}
   764 		}
   766 	}
   765 	}
   767 #endif //#if defined(USE_EAP_EXPANDED_TYPES)
       
   768 
   766 
   769 	//----------------------------------------------------------
   767 	//----------------------------------------------------------
   770 
   768 
   771 #if defined(USE_FAST_EAP_TYPE)
   769 #if defined(USE_FAST_EAP_TYPE)
   772 	
   770 	
  1010 		(EAPL("eap_type_mschapv2_c::reset(): this = 0x%08x\n"),
  1008 		(EAPL("eap_type_mschapv2_c::reset(): this = 0x%08x\n"),
  1011 		this));
  1009 		this));
  1012 
  1010 
  1013 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns: eap_type_mschapv2_c::reset()");
  1011 	EAP_TRACE_RETURN_STRING(m_am_tools, "returns: eap_type_mschapv2_c::reset()");
  1014 
  1012 
  1015 	m_session.set_state(eap_type_mschapv2_state_none);
  1013 	m_session.reset();
  1016 
  1014 
  1017 	m_username_utf8.reset();
  1015 	m_username_utf8.reset();
  1018 	eap_variable_data_c username_uc(m_am_tools);
  1016 	eap_variable_data_c username_uc(m_am_tools);
  1019 
  1017 
  1020 	eap_status_e status = m_am_type_mschapv2->type_configure_read(
  1018 	eap_status_e status = m_am_type_mschapv2->type_configure_read(
  1043 
  1041 
  1044 	m_old_password_utf8.reset();
  1042 	m_old_password_utf8.reset();
  1045 
  1043 
  1046 	m_is_notification_sent = false;
  1044 	m_is_notification_sent = false;
  1047 	m_is_reauthentication = false;
  1045 	m_is_reauthentication = false;
       
  1046 
       
  1047 	m_is_pending = false;
       
  1048 	m_identity_asked = false;
  1048 
  1049 
  1049 	status = m_am_type_mschapv2->reset();
  1050 	status = m_am_type_mschapv2->reset();
  1050 	if (status != eap_status_ok)
  1051 	if (status != eap_status_ok)
  1051 	{
  1052 	{
  1052 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
  1053 		EAP_TRACE_END(m_am_tools, TRACE_FLAGS_DEFAULT);
  1503 				key_bit_shifting = 7 - (key_bit_no % 8);
  1504 				key_bit_shifting = 7 - (key_bit_no % 8);
  1504 				newkey_bit_shifting = 7 - (key_bit_no % 7);
  1505 				newkey_bit_shifting = 7 - (key_bit_no % 7);
  1505 
  1506 
  1506 				if (key[key_byte] & (1 << key_bit_shifting)) // If bit is 1...
  1507 				if (key[key_byte] & (1 << key_bit_shifting)) // If bit is 1...
  1507 				{
  1508 				{
  1508 					newkey[newkey_byte] |= (1 << newkey_bit_shifting); // ...set bit to 1
  1509 					newkey[newkey_byte] = static_cast<u8_t>(newkey[newkey_byte] | (1 << newkey_bit_shifting)); // ...set bit to 1
  1509 					bit_counter++;
  1510 					bit_counter++;
  1510 				}
  1511 				}
  1511 			}
  1512 			}
  1512 
  1513 
  1513 			if (bit_counter % 2 == 0) // If even number of bits...
  1514 			if (bit_counter % 2 == 0) // If even number of bits...
  1517 			}
  1518 			}
  1518 		}
  1519 		}
  1519 	}
  1520 	}
  1520 
  1521 
  1521 	// Copy key three times into triple size key because we are internally using 3des instead of des
  1522 	// Copy key three times into triple size key because we are internally using 3des instead of des
  1522 	// des: Ek == 3des: Ek3(Dk2(Ek1)) when k == k1 == k2 == k3
  1523 	// des: Ek == 3des: Ek3(Dk2(Ek1)) when k == key1 == key2 == key3
  1523 	m_am_tools->memmove(newkey + EAP_MSCHAPV2_DES_KEY_SIZE, newkey, EAP_MSCHAPV2_DES_KEY_SIZE);
  1524 	m_am_tools->memmove(newkey + EAP_MSCHAPV2_DES_KEY_SIZE, newkey, EAP_MSCHAPV2_DES_KEY_SIZE);
  1524 	m_am_tools->memmove(newkey + 2 * EAP_MSCHAPV2_DES_KEY_SIZE, newkey, EAP_MSCHAPV2_DES_KEY_SIZE);
  1525 	m_am_tools->memmove(newkey + 2 * EAP_MSCHAPV2_DES_KEY_SIZE, newkey, EAP_MSCHAPV2_DES_KEY_SIZE);
  1525 
  1526 
  1526 	eap_status_e status;
  1527 	eap_status_e status;
  1527 
  1528 
  1724 		return EAP_STATUS_RETURN(m_am_tools, status);
  1725 		return EAP_STATUS_RETURN(m_am_tools, status);
  1725 	}
  1726 	}
  1726 
  1727 
  1727 	m_am_tools->memmove(authenticator_response, "S=", 2);
  1728 	m_am_tools->memmove(authenticator_response, "S=", 2);
  1728 	u32_t length = EAP_MSCHAPV2_SHA1_DIGEST_SIZE * 2;
  1729 	u32_t length = EAP_MSCHAPV2_SHA1_DIGEST_SIZE * 2;
  1729 	m_am_tools->convert_bytes_to_hex_ascii(
  1730 	(void)m_am_tools->convert_bytes_to_hex_ascii(
  1730 		digest, 
  1731 		digest, 
  1731 		EAP_MSCHAPV2_SHA1_DIGEST_SIZE,
  1732 		EAP_MSCHAPV2_SHA1_DIGEST_SIZE,
  1732 		authenticator_response + 2,
  1733 		authenticator_response + 2,
  1733 		&length);
  1734 		&length);
  1734 
  1735