get_ui_context() upgraded

This commit is contained in:
Simon Rozman 2017-02-01 10:52:57 +01:00
parent 57372b8f95
commit b632f0202f
8 changed files with 50 additions and 45 deletions

View File

@ -161,12 +161,9 @@ namespace eap
/// ///
/// \sa [EapPeerGetUIContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363612.aspx) /// \sa [EapPeerGetUIContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363612.aspx)
/// ///
/// \param[out] ppUIContextData A pointer to an address that contains a byte buffer with the supplicant user interface context data from EAPHost. /// \param[out] context_data Supplicant user interface context data from EAPHost.
/// \param[out] pdwUIContextDataSize A pointer to a value that specifies the size of the user interface context data byte buffer returned in \p ppUIContextData.
/// ///
virtual void get_ui_context( virtual void get_ui_context(_Out_ sanitizing_blob &context_data);
_Out_ BYTE **ppUIContextData,
_Out_ DWORD *pdwUIContextDataSize);
/// ///
/// Provides a user interface context to the EAP method. /// Provides a user interface context to the EAP method.
@ -283,9 +280,7 @@ namespace eap
/// \name User Interaction /// \name User Interaction
/// @{ /// @{
virtual void get_ui_context( virtual void get_ui_context(_Out_ sanitizing_blob &context_data);
_Out_ BYTE **ppUIContextData,
_Out_ DWORD *pdwUIContextDataSize);
virtual EapPeerMethodResponseAction set_ui_context( virtual EapPeerMethodResponseAction set_ui_context(
_In_count_(dwUIContextDataSize) const BYTE *pUIContextData, _In_count_(dwUIContextDataSize) const BYTE *pUIContextData,

View File

@ -77,16 +77,10 @@ void eap::method::get_result(
} }
void eap::method::get_ui_context( void eap::method::get_ui_context(_Out_ sanitizing_blob &context_data)
_Out_ BYTE **ppUIContextData,
_Out_ DWORD *pdwUIContextDataSize)
{ {
assert(ppUIContextData);
assert(pdwUIContextDataSize);
// Default implementation returns blank context data. // Default implementation returns blank context data.
*ppUIContextData = NULL; context_data.clear();
*pdwUIContextDataSize = 0;
} }
@ -199,14 +193,12 @@ void eap::method_tunnel::get_result(
} }
void eap::method_tunnel::get_ui_context( void eap::method_tunnel::get_ui_context(_Out_ sanitizing_blob &context_data)
_Out_ BYTE **ppUIContextData,
_Out_ DWORD *pdwUIContextDataSize)
{ {
assert(m_inner); assert(m_inner);
// Default implementation forwards UI context handling to the inner method. // Default implementation forwards UI context handling to the inner method.
m_inner->get_ui_context(ppUIContextData, pdwUIContextDataSize); m_inner->get_ui_context(context_data);
} }

View File

@ -105,9 +105,7 @@ namespace eap
/// \name User Interaction /// \name User Interaction
/// @{ /// @{
virtual void get_ui_context( virtual void get_ui_context(_Out_ sanitizing_blob &context_data);
_Out_ BYTE **ppUIContextData,
_Out_ DWORD *pdwUIContextDataSize);
virtual EapPeerMethodResponseAction set_ui_context( virtual EapPeerMethodResponseAction set_ui_context(
_In_count_(dwUIContextDataSize) const BYTE *pUIContextData, _In_count_(dwUIContextDataSize) const BYTE *pUIContextData,

View File

@ -209,19 +209,23 @@ void eap::method_eaphost::get_result(
} }
void eap::method_eaphost::get_ui_context( void eap::method_eaphost::get_ui_context(_Out_ sanitizing_blob &context_data)
_Out_ BYTE **ppUIContextData,
_Out_ DWORD *pdwUIContextDataSize)
{ {
// Get EapHost peer UI context data. // Get EapHost peer UI context data.
DWORD dwUIContextDataSize;
LPBYTE pUIContextData;
eap_error_runtime error; eap_error_runtime error;
DWORD dwResult = EapHostPeerGetUIContext( DWORD dwResult = EapHostPeerGetUIContext(
m_session_id, m_session_id,
pdwUIContextDataSize, &dwUIContextDataSize,
ppUIContextData, &pUIContextData,
&error._Myptr); &error._Myptr);
if (dwResult == ERROR_SUCCESS) { if (dwResult == ERROR_SUCCESS) {
// UI context data successfuly returned. // UI context data successfuly returned.
context_data.assign(pUIContextData, pUIContextData + dwUIContextDataSize);
// TODO: Test if EapHostPeerGetUIContext() requires us to free the buffer.
//EapHostPeerFreeMemory(pUIContextData);
} else if (error) } else if (error)
throw eap_runtime_error(*error , __FUNCTION__ " EapHostPeerGetUIContext failed."); throw eap_runtime_error(*error , __FUNCTION__ " EapHostPeerGetUIContext failed.");
else else

View File

@ -99,9 +99,7 @@ namespace eap
/// \name User Interaction /// \name User Interaction
/// @{ /// @{
virtual void get_ui_context( virtual void get_ui_context(_Out_ sanitizing_blob &context_data);
_Out_ BYTE **ppUIContextData,
_Out_ DWORD *pdwUIContextDataSize);
virtual EapPeerMethodResponseAction set_ui_context( virtual EapPeerMethodResponseAction set_ui_context(
_In_count_(dwUIContextDataSize) const BYTE *pUIContextData, _In_count_(dwUIContextDataSize) const BYTE *pUIContextData,

View File

@ -122,16 +122,12 @@ void eap::method_gtc::get_result(
} }
void eap::method_gtc::get_ui_context( void eap::method_gtc::get_ui_context(_Out_ sanitizing_blob &context_data)
_Out_ BYTE **ppUIContextData,
_Out_ DWORD *pdwUIContextDataSize)
{ {
assert(ppUIContextData); // Return authenticator string.
assert(pdwUIContextDataSize); context_data.assign(
reinterpret_cast<sanitizing_blob::const_pointer>(m_message.data() ),
// Return a direct pointer to authenticator string. reinterpret_cast<sanitizing_blob::const_pointer>(m_message.data() + m_message.length()));
*pdwUIContextDataSize = (DWORD)(sizeof(sanitizing_wstring::value_type)*m_message.length());
*ppUIContextData = const_cast<LPBYTE>(reinterpret_cast<LPCBYTE>(m_message.data()));
} }
@ -141,7 +137,7 @@ EapPeerMethodResponseAction eap::method_gtc::set_ui_context(
{ {
// Save GTC reply. // Save GTC reply.
m_reply.assign( m_reply.assign(
reinterpret_cast<sanitizing_wstring::const_pointer>(pUIContextData), reinterpret_cast<sanitizing_wstring::const_pointer>(pUIContextData ),
reinterpret_cast<sanitizing_wstring::const_pointer>(pUIContextData + dwUIContextDataSize)); reinterpret_cast<sanitizing_wstring::const_pointer>(pUIContextData + dwUIContextDataSize));
// Send the reply. // Send the reply.

View File

@ -201,6 +201,9 @@ namespace eap
#ifdef EAP_USE_NATIVE_CREDENTIAL_CACHE #ifdef EAP_USE_NATIVE_CREDENTIAL_CACHE
BYTE *m_blob_cred; ///< Credentials BLOB BYTE *m_blob_cred; ///< Credentials BLOB
#endif #endif
// The following members are required to avoid memory leakage in get_ui_context()
BYTE *m_blob_ui_ctx; ///< User Interface context data
}; };
/// ///

View File

@ -357,7 +357,20 @@ void eap::peer_ttls::get_ui_context(
_Out_ BYTE **ppUIContextData, _Out_ BYTE **ppUIContextData,
_Out_ DWORD *pdwUIContextDataSize) _Out_ DWORD *pdwUIContextDataSize)
{ {
static_cast<session*>(hSession)->m_method->get_ui_context(ppUIContextData, pdwUIContextDataSize); assert(ppUIContextData);
assert(pdwUIContextDataSize);
auto s = static_cast<session*>(hSession);
// Get context data from method.
sanitizing_blob context_data;
s->m_method->get_ui_context(context_data);
// Pack data.
pack(context_data, ppUIContextData, pdwUIContextDataSize);
if (s->m_blob_ui_ctx)
free_memory(s->m_blob_ui_ctx);
s->m_blob_ui_ctx = *ppUIContextData;
} }
@ -368,7 +381,9 @@ void eap::peer_ttls::set_ui_context(
_Out_ EapPeerMethodOutput *pEapOutput) _Out_ EapPeerMethodOutput *pEapOutput)
{ {
assert(pEapOutput); assert(pEapOutput);
pEapOutput->action = static_cast<session*>(hSession)->m_method->set_ui_context(pUIContextData, dwUIContextDataSize);
sanitizing_blob data(std::move(unpack(pUIContextData, dwUIContextDataSize)));
pEapOutput->action = static_cast<session*>(hSession)->m_method->set_ui_context(data.data(), (DWORD)data.size());
pEapOutput->fAllowNotifications = TRUE; pEapOutput->fAllowNotifications = TRUE;
} }
@ -505,10 +520,11 @@ eap::peer_ttls::session::session(_In_ module &mod) :
m_module(mod), m_module(mod),
m_cfg(mod), m_cfg(mod),
m_cred(mod, m_cfg), m_cred(mod, m_cfg),
m_blob_cfg(NULL) m_blob_cfg(NULL),
#ifdef EAP_USE_NATIVE_CREDENTIAL_CACHE #ifdef EAP_USE_NATIVE_CREDENTIAL_CACHE
, m_blob_cred(NULL) m_blob_cred(NULL),
#endif #endif
m_blob_ui_ctx(NULL)
{} {}
@ -521,6 +537,9 @@ eap::peer_ttls::session::~session()
if (m_blob_cred) if (m_blob_cred)
m_module.free_memory(m_blob_cred); m_module.free_memory(m_blob_cred);
#endif #endif
if (m_blob_ui_ctx)
m_module.free_memory(m_blob_ui_ctx);
} }