eap::metod thorough redesign:
- Support for method stacking introduced - EAP-TLS method has been discontinued - ownTLS has been discontinued
This commit is contained in:
@@ -21,14 +21,23 @@
|
||||
namespace eap
|
||||
{
|
||||
///
|
||||
/// EAP and non-EAP method base class
|
||||
/// Method base class
|
||||
///
|
||||
class method;
|
||||
|
||||
///
|
||||
/// Non-EAP method base class
|
||||
/// Tunnel method base class
|
||||
///
|
||||
class method_noneap;
|
||||
/// This is a base class for all the methods that encapsulate inner methods to provide stacking framework.
|
||||
///
|
||||
class method_tunnel;
|
||||
|
||||
///
|
||||
/// EAP tunnel method
|
||||
///
|
||||
/// This method encapsulates inner data in EAP packets.
|
||||
///
|
||||
class method_eap;
|
||||
}
|
||||
|
||||
#pragma once
|
||||
@@ -55,25 +64,23 @@ namespace eap
|
||||
|
||||
public:
|
||||
///
|
||||
/// Constructs an EAP method
|
||||
/// Constructs a method
|
||||
///
|
||||
/// \param[in] mod EAP module to use for global services
|
||||
/// \param[in] cfg Method configuration
|
||||
/// \param[in] cred User credentials
|
||||
/// \param[in] mod Module to use for global services
|
||||
///
|
||||
method(_In_ module &module, _In_ config_method &cfg, _In_ credentials &cred);
|
||||
method(_In_ module &mod);
|
||||
|
||||
///
|
||||
/// Moves an EAP method
|
||||
/// Moves a method
|
||||
///
|
||||
/// \param[in] other EAP method to move from
|
||||
/// \param[in] other Method to move from
|
||||
///
|
||||
method(_Inout_ method &&other);
|
||||
|
||||
///
|
||||
/// Moves an EAP method
|
||||
/// Moves a method
|
||||
///
|
||||
/// \param[in] other EAP method to move from
|
||||
/// \param[in] other Method to move from
|
||||
///
|
||||
/// \returns Reference to this object
|
||||
///
|
||||
@@ -115,8 +122,8 @@ namespace eap
|
||||
/// \sa [EapPeerGetResponsePacket function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363610.aspx)
|
||||
///
|
||||
virtual void get_response_packet(
|
||||
_Inout_bytecap_(*dwSendPacketSize) void *pSendPacket,
|
||||
_Inout_ DWORD *pdwSendPacketSize) = 0;
|
||||
_Out_ sanitizing_blob &packet,
|
||||
_In_opt_ DWORD size_max = MAXDWORD) = 0;
|
||||
|
||||
///
|
||||
/// Obtains the result of an authentication session from the EAP method.
|
||||
@@ -176,89 +183,193 @@ namespace eap
|
||||
/// @}
|
||||
|
||||
public:
|
||||
module &m_module; ///< EAP module
|
||||
config_method &m_cfg; ///< Connection configuration
|
||||
credentials &m_cred; ///< User credentials
|
||||
std::vector<winstd::eap_attr> m_eap_attr; ///< EAP attributes
|
||||
module &m_module; ///< Module for global services
|
||||
};
|
||||
|
||||
|
||||
class method_noneap : public method
|
||||
class method_tunnel : public method
|
||||
{
|
||||
WINSTD_NONCOPYABLE(method_noneap)
|
||||
WINSTD_NONCOPYABLE(method_tunnel)
|
||||
|
||||
public:
|
||||
///
|
||||
/// Constructs a non-EAP method
|
||||
/// Constructs a method
|
||||
///
|
||||
/// \param[in] mod EAP module to use for global services
|
||||
/// \param[in] cfg Method configuration
|
||||
/// \param[in] cred User credentials
|
||||
/// \param[in] mod Module to use for global services
|
||||
/// \param[in] inner Inner method
|
||||
///
|
||||
method_noneap(_In_ module &module, _In_ config_method &cfg, _In_ credentials &cred);
|
||||
method_tunnel(_In_ module &mod, _In_ method *inner);
|
||||
|
||||
///
|
||||
/// Moves a non-EAP method
|
||||
/// Moves a method
|
||||
///
|
||||
/// \param[in] other EAP method to move from
|
||||
/// \param[in] other Method to move from
|
||||
///
|
||||
method_noneap(_Inout_ method_noneap &&other);
|
||||
method_tunnel(_Inout_ method_tunnel &&other);
|
||||
|
||||
///
|
||||
/// Moves a non-EAP method
|
||||
/// Moves a method
|
||||
///
|
||||
/// \param[in] other EAP method to move from
|
||||
/// \param[in] other Method to move from
|
||||
///
|
||||
/// \returns Reference to this object
|
||||
///
|
||||
method_noneap& operator=(_Inout_ method_noneap &&other);
|
||||
method_tunnel& operator=(_Inout_ method_tunnel &&other);
|
||||
|
||||
/// \name Packet processing
|
||||
/// @{
|
||||
|
||||
///
|
||||
/// Obtains a response packet from the non-EAP method.
|
||||
/// Starts an EAP authentication session on the peer EapHost using the EAP method.
|
||||
///
|
||||
/// \sa [EapPeerBeginSession function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363600.aspx)
|
||||
///
|
||||
virtual void begin_session(
|
||||
_In_ DWORD dwFlags,
|
||||
_In_ const EapAttributes *pAttributeArray,
|
||||
_In_ HANDLE hTokenImpersonateUser,
|
||||
_In_opt_ DWORD dwMaxSendPacketSize = MAXDWORD);
|
||||
|
||||
///
|
||||
/// Ends an EAP authentication session for the EAP method.
|
||||
///
|
||||
/// \sa [EapPeerEndSession function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363604.aspx)
|
||||
///
|
||||
virtual void end_session();
|
||||
|
||||
///
|
||||
/// Processes a packet received by EapHost from a supplicant.
|
||||
///
|
||||
/// \sa [EapPeerProcessRequestPacket function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363621.aspx)
|
||||
///
|
||||
virtual EapPeerMethodResponseAction process_request_packet(
|
||||
_In_bytecount_(dwReceivedPacketSize) const void *pReceivedPacket,
|
||||
_In_ DWORD dwReceivedPacketSize);
|
||||
|
||||
///
|
||||
/// Obtains a response packet from the EAP method.
|
||||
///
|
||||
/// \sa [EapPeerGetResponsePacket function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363610.aspx)
|
||||
///
|
||||
virtual void get_response_packet(
|
||||
_Inout_bytecap_(*dwSendPacketSize) void *pSendPacket,
|
||||
_Inout_ DWORD *pdwSendPacketSize);
|
||||
_Out_ sanitizing_blob &packet,
|
||||
_In_opt_ DWORD size_max = MAXDWORD);
|
||||
|
||||
///
|
||||
/// Obtains the result of an authentication session from the EAP method.
|
||||
///
|
||||
/// \sa [EapPeerGetResult function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363611.aspx)
|
||||
///
|
||||
virtual void get_result(
|
||||
_In_ EapPeerMethodResultReason reason,
|
||||
_Inout_ EapPeerMethodResult *pResult);
|
||||
|
||||
/// @}
|
||||
|
||||
/// \name User Interaction
|
||||
/// @{
|
||||
|
||||
///
|
||||
/// Obtains the user interface context from the EAP method.
|
||||
///
|
||||
/// \note This function is always followed by the `EapPeerInvokeInteractiveUI()` function, which is followed by the `EapPeerSetUIContext()` function.
|
||||
///
|
||||
/// \sa [EapPeerGetUIContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363612.aspx)
|
||||
///
|
||||
virtual void get_ui_context(
|
||||
_Inout_ BYTE **ppUIContextData,
|
||||
_Inout_ DWORD *pdwUIContextDataSize);
|
||||
|
||||
///
|
||||
/// Provides a user interface context to the EAP method.
|
||||
///
|
||||
/// \note This function is called after the UI has been raised through the `EapPeerGetUIContext()` function.
|
||||
///
|
||||
/// \sa [EapPeerSetUIContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363626.aspx)
|
||||
///
|
||||
virtual EapPeerMethodResponseAction set_ui_context(
|
||||
_In_count_(dwUIContextDataSize) const BYTE *pUIContextData,
|
||||
_In_ DWORD dwUIContextDataSize);
|
||||
|
||||
/// @}
|
||||
|
||||
/// \name EAP Response Attributes
|
||||
/// @{
|
||||
|
||||
///
|
||||
/// Obtains an array of EAP response attributes from the EAP method.
|
||||
///
|
||||
/// \sa [EapPeerGetResponseAttributes function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363609.aspx)
|
||||
///
|
||||
virtual void get_response_attributes(_Inout_ EapAttributes *pAttribs);
|
||||
|
||||
///
|
||||
/// Provides an updated array of EAP response attributes to the EAP method.
|
||||
///
|
||||
/// \sa [EapPeerSetResponseAttributes function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363625.aspx)
|
||||
///
|
||||
virtual EapPeerMethodResponseAction set_response_attributes(_In_ const EapAttributes *pAttribs);
|
||||
|
||||
/// @}
|
||||
|
||||
protected:
|
||||
std::unique_ptr<method> m_inner; ///< Inner method
|
||||
};
|
||||
|
||||
|
||||
class method_eap : public method_tunnel
|
||||
{
|
||||
WINSTD_NONCOPYABLE(method_eap)
|
||||
|
||||
public:
|
||||
///
|
||||
/// Appends Diameter AVP to response packet
|
||||
/// Constructs a method
|
||||
///
|
||||
/// \param[in] code AVP code
|
||||
/// \param[in] flags AVP flags
|
||||
/// \param[in] data AVP data (<16777212B)
|
||||
/// \param[in] size Size of \p data in bytes
|
||||
/// \param[in] mod Module to use for global services
|
||||
/// \param[in] eap_method EAP method type
|
||||
/// \param[in] inner Inner method
|
||||
///
|
||||
void append_avp(
|
||||
_In_ unsigned int code,
|
||||
_In_ unsigned char flags,
|
||||
_In_bytecount_(size) const void *data,
|
||||
_In_ unsigned int size);
|
||||
method_eap(_In_ module &mod, _In_ winstd::eap_type_t eap_method, _In_ method *inner);
|
||||
|
||||
///
|
||||
/// Appends Diameter AVP to response packet
|
||||
/// Moves a method
|
||||
///
|
||||
/// \param[in] code AVP code
|
||||
/// \param[in] vendor_id Vendor-ID
|
||||
/// \param[in] flags AVP flags
|
||||
/// \param[in] data AVP data (<16777212B)
|
||||
/// \param[in] size Size of \p data in bytes
|
||||
/// \param[in] other Method to move from
|
||||
///
|
||||
void append_avp(
|
||||
_In_ unsigned int code,
|
||||
_In_ unsigned int vendor_id,
|
||||
_In_ unsigned char flags,
|
||||
_In_bytecount_(size) const void *data,
|
||||
_In_ unsigned int size);
|
||||
method_eap(_Inout_ method_eap &&other);
|
||||
|
||||
///
|
||||
/// Moves a method
|
||||
///
|
||||
/// \param[in] other Method to move from
|
||||
///
|
||||
/// \returns Reference to this object
|
||||
///
|
||||
method_eap& operator=(_Inout_ method_eap &&other);
|
||||
|
||||
/// \name Packet processing
|
||||
/// @{
|
||||
|
||||
///
|
||||
/// Processes a packet received by EapHost from a supplicant.
|
||||
///
|
||||
/// \sa [EapPeerProcessRequestPacket function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363621.aspx)
|
||||
///
|
||||
virtual EapPeerMethodResponseAction process_request_packet(
|
||||
_In_bytecount_(dwReceivedPacketSize) const void *pReceivedPacket,
|
||||
_In_ DWORD dwReceivedPacketSize);
|
||||
|
||||
///
|
||||
/// Obtains a response packet from the EAP method.
|
||||
///
|
||||
/// \sa [EapPeerGetResponsePacket function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363610.aspx)
|
||||
///
|
||||
virtual void get_response_packet(
|
||||
_Out_ sanitizing_blob &packet,
|
||||
_In_opt_ DWORD size_max = MAXDWORD);
|
||||
|
||||
protected:
|
||||
sanitizing_blob m_packet_res; ///< Response packet
|
||||
const winstd::eap_type_t m_eap_method; ///< EAP method type
|
||||
unsigned char m_id; ///< Request packet ID
|
||||
};
|
||||
}
|
||||
|
@@ -28,19 +28,14 @@ using namespace winstd;
|
||||
// eap::method
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
eap::method::method(_In_ module &module, _In_ config_method &cfg, _In_ credentials &cred) :
|
||||
m_module(module),
|
||||
m_cfg(cfg),
|
||||
m_cred(cred)
|
||||
eap::method::method(_In_ module &mod) :
|
||||
m_module(mod)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
eap::method::method(_Inout_ method &&other) :
|
||||
m_module ( other.m_module ),
|
||||
m_cfg ( other.m_cfg ),
|
||||
m_cred ( other.m_cred ),
|
||||
m_eap_attr(std::move(other.m_eap_attr))
|
||||
m_module(other.m_module)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -49,9 +44,6 @@ eap::method& eap::method::operator=(_Inout_ method &&other)
|
||||
{
|
||||
if (this != std::addressof(other)) {
|
||||
assert(std::addressof(m_module) == std::addressof(other.m_module)); // Move method within same module only!
|
||||
assert(std::addressof(m_cfg ) == std::addressof(other.m_cfg )); // Move method with same configuration only!
|
||||
assert(std::addressof(m_cred ) == std::addressof(other.m_cred )); // Move method with same credentials only!
|
||||
m_eap_attr = std::move(other.m_eap_attr);
|
||||
}
|
||||
|
||||
return *this;
|
||||
@@ -68,11 +60,6 @@ void eap::method::begin_session(
|
||||
UNREFERENCED_PARAMETER(pAttributeArray);
|
||||
UNREFERENCED_PARAMETER(hTokenImpersonateUser);
|
||||
UNREFERENCED_PARAMETER(dwMaxSendPacketSize);
|
||||
|
||||
// Presume authentication will fail with generic protocol failure. (Pesimist!!!)
|
||||
// We will reset once we get get_result(Success) call.
|
||||
m_cfg.m_last_status = config_method::status_auth_failed;
|
||||
m_cfg.m_last_msg.clear();
|
||||
}
|
||||
|
||||
|
||||
@@ -85,27 +72,8 @@ void eap::method::get_result(
|
||||
_In_ EapPeerMethodResultReason reason,
|
||||
_Inout_ EapPeerMethodResult *pResult)
|
||||
{
|
||||
assert(pResult);
|
||||
|
||||
switch (reason) {
|
||||
case EapPeerMethodResultSuccess: {
|
||||
m_module.log_event(&EAPMETHOD_METHOD_SUCCESS, event_data((unsigned int)m_cfg.get_method_id()), event_data::blank);
|
||||
m_cfg.m_last_status = config_method::status_success;
|
||||
break;
|
||||
}
|
||||
|
||||
case EapPeerMethodResultFailure:
|
||||
m_module.log_event(&EAPMETHOD_METHOD_FAILURE_ERROR2, event_data((unsigned int)m_cfg.get_method_id()), event_data((unsigned int)m_cfg.m_last_status), event_data::blank);
|
||||
break;
|
||||
|
||||
default:
|
||||
throw win_runtime_error(ERROR_NOT_SUPPORTED, __FUNCTION__ " Not supported.");
|
||||
}
|
||||
|
||||
// Always ask EAP host to save the connection data. And it will save it *only* when we report "success".
|
||||
// Don't worry. EapHost is well aware of failed authentication condition.
|
||||
pResult->fSaveConnectionData = TRUE;
|
||||
pResult->fIsSuccess = TRUE;
|
||||
UNREFERENCED_PARAMETER(reason);
|
||||
UNREFERENCED_PARAMETER(pResult);
|
||||
}
|
||||
|
||||
|
||||
@@ -154,107 +122,192 @@ EapPeerMethodResponseAction eap::method::set_response_attributes(_In_ const EapA
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// eap::method_noneap
|
||||
// eap::method_tunnel
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
eap::method_noneap::method_noneap(_In_ module &module, _In_ config_method &cfg, _In_ credentials &cred) : method(module, cfg, cred)
|
||||
eap::method_tunnel::method_tunnel(_In_ module &mod, _In_ method *inner) :
|
||||
m_inner(inner),
|
||||
method(mod)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
eap::method_noneap::method_noneap(_Inout_ method_noneap &&other) :
|
||||
m_packet_res(std::move(other.m_packet_res)),
|
||||
method (std::move(other ))
|
||||
eap::method_tunnel::method_tunnel(_Inout_ method_tunnel &&other) :
|
||||
m_inner(std::move(other.m_inner)),
|
||||
method (std::move(other ))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
eap::method_noneap& eap::method_noneap::operator=(_Inout_ method_noneap &&other)
|
||||
eap::method_tunnel& eap::method_tunnel::operator=(_Inout_ method_tunnel &&other)
|
||||
{
|
||||
if (this != std::addressof(other)) {
|
||||
assert(std::addressof(m_cred) == std::addressof(other.m_cred)); // Move method with same credentials only!
|
||||
(method&)*this = std::move(other );
|
||||
m_packet_res = std::move(other.m_packet_res);
|
||||
(method&)*this = std::move(other );
|
||||
m_inner = std::move(other.m_inner);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void eap::method_noneap::get_response_packet(
|
||||
_Inout_bytecap_(*dwSendPacketSize) void *pSendPacket,
|
||||
_Inout_ DWORD *pdwSendPacketSize)
|
||||
void eap::method_tunnel::begin_session(
|
||||
_In_ DWORD dwFlags,
|
||||
_In_ const EapAttributes *pAttributeArray,
|
||||
_In_ HANDLE hTokenImpersonateUser,
|
||||
_In_opt_ DWORD dwMaxSendPacketSize)
|
||||
{
|
||||
assert(pdwSendPacketSize);
|
||||
assert(pSendPacket);
|
||||
method::begin_session(dwFlags, pAttributeArray, hTokenImpersonateUser, dwMaxSendPacketSize);
|
||||
|
||||
size_t size_packet = m_packet_res.size();
|
||||
if (size_packet > *pdwSendPacketSize)
|
||||
throw invalid_argument(string_printf(__FUNCTION__ " This method does not support packet fragmentation, but the data size is too big to fit in one packet (packet: %u, maximum: %u).", size_packet, *pdwSendPacketSize).c_str());
|
||||
|
||||
memcpy(pSendPacket, m_packet_res.data(), size_packet);
|
||||
*pdwSendPacketSize = (DWORD)size_packet;
|
||||
m_packet_res.clear();
|
||||
assert(m_inner);
|
||||
m_inner->begin_session(dwFlags, pAttributeArray, hTokenImpersonateUser, dwMaxSendPacketSize);
|
||||
}
|
||||
|
||||
|
||||
void eap::method_noneap::append_avp(
|
||||
_In_ unsigned int code,
|
||||
_In_ unsigned char flags,
|
||||
_In_bytecount_(size) const void *data,
|
||||
_In_ unsigned int size)
|
||||
void eap::method_tunnel::end_session()
|
||||
{
|
||||
unsigned int
|
||||
padding = (unsigned int)((4 - size) % 4),
|
||||
size_outer;
|
||||
assert(m_inner);
|
||||
m_inner->end_session();
|
||||
|
||||
m_packet_res.reserve(
|
||||
m_packet_res.size() +
|
||||
(size_outer =
|
||||
sizeof(diameter_avp_header) + // Diameter header
|
||||
size) + // Data
|
||||
padding); // Data padding
|
||||
|
||||
// Diameter AVP header
|
||||
diameter_avp_header hdr;
|
||||
*reinterpret_cast<unsigned int*>(hdr.code) = htonl(code);
|
||||
hdr.flags = flags;
|
||||
hton24(size_outer, hdr.length);
|
||||
m_packet_res.insert(m_packet_res.end(), reinterpret_cast<const unsigned char*>(&hdr), reinterpret_cast<const unsigned char*>(&hdr + 1));
|
||||
|
||||
// Data
|
||||
m_packet_res.insert(m_packet_res.end(), reinterpret_cast<const unsigned char*>(data), reinterpret_cast<const unsigned char*>(data) + size);
|
||||
m_packet_res.insert(m_packet_res.end(), padding, 0);
|
||||
method::end_session();
|
||||
}
|
||||
|
||||
|
||||
void eap::method_noneap::append_avp(
|
||||
_In_ unsigned int code,
|
||||
_In_ unsigned int vendor_id,
|
||||
_In_ unsigned char flags,
|
||||
_In_bytecount_(size) const void *data,
|
||||
_In_ unsigned int size)
|
||||
EapPeerMethodResponseAction eap::method_tunnel::process_request_packet(
|
||||
_In_bytecount_(dwReceivedPacketSize) const void *pReceivedPacket,
|
||||
_In_ DWORD dwReceivedPacketSize)
|
||||
{
|
||||
unsigned int
|
||||
padding = (unsigned int)((4 - size) % 4),
|
||||
size_outer;
|
||||
|
||||
m_packet_res.reserve(
|
||||
m_packet_res.size() +
|
||||
(size_outer =
|
||||
sizeof(diameter_avp_header_ven) + // Diameter header
|
||||
size) + // Data
|
||||
padding); // Data padding
|
||||
|
||||
// Diameter AVP header
|
||||
diameter_avp_header_ven hdr;
|
||||
*reinterpret_cast<unsigned int*>(hdr.code) = htonl(code);
|
||||
hdr.flags = flags | diameter_avp_flag_vendor;
|
||||
hton24(size_outer, hdr.length);
|
||||
*reinterpret_cast<unsigned int*>(hdr.vendor) = htonl(vendor_id);
|
||||
m_packet_res.insert(m_packet_res.end(), reinterpret_cast<const unsigned char*>(&hdr), reinterpret_cast<const unsigned char*>(&hdr + 1));
|
||||
|
||||
// Data
|
||||
m_packet_res.insert(m_packet_res.end(), reinterpret_cast<const unsigned char*>(data), reinterpret_cast<const unsigned char*>(data) + size);
|
||||
m_packet_res.insert(m_packet_res.end(), padding, 0);
|
||||
assert(m_inner);
|
||||
return m_inner->process_request_packet(pReceivedPacket, dwReceivedPacketSize);
|
||||
}
|
||||
|
||||
|
||||
void eap::method_tunnel::get_response_packet(
|
||||
_Out_ sanitizing_blob &packet,
|
||||
_In_opt_ DWORD size_max)
|
||||
{
|
||||
assert(m_inner);
|
||||
m_inner->get_response_packet(packet, size_max);
|
||||
}
|
||||
|
||||
|
||||
void eap::method_tunnel::get_result(
|
||||
_In_ EapPeerMethodResultReason reason,
|
||||
_Inout_ EapPeerMethodResult *pResult)
|
||||
{
|
||||
assert(m_inner);
|
||||
m_inner->get_result(reason, pResult);
|
||||
}
|
||||
|
||||
|
||||
void eap::method_tunnel::get_ui_context(
|
||||
_Inout_ BYTE **ppUIContextData,
|
||||
_Inout_ DWORD *pdwUIContextDataSize)
|
||||
{
|
||||
assert(m_inner);
|
||||
m_inner->get_ui_context(ppUIContextData, pdwUIContextDataSize);
|
||||
}
|
||||
|
||||
|
||||
EapPeerMethodResponseAction eap::method_tunnel::set_ui_context(
|
||||
_In_count_(dwUIContextDataSize) const BYTE *pUIContextData,
|
||||
_In_ DWORD dwUIContextDataSize)
|
||||
{
|
||||
assert(m_inner);
|
||||
return m_inner->set_ui_context(pUIContextData, dwUIContextDataSize);
|
||||
}
|
||||
|
||||
|
||||
void eap::method_tunnel::get_response_attributes(_Inout_ EapAttributes *pAttribs)
|
||||
{
|
||||
assert(m_inner);
|
||||
m_inner->get_response_attributes(pAttribs);
|
||||
}
|
||||
|
||||
|
||||
EapPeerMethodResponseAction eap::method_tunnel::set_response_attributes(_In_ const EapAttributes *pAttribs)
|
||||
{
|
||||
assert(m_inner);
|
||||
return m_inner->set_response_attributes(pAttribs);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// eap::method_eap
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
eap::method_eap::method_eap(_In_ module &mod, _In_ eap_type_t eap_method, _In_ method *inner) :
|
||||
m_eap_method(eap_method),
|
||||
m_id(0),
|
||||
method_tunnel(mod, inner)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
eap::method_eap::method_eap(_Inout_ method_eap &&other) :
|
||||
m_eap_method (std::move(other.m_eap_method)),
|
||||
m_id (std::move(other.m_id )),
|
||||
method_tunnel(std::move(other ))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
eap::method_eap& eap::method_eap::operator=(_Inout_ method_eap &&other)
|
||||
{
|
||||
if (this != std::addressof(other)) {
|
||||
assert(m_eap_method == other.m_eap_method); // Move method within same EAP method type only!
|
||||
(method_tunnel&)*this = std::move(other );
|
||||
m_id = std::move(other.m_id);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
EapPeerMethodResponseAction eap::method_eap::process_request_packet(
|
||||
_In_bytecount_(dwReceivedPacketSize) const void *pReceivedPacket,
|
||||
_In_ DWORD dwReceivedPacketSize)
|
||||
{
|
||||
assert(dwReceivedPacketSize >= sizeof(EapPacket)); // Request packet should contain an EAP packet header at least.
|
||||
auto hdr = reinterpret_cast<const EapPacket*>(pReceivedPacket);
|
||||
|
||||
// Parse EAP header.
|
||||
if (hdr->Code != EapCodeRequest)
|
||||
throw invalid_argument(string_printf(__FUNCTION__ " Unknown EAP packet received (expected: %u, received: %u).", EapCodeRequest, (int)hdr->Code));
|
||||
DWORD size_packet = ntohs(*reinterpret_cast<const unsigned short*>(hdr->Length));
|
||||
if (size_packet > dwReceivedPacketSize)
|
||||
throw invalid_argument(string_printf(__FUNCTION__ " Incorrect EAP packet length (expected: %uB, received: %uB).", size_packet, dwReceivedPacketSize));
|
||||
if (hdr->Data[0] != m_eap_method)
|
||||
throw invalid_argument(string_printf(__FUNCTION__ " Unsupported EAP method (expected: %u, received: %u).", (int)m_eap_method, (int)hdr->Data[0]));
|
||||
|
||||
// Save request packet ID to make matching response packet in get_response_packet() later.
|
||||
m_id = hdr->Id;
|
||||
|
||||
// Process the data with underlying method.
|
||||
return method_tunnel::process_request_packet(hdr->Data + 1, size_packet - sizeof(EapPacket));
|
||||
}
|
||||
|
||||
|
||||
void eap::method_eap::get_response_packet(
|
||||
_Out_ sanitizing_blob &packet,
|
||||
_In_opt_ DWORD size_max)
|
||||
{
|
||||
assert(size_max >= sizeof(EapPacket)); // We should be able to respond with at least an EAP packet header.
|
||||
|
||||
if (size_max > MAXWORD) size_max = MAXWORD; // EAP packets maximum size is 64kB.
|
||||
packet.reserve(size_max); // To avoid reallocation when inserting EAP packet header later.
|
||||
|
||||
// Get data from underlying method.
|
||||
method_tunnel::get_response_packet(packet, size_max - sizeof(EapPacket));
|
||||
|
||||
// Prepare EAP packet header.
|
||||
EapPacket hdr;
|
||||
hdr.Code = (BYTE)EapCodeResponse;
|
||||
hdr.Id = m_id;
|
||||
size_t size_packet = packet.size() + sizeof(EapPacket);
|
||||
assert(size_packet <= MAXWORD); // Packets spanning over 64kB are not supported.
|
||||
*reinterpret_cast<unsigned short*>(hdr.Length) = htons((unsigned short)size_packet);
|
||||
hdr.Data[0] = m_eap_method;
|
||||
|
||||
// Insert EAP packet header before data.
|
||||
packet.insert(packet.begin(), reinterpret_cast<const unsigned char*>(&hdr), reinterpret_cast<const unsigned char*>(&hdr + 1));
|
||||
}
|
||||
|
Reference in New Issue
Block a user