peer and peer_ui are no longer templates; method specific BLOB management moved from Main(_UI).cpp to modules.

This commit is contained in:
2016-08-05 15:45:45 +02:00
parent 437f5f91b8
commit 54bb2050fa
13 changed files with 599 additions and 445 deletions

View File

@@ -35,7 +35,7 @@ namespace eap
namespace eap
{
class peer_ttls_ui : public peer_ui<credentials_ttls, bool, bool>
class peer_ttls_ui : public peer_ui
{
public:
///
@@ -48,66 +48,86 @@ namespace eap
///
virtual config_method* make_config_method();
///
/// Converts XML into the configuration BLOB.
///
/// \sa [EapPeerConfigXml2Blob function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363602.aspx)
///
virtual bool config_xml2blob(
_In_ DWORD dwFlags,
_In_ IXMLDOMNode *pConfigRoot,
_Out_ BYTE **pConnectionDataOut,
_Out_ DWORD *pdwConnectionDataOutSize,
_Out_ EAP_ERROR **ppEapError);
///
/// Converts the configuration BLOB to XML.
///
/// The configuration BLOB is returned in the ppConnectionDataOut parameter of the EapPeerInvokeConfigUI function.
///
/// \sa [EapPeerConfigBlob2Xml function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363601.aspx)
///
virtual bool config_blob2xml(
_In_ DWORD dwFlags,
_In_count_(dwConnectionDataSize) const BYTE *pConnectionData,
_In_ DWORD dwConnectionDataSize,
_In_ IXMLDOMDocument *pDoc,
_In_ IXMLDOMNode *pConfigRoot,
_Out_ EAP_ERROR **ppEapError);
///
/// Raises the EAP method's specific connection configuration user interface dialog on the client.
///
/// \sa [EapPeerInvokeConfigUI function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363614.aspx)
///
/// \param[in] hwndParent Parent window
/// \param[inout] cfg Configuration to edit
/// \param[out] ppEapError Pointer to error descriptor in case of failure. Free using `module::free_error_memory()`.
///
/// \returns
/// - \c true if succeeded
/// - \c false otherwise. See \p ppEapError for details.
///
virtual bool invoke_config_ui(
_In_ HWND hwndParent,
_Inout_ config_providers &cfg,
_Out_ EAP_ERROR **ppEapError);
_In_ HWND hwndParent,
_In_count_(dwConnectionDataInSize) const BYTE *pConnectionDataIn,
_In_ DWORD dwConnectionDataInSize,
_Out_ BYTE **ppConnectionDataOut,
_Out_ DWORD *pdwConnectionDataOutSize,
_Out_ EAP_ERROR **ppEapError);
///
/// Raises a custom interactive user interface dialog to obtain user identity information for the EAP method on the client.
///
/// \sa [EapPeerInvokeIdentityUI function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363615.aspx)
///
/// \param[in] hwndParent Parent window
/// \param[in] dwFlags Flags passed to `EapPeerInvokeIdentityUI()` call
/// \param[inout] cfg Configuration
/// \param[inout] cred User credentials to edit
/// \param[out] ppwszIdentity Pointer to user identity. Free using `module::free_memory()`.
/// \param[out] ppEapError Pointer to error descriptor in case of failure. Free using `module::free_error_memory()`.
///
/// \returns
/// - \c true if succeeded
/// - \c false otherwise. See \p ppEapError for details.
///
virtual bool invoke_identity_ui(
_In_ HWND hwndParent,
_In_ DWORD dwFlags,
_Inout_ config_providers &cfg,
_Inout_ credentials_type &cred,
_Out_ LPWSTR *ppwszIdentity,
_Out_ EAP_ERROR **ppEapError);
_In_ HWND hwndParent,
_In_ DWORD dwFlags,
_In_count_(dwConnectionDataSize) const BYTE *pConnectionData,
_In_ DWORD dwConnectionDataSize,
_In_count_(dwUserDataSize) const BYTE *pUserData,
_In_ DWORD dwUserDataSize,
_Out_ BYTE **ppUserDataOut,
_Out_ DWORD *pdwUserDataOutSize,
_Out_ LPWSTR *ppwszIdentity,
_Out_ EAP_ERROR **ppEapError);
///
/// Raises a custom interactive user interface dialog for the EAP method on the client.
///
/// \sa [EapPeerInvokeInteractiveUI function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363616.aspx)
///
/// \param[in] hwndParent Parent window
/// \param[in] req Interactive request
/// \param[out] res Interactive response
/// \param[out] ppEapError Pointer to error descriptor in case of failure. Free using `module::free_error_memory()`.
///
/// \returns
/// - \c true if succeeded
/// - \c false otherwise. See \p ppEapError for details.
///
virtual bool invoke_interactive_ui(
_In_ HWND hwndParent,
_In_ const interactive_request_type &req,
_Out_ interactive_response_type &res,
_Out_ EAP_ERROR **ppEapError);
_In_ HWND hwndParent,
_In_count_(dwUIContextDataSize) const BYTE *pUIContextData,
_In_ DWORD dwUIContextDataSize,
_Out_ BYTE **ppDataFromInteractiveUI,
_Out_ DWORD *pdwDataFromInteractiveUISize,
_Out_ EAP_ERROR **ppEapError);
};
}

View File

@@ -25,7 +25,7 @@
// eap::peer_ttls_ui
//////////////////////////////////////////////////////////////////////
eap::peer_ttls_ui::peer_ttls_ui() : peer_ui<eap::credentials_ttls, bool, bool>(winstd::eap_type_ttls)
eap::peer_ttls_ui::peer_ttls_ui() : peer_ui(winstd::eap_type_ttls)
{
}
@@ -36,12 +36,57 @@ eap::config_method* eap::peer_ttls_ui::make_config_method()
}
bool eap::peer_ttls_ui::invoke_config_ui(
_In_ HWND hwndParent,
_Inout_ config_providers &cfg,
_Out_ EAP_ERROR **ppEapError)
bool eap::peer_ttls_ui::config_xml2blob(
_In_ DWORD dwFlags,
_In_ IXMLDOMNode *pConfigRoot,
_Out_ BYTE **pConnectionDataOut,
_Out_ DWORD *pdwConnectionDataOutSize,
_Out_ EAP_ERROR **ppEapError)
{
UNREFERENCED_PARAMETER(ppEapError);
UNREFERENCED_PARAMETER(dwFlags);
// Load configuration from XML.
eap::config_providers cfg(this);
if (!cfg.load(pConfigRoot, ppEapError))
return false;
// Pack configuration.
return pack(cfg, pConnectionDataOut, pdwConnectionDataOutSize, ppEapError);
}
bool eap::peer_ttls_ui::config_blob2xml(
_In_ DWORD dwFlags,
_In_count_(dwConnectionDataSize) const BYTE *pConnectionData,
_In_ DWORD dwConnectionDataSize,
_In_ IXMLDOMDocument *pDoc,
_In_ IXMLDOMNode *pConfigRoot,
_Out_ EAP_ERROR **ppEapError)
{
UNREFERENCED_PARAMETER(dwFlags);
// Unpack configuration.
eap::config_providers cfg(this);
if (!unpack(cfg, pConnectionData, dwConnectionDataSize, ppEapError))
return false;
// Save configuration to XML.
return cfg.save(pDoc, pConfigRoot, ppEapError);
}
bool eap::peer_ttls_ui::invoke_config_ui(
_In_ HWND hwndParent,
_In_count_(dwConnectionDataInSize) const BYTE *pConnectionDataIn,
_In_ DWORD dwConnectionDataInSize,
_Out_ BYTE **ppConnectionDataOut,
_Out_ DWORD *pdwConnectionDataOutSize,
_Out_ EAP_ERROR **ppEapError)
{
// Unpack configuration.
eap::config_providers cfg(this);
if (dwConnectionDataInSize && !unpack(cfg, pConnectionDataIn, dwConnectionDataInSize, ppEapError))
return false;
// Initialize application.
new wxApp();
@@ -70,23 +115,35 @@ bool eap::peer_ttls_ui::invoke_config_ui(
return false;
}
return true;
// Pack new configuration.
return pack(cfg, ppConnectionDataOut, pdwConnectionDataOutSize, ppEapError);
}
bool eap::peer_ttls_ui::invoke_identity_ui(
_In_ HWND hwndParent,
_In_ DWORD dwFlags,
_Inout_ config_providers &cfg,
_Inout_ credentials_type &cred,
_Out_ LPWSTR *ppwszIdentity,
_Out_ EAP_ERROR **ppEapError)
_In_ HWND hwndParent,
_In_ DWORD dwFlags,
_In_count_(dwConnectionDataSize) const BYTE *pConnectionData,
_In_ DWORD dwConnectionDataSize,
_In_count_(dwUserDataSize) const BYTE *pUserData,
_In_ DWORD dwUserDataSize,
_Out_ BYTE **ppUserDataOut,
_Out_ DWORD *pdwUserDataOutSize,
_Out_ LPWSTR *ppwszIdentity,
_Out_ EAP_ERROR **ppEapError)
{
if (cfg.m_providers.empty() || cfg.m_providers.front().m_methods.empty()) {
eap::config_providers cfg(this);
if (!unpack(cfg, pConnectionData, dwConnectionDataSize, ppEapError))
return false;
else if (cfg.m_providers.empty() || cfg.m_providers.front().m_methods.empty()) {
*ppEapError = make_error(ERROR_INVALID_PARAMETER, _T(__FUNCTION__) _T(" Configuration has no providers and/or methods."));
return false;
}
credentials_ttls cred(this);
if (dwUserDataSize && !unpack(cred, pUserData, dwUserDataSize, ppEapError))
return false;
const config_provider &cfg_prov(cfg.m_providers.front());
config_method_ttls *cfg_method = dynamic_cast<config_method_ttls*>(cfg_prov.m_methods.front().get());
assert(cfg_method);
@@ -138,18 +195,23 @@ bool eap::peer_ttls_ui::invoke_identity_ui(
*ppwszIdentity = (WCHAR*)alloc_memory(size);
memcpy(*ppwszIdentity, identity.c_str(), size);
return true;
// Pack credentials.
return pack(cred, ppUserDataOut, pdwUserDataOutSize, ppEapError);
}
bool eap::peer_ttls_ui::invoke_interactive_ui(
_In_ HWND hwndParent,
_In_ const interactive_request_type &req,
_Out_ interactive_response_type &res,
_Out_ EAP_ERROR **ppEapError)
_In_ HWND hwndParent,
_In_count_(dwUIContextDataSize) const BYTE *pUIContextData,
_In_ DWORD dwUIContextDataSize,
_Out_ BYTE **ppDataFromInteractiveUI,
_Out_ DWORD *pdwDataFromInteractiveUISize,
_Out_ EAP_ERROR **ppEapError)
{
UNREFERENCED_PARAMETER(req);
UNREFERENCED_PARAMETER(res);
UNREFERENCED_PARAMETER(pUIContextData);
UNREFERENCED_PARAMETER(dwUIContextDataSize);
UNREFERENCED_PARAMETER(ppDataFromInteractiveUI);
UNREFERENCED_PARAMETER(pdwDataFromInteractiveUISize);
UNREFERENCED_PARAMETER(ppEapError);
InitCommonControls();