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