eap::config_provider changed from template to class followed by a mass detemplatization of other classes
This commit is contained in:
parent
a7d75ea72d
commit
9376404164
@ -236,7 +236,7 @@ DWORD APIENTRY EapPeerGetIdentity(
|
||||
else if (!ppwszIdentity)
|
||||
g_peer.log_error(*ppEapError = g_peer.make_error(dwResult = ERROR_INVALID_PARAMETER, _T(__FUNCTION__) _T(" ppwszIdentity is NULL.")));
|
||||
else {
|
||||
_EAPMETHOD_PEER::config_providers_type cfg(g_peer);
|
||||
eap::config_providers cfg(g_peer);
|
||||
_EAPMETHOD_PEER::credentials_type cred(g_peer);
|
||||
if (!g_peer.unpack(cfg, pConnectionData, dwConnectionDataSize, ppEapError) ||
|
||||
!g_peer.unpack(cred, pUserData, dwUserDataSize, ppEapError) ||
|
||||
@ -684,7 +684,7 @@ DWORD WINAPI EapPeerGetMethodProperties(
|
||||
else if (!pMethodPropertyArray)
|
||||
g_peer.log_error(*ppEapError = g_peer.make_error(dwResult = ERROR_INVALID_PARAMETER, _T(__FUNCTION__) _T(" pMethodPropertyArray is NULL.")));
|
||||
else {
|
||||
_EAPMETHOD_PEER::config_providers_type cfg(g_peer);
|
||||
eap::config_providers cfg(g_peer);
|
||||
_EAPMETHOD_PEER::credentials_type cred(g_peer);
|
||||
if (!g_peer.unpack(cfg, pEapConnData, dwEapConnDataSize, ppEapError) ||
|
||||
!g_peer.unpack(cred, pUserData, dwUserDataSize, ppEapError) ||
|
||||
|
@ -142,7 +142,7 @@ DWORD WINAPI EapPeerConfigXml2Blob(
|
||||
|
||||
// Load configuration.
|
||||
pConfigDoc->setProperty(bstr(L"SelectionNamespaces"), variant(L"xmlns:eap-metadata=\"urn:ietf:params:xml:ns:yang:ietf-eap-metadata\""));
|
||||
_EAPMETHOD_PEER_UI::config_providers_type cfg(g_peer);
|
||||
eap::config_providers cfg(g_peer);
|
||||
if (!cfg.load(pXmlElConfig, ppEapError) ||
|
||||
!g_peer.pack(cfg, ppConfigOut, pdwConfigOutSize, ppEapError))
|
||||
{
|
||||
@ -198,7 +198,7 @@ DWORD WINAPI EapPeerConfigBlob2Xml(
|
||||
HRESULT hr;
|
||||
|
||||
// Unpack configuration.
|
||||
_EAPMETHOD_PEER_UI::config_providers_type cfg(g_peer);
|
||||
eap::config_providers cfg(g_peer);
|
||||
if (!g_peer.unpack(cfg, pConfigIn, dwConfigInSize, ppEapError)) {
|
||||
if (*ppEapError) {
|
||||
g_peer.log_error(*ppEapError);
|
||||
@ -294,7 +294,7 @@ DWORD WINAPI EapPeerInvokeConfigUI(
|
||||
else if (!ppConnectionDataOut)
|
||||
g_peer.log_error(*ppEapError = g_peer.make_error(dwResult = ERROR_INVALID_PARAMETER, _T(__FUNCTION__) _T(" ppConnectionDataOut is NULL.")));
|
||||
else {
|
||||
_EAPMETHOD_PEER_UI::config_providers_type cfg(g_peer);
|
||||
eap::config_providers cfg(g_peer);
|
||||
if (!g_peer.unpack(cfg, pConnectionDataIn, dwConnectionDataInSize, ppEapError) ||
|
||||
!g_peer.invoke_config_ui(hwndParent, cfg, ppEapError) ||
|
||||
!g_peer.pack(cfg, ppConnectionDataOut, pdwConnectionDataOutSize, ppEapError))
|
||||
@ -359,7 +359,7 @@ DWORD WINAPI EapPeerInvokeIdentityUI(
|
||||
else if (!ppwszIdentity)
|
||||
g_peer.log_error(*ppEapError = g_peer.make_error(dwResult = ERROR_INVALID_PARAMETER, _T(__FUNCTION__) _T(" ppwszIdentity is NULL.")));
|
||||
else {
|
||||
_EAPMETHOD_PEER_UI::config_providers_type cfg(g_peer);
|
||||
eap::config_providers cfg(g_peer);
|
||||
_EAPMETHOD_PEER_UI::credentials_type cred(g_peer);
|
||||
if (!g_peer.unpack(cfg, pConnectionData, dwConnectionDataSize, ppEapError) ||
|
||||
!g_peer.unpack(cred, pUserData, dwUserDataSize, ppEapError) ||
|
||||
|
@ -33,14 +33,14 @@ namespace eap
|
||||
class config_method;
|
||||
|
||||
///
|
||||
/// Single provider configuration
|
||||
/// Base class for single provider configuration storage
|
||||
///
|
||||
template <class _Tmeth> class config_provider;
|
||||
class config_provider;
|
||||
|
||||
///
|
||||
/// List of providers configuration
|
||||
/// Base class for the list of providers configuration storage
|
||||
///
|
||||
template <class _Tprov> class config_providers;
|
||||
class config_providers;
|
||||
}
|
||||
|
||||
namespace eapserial
|
||||
@ -324,7 +324,6 @@ namespace eap
|
||||
};
|
||||
|
||||
|
||||
template <class _Tmeth>
|
||||
class config_provider : public config
|
||||
{
|
||||
public:
|
||||
@ -333,52 +332,21 @@ namespace eap
|
||||
///
|
||||
/// \param[in] mod Reference of the EAP module to use for global services
|
||||
///
|
||||
config_provider(_In_ module &mod) :
|
||||
m_read_only(false),
|
||||
config(mod)
|
||||
{
|
||||
}
|
||||
config_provider(_In_ module &mod);
|
||||
|
||||
///
|
||||
/// Copies configuration
|
||||
///
|
||||
/// \param[in] other Configuration to copy from
|
||||
///
|
||||
config_provider(_In_ const config_provider &other) :
|
||||
m_read_only(other.m_read_only),
|
||||
m_id(other.m_id),
|
||||
m_name(other.m_name),
|
||||
m_help_email(other.m_help_email),
|
||||
m_help_web(other.m_help_web),
|
||||
m_help_phone(other.m_help_phone),
|
||||
m_lbl_alt_credential(other.m_lbl_alt_credential),
|
||||
m_lbl_alt_identity(other.m_lbl_alt_identity),
|
||||
m_lbl_alt_password(other.m_lbl_alt_password),
|
||||
config(other)
|
||||
{
|
||||
for (std::list<std::unique_ptr<config_method> >::const_iterator method = other.m_methods.cbegin(), method_end = other.m_methods.cend(); method != method_end; ++method)
|
||||
m_methods.push_back(std::move(std::unique_ptr<config_method>(*method ? (config_method*)method->get()->clone() : nullptr)));
|
||||
}
|
||||
config_provider(_In_ const config_provider &other);
|
||||
|
||||
///
|
||||
/// Moves configuration
|
||||
///
|
||||
/// \param[in] other Configuration to move from
|
||||
///
|
||||
config_provider(_Inout_ config_provider &&other) :
|
||||
m_read_only(std::move(other.m_read_only)),
|
||||
m_id(std::move(other.m_id)),
|
||||
m_name(std::move(other.m_name)),
|
||||
m_help_email(std::move(other.m_help_email)),
|
||||
m_help_web(std::move(other.m_help_web)),
|
||||
m_help_phone(std::move(other.m_help_phone)),
|
||||
m_lbl_alt_credential(std::move(other.m_lbl_alt_credential)),
|
||||
m_lbl_alt_identity(std::move(other.m_lbl_alt_identity)),
|
||||
m_lbl_alt_password(std::move(other.m_lbl_alt_password)),
|
||||
m_methods(std::move(other.m_methods)),
|
||||
config(std::move(other))
|
||||
{
|
||||
}
|
||||
config_provider(_Inout_ config_provider &&other);
|
||||
|
||||
///
|
||||
/// Copies configuration
|
||||
@ -387,27 +355,7 @@ namespace eap
|
||||
///
|
||||
/// \returns Reference to this object
|
||||
///
|
||||
config_provider& operator=(_In_ const config_provider &other)
|
||||
{
|
||||
if (this != &other) {
|
||||
(config&)*this = other;
|
||||
m_read_only = other.m_read_only;
|
||||
m_id = other.m_id;
|
||||
m_name = other.m_name;
|
||||
m_help_email = other.m_help_email;
|
||||
m_help_web = other.m_help_web;
|
||||
m_help_phone = other.m_help_phone;
|
||||
m_lbl_alt_credential = other.m_lbl_alt_credential;
|
||||
m_lbl_alt_identity = other.m_lbl_alt_identity;
|
||||
m_lbl_alt_password = other.m_lbl_alt_password;
|
||||
|
||||
m_methods.clear();
|
||||
for (std::list<std::unique_ptr<config_method> >::const_iterator method = other.m_methods.cbegin(), method_end = other.m_methods.cend(); method != method_end; ++method)
|
||||
m_methods.push_back(std::move(std::unique_ptr<config_method>(*method ? (config_method*)method->get()->clone() : nullptr)));
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
config_provider& operator=(_In_ const config_provider &other);
|
||||
|
||||
///
|
||||
/// Moves configuration
|
||||
@ -416,31 +364,14 @@ namespace eap
|
||||
///
|
||||
/// \returns Reference to this object
|
||||
///
|
||||
config_provider& operator=(_Inout_ config_provider &&other)
|
||||
{
|
||||
if (this != &other) {
|
||||
(config&&)*this = std::move(other);
|
||||
m_read_only = std::move(m_read_only);
|
||||
m_id = std::move(other.m_id);
|
||||
m_name = std::move(other.m_name);
|
||||
m_help_email = std::move(other.m_help_email);
|
||||
m_help_web = std::move(other.m_help_web);
|
||||
m_help_phone = std::move(other.m_help_phone);
|
||||
m_lbl_alt_credential = std::move(other.m_lbl_alt_credential);
|
||||
m_lbl_alt_identity = std::move(other.m_lbl_alt_identity);
|
||||
m_lbl_alt_password = std::move(other.m_lbl_alt_password);
|
||||
m_methods = std::move(other.m_methods);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
config_provider& operator=(_Inout_ config_provider &&other);
|
||||
|
||||
///
|
||||
/// Clones configuration
|
||||
///
|
||||
/// \returns Pointer to cloned configuration
|
||||
///
|
||||
virtual config* clone() const { return new config_provider<_Tmeth>(*this); }
|
||||
virtual config* clone() const;
|
||||
|
||||
/// \name XML configuration management
|
||||
/// @{
|
||||
@ -456,119 +387,7 @@ namespace eap
|
||||
/// - \c true if succeeded
|
||||
/// - \c false otherwise. See \p ppEapError for details.
|
||||
///
|
||||
virtual bool save(_In_ IXMLDOMDocument *pDoc, _In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **ppEapError) const
|
||||
{
|
||||
if (!config::save(pDoc, pConfigRoot, ppEapError))
|
||||
return false;
|
||||
|
||||
const winstd::bstr bstrNamespace(L"urn:ietf:params:xml:ns:yang:ietf-eap-metadata");
|
||||
DWORD dwResult;
|
||||
HRESULT hr;
|
||||
|
||||
// <read-only>
|
||||
if ((dwResult = eapxml::put_element_value(pDoc, pConfigRoot, winstd::bstr(L"read-only"), bstrNamespace, m_read_only)) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <read-only> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <ID>
|
||||
if (!m_id.empty())
|
||||
if ((dwResult = eapxml::put_element_value(pDoc, pConfigRoot, winstd::bstr(L"ID"), bstrNamespace, winstd::bstr(m_id))) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <ID> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <ProviderInfo>
|
||||
winstd::com_obj<IXMLDOMElement> pXmlElProviderInfo;
|
||||
if ((dwResult = eapxml::create_element(pDoc, pConfigRoot, winstd::bstr(L"eap-metadata:ProviderInfo"), winstd::bstr(L"ProviderInfo"), bstrNamespace, &pXmlElProviderInfo)) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <ProviderInfo> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <ProviderInfo>/<DisplayName>
|
||||
if (!m_name.empty())
|
||||
if ((dwResult = eapxml::put_element_value(pDoc, pXmlElProviderInfo, winstd::bstr(L"DisplayName"), bstrNamespace, winstd::bstr(m_name))) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <DisplayName> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <ProviderInfo>/<Helpdesk>
|
||||
winstd::com_obj<IXMLDOMElement> pXmlElHelpdesk;
|
||||
if ((dwResult = eapxml::create_element(pDoc, pXmlElProviderInfo, winstd::bstr(L"eap-metadata:Helpdesk"), winstd::bstr(L"Helpdesk"), bstrNamespace, &pXmlElHelpdesk)) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <Helpdesk> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <ProviderInfo>/<Helpdesk>/<EmailAddress>
|
||||
if (!m_help_email.empty())
|
||||
if ((dwResult = eapxml::put_element_value(pDoc, pXmlElHelpdesk, winstd::bstr(L"EmailAddress"), bstrNamespace, winstd::bstr(m_help_email))) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <EmailAddress> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <ProviderInfo>/<Helpdesk>/<WebAddress>
|
||||
if (!m_help_web.empty())
|
||||
if ((dwResult = eapxml::put_element_value(pDoc, pXmlElHelpdesk, winstd::bstr(L"WebAddress"), bstrNamespace, winstd::bstr(m_help_web))) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <WebAddress> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <ProviderInfo>/<Helpdesk>/<Phone>
|
||||
if (!m_help_phone.empty())
|
||||
if ((dwResult = eapxml::put_element_value(pDoc, pXmlElHelpdesk, winstd::bstr(L"Phone"), bstrNamespace, winstd::bstr(m_help_phone))) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <Phone> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <ProviderInfo>/<CredentialPrompt>
|
||||
if (!m_lbl_alt_credential.empty())
|
||||
if ((dwResult = eapxml::put_element_value(pDoc, pXmlElProviderInfo, winstd::bstr(L"CredentialPrompt"), bstrNamespace, winstd::bstr(m_lbl_alt_credential))) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <CredentialPrompt> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <ProviderInfo>/<UserNameLabel>
|
||||
if (!m_lbl_alt_identity.empty())
|
||||
if ((dwResult = eapxml::put_element_value(pDoc, pXmlElProviderInfo, winstd::bstr(L"UserNameLabel"), bstrNamespace, winstd::bstr(m_lbl_alt_identity))) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <UserNameLabel> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <ProviderInfo>/<PasswordLabel>
|
||||
if (!m_lbl_alt_password.empty())
|
||||
if ((dwResult = eapxml::put_element_value(pDoc, pXmlElProviderInfo, winstd::bstr(L"PasswordLabel"), bstrNamespace, winstd::bstr(m_lbl_alt_password))) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <PasswordLabel> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <AuthenticationMethods>
|
||||
winstd::com_obj<IXMLDOMElement> pXmlElAuthenticationMethods;
|
||||
if ((dwResult = eapxml::create_element(pDoc, pConfigRoot, winstd::bstr(L"eap-metadata:AuthenticationMethods"), winstd::bstr(L"AuthenticationMethods"), bstrNamespace, &pXmlElAuthenticationMethods)) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <AuthenticationMethods> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
for (std::list<std::unique_ptr<config_method> >::const_iterator method = m_methods.cbegin(), method_end = m_methods.cend(); method != method_end; ++method) {
|
||||
// <AuthenticationMethod>
|
||||
winstd::com_obj<IXMLDOMElement> pXmlElAuthenticationMethod;
|
||||
if ((dwResult = eapxml::create_element(pDoc, winstd::bstr(L"AuthenticationMethod"), bstrNamespace, &pXmlElAuthenticationMethod))) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <AuthenticationMethod> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <AuthenticationMethod>/...
|
||||
if (!method->get()->save(pDoc, pXmlElAuthenticationMethod, ppEapError))
|
||||
return false;
|
||||
|
||||
if (FAILED(hr = pXmlElAuthenticationMethods->appendChild(pXmlElAuthenticationMethod, NULL))) {
|
||||
*ppEapError = m_module.make_error(HRESULT_CODE(hr), _T(__FUNCTION__) _T(" Error appending <AuthenticationMethod> element."));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool save(_In_ IXMLDOMDocument *pDoc, _In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **ppEapError) const;
|
||||
|
||||
///
|
||||
/// Load configuration from XML document
|
||||
@ -580,108 +399,7 @@ namespace eap
|
||||
/// - \c true if succeeded
|
||||
/// - \c false otherwise. See \p ppEapError for details.
|
||||
///
|
||||
virtual bool load(_In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **ppEapError)
|
||||
{
|
||||
assert(pConfigRoot);
|
||||
assert(ppEapError);
|
||||
DWORD dwResult;
|
||||
std::wstring xpath(eapxml::get_xpath(pConfigRoot));
|
||||
|
||||
if (!config::load(pConfigRoot, ppEapError))
|
||||
return false;
|
||||
|
||||
// <read-only>
|
||||
if ((dwResult = eapxml::get_element_value(pConfigRoot, winstd::bstr(L"eap-metadata:read-only"), &m_read_only)) != ERROR_SUCCESS)
|
||||
m_read_only = true;
|
||||
m_module.log_config((xpath + L"/read-only").c_str(), m_read_only);
|
||||
|
||||
// <ID>
|
||||
m_id.clear();
|
||||
eapxml::get_element_value(pConfigRoot, winstd::bstr(L"eap-metadata:ID"), m_id);
|
||||
m_module.log_config((xpath + L"/ID").c_str(), m_id.c_str());
|
||||
|
||||
// <ProviderInfo>
|
||||
m_name.clear();
|
||||
m_help_email.clear();
|
||||
m_help_web.clear();
|
||||
m_help_phone.clear();
|
||||
m_lbl_alt_credential.clear();
|
||||
m_lbl_alt_identity.clear();
|
||||
m_lbl_alt_password.clear();
|
||||
winstd::com_obj<IXMLDOMElement> pXmlElProviderInfo;
|
||||
if (eapxml::select_element(pConfigRoot, winstd::bstr(L"eap-metadata:ProviderInfo"), &pXmlElProviderInfo) == ERROR_SUCCESS) {
|
||||
std::wstring lang;
|
||||
LoadString(m_module.m_instance, 2, lang);
|
||||
std::wstring xpathProviderInfo(xpath + L"/ProviderInfo");
|
||||
|
||||
// <DisplayName>
|
||||
eapxml::get_element_localized(pXmlElProviderInfo, winstd::bstr(L"eap-metadata:DisplayName"), lang.c_str(), m_name);
|
||||
m_module.log_config((xpathProviderInfo + L"/DisplayName").c_str(), m_name.c_str());
|
||||
|
||||
winstd::com_obj<IXMLDOMElement> pXmlElHelpdesk;
|
||||
if (eapxml::select_element(pXmlElProviderInfo, winstd::bstr(L"eap-metadata:Helpdesk"), &pXmlElHelpdesk) == ERROR_SUCCESS) {
|
||||
std::wstring xpathHelpdesk(xpathProviderInfo + L"/Helpdesk");
|
||||
|
||||
// <Helpdesk>/<EmailAddress>
|
||||
eapxml::get_element_localized(pXmlElHelpdesk, winstd::bstr(L"eap-metadata:EmailAddress"), lang.c_str(), m_help_email);
|
||||
m_module.log_config((xpathHelpdesk + L"/EmailAddress").c_str(), m_help_email.c_str());
|
||||
|
||||
// <Helpdesk>/<WebAddress>
|
||||
eapxml::get_element_localized(pXmlElHelpdesk, winstd::bstr(L"eap-metadata:WebAddress"), lang.c_str(), m_help_web);
|
||||
m_module.log_config((xpathHelpdesk + L"/WebAddress").c_str(), m_help_web.c_str());
|
||||
|
||||
// <Helpdesk>/<Phone>
|
||||
eapxml::get_element_localized(pXmlElHelpdesk, winstd::bstr(L"eap-metadata:Phone"), lang.c_str(), m_help_phone);
|
||||
m_module.log_config((xpathHelpdesk + L"/Phone").c_str(), m_help_phone.c_str());
|
||||
}
|
||||
|
||||
// <CredentialPrompt>
|
||||
eapxml::get_element_localized(pXmlElProviderInfo, winstd::bstr(L"eap-metadata:CredentialPrompt"), lang.c_str(), m_lbl_alt_credential);
|
||||
m_module.log_config((xpathProviderInfo + L"/CredentialPrompt").c_str(), m_lbl_alt_credential.c_str());
|
||||
|
||||
// <UserNameLabel>
|
||||
eapxml::get_element_localized(pXmlElProviderInfo, winstd::bstr(L"eap-metadata:UserNameLabel"), lang.c_str(), m_lbl_alt_identity);
|
||||
m_module.log_config((xpathProviderInfo + L"/UserNameLabel").c_str(), m_lbl_alt_identity.c_str());
|
||||
|
||||
// <PasswordLabel>
|
||||
eapxml::get_element_localized(pXmlElProviderInfo, winstd::bstr(L"eap-metadata:PasswordLabel"), lang.c_str(), m_lbl_alt_password);
|
||||
m_module.log_config((xpathProviderInfo + L"/PasswordLabel").c_str(), m_lbl_alt_password.c_str());
|
||||
}
|
||||
|
||||
// Iterate authentication methods (<AuthenticationMethods>).
|
||||
m_methods.clear();
|
||||
winstd::com_obj<IXMLDOMNodeList> pXmlListMethods;
|
||||
if ((dwResult = eapxml::select_nodes(pConfigRoot, winstd::bstr(L"eap-metadata:AuthenticationMethods/eap-metadata:AuthenticationMethod"), &pXmlListMethods)) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(ERROR_NOT_FOUND, _T(__FUNCTION__) _T(" Error selecting <AuthenticationMethods>/<AuthenticationMethod> elements."), _T("Please make sure profile XML is a valid ") _T(PRODUCT_NAME_STR) _T(" profile XML document."));
|
||||
return false;
|
||||
}
|
||||
long lCount = 0;
|
||||
pXmlListMethods->get_length(&lCount);
|
||||
for (long i = 0; i < lCount; i++) {
|
||||
winstd::com_obj<IXMLDOMNode> pXmlElMethod;
|
||||
pXmlListMethods->get_item(i, &pXmlElMethod);
|
||||
|
||||
std::unique_ptr<config_method> cfg(m_module.make_config_method());
|
||||
|
||||
// Check EAP method type (<EAPMethod>).
|
||||
DWORD dwMethodID;
|
||||
if (eapxml::get_element_value(pXmlElMethod, winstd::bstr(L"eap-metadata:EAPMethod"), &dwMethodID) == ERROR_SUCCESS) {
|
||||
if ((type_t)dwMethodID != cfg->get_method_id()) {
|
||||
// Wrong type.
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Load configuration.
|
||||
if (!cfg->load(pXmlElMethod, ppEapError))
|
||||
return false;
|
||||
|
||||
// Add configuration to the list.
|
||||
m_methods.push_back(std::move(cfg));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
virtual bool load(_In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **ppEapError);
|
||||
|
||||
/// @}
|
||||
|
||||
@ -693,76 +411,21 @@ namespace eap
|
||||
///
|
||||
/// \param[inout] cursor Memory cursor
|
||||
///
|
||||
virtual void pack(_Inout_ unsigned char *&cursor) const
|
||||
{
|
||||
eap::config::pack(cursor);
|
||||
eapserial::pack(cursor, m_read_only );
|
||||
eapserial::pack(cursor, m_id );
|
||||
eapserial::pack(cursor, m_name );
|
||||
eapserial::pack(cursor, m_help_email );
|
||||
eapserial::pack(cursor, m_help_web );
|
||||
eapserial::pack(cursor, m_help_phone );
|
||||
eapserial::pack(cursor, m_lbl_alt_credential);
|
||||
eapserial::pack(cursor, m_lbl_alt_identity );
|
||||
eapserial::pack(cursor, m_lbl_alt_password );
|
||||
eapserial::pack(cursor, m_methods );
|
||||
}
|
||||
|
||||
virtual void pack(_Inout_ unsigned char *&cursor) const;
|
||||
|
||||
///
|
||||
/// Returns packed size of a configuration
|
||||
///
|
||||
/// \returns Size of data when packed (in bytes)
|
||||
///
|
||||
virtual size_t get_pk_size() const
|
||||
{
|
||||
return
|
||||
eap::config::get_pk_size() +
|
||||
eapserial::get_pk_size(m_read_only ) +
|
||||
eapserial::get_pk_size(m_id ) +
|
||||
eapserial::get_pk_size(m_name ) +
|
||||
eapserial::get_pk_size(m_help_email ) +
|
||||
eapserial::get_pk_size(m_help_web ) +
|
||||
eapserial::get_pk_size(m_help_phone ) +
|
||||
eapserial::get_pk_size(m_lbl_alt_credential) +
|
||||
eapserial::get_pk_size(m_lbl_alt_identity ) +
|
||||
eapserial::get_pk_size(m_lbl_alt_password ) +
|
||||
eapserial::get_pk_size(m_methods );
|
||||
}
|
||||
|
||||
virtual size_t get_pk_size() const;
|
||||
|
||||
///
|
||||
/// Unpacks a configuration
|
||||
///
|
||||
/// \param[inout] cursor Memory cursor
|
||||
///
|
||||
virtual void unpack(_Inout_ const unsigned char *&cursor)
|
||||
{
|
||||
eap::config::unpack(cursor);
|
||||
eapserial::unpack(cursor, m_read_only );
|
||||
eapserial::unpack(cursor, m_id );
|
||||
eapserial::unpack(cursor, m_name );
|
||||
eapserial::unpack(cursor, m_help_email );
|
||||
eapserial::unpack(cursor, m_help_web );
|
||||
eapserial::unpack(cursor, m_help_phone );
|
||||
eapserial::unpack(cursor, m_lbl_alt_credential);
|
||||
eapserial::unpack(cursor, m_lbl_alt_identity );
|
||||
eapserial::unpack(cursor, m_lbl_alt_password );
|
||||
|
||||
std::list<config_method>::size_type count;
|
||||
bool is_nonnull;
|
||||
eapserial::unpack(cursor, count);
|
||||
m_methods.clear();
|
||||
for (std::list<config_method>::size_type i = 0; i < count; i++) {
|
||||
eapserial::unpack(cursor, is_nonnull);
|
||||
if (is_nonnull) {
|
||||
std::unique_ptr<config_method> el(m_module.make_config_method());
|
||||
el->unpack(cursor);
|
||||
m_methods.push_back(std::move(el));
|
||||
} else
|
||||
m_methods.push_back(nullptr);
|
||||
}
|
||||
}
|
||||
virtual void unpack(_Inout_ const unsigned char *&cursor);
|
||||
|
||||
/// @}
|
||||
|
||||
@ -780,7 +443,6 @@ namespace eap
|
||||
};
|
||||
|
||||
|
||||
template <class _Tprov>
|
||||
class config_providers : public config
|
||||
{
|
||||
public:
|
||||
@ -789,31 +451,21 @@ namespace eap
|
||||
///
|
||||
/// \param[in] mod Reference of the EAP module to use for global services
|
||||
///
|
||||
config_providers(_In_ module &mod) : config(mod)
|
||||
{
|
||||
}
|
||||
config_providers(_In_ module &mod);
|
||||
|
||||
///
|
||||
/// Copies configuration
|
||||
///
|
||||
/// \param[in] other Configuration to copy from
|
||||
///
|
||||
config_providers(_In_ const config_providers &other) :
|
||||
m_providers(other.m_providers),
|
||||
config(other)
|
||||
{
|
||||
}
|
||||
config_providers(_In_ const config_providers &other);
|
||||
|
||||
///
|
||||
/// Moves configuration
|
||||
///
|
||||
/// \param[in] other Configuration to move from
|
||||
///
|
||||
config_providers(_Inout_ config_providers &&other) :
|
||||
m_providers(std::move(other.m_providers)),
|
||||
config(std::move(other))
|
||||
{
|
||||
}
|
||||
config_providers(_Inout_ config_providers &&other);
|
||||
|
||||
///
|
||||
/// Copies configuration
|
||||
@ -822,15 +474,7 @@ namespace eap
|
||||
///
|
||||
/// \returns Reference to this object
|
||||
///
|
||||
config_providers& operator=(_In_ const config_providers &other)
|
||||
{
|
||||
if (this != &other) {
|
||||
(config&)*this = other;
|
||||
m_providers = other.m_providers;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
config_providers& operator=(_In_ const config_providers &other);
|
||||
|
||||
///
|
||||
/// Moves configuration
|
||||
@ -839,22 +483,14 @@ namespace eap
|
||||
///
|
||||
/// \returns Reference to this object
|
||||
///
|
||||
config_providers& operator=(_Inout_ config_providers &&other)
|
||||
{
|
||||
if (this != &other) {
|
||||
(config&&)*this = std::move(other);
|
||||
m_providers = std::move(other.m_providers);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
config_providers& operator=(_Inout_ config_providers &&other);
|
||||
|
||||
///
|
||||
/// Clones configuration
|
||||
///
|
||||
/// \returns Pointer to cloned configuration
|
||||
///
|
||||
virtual config* clone() const { return new config_providers<_Tprov>(*this); }
|
||||
virtual config* clone() const;
|
||||
|
||||
/// \name XML configuration management
|
||||
/// @{
|
||||
@ -870,43 +506,7 @@ namespace eap
|
||||
/// - \c true if succeeded
|
||||
/// - \c false otherwise. See \p ppEapError for details.
|
||||
///
|
||||
virtual bool save(_In_ IXMLDOMDocument *pDoc, _In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **ppEapError) const
|
||||
{
|
||||
if (!config::save(pDoc, pConfigRoot, ppEapError))
|
||||
return false;
|
||||
|
||||
const winstd::bstr bstrNamespace(L"urn:ietf:params:xml:ns:yang:ietf-eap-metadata");
|
||||
DWORD dwResult;
|
||||
HRESULT hr;
|
||||
|
||||
// Select <EAPIdentityProviderList> node.
|
||||
winstd::com_obj<IXMLDOMNode> pXmlElIdentityProviderList;
|
||||
if ((dwResult = eapxml::select_node(pConfigRoot, winstd::bstr(L"eap-metadata:EAPIdentityProviderList"), &pXmlElIdentityProviderList)) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(ERROR_NOT_FOUND, _T(__FUNCTION__) _T(" Error selecting <EAPIdentityProviderList> element."), _T("Please make sure profile XML is a valid ") _T(PRODUCT_NAME_STR) _T(" profile XML document."));
|
||||
return false;
|
||||
}
|
||||
|
||||
for (std::list<_Tprov>::const_iterator provider = m_providers.cbegin(), provider_end = m_providers.cend(); provider != provider_end; ++provider) {
|
||||
// <EAPIdentityProvider>
|
||||
winstd::com_obj<IXMLDOMElement> pXmlElIdentityProvider;
|
||||
if ((dwResult = eapxml::create_element(pDoc, winstd::bstr(L"EAPIdentityProvider"), bstrNamespace, &pXmlElIdentityProvider))) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <EAPIdentityProvider> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <EAPIdentityProvider>/...
|
||||
if (!provider->save(pDoc, pXmlElIdentityProvider, ppEapError))
|
||||
return false;
|
||||
|
||||
if (FAILED(hr = pXmlElIdentityProviderList->appendChild(pXmlElIdentityProvider, NULL))) {
|
||||
*ppEapError = m_module.make_error(HRESULT_CODE(hr), _T(__FUNCTION__) _T(" Error appending <EAPIdentityProvider> element."));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
virtual bool save(_In_ IXMLDOMDocument *pDoc, _In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **ppEapError) const;
|
||||
|
||||
///
|
||||
/// Load configuration from XML document
|
||||
@ -918,39 +518,7 @@ namespace eap
|
||||
/// - \c true if succeeded
|
||||
/// - \c false otherwise. See \p ppEapError for details.
|
||||
///
|
||||
virtual bool load(_In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **ppEapError)
|
||||
{
|
||||
assert(pConfigRoot);
|
||||
assert(ppEapError);
|
||||
DWORD dwResult;
|
||||
|
||||
if (!config::load(pConfigRoot, ppEapError))
|
||||
return false;
|
||||
|
||||
// Iterate authentication providers (<EAPIdentityProvider>).
|
||||
winstd::com_obj<IXMLDOMNodeList> pXmlListProviders;
|
||||
if ((dwResult = eapxml::select_nodes(pConfigRoot, winstd::bstr(L"eap-metadata:EAPIdentityProviderList/eap-metadata:EAPIdentityProvider"), &pXmlListProviders)) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(ERROR_NOT_FOUND, _T(__FUNCTION__) _T(" Error selecting <EAPIdentityProviderList><EAPIdentityProvider> elements."), _T("Please make sure profile XML is a valid ") _T(PRODUCT_NAME_STR) _T(" profile XML document."));
|
||||
return false;
|
||||
}
|
||||
long lCount = 0;
|
||||
pXmlListProviders->get_length(&lCount);
|
||||
for (long i = 0; i < lCount; i++) {
|
||||
winstd::com_obj<IXMLDOMNode> pXmlElProvider;
|
||||
pXmlListProviders->get_item(i, &pXmlElProvider);
|
||||
|
||||
_Tprov prov(m_module);
|
||||
|
||||
// Load provider.
|
||||
if (!prov.load(pXmlElProvider, ppEapError))
|
||||
return false;
|
||||
|
||||
// Add provider to the list.
|
||||
m_providers.push_back(std::move(prov));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
virtual bool load(_In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **ppEapError);
|
||||
|
||||
/// @}
|
||||
|
||||
@ -962,49 +530,26 @@ namespace eap
|
||||
///
|
||||
/// \param[inout] cursor Memory cursor
|
||||
///
|
||||
virtual void pack(_Inout_ unsigned char *&cursor) const
|
||||
{
|
||||
eap::config::pack(cursor);
|
||||
eapserial::pack(cursor, m_providers);
|
||||
}
|
||||
|
||||
virtual void pack(_Inout_ unsigned char *&cursor) const;
|
||||
|
||||
///
|
||||
/// Returns packed size of a configuration
|
||||
///
|
||||
/// \returns Size of data when packed (in bytes)
|
||||
///
|
||||
virtual size_t get_pk_size() const
|
||||
{
|
||||
return
|
||||
eap::config::get_pk_size() +
|
||||
eapserial::get_pk_size(m_providers);
|
||||
}
|
||||
|
||||
virtual size_t get_pk_size() const;
|
||||
|
||||
///
|
||||
/// Unpacks a configuration
|
||||
///
|
||||
/// \param[inout] cursor Memory cursor
|
||||
///
|
||||
virtual void unpack(_Inout_ const unsigned char *&cursor)
|
||||
{
|
||||
eap::config::unpack(cursor);
|
||||
|
||||
std::list<_Tprov>::size_type count = *(const std::list<_Tprov>::size_type*&)cursor;
|
||||
eapserial::unpack(cursor, count);
|
||||
m_providers.clear();
|
||||
for (std::list<_Tprov>::size_type i = 0; i < count; i++) {
|
||||
_Tprov el(m_module);
|
||||
el.unpack(cursor);
|
||||
m_providers.push_back(std::move(el));
|
||||
}
|
||||
}
|
||||
virtual void unpack(_Inout_ const unsigned char *&cursor);
|
||||
|
||||
/// @}
|
||||
|
||||
public:
|
||||
std::list<_Tprov> m_providers; ///< List of provider configurations
|
||||
std::list<eap::config_provider> m_providers; ///< List of provider configurations
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -668,16 +668,6 @@ namespace eap
|
||||
///
|
||||
typedef _Tmeth config_method_type;
|
||||
|
||||
///
|
||||
/// Provider configuration data type
|
||||
///
|
||||
typedef config_provider<config_method_type> config_provider_type;
|
||||
|
||||
///
|
||||
/// Configuration data type
|
||||
///
|
||||
typedef config_providers<config_provider_type> config_providers_type;
|
||||
|
||||
///
|
||||
/// Credentials data type
|
||||
///
|
||||
@ -750,13 +740,13 @@ namespace eap
|
||||
/// - \c false otherwise. See \p ppEapError for details.
|
||||
///
|
||||
virtual bool get_identity(
|
||||
_In_ DWORD dwFlags,
|
||||
_In_ const config_providers_type &cfg,
|
||||
_Inout_ credentials_type &cred,
|
||||
_In_ HANDLE hTokenImpersonateUser,
|
||||
_Out_ BOOL *pfInvokeUI,
|
||||
_Out_ WCHAR **ppwszIdentity,
|
||||
_Out_ EAP_ERROR **ppEapError) = 0;
|
||||
_In_ DWORD dwFlags,
|
||||
_In_ const config_providers &cfg,
|
||||
_Inout_ credentials_type &cred,
|
||||
_In_ HANDLE hTokenImpersonateUser,
|
||||
_Out_ BOOL *pfInvokeUI,
|
||||
_Out_ WCHAR **ppwszIdentity,
|
||||
_Out_ EAP_ERROR **ppEapError) = 0;
|
||||
|
||||
///
|
||||
/// Defines the implementation of an EAP method-specific function that retrieves the properties of an EAP method given the connection and user data.
|
||||
@ -771,7 +761,7 @@ namespace eap
|
||||
_In_ DWORD dwVersion,
|
||||
_In_ DWORD dwFlags,
|
||||
_In_ HANDLE hUserImpersonationToken,
|
||||
_In_ const config_providers_type &cfg,
|
||||
_In_ const config_providers &cfg,
|
||||
_In_ const credentials_type &cred,
|
||||
_Out_ EAP_METHOD_PROPERTY_ARRAY *pMethodPropertyArray,
|
||||
_Out_ EAP_ERROR **ppEapError) const = 0;
|
||||
|
@ -49,16 +49,6 @@ namespace eap
|
||||
///
|
||||
typedef _Tmeth config_method_type;
|
||||
|
||||
///
|
||||
/// Provider configuration data type
|
||||
///
|
||||
typedef config_provider<config_method_type> config_provider_type;
|
||||
|
||||
///
|
||||
/// Configuration data type
|
||||
///
|
||||
typedef config_providers<config_provider_type> config_providers_type;
|
||||
|
||||
///
|
||||
/// Credentials data type
|
||||
///
|
||||
@ -365,7 +355,7 @@ namespace eap
|
||||
|
||||
public:
|
||||
module &m_module; ///< Reference of the EAP module
|
||||
config_providers_type m_cfg; ///< Session configuration
|
||||
config_providers m_cfg; ///< Session configuration
|
||||
credentials_type m_cred; ///< User credentials
|
||||
interactive_request_type m_intreq; ///< Interactive UI request data
|
||||
};
|
||||
|
@ -120,10 +120,10 @@ eap::config_method::config_method(_In_ const config_method &other) :
|
||||
|
||||
|
||||
eap::config_method::config_method(_Inout_ config_method &&other) :
|
||||
m_allow_save(std::move(other.m_allow_save)),
|
||||
m_anonymous_identity(std::move(other.m_anonymous_identity)),
|
||||
m_preshared(std::move(other.m_preshared)),
|
||||
config(std::move(other))
|
||||
m_allow_save(move(other.m_allow_save)),
|
||||
m_anonymous_identity(move(other.m_anonymous_identity)),
|
||||
m_preshared(move(other.m_preshared)),
|
||||
config(move(other))
|
||||
{
|
||||
}
|
||||
|
||||
@ -144,10 +144,10 @@ eap::config_method& eap::config_method::operator=(_In_ const config_method &othe
|
||||
eap::config_method& eap::config_method::operator=(_Inout_ config_method &&other)
|
||||
{
|
||||
if (this != &other) {
|
||||
(config&&)*this = std::move(other);
|
||||
m_allow_save = std::move(other.m_allow_save);
|
||||
m_anonymous_identity = std::move(other.m_anonymous_identity);
|
||||
m_preshared = std::move(other.m_preshared);
|
||||
(config&&)*this = move(other);
|
||||
m_allow_save = move(other.m_allow_save);
|
||||
m_anonymous_identity = move(other.m_anonymous_identity);
|
||||
m_preshared = move(other.m_preshared);
|
||||
}
|
||||
|
||||
return *this;
|
||||
@ -163,25 +163,25 @@ bool eap::config_method::save(_In_ IXMLDOMDocument *pDoc, _In_ IXMLDOMNode *pCon
|
||||
if (!config::save(pDoc, pConfigRoot, ppEapError))
|
||||
return false;
|
||||
|
||||
const winstd::bstr bstrNamespace(L"urn:ietf:params:xml:ns:yang:ietf-eap-metadata");
|
||||
const bstr bstrNamespace(L"urn:ietf:params:xml:ns:yang:ietf-eap-metadata");
|
||||
DWORD dwResult;
|
||||
|
||||
// <ClientSideCredential>
|
||||
winstd::com_obj<IXMLDOMElement> pXmlElClientSideCredential;
|
||||
if ((dwResult = eapxml::create_element(pDoc, pConfigRoot, winstd::bstr(L"eap-metadata:ClientSideCredential"), winstd::bstr(L"ClientSideCredential"), bstrNamespace, &pXmlElClientSideCredential)) != ERROR_SUCCESS) {
|
||||
com_obj<IXMLDOMElement> pXmlElClientSideCredential;
|
||||
if ((dwResult = eapxml::create_element(pDoc, pConfigRoot, bstr(L"eap-metadata:ClientSideCredential"), bstr(L"ClientSideCredential"), bstrNamespace, &pXmlElClientSideCredential)) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <ClientSideCredential> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <ClientSideCredential>/<allow-save>
|
||||
if ((dwResult = eapxml::put_element_value(pDoc, pXmlElClientSideCredential, winstd::bstr(L"allow-save"), bstrNamespace, m_allow_save)) != ERROR_SUCCESS) {
|
||||
if ((dwResult = eapxml::put_element_value(pDoc, pXmlElClientSideCredential, bstr(L"allow-save"), bstrNamespace, m_allow_save)) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <allow-save> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <ClientSideCredential>/<AnonymousIdentity>
|
||||
if (!m_anonymous_identity.empty())
|
||||
if ((dwResult = eapxml::put_element_value(pDoc, pXmlElClientSideCredential, winstd::bstr(L"AnonymousIdentity"), bstrNamespace, winstd::bstr(m_anonymous_identity))) != ERROR_SUCCESS) {
|
||||
if ((dwResult = eapxml::put_element_value(pDoc, pXmlElClientSideCredential, bstr(L"AnonymousIdentity"), bstrNamespace, bstr(m_anonymous_identity))) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <AnonymousIdentity> element."));
|
||||
return false;
|
||||
}
|
||||
@ -207,22 +207,22 @@ bool eap::config_method::load(_In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **p
|
||||
m_anonymous_identity.clear();
|
||||
|
||||
// <ClientSideCredential>
|
||||
winstd::com_obj<IXMLDOMElement> pXmlElClientSideCredential;
|
||||
if (eapxml::select_element(pConfigRoot, winstd::bstr(L"eap-metadata:ClientSideCredential"), &pXmlElClientSideCredential) == ERROR_SUCCESS) {
|
||||
std::wstring xpath(eapxml::get_xpath(pXmlElClientSideCredential));
|
||||
com_obj<IXMLDOMElement> pXmlElClientSideCredential;
|
||||
if (eapxml::select_element(pConfigRoot, bstr(L"eap-metadata:ClientSideCredential"), &pXmlElClientSideCredential) == ERROR_SUCCESS) {
|
||||
wstring xpath(eapxml::get_xpath(pXmlElClientSideCredential));
|
||||
|
||||
// <allow-save>
|
||||
eapxml::get_element_value(pXmlElClientSideCredential, winstd::bstr(L"eap-metadata:allow-save"), &m_allow_save);
|
||||
eapxml::get_element_value(pXmlElClientSideCredential, bstr(L"eap-metadata:allow-save"), &m_allow_save);
|
||||
m_module.log_config((xpath + L"/allow-save").c_str(), m_allow_save);
|
||||
|
||||
// <AnonymousIdentity>
|
||||
eapxml::get_element_value(pXmlElClientSideCredential, winstd::bstr(L"eap-metadata:AnonymousIdentity"), m_anonymous_identity);
|
||||
eapxml::get_element_value(pXmlElClientSideCredential, bstr(L"eap-metadata:AnonymousIdentity"), m_anonymous_identity);
|
||||
m_module.log_config((xpath + L"/AnonymousIdentity").c_str(), m_anonymous_identity.c_str());
|
||||
|
||||
std::unique_ptr<credentials> preshared(make_credentials());
|
||||
unique_ptr<credentials> preshared(make_credentials());
|
||||
assert(preshared);
|
||||
if (preshared->load(pXmlElClientSideCredential, ppEapError)) {
|
||||
m_preshared = std::move(preshared);
|
||||
m_preshared = move(preshared);
|
||||
} else {
|
||||
// This is not really an error - merely an indication pre-shared credentials are unavailable.
|
||||
if (*ppEapError) {
|
||||
@ -238,7 +238,7 @@ bool eap::config_method::load(_In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **p
|
||||
|
||||
void eap::config_method::pack(_Inout_ unsigned char *&cursor) const
|
||||
{
|
||||
eap::config::pack(cursor);
|
||||
config::pack(cursor);
|
||||
eapserial::pack(cursor, m_allow_save );
|
||||
eapserial::pack(cursor, m_anonymous_identity);
|
||||
if (m_preshared) {
|
||||
@ -252,7 +252,7 @@ void eap::config_method::pack(_Inout_ unsigned char *&cursor) const
|
||||
size_t eap::config_method::get_pk_size() const
|
||||
{
|
||||
return
|
||||
eap::config::get_pk_size() +
|
||||
config::get_pk_size() +
|
||||
eapserial::get_pk_size(m_allow_save ) +
|
||||
eapserial::get_pk_size(m_anonymous_identity) +
|
||||
(m_preshared ?
|
||||
@ -264,7 +264,7 @@ size_t eap::config_method::get_pk_size() const
|
||||
|
||||
void eap::config_method::unpack(_Inout_ const unsigned char *&cursor)
|
||||
{
|
||||
eap::config::unpack(cursor);
|
||||
config::unpack(cursor);
|
||||
eapserial::unpack(cursor, m_allow_save );
|
||||
eapserial::unpack(cursor, m_anonymous_identity);
|
||||
|
||||
@ -277,3 +277,530 @@ void eap::config_method::unpack(_Inout_ const unsigned char *&cursor)
|
||||
} else
|
||||
m_preshared.reset(nullptr);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// eap::config_provider
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
eap::config_provider::config_provider(_In_ module &mod) :
|
||||
m_read_only(false),
|
||||
config(mod)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
eap::config_provider::config_provider(_In_ const config_provider &other) :
|
||||
m_read_only(other.m_read_only),
|
||||
m_id(other.m_id),
|
||||
m_name(other.m_name),
|
||||
m_help_email(other.m_help_email),
|
||||
m_help_web(other.m_help_web),
|
||||
m_help_phone(other.m_help_phone),
|
||||
m_lbl_alt_credential(other.m_lbl_alt_credential),
|
||||
m_lbl_alt_identity(other.m_lbl_alt_identity),
|
||||
m_lbl_alt_password(other.m_lbl_alt_password),
|
||||
config(other)
|
||||
{
|
||||
for (list<unique_ptr<config_method> >::const_iterator method = other.m_methods.cbegin(), method_end = other.m_methods.cend(); method != method_end; ++method)
|
||||
m_methods.push_back(move(unique_ptr<config_method>(*method ? (config_method*)method->get()->clone() : nullptr)));
|
||||
}
|
||||
|
||||
|
||||
eap::config_provider::config_provider(_Inout_ config_provider &&other) :
|
||||
m_read_only(move(other.m_read_only)),
|
||||
m_id(move(other.m_id)),
|
||||
m_name(move(other.m_name)),
|
||||
m_help_email(move(other.m_help_email)),
|
||||
m_help_web(move(other.m_help_web)),
|
||||
m_help_phone(move(other.m_help_phone)),
|
||||
m_lbl_alt_credential(move(other.m_lbl_alt_credential)),
|
||||
m_lbl_alt_identity(move(other.m_lbl_alt_identity)),
|
||||
m_lbl_alt_password(move(other.m_lbl_alt_password)),
|
||||
m_methods(move(other.m_methods)),
|
||||
config(move(other))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
eap::config_provider& eap::config_provider::operator=(_In_ const config_provider &other)
|
||||
{
|
||||
if (this != &other) {
|
||||
(config&)*this = other;
|
||||
m_read_only = other.m_read_only;
|
||||
m_id = other.m_id;
|
||||
m_name = other.m_name;
|
||||
m_help_email = other.m_help_email;
|
||||
m_help_web = other.m_help_web;
|
||||
m_help_phone = other.m_help_phone;
|
||||
m_lbl_alt_credential = other.m_lbl_alt_credential;
|
||||
m_lbl_alt_identity = other.m_lbl_alt_identity;
|
||||
m_lbl_alt_password = other.m_lbl_alt_password;
|
||||
|
||||
m_methods.clear();
|
||||
for (list<unique_ptr<config_method> >::const_iterator method = other.m_methods.cbegin(), method_end = other.m_methods.cend(); method != method_end; ++method)
|
||||
m_methods.push_back(move(unique_ptr<config_method>(*method ? (config_method*)method->get()->clone() : nullptr)));
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
eap::config_provider& eap::config_provider::operator=(_Inout_ config_provider &&other)
|
||||
{
|
||||
if (this != &other) {
|
||||
(config&&)*this = move(other);
|
||||
m_read_only = move(m_read_only);
|
||||
m_id = move(other.m_id);
|
||||
m_name = move(other.m_name);
|
||||
m_help_email = move(other.m_help_email);
|
||||
m_help_web = move(other.m_help_web);
|
||||
m_help_phone = move(other.m_help_phone);
|
||||
m_lbl_alt_credential = move(other.m_lbl_alt_credential);
|
||||
m_lbl_alt_identity = move(other.m_lbl_alt_identity);
|
||||
m_lbl_alt_password = move(other.m_lbl_alt_password);
|
||||
m_methods = move(other.m_methods);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
eap::config* eap::config_provider::clone() const
|
||||
{
|
||||
return new config_provider(*this);
|
||||
}
|
||||
|
||||
|
||||
bool eap::config_provider::save(_In_ IXMLDOMDocument *pDoc, _In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **ppEapError) const
|
||||
{
|
||||
if (!config::save(pDoc, pConfigRoot, ppEapError))
|
||||
return false;
|
||||
|
||||
const bstr bstrNamespace(L"urn:ietf:params:xml:ns:yang:ietf-eap-metadata");
|
||||
DWORD dwResult;
|
||||
HRESULT hr;
|
||||
|
||||
// <read-only>
|
||||
if ((dwResult = eapxml::put_element_value(pDoc, pConfigRoot, bstr(L"read-only"), bstrNamespace, m_read_only)) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <read-only> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <ID>
|
||||
if (!m_id.empty())
|
||||
if ((dwResult = eapxml::put_element_value(pDoc, pConfigRoot, bstr(L"ID"), bstrNamespace, bstr(m_id))) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <ID> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <ProviderInfo>
|
||||
com_obj<IXMLDOMElement> pXmlElProviderInfo;
|
||||
if ((dwResult = eapxml::create_element(pDoc, pConfigRoot, bstr(L"eap-metadata:ProviderInfo"), bstr(L"ProviderInfo"), bstrNamespace, &pXmlElProviderInfo)) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <ProviderInfo> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <ProviderInfo>/<DisplayName>
|
||||
if (!m_name.empty())
|
||||
if ((dwResult = eapxml::put_element_value(pDoc, pXmlElProviderInfo, bstr(L"DisplayName"), bstrNamespace, bstr(m_name))) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <DisplayName> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <ProviderInfo>/<Helpdesk>
|
||||
com_obj<IXMLDOMElement> pXmlElHelpdesk;
|
||||
if ((dwResult = eapxml::create_element(pDoc, pXmlElProviderInfo, bstr(L"eap-metadata:Helpdesk"), bstr(L"Helpdesk"), bstrNamespace, &pXmlElHelpdesk)) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <Helpdesk> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <ProviderInfo>/<Helpdesk>/<EmailAddress>
|
||||
if (!m_help_email.empty())
|
||||
if ((dwResult = eapxml::put_element_value(pDoc, pXmlElHelpdesk, bstr(L"EmailAddress"), bstrNamespace, bstr(m_help_email))) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <EmailAddress> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <ProviderInfo>/<Helpdesk>/<WebAddress>
|
||||
if (!m_help_web.empty())
|
||||
if ((dwResult = eapxml::put_element_value(pDoc, pXmlElHelpdesk, bstr(L"WebAddress"), bstrNamespace, bstr(m_help_web))) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <WebAddress> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <ProviderInfo>/<Helpdesk>/<Phone>
|
||||
if (!m_help_phone.empty())
|
||||
if ((dwResult = eapxml::put_element_value(pDoc, pXmlElHelpdesk, bstr(L"Phone"), bstrNamespace, bstr(m_help_phone))) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <Phone> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <ProviderInfo>/<CredentialPrompt>
|
||||
if (!m_lbl_alt_credential.empty())
|
||||
if ((dwResult = eapxml::put_element_value(pDoc, pXmlElProviderInfo, bstr(L"CredentialPrompt"), bstrNamespace, bstr(m_lbl_alt_credential))) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <CredentialPrompt> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <ProviderInfo>/<UserNameLabel>
|
||||
if (!m_lbl_alt_identity.empty())
|
||||
if ((dwResult = eapxml::put_element_value(pDoc, pXmlElProviderInfo, bstr(L"UserNameLabel"), bstrNamespace, bstr(m_lbl_alt_identity))) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <UserNameLabel> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <ProviderInfo>/<PasswordLabel>
|
||||
if (!m_lbl_alt_password.empty())
|
||||
if ((dwResult = eapxml::put_element_value(pDoc, pXmlElProviderInfo, bstr(L"PasswordLabel"), bstrNamespace, bstr(m_lbl_alt_password))) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <PasswordLabel> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <AuthenticationMethods>
|
||||
com_obj<IXMLDOMElement> pXmlElAuthenticationMethods;
|
||||
if ((dwResult = eapxml::create_element(pDoc, pConfigRoot, bstr(L"eap-metadata:AuthenticationMethods"), bstr(L"AuthenticationMethods"), bstrNamespace, &pXmlElAuthenticationMethods)) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <AuthenticationMethods> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
for (list<unique_ptr<config_method> >::const_iterator method = m_methods.cbegin(), method_end = m_methods.cend(); method != method_end; ++method) {
|
||||
// <AuthenticationMethod>
|
||||
com_obj<IXMLDOMElement> pXmlElAuthenticationMethod;
|
||||
if ((dwResult = eapxml::create_element(pDoc, bstr(L"AuthenticationMethod"), bstrNamespace, &pXmlElAuthenticationMethod))) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <AuthenticationMethod> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <AuthenticationMethod>/...
|
||||
if (!method->get()->save(pDoc, pXmlElAuthenticationMethod, ppEapError))
|
||||
return false;
|
||||
|
||||
if (FAILED(hr = pXmlElAuthenticationMethods->appendChild(pXmlElAuthenticationMethod, NULL))) {
|
||||
*ppEapError = m_module.make_error(HRESULT_CODE(hr), _T(__FUNCTION__) _T(" Error appending <AuthenticationMethod> element."));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool eap::config_provider::load(_In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **ppEapError)
|
||||
{
|
||||
assert(pConfigRoot);
|
||||
assert(ppEapError);
|
||||
DWORD dwResult;
|
||||
wstring xpath(eapxml::get_xpath(pConfigRoot));
|
||||
|
||||
if (!config::load(pConfigRoot, ppEapError))
|
||||
return false;
|
||||
|
||||
// <read-only>
|
||||
if ((dwResult = eapxml::get_element_value(pConfigRoot, bstr(L"eap-metadata:read-only"), &m_read_only)) != ERROR_SUCCESS)
|
||||
m_read_only = true;
|
||||
m_module.log_config((xpath + L"/read-only").c_str(), m_read_only);
|
||||
|
||||
// <ID>
|
||||
m_id.clear();
|
||||
eapxml::get_element_value(pConfigRoot, bstr(L"eap-metadata:ID"), m_id);
|
||||
m_module.log_config((xpath + L"/ID").c_str(), m_id.c_str());
|
||||
|
||||
// <ProviderInfo>
|
||||
m_name.clear();
|
||||
m_help_email.clear();
|
||||
m_help_web.clear();
|
||||
m_help_phone.clear();
|
||||
m_lbl_alt_credential.clear();
|
||||
m_lbl_alt_identity.clear();
|
||||
m_lbl_alt_password.clear();
|
||||
com_obj<IXMLDOMElement> pXmlElProviderInfo;
|
||||
if (eapxml::select_element(pConfigRoot, bstr(L"eap-metadata:ProviderInfo"), &pXmlElProviderInfo) == ERROR_SUCCESS) {
|
||||
wstring lang;
|
||||
LoadString(m_module.m_instance, 2, lang);
|
||||
wstring xpathProviderInfo(xpath + L"/ProviderInfo");
|
||||
|
||||
// <DisplayName>
|
||||
eapxml::get_element_localized(pXmlElProviderInfo, bstr(L"eap-metadata:DisplayName"), lang.c_str(), m_name);
|
||||
m_module.log_config((xpathProviderInfo + L"/DisplayName").c_str(), m_name.c_str());
|
||||
|
||||
com_obj<IXMLDOMElement> pXmlElHelpdesk;
|
||||
if (eapxml::select_element(pXmlElProviderInfo, bstr(L"eap-metadata:Helpdesk"), &pXmlElHelpdesk) == ERROR_SUCCESS) {
|
||||
wstring xpathHelpdesk(xpathProviderInfo + L"/Helpdesk");
|
||||
|
||||
// <Helpdesk>/<EmailAddress>
|
||||
eapxml::get_element_localized(pXmlElHelpdesk, bstr(L"eap-metadata:EmailAddress"), lang.c_str(), m_help_email);
|
||||
m_module.log_config((xpathHelpdesk + L"/EmailAddress").c_str(), m_help_email.c_str());
|
||||
|
||||
// <Helpdesk>/<WebAddress>
|
||||
eapxml::get_element_localized(pXmlElHelpdesk, bstr(L"eap-metadata:WebAddress"), lang.c_str(), m_help_web);
|
||||
m_module.log_config((xpathHelpdesk + L"/WebAddress").c_str(), m_help_web.c_str());
|
||||
|
||||
// <Helpdesk>/<Phone>
|
||||
eapxml::get_element_localized(pXmlElHelpdesk, bstr(L"eap-metadata:Phone"), lang.c_str(), m_help_phone);
|
||||
m_module.log_config((xpathHelpdesk + L"/Phone").c_str(), m_help_phone.c_str());
|
||||
}
|
||||
|
||||
// <CredentialPrompt>
|
||||
eapxml::get_element_localized(pXmlElProviderInfo, bstr(L"eap-metadata:CredentialPrompt"), lang.c_str(), m_lbl_alt_credential);
|
||||
m_module.log_config((xpathProviderInfo + L"/CredentialPrompt").c_str(), m_lbl_alt_credential.c_str());
|
||||
|
||||
// <UserNameLabel>
|
||||
eapxml::get_element_localized(pXmlElProviderInfo, bstr(L"eap-metadata:UserNameLabel"), lang.c_str(), m_lbl_alt_identity);
|
||||
m_module.log_config((xpathProviderInfo + L"/UserNameLabel").c_str(), m_lbl_alt_identity.c_str());
|
||||
|
||||
// <PasswordLabel>
|
||||
eapxml::get_element_localized(pXmlElProviderInfo, bstr(L"eap-metadata:PasswordLabel"), lang.c_str(), m_lbl_alt_password);
|
||||
m_module.log_config((xpathProviderInfo + L"/PasswordLabel").c_str(), m_lbl_alt_password.c_str());
|
||||
}
|
||||
|
||||
// Iterate authentication methods (<AuthenticationMethods>).
|
||||
m_methods.clear();
|
||||
com_obj<IXMLDOMNodeList> pXmlListMethods;
|
||||
if ((dwResult = eapxml::select_nodes(pConfigRoot, bstr(L"eap-metadata:AuthenticationMethods/eap-metadata:AuthenticationMethod"), &pXmlListMethods)) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(ERROR_NOT_FOUND, _T(__FUNCTION__) _T(" Error selecting <AuthenticationMethods>/<AuthenticationMethod> elements."), _T("Please make sure profile XML is a valid ") _T(PRODUCT_NAME_STR) _T(" profile XML document."));
|
||||
return false;
|
||||
}
|
||||
long lCount = 0;
|
||||
pXmlListMethods->get_length(&lCount);
|
||||
for (long i = 0; i < lCount; i++) {
|
||||
com_obj<IXMLDOMNode> pXmlElMethod;
|
||||
pXmlListMethods->get_item(i, &pXmlElMethod);
|
||||
|
||||
unique_ptr<config_method> cfg(m_module.make_config_method());
|
||||
|
||||
// Check EAP method type (<EAPMethod>).
|
||||
DWORD dwMethodID;
|
||||
if (eapxml::get_element_value(pXmlElMethod, bstr(L"eap-metadata:EAPMethod"), &dwMethodID) == ERROR_SUCCESS) {
|
||||
if ((type_t)dwMethodID != cfg->get_method_id()) {
|
||||
// Wrong type.
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Load configuration.
|
||||
if (!cfg->load(pXmlElMethod, ppEapError))
|
||||
return false;
|
||||
|
||||
// Add configuration to the list.
|
||||
m_methods.push_back(move(cfg));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void eap::config_provider::pack(_Inout_ unsigned char *&cursor) const
|
||||
{
|
||||
config::pack(cursor);
|
||||
eapserial::pack(cursor, m_read_only );
|
||||
eapserial::pack(cursor, m_id );
|
||||
eapserial::pack(cursor, m_name );
|
||||
eapserial::pack(cursor, m_help_email );
|
||||
eapserial::pack(cursor, m_help_web );
|
||||
eapserial::pack(cursor, m_help_phone );
|
||||
eapserial::pack(cursor, m_lbl_alt_credential);
|
||||
eapserial::pack(cursor, m_lbl_alt_identity );
|
||||
eapserial::pack(cursor, m_lbl_alt_password );
|
||||
eapserial::pack(cursor, m_methods );
|
||||
}
|
||||
|
||||
|
||||
size_t eap::config_provider::get_pk_size() const
|
||||
{
|
||||
return
|
||||
config::get_pk_size() +
|
||||
eapserial::get_pk_size(m_read_only ) +
|
||||
eapserial::get_pk_size(m_id ) +
|
||||
eapserial::get_pk_size(m_name ) +
|
||||
eapserial::get_pk_size(m_help_email ) +
|
||||
eapserial::get_pk_size(m_help_web ) +
|
||||
eapserial::get_pk_size(m_help_phone ) +
|
||||
eapserial::get_pk_size(m_lbl_alt_credential) +
|
||||
eapserial::get_pk_size(m_lbl_alt_identity ) +
|
||||
eapserial::get_pk_size(m_lbl_alt_password ) +
|
||||
eapserial::get_pk_size(m_methods );
|
||||
}
|
||||
|
||||
|
||||
void eap::config_provider::unpack(_Inout_ const unsigned char *&cursor)
|
||||
{
|
||||
config::unpack(cursor);
|
||||
eapserial::unpack(cursor, m_read_only );
|
||||
eapserial::unpack(cursor, m_id );
|
||||
eapserial::unpack(cursor, m_name );
|
||||
eapserial::unpack(cursor, m_help_email );
|
||||
eapserial::unpack(cursor, m_help_web );
|
||||
eapserial::unpack(cursor, m_help_phone );
|
||||
eapserial::unpack(cursor, m_lbl_alt_credential);
|
||||
eapserial::unpack(cursor, m_lbl_alt_identity );
|
||||
eapserial::unpack(cursor, m_lbl_alt_password );
|
||||
|
||||
list<config_method>::size_type count;
|
||||
bool is_nonnull;
|
||||
eapserial::unpack(cursor, count);
|
||||
m_methods.clear();
|
||||
for (list<config_method>::size_type i = 0; i < count; i++) {
|
||||
eapserial::unpack(cursor, is_nonnull);
|
||||
if (is_nonnull) {
|
||||
unique_ptr<config_method> el(m_module.make_config_method());
|
||||
el->unpack(cursor);
|
||||
m_methods.push_back(move(el));
|
||||
} else
|
||||
m_methods.push_back(nullptr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// eap::config_providers
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
eap::config_providers::config_providers(_In_ module &mod) : config(mod)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
eap::config_providers::config_providers(_In_ const config_providers &other) :
|
||||
m_providers(other.m_providers),
|
||||
config(other)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
eap::config_providers::config_providers(_Inout_ config_providers &&other) :
|
||||
m_providers(move(other.m_providers)),
|
||||
config(move(other))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
eap::config_providers& eap::config_providers::operator=(_In_ const config_providers &other)
|
||||
{
|
||||
if (this != &other) {
|
||||
(config&)*this = other;
|
||||
m_providers = other.m_providers;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
eap::config_providers& eap::config_providers::operator=(_Inout_ config_providers &&other)
|
||||
{
|
||||
if (this != &other) {
|
||||
(config&&)*this = move(other);
|
||||
m_providers = move(other.m_providers);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
eap::config* eap::config_providers::clone() const
|
||||
{
|
||||
return new config_providers(*this);
|
||||
}
|
||||
|
||||
|
||||
bool eap::config_providers::save(_In_ IXMLDOMDocument *pDoc, _In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **ppEapError) const
|
||||
{
|
||||
if (!config::save(pDoc, pConfigRoot, ppEapError))
|
||||
return false;
|
||||
|
||||
const bstr bstrNamespace(L"urn:ietf:params:xml:ns:yang:ietf-eap-metadata");
|
||||
DWORD dwResult;
|
||||
HRESULT hr;
|
||||
|
||||
// Select <EAPIdentityProviderList> node.
|
||||
com_obj<IXMLDOMNode> pXmlElIdentityProviderList;
|
||||
if ((dwResult = eapxml::select_node(pConfigRoot, bstr(L"eap-metadata:EAPIdentityProviderList"), &pXmlElIdentityProviderList)) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(ERROR_NOT_FOUND, _T(__FUNCTION__) _T(" Error selecting <EAPIdentityProviderList> element."), _T("Please make sure profile XML is a valid ") _T(PRODUCT_NAME_STR) _T(" profile XML document."));
|
||||
return false;
|
||||
}
|
||||
|
||||
for (list<config_provider>::const_iterator provider = m_providers.cbegin(), provider_end = m_providers.cend(); provider != provider_end; ++provider) {
|
||||
// <EAPIdentityProvider>
|
||||
com_obj<IXMLDOMElement> pXmlElIdentityProvider;
|
||||
if ((dwResult = eapxml::create_element(pDoc, bstr(L"EAPIdentityProvider"), bstrNamespace, &pXmlElIdentityProvider))) {
|
||||
*ppEapError = m_module.make_error(dwResult, _T(__FUNCTION__) _T(" Error creating <EAPIdentityProvider> element."));
|
||||
return false;
|
||||
}
|
||||
|
||||
// <EAPIdentityProvider>/...
|
||||
if (!provider->save(pDoc, pXmlElIdentityProvider, ppEapError))
|
||||
return false;
|
||||
|
||||
if (FAILED(hr = pXmlElIdentityProviderList->appendChild(pXmlElIdentityProvider, NULL))) {
|
||||
*ppEapError = m_module.make_error(HRESULT_CODE(hr), _T(__FUNCTION__) _T(" Error appending <EAPIdentityProvider> element."));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool eap::config_providers::load(_In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **ppEapError)
|
||||
{
|
||||
assert(pConfigRoot);
|
||||
assert(ppEapError);
|
||||
DWORD dwResult;
|
||||
|
||||
if (!config::load(pConfigRoot, ppEapError))
|
||||
return false;
|
||||
|
||||
// Iterate authentication providers (<EAPIdentityProvider>).
|
||||
com_obj<IXMLDOMNodeList> pXmlListProviders;
|
||||
if ((dwResult = eapxml::select_nodes(pConfigRoot, bstr(L"eap-metadata:EAPIdentityProviderList/eap-metadata:EAPIdentityProvider"), &pXmlListProviders)) != ERROR_SUCCESS) {
|
||||
*ppEapError = m_module.make_error(ERROR_NOT_FOUND, _T(__FUNCTION__) _T(" Error selecting <EAPIdentityProviderList><EAPIdentityProvider> elements."), _T("Please make sure profile XML is a valid ") _T(PRODUCT_NAME_STR) _T(" profile XML document."));
|
||||
return false;
|
||||
}
|
||||
long lCount = 0;
|
||||
pXmlListProviders->get_length(&lCount);
|
||||
for (long i = 0; i < lCount; i++) {
|
||||
com_obj<IXMLDOMNode> pXmlElProvider;
|
||||
pXmlListProviders->get_item(i, &pXmlElProvider);
|
||||
|
||||
config_provider prov(m_module);
|
||||
|
||||
// Load provider.
|
||||
if (!prov.load(pXmlElProvider, ppEapError))
|
||||
return false;
|
||||
|
||||
// Add provider to the list.
|
||||
m_providers.push_back(move(prov));
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void eap::config_providers::pack(_Inout_ unsigned char *&cursor) const
|
||||
{
|
||||
config::pack(cursor);
|
||||
eapserial::pack(cursor, m_providers);
|
||||
}
|
||||
|
||||
|
||||
size_t eap::config_providers::get_pk_size() const
|
||||
{
|
||||
return
|
||||
config::get_pk_size() +
|
||||
eapserial::get_pk_size(m_providers);
|
||||
}
|
||||
|
||||
|
||||
void eap::config_providers::unpack(_Inout_ const unsigned char *&cursor)
|
||||
{
|
||||
config::unpack(cursor);
|
||||
|
||||
list<config_provider>::size_type count;
|
||||
eapserial::unpack(cursor, count);
|
||||
m_providers.clear();
|
||||
for (list<config_provider>::size_type i = 0; i < count; i++) {
|
||||
config_provider el(m_module);
|
||||
el.unpack(cursor);
|
||||
m_providers.push_back(move(el));
|
||||
}
|
||||
}
|
||||
|
@ -24,6 +24,11 @@
|
||||
#include <Windows.h>
|
||||
|
||||
|
||||
///
|
||||
/// Reusable EAP dialog banner for `wxEAPConfigDialog` and `wxEAPCredentialsDialog`
|
||||
///
|
||||
class wxEAPBannerPanel;
|
||||
|
||||
///
|
||||
/// EAP top-most configuration dialog
|
||||
///
|
||||
@ -32,22 +37,17 @@ template <class _Tmeth, class _wxT> class wxEAPConfigDialog;
|
||||
///
|
||||
/// EAP top-most credential dialog
|
||||
///
|
||||
template <class _Tprov> class wxEAPCredentialsDialog;
|
||||
|
||||
///
|
||||
/// Reusable EAP dialog banner for `wxEAPConfigDialog` and `wxEAPCredentialsDialog`
|
||||
///
|
||||
class wxEAPBannerPanel;
|
||||
class wxEAPCredentialsDialog;
|
||||
|
||||
///
|
||||
/// EAP Provider-locked congifuration note
|
||||
///
|
||||
template <class _Tprov> class wxEAPProviderLockedPanel;
|
||||
class wxEAPProviderLockedPanel;
|
||||
|
||||
///
|
||||
/// Base template for credential configuration panel
|
||||
///
|
||||
template <class _Tprov, class _Tmeth, class _wxT> class wxEAPCredentialsConfigPanel;
|
||||
template <class _Tmeth, class _wxT> class wxEAPCredentialsConfigPanel;
|
||||
|
||||
///
|
||||
/// Base template for all credential entry panels
|
||||
@ -57,7 +57,7 @@ template <class _Tbase> class wxEAPCredentialsPanelBase;
|
||||
///
|
||||
/// Generic password credential entry panel
|
||||
///
|
||||
template <class _Tprov> class wxPasswordCredentialsPanel;
|
||||
class wxPasswordCredentialsPanel;
|
||||
|
||||
///
|
||||
/// Sets icon from resource
|
||||
@ -84,20 +84,25 @@ inline bool wxSetIconFromResource(wxStaticBitmap *bmp, wxIcon &icon, HINSTANCE h
|
||||
#include <memory>
|
||||
|
||||
|
||||
class wxEAPBannerPanel : public wxEAPBannerPanelBase
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Constructs a banner pannel and set the title text to product name
|
||||
///
|
||||
wxEAPBannerPanel(wxWindow* parent);
|
||||
|
||||
protected:
|
||||
/// \cond internal
|
||||
virtual bool AcceptsFocusFromKeyboard() const;
|
||||
/// \endcond
|
||||
};
|
||||
|
||||
|
||||
template <class _Tmeth, class _wxT>
|
||||
class wxEAPConfigDialog : public wxEAPConfigDialogBase
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Configuration provider data type
|
||||
///
|
||||
typedef eap::config_provider<_Tmeth> _Tprov;
|
||||
|
||||
///
|
||||
/// Configuration data type
|
||||
///
|
||||
typedef eap::config_providers<_Tprov> config_providers_type;
|
||||
|
||||
///
|
||||
/// This data type
|
||||
///
|
||||
@ -107,14 +112,14 @@ public:
|
||||
///
|
||||
/// Constructs a configuration dialog
|
||||
///
|
||||
wxEAPConfigDialog(config_providers_type &cfg, wxWindow* parent) :
|
||||
wxEAPConfigDialog(eap::config_providers &cfg, wxWindow* parent) :
|
||||
m_cfg(cfg),
|
||||
wxEAPConfigDialogBase(parent)
|
||||
{
|
||||
// Set extra style here, as wxFormBuilder overrides all default flags.
|
||||
this->SetExtraStyle(this->GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY);
|
||||
|
||||
for (std::list<_Tprov>::iterator provider = m_cfg.m_providers.begin(), provider_end = m_cfg.m_providers.end(); provider != provider_end; ++provider) {
|
||||
for (std::list<eap::config_provider>::iterator provider = m_cfg.m_providers.begin(), provider_end = m_cfg.m_providers.end(); provider != provider_end; ++provider) {
|
||||
bool is_single = provider->m_methods.size() == 1;
|
||||
std::list<std::unique_ptr<eap::config_method> >::size_type count = 0;
|
||||
std::list<std::unique_ptr<eap::config_method> >::iterator method = provider->m_methods.begin(), method_end = provider->m_methods.end();
|
||||
@ -150,154 +155,42 @@ protected:
|
||||
|
||||
|
||||
protected:
|
||||
config_providers_type &m_cfg; ///< EAP providers configuration
|
||||
eap::config_providers &m_cfg; ///< EAP providers configuration
|
||||
};
|
||||
|
||||
|
||||
template <class _Tprov>
|
||||
class wxEAPCredentialsDialog : public wxEAPCredentialsDialogBase
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Constructs a credential dialog
|
||||
///
|
||||
wxEAPCredentialsDialog(_Tprov &prov, wxWindow* parent) : wxEAPCredentialsDialogBase(parent)
|
||||
{
|
||||
// Set extra style here, as wxFormBuilder overrides all default flags.
|
||||
this->SetExtraStyle(this->GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY);
|
||||
|
||||
// Set banner title.
|
||||
m_banner->m_title->SetLabel(wxString::Format(_("%s Credentials"), prov.m_id.c_str()));
|
||||
|
||||
m_buttonsOK->SetDefault();
|
||||
}
|
||||
|
||||
wxEAPCredentialsDialog(const eap::config_provider &prov, wxWindow* parent);
|
||||
|
||||
///
|
||||
/// Adds panels to the dialog
|
||||
///
|
||||
void AddContents(wxPanel **contents, size_t content_count)
|
||||
{
|
||||
if (content_count) {
|
||||
for (size_t i = 0; i < content_count; i++)
|
||||
m_panels->Add(contents[i], 0, wxALL|wxEXPAND, 5);
|
||||
|
||||
this->Layout();
|
||||
this->GetSizer()->Fit(this);
|
||||
contents[0]->SetFocusFromKbd();
|
||||
}
|
||||
}
|
||||
|
||||
void AddContents(wxPanel **contents, size_t content_count);
|
||||
|
||||
protected:
|
||||
/// \cond internal
|
||||
|
||||
virtual void OnInitDialog(wxInitDialogEvent& event)
|
||||
{
|
||||
for (wxSizerItemList::compatibility_iterator panel = m_panels->GetChildren().GetFirst(); panel; panel = panel->GetNext())
|
||||
panel->GetData()->GetWindow()->GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
|
||||
virtual void OnInitDialog(wxInitDialogEvent& event);
|
||||
/// \endcond
|
||||
};
|
||||
|
||||
|
||||
class wxEAPBannerPanel : public wxEAPBannerPanelBase
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Constructs a banner pannel and set the title text to product name
|
||||
///
|
||||
wxEAPBannerPanel(wxWindow* parent);
|
||||
|
||||
protected:
|
||||
/// \cond internal
|
||||
virtual bool AcceptsFocusFromKeyboard() const { return false; }
|
||||
/// \endcond
|
||||
};
|
||||
|
||||
|
||||
template <class _Tprov>
|
||||
class wxEAPProviderLockedPanel : public wxEAPProviderLockedPanelBase
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Constructs a notice pannel and set the title text
|
||||
///
|
||||
wxEAPProviderLockedPanel(_Tprov &prov, wxWindow* parent) :
|
||||
m_prov(prov),
|
||||
wxEAPProviderLockedPanelBase(parent)
|
||||
{
|
||||
// Load and set icon.
|
||||
if (m_shell32.load(_T("shell32.dll"), NULL, LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE))
|
||||
wxSetIconFromResource(m_provider_locked_icon, m_icon, m_shell32, MAKEINTRESOURCE(48));
|
||||
|
||||
m_provider_locked_label->SetLabel(wxString::Format(_("%s has pre-set parts of this configuration. Those parts are locked to prevent accidental modification."),
|
||||
!m_prov.m_name.empty() ? m_prov.m_name.c_str() :
|
||||
!m_prov.m_id .empty() ? winstd::string_printf(_("Your %ls provider"), m_prov.m_id.c_str()).c_str() : _("Your provider")));
|
||||
m_provider_locked_label->Wrap(452);
|
||||
|
||||
if (!m_prov.m_help_email.empty() || !m_prov.m_help_web.empty() || !m_prov.m_help_phone.empty()) {
|
||||
wxStaticText *provider_notice = new wxStaticText(this, wxID_ANY, wxString::Format(_("For additional help and instructions, please contact %s at:"),
|
||||
!m_prov.m_name.empty() ? m_prov.m_name.c_str() :
|
||||
!m_prov.m_id .empty() ? winstd::string_printf(_("your %ls provider"), m_prov.m_id.c_str()).c_str() : _("your provider")), wxDefaultPosition, wxDefaultSize, 0);
|
||||
provider_notice->Wrap(452);
|
||||
m_provider_locked_vert->Add(provider_notice, 0, wxUP|wxLEFT|wxRIGHT|wxEXPAND, 5);
|
||||
|
||||
wxFlexGridSizer* sb_contact_tbl;
|
||||
sb_contact_tbl = new wxFlexGridSizer(0, 2, 5, 5);
|
||||
sb_contact_tbl->AddGrowableCol(1);
|
||||
sb_contact_tbl->SetFlexibleDirection(wxBOTH);
|
||||
sb_contact_tbl->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED);
|
||||
|
||||
wxFont font_wingdings(-1, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxT("Wingdings"));
|
||||
|
||||
if (!m_prov.m_help_web.empty()) {
|
||||
wxStaticText *label = new wxStaticText(this, wxID_ANY, wxT("\xb6"), wxDefaultPosition, wxDefaultSize, 0);
|
||||
label->Wrap(-1);
|
||||
label->SetFont(font_wingdings);
|
||||
sb_contact_tbl->Add(label, 0, wxEXPAND|wxALIGN_TOP, 5);
|
||||
|
||||
wxHyperlinkCtrl *value = new wxHyperlinkCtrl(this, wxID_ANY, m_prov.m_help_web, m_prov.m_help_web, wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE);
|
||||
value->SetToolTip(_("Open the default web browser"));
|
||||
sb_contact_tbl->Add(value, 0, wxEXPAND|wxALIGN_TOP, 5);
|
||||
}
|
||||
|
||||
if (!m_prov.m_help_email.empty()) {
|
||||
wxStaticText *label = new wxStaticText(this, wxID_ANY, wxT("\x2a"), wxDefaultPosition, wxDefaultSize, 0);
|
||||
label->Wrap(-1);
|
||||
label->SetFont(font_wingdings);
|
||||
sb_contact_tbl->Add(label, 0, wxEXPAND|wxALIGN_TOP, 5);
|
||||
|
||||
wxHyperlinkCtrl *value = new wxHyperlinkCtrl(this, wxID_ANY, m_prov.m_help_email, wxString(wxT("mailto:")) + m_prov.m_help_email, wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE);
|
||||
value->SetToolTip(_("Open your e-mail program"));
|
||||
sb_contact_tbl->Add(value, 0, wxEXPAND|wxALIGN_TOP, 5);
|
||||
}
|
||||
|
||||
if (!m_prov.m_help_phone.empty()) {
|
||||
wxStaticText *label = new wxStaticText(this, wxID_ANY, wxT("\x29"), wxDefaultPosition, wxDefaultSize, 0);
|
||||
label->Wrap(-1);
|
||||
label->SetFont(font_wingdings);
|
||||
sb_contact_tbl->Add(label, 0, wxEXPAND|wxALIGN_TOP, 5);
|
||||
|
||||
wxHyperlinkCtrl *value = new wxHyperlinkCtrl(this, wxID_ANY, m_prov.m_help_phone, wxString(wxT("tel:")) + GetPhoneNumber(m_prov.m_help_phone.c_str()), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE);
|
||||
value->SetToolTip(_("Dial the phone number"));
|
||||
sb_contact_tbl->Add(value, 0, wxEXPAND|wxALIGN_TOP, 5);
|
||||
}
|
||||
|
||||
m_provider_locked_vert->Add(sb_contact_tbl, 0, wxLEFT|wxRIGHT|wxDOWN|wxEXPAND, 5);
|
||||
}
|
||||
|
||||
this->Layout();
|
||||
}
|
||||
wxEAPProviderLockedPanel(const eap::config_provider &prov, wxWindow* parent);
|
||||
|
||||
protected:
|
||||
/// \cond internal
|
||||
|
||||
virtual bool AcceptsFocusFromKeyboard() const
|
||||
{
|
||||
return !m_prov.m_help_email.empty() || !m_prov.m_help_web.empty() || !m_prov.m_help_phone.empty();
|
||||
}
|
||||
virtual bool AcceptsFocusFromKeyboard() const;
|
||||
|
||||
template<class _Elem, class _Traits, class _Ax>
|
||||
static std::basic_string<_Elem, _Traits, _Ax> GetPhoneNumber(_In_z_ const _Elem *num)
|
||||
@ -323,13 +216,13 @@ protected:
|
||||
/// \endcond
|
||||
|
||||
protected:
|
||||
_Tprov &m_prov; ///< EAP provider
|
||||
winstd::library m_shell32; ///< shell32.dll resource library reference
|
||||
wxIcon m_icon; ///< Panel icon
|
||||
const eap::config_provider &m_prov; ///< EAP provider
|
||||
winstd::library m_shell32; ///< shell32.dll resource library reference
|
||||
wxIcon m_icon; ///< Panel icon
|
||||
};
|
||||
|
||||
|
||||
template <class _Tprov, class _Tmeth, class _wxT>
|
||||
template <class _Tmeth, class _wxT>
|
||||
class wxEAPCredentialsConfigPanel : public wxEAPCredentialsConfigPanelBase
|
||||
{
|
||||
public:
|
||||
@ -341,7 +234,7 @@ public:
|
||||
/// \param[in] pszCredTarget Target name of credentials in Windows Credential Manager. Can be further decorated to create final target name.
|
||||
/// \param[in] parent Parent window
|
||||
///
|
||||
wxEAPCredentialsConfigPanel(_Tprov &prov, _Tmeth &cfg, LPCTSTR pszCredTarget, wxWindow *parent) :
|
||||
wxEAPCredentialsConfigPanel(const eap::config_provider &prov, _Tmeth &cfg, LPCTSTR pszCredTarget, wxWindow *parent) :
|
||||
m_prov(prov),
|
||||
m_cfg(cfg),
|
||||
m_target(pszCredTarget),
|
||||
@ -445,7 +338,7 @@ protected:
|
||||
{
|
||||
UNREFERENCED_PARAMETER(event);
|
||||
|
||||
wxEAPCredentialsDialog<_Tprov> dlg(m_prov, this);
|
||||
wxEAPCredentialsDialog dlg(m_prov, this);
|
||||
|
||||
_wxT *panel = new _wxT(m_prov, *m_cred, m_target.c_str(), &dlg, true);
|
||||
|
||||
@ -467,7 +360,7 @@ protected:
|
||||
{
|
||||
UNREFERENCED_PARAMETER(event);
|
||||
|
||||
wxEAPCredentialsDialog<_Tprov> dlg(m_prov, this);
|
||||
wxEAPCredentialsDialog dlg(m_prov, this);
|
||||
|
||||
_wxT *panel = new _wxT(m_prov, *m_cred, _T(""), &dlg, true);
|
||||
|
||||
@ -478,7 +371,7 @@ protected:
|
||||
/// \endcond
|
||||
|
||||
protected:
|
||||
_Tprov &m_prov; ///< EAP provider
|
||||
const eap::config_provider &m_prov; ///< EAP provider
|
||||
_Tmeth &m_cfg; ///< EAP configuration
|
||||
winstd::library m_shell32; ///< shell32.dll resource library reference
|
||||
wxIcon m_icon; ///< Panel icon
|
||||
@ -565,7 +458,6 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
template <class _Tprov>
|
||||
class wxPasswordCredentialsPanel : public wxEAPCredentialsPanelBase<wxEAPCredentialsPanelPassBase>
|
||||
{
|
||||
public:
|
||||
@ -578,67 +470,12 @@ public:
|
||||
/// \param[in] parent Parent window
|
||||
/// \param[in] is_config Is this panel used to pre-enter credentials? When \c true, the "Remember" checkbox is always selected and disabled.
|
||||
///
|
||||
wxPasswordCredentialsPanel(_Tprov &prov, eap::credentials &cred, LPCTSTR pszCredTarget, wxWindow* parent, bool is_config = false) :
|
||||
m_cred((eap::credentials_pass&)cred),
|
||||
wxEAPCredentialsPanelBase<wxEAPCredentialsPanelPassBase>(cred, pszCredTarget, parent, is_config)
|
||||
{
|
||||
// Load and set icon.
|
||||
if (m_shell32.load(_T("shell32.dll"), NULL, LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE))
|
||||
wxSetIconFromResource(m_credentials_icon, m_icon, m_shell32, MAKEINTRESOURCE(269));
|
||||
|
||||
bool layout = false;
|
||||
if (!prov.m_lbl_alt_credential.empty()) {
|
||||
m_credentials_label->SetLabel(prov.m_lbl_alt_credential);
|
||||
m_credentials_label->Wrap( 446 );
|
||||
layout = true;
|
||||
}
|
||||
|
||||
if (!prov.m_lbl_alt_identity.empty()) {
|
||||
m_identity_label->SetLabel(prov.m_lbl_alt_identity);
|
||||
layout = true;
|
||||
}
|
||||
|
||||
if (!prov.m_lbl_alt_password.empty()) {
|
||||
m_password_label->SetLabel(prov.m_lbl_alt_password);
|
||||
layout = true;
|
||||
}
|
||||
|
||||
if (layout)
|
||||
this->Layout();
|
||||
}
|
||||
wxPasswordCredentialsPanel(const eap::config_provider &prov, eap::credentials &cred, LPCTSTR pszCredTarget, wxWindow* parent, bool is_config = false);
|
||||
|
||||
protected:
|
||||
/// \cond internal
|
||||
|
||||
virtual bool TransferDataToWindow()
|
||||
{
|
||||
// Inherited TransferDataToWindow() calls m_cred.retrieve().
|
||||
// Therefore, call it now, to set m_cred.
|
||||
wxCHECK(__super::TransferDataToWindow(), false);
|
||||
|
||||
m_identity->SetValue(m_cred.m_identity);
|
||||
m_identity->SetSelection(0, -1);
|
||||
m_password->SetValue(m_cred.m_password.empty() ? wxEmptyString : s_dummy_password);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
virtual bool TransferDataFromWindow()
|
||||
{
|
||||
m_cred.m_identity = m_identity->GetValue();
|
||||
|
||||
wxString pass = m_password->GetValue();
|
||||
if (pass.compare(s_dummy_password) != 0) {
|
||||
m_cred.m_password = pass;
|
||||
pass.assign(pass.length(), wxT('*'));
|
||||
}
|
||||
|
||||
// Inherited TransferDataFromWindow() calls m_cred.store().
|
||||
// Therefore, call it only now, that m_cred is set.
|
||||
return __super::TransferDataFromWindow();
|
||||
}
|
||||
|
||||
virtual bool TransferDataToWindow();
|
||||
virtual bool TransferDataFromWindow();
|
||||
/// \endcond
|
||||
|
||||
protected:
|
||||
@ -651,10 +488,6 @@ private:
|
||||
};
|
||||
|
||||
|
||||
template <class _Tprov>
|
||||
const wxStringCharType *wxPasswordCredentialsPanel<_Tprov>::s_dummy_password = wxT("dummypass");
|
||||
|
||||
|
||||
inline bool wxSetIconFromResource(wxStaticBitmap *bmp, wxIcon &icon, HINSTANCE hinst, PCWSTR pszName)
|
||||
{
|
||||
wxASSERT(bmp);
|
||||
|
@ -58,9 +58,9 @@ namespace eap
|
||||
/// - \c false otherwise. See \p ppEapError for details.
|
||||
///
|
||||
virtual bool invoke_config_ui(
|
||||
_In_ HWND hwndParent,
|
||||
_Inout_ config_providers_type &cfg,
|
||||
_Out_ EAP_ERROR **ppEapError) = 0;
|
||||
_In_ HWND hwndParent,
|
||||
_Inout_ config_providers &cfg,
|
||||
_Out_ EAP_ERROR **ppEapError) = 0;
|
||||
|
||||
///
|
||||
/// Raises a custom interactive user interface dialog to obtain user identity information for the EAP method on the client.
|
||||
@ -79,12 +79,12 @@ namespace eap
|
||||
/// - \c false otherwise. See \p ppEapError for details.
|
||||
///
|
||||
virtual bool invoke_identity_ui(
|
||||
_In_ HWND hwndParent,
|
||||
_In_ DWORD dwFlags,
|
||||
_Inout_ config_providers_type &cfg,
|
||||
_Inout_ credentials_type &cred,
|
||||
_Out_ LPWSTR *ppwszIdentity,
|
||||
_Out_ EAP_ERROR **ppEapError) = 0;
|
||||
_In_ HWND hwndParent,
|
||||
_In_ DWORD dwFlags,
|
||||
_Inout_ config_providers &cfg,
|
||||
_Inout_ credentials_type &cred,
|
||||
_Out_ LPWSTR *ppwszIdentity,
|
||||
_Out_ EAP_ERROR **ppEapError) = 0;
|
||||
|
||||
///
|
||||
/// Raises a custom interactive user interface dialog for the EAP method on the client.
|
||||
|
@ -29,3 +29,190 @@ wxEAPBannerPanel::wxEAPBannerPanel(wxWindow* parent) : wxEAPBannerPanelBase(pare
|
||||
{
|
||||
m_title->SetLabelText(wxT(PRODUCT_NAME_STR));
|
||||
}
|
||||
|
||||
|
||||
bool wxEAPBannerPanel::AcceptsFocusFromKeyboard() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// wxEAPCredentialsDialog
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
wxEAPCredentialsDialog::wxEAPCredentialsDialog(const eap::config_provider &prov, wxWindow* parent) : wxEAPCredentialsDialogBase(parent)
|
||||
{
|
||||
// Set extra style here, as wxFormBuilder overrides all default flags.
|
||||
this->SetExtraStyle(this->GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY);
|
||||
|
||||
// Set banner title.
|
||||
m_banner->m_title->SetLabel(wxString::Format(_("%s Credentials"), prov.m_id.c_str()));
|
||||
|
||||
m_buttonsOK->SetDefault();
|
||||
}
|
||||
|
||||
|
||||
void wxEAPCredentialsDialog::AddContents(wxPanel **contents, size_t content_count)
|
||||
{
|
||||
if (content_count) {
|
||||
for (size_t i = 0; i < content_count; i++)
|
||||
m_panels->Add(contents[i], 0, wxALL|wxEXPAND, 5);
|
||||
|
||||
this->Layout();
|
||||
this->GetSizer()->Fit(this);
|
||||
contents[0]->SetFocusFromKbd();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void wxEAPCredentialsDialog::OnInitDialog(wxInitDialogEvent& event)
|
||||
{
|
||||
for (wxSizerItemList::compatibility_iterator panel = m_panels->GetChildren().GetFirst(); panel; panel = panel->GetNext())
|
||||
panel->GetData()->GetWindow()->GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// wxEAPProviderLockedPanel
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
wxEAPProviderLockedPanel::wxEAPProviderLockedPanel(const eap::config_provider &prov, wxWindow* parent) :
|
||||
m_prov(prov),
|
||||
wxEAPProviderLockedPanelBase(parent)
|
||||
{
|
||||
// Load and set icon.
|
||||
if (m_shell32.load(_T("shell32.dll"), NULL, LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE))
|
||||
wxSetIconFromResource(m_provider_locked_icon, m_icon, m_shell32, MAKEINTRESOURCE(48));
|
||||
|
||||
m_provider_locked_label->SetLabel(wxString::Format(_("%s has pre-set parts of this configuration. Those parts are locked to prevent accidental modification."),
|
||||
!m_prov.m_name.empty() ? m_prov.m_name.c_str() :
|
||||
!m_prov.m_id .empty() ? winstd::string_printf(_("Your %ls provider"), m_prov.m_id.c_str()).c_str() : _("Your provider")));
|
||||
m_provider_locked_label->Wrap(452);
|
||||
|
||||
if (!m_prov.m_help_email.empty() || !m_prov.m_help_web.empty() || !m_prov.m_help_phone.empty()) {
|
||||
wxStaticText *provider_notice = new wxStaticText(this, wxID_ANY, wxString::Format(_("For additional help and instructions, please contact %s at:"),
|
||||
!m_prov.m_name.empty() ? m_prov.m_name.c_str() :
|
||||
!m_prov.m_id .empty() ? winstd::string_printf(_("your %ls provider"), m_prov.m_id.c_str()).c_str() : _("your provider")), wxDefaultPosition, wxDefaultSize, 0);
|
||||
provider_notice->Wrap(452);
|
||||
m_provider_locked_vert->Add(provider_notice, 0, wxUP|wxLEFT|wxRIGHT|wxEXPAND, 5);
|
||||
|
||||
wxFlexGridSizer* sb_contact_tbl;
|
||||
sb_contact_tbl = new wxFlexGridSizer(0, 2, 5, 5);
|
||||
sb_contact_tbl->AddGrowableCol(1);
|
||||
sb_contact_tbl->SetFlexibleDirection(wxBOTH);
|
||||
sb_contact_tbl->SetNonFlexibleGrowMode(wxFLEX_GROWMODE_SPECIFIED);
|
||||
|
||||
wxFont font_wingdings(-1, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxT("Wingdings"));
|
||||
|
||||
if (!m_prov.m_help_web.empty()) {
|
||||
wxStaticText *label = new wxStaticText(this, wxID_ANY, wxT("\xb6"), wxDefaultPosition, wxDefaultSize, 0);
|
||||
label->Wrap(-1);
|
||||
label->SetFont(font_wingdings);
|
||||
sb_contact_tbl->Add(label, 0, wxEXPAND|wxALIGN_TOP, 5);
|
||||
|
||||
wxHyperlinkCtrl *value = new wxHyperlinkCtrl(this, wxID_ANY, m_prov.m_help_web, m_prov.m_help_web, wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE);
|
||||
value->SetToolTip(_("Open the default web browser"));
|
||||
sb_contact_tbl->Add(value, 0, wxEXPAND|wxALIGN_TOP, 5);
|
||||
}
|
||||
|
||||
if (!m_prov.m_help_email.empty()) {
|
||||
wxStaticText *label = new wxStaticText(this, wxID_ANY, wxT("\x2a"), wxDefaultPosition, wxDefaultSize, 0);
|
||||
label->Wrap(-1);
|
||||
label->SetFont(font_wingdings);
|
||||
sb_contact_tbl->Add(label, 0, wxEXPAND|wxALIGN_TOP, 5);
|
||||
|
||||
wxHyperlinkCtrl *value = new wxHyperlinkCtrl(this, wxID_ANY, m_prov.m_help_email, wxString(wxT("mailto:")) + m_prov.m_help_email, wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE);
|
||||
value->SetToolTip(_("Open your e-mail program"));
|
||||
sb_contact_tbl->Add(value, 0, wxEXPAND|wxALIGN_TOP, 5);
|
||||
}
|
||||
|
||||
if (!m_prov.m_help_phone.empty()) {
|
||||
wxStaticText *label = new wxStaticText(this, wxID_ANY, wxT("\x29"), wxDefaultPosition, wxDefaultSize, 0);
|
||||
label->Wrap(-1);
|
||||
label->SetFont(font_wingdings);
|
||||
sb_contact_tbl->Add(label, 0, wxEXPAND|wxALIGN_TOP, 5);
|
||||
|
||||
wxHyperlinkCtrl *value = new wxHyperlinkCtrl(this, wxID_ANY, m_prov.m_help_phone, wxString(wxT("tel:")) + GetPhoneNumber(m_prov.m_help_phone.c_str()), wxDefaultPosition, wxDefaultSize, wxHL_DEFAULT_STYLE);
|
||||
value->SetToolTip(_("Dial the phone number"));
|
||||
sb_contact_tbl->Add(value, 0, wxEXPAND|wxALIGN_TOP, 5);
|
||||
}
|
||||
|
||||
m_provider_locked_vert->Add(sb_contact_tbl, 0, wxLEFT|wxRIGHT|wxDOWN|wxEXPAND, 5);
|
||||
}
|
||||
|
||||
this->Layout();
|
||||
}
|
||||
|
||||
|
||||
bool wxEAPProviderLockedPanel::AcceptsFocusFromKeyboard() const
|
||||
{
|
||||
return !m_prov.m_help_email.empty() || !m_prov.m_help_web.empty() || !m_prov.m_help_phone.empty();
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// wxPasswordCredentialsPanel
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
wxPasswordCredentialsPanel::wxPasswordCredentialsPanel(const eap::config_provider &prov, eap::credentials &cred, LPCTSTR pszCredTarget, wxWindow* parent, bool is_config) :
|
||||
m_cred((eap::credentials_pass&)cred),
|
||||
wxEAPCredentialsPanelBase<wxEAPCredentialsPanelPassBase>(cred, pszCredTarget, parent, is_config)
|
||||
{
|
||||
// Load and set icon.
|
||||
if (m_shell32.load(_T("shell32.dll"), NULL, LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE))
|
||||
wxSetIconFromResource(m_credentials_icon, m_icon, m_shell32, MAKEINTRESOURCE(269));
|
||||
|
||||
bool layout = false;
|
||||
if (!prov.m_lbl_alt_credential.empty()) {
|
||||
m_credentials_label->SetLabel(prov.m_lbl_alt_credential);
|
||||
m_credentials_label->Wrap( 446 );
|
||||
layout = true;
|
||||
}
|
||||
|
||||
if (!prov.m_lbl_alt_identity.empty()) {
|
||||
m_identity_label->SetLabel(prov.m_lbl_alt_identity);
|
||||
layout = true;
|
||||
}
|
||||
|
||||
if (!prov.m_lbl_alt_password.empty()) {
|
||||
m_password_label->SetLabel(prov.m_lbl_alt_password);
|
||||
layout = true;
|
||||
}
|
||||
|
||||
if (layout)
|
||||
this->Layout();
|
||||
}
|
||||
|
||||
|
||||
bool wxPasswordCredentialsPanel::TransferDataToWindow()
|
||||
{
|
||||
// Inherited TransferDataToWindow() calls m_cred.retrieve().
|
||||
// Therefore, call it now, to set m_cred.
|
||||
wxCHECK(__super::TransferDataToWindow(), false);
|
||||
|
||||
m_identity->SetValue(m_cred.m_identity);
|
||||
m_identity->SetSelection(0, -1);
|
||||
m_password->SetValue(m_cred.m_password.empty() ? wxEmptyString : s_dummy_password);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool wxPasswordCredentialsPanel::TransferDataFromWindow()
|
||||
{
|
||||
m_cred.m_identity = m_identity->GetValue();
|
||||
|
||||
wxString pass = m_password->GetValue();
|
||||
if (pass.compare(s_dummy_password) != 0) {
|
||||
m_cred.m_password = pass;
|
||||
pass.assign(pass.length(), wxT('*'));
|
||||
}
|
||||
|
||||
// Inherited TransferDataFromWindow() calls m_cred.store().
|
||||
// Therefore, call it only now, that m_cred is set.
|
||||
return __super::TransferDataFromWindow();
|
||||
}
|
||||
|
||||
|
||||
const wxStringCharType *wxPasswordCredentialsPanel::s_dummy_password = wxT("dummypass");
|
||||
|
@ -83,6 +83,7 @@
|
||||
<ClInclude Include="..\src\StdAfx.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\src\PAP_UI.cpp" />
|
||||
<ClCompile Include="..\src\StdAfx.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
|
||||
|
@ -26,5 +26,8 @@
|
||||
<ClCompile Include="..\src\StdAfx.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\PAP_UI.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -25,12 +25,12 @@
|
||||
///
|
||||
/// PAP credential configuration panel
|
||||
///
|
||||
template <class _Tprov> class wxPAPCredentialsConfigPanel;
|
||||
typedef wxEAPCredentialsConfigPanel<eap::config_method_pap, wxPasswordCredentialsPanel> wxPAPCredentialsConfigPanel;
|
||||
|
||||
///
|
||||
/// PAP configuration panel
|
||||
///
|
||||
template <class _Tprov> class wxPAPConfigPanel;
|
||||
class wxPAPConfigPanel;
|
||||
|
||||
#pragma once
|
||||
|
||||
@ -40,69 +40,24 @@ template <class _Tprov> class wxPAPConfigPanel;
|
||||
#include <Windows.h>
|
||||
|
||||
|
||||
template <class _Tprov>
|
||||
class wxPAPCredentialsConfigPanel : public wxEAPCredentialsConfigPanel<_Tprov, eap::config_method_pap, wxPasswordCredentialsPanel<_Tprov> >
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Constructs a PAP credential configuration panel
|
||||
///
|
||||
/// \param[inout] prov Provider configuration data
|
||||
/// \param[inout] cfg Configuration data
|
||||
/// \param[in] pszCredTarget Target name of credentials in Windows Credential Manager. Can be further decorated to create final target name.
|
||||
/// \param[in] parent Parent window
|
||||
///
|
||||
wxPAPCredentialsConfigPanel(_Tprov &prov, eap::config_method_pap &cfg, LPCTSTR pszCredTarget, wxWindow *parent) :
|
||||
wxEAPCredentialsConfigPanel<_Tprov, eap::config_method_pap, wxPasswordCredentialsPanel<_Tprov> >(prov, cfg, pszCredTarget, parent)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class _Tprov>
|
||||
class wxPAPConfigPanel : public wxPanel
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Constructs a configuration panel
|
||||
///
|
||||
wxPAPConfigPanel(_Tprov &prov, eap::config_method_pap &cfg, LPCTSTR pszCredTarget, wxWindow* parent) : wxPanel(parent)
|
||||
{
|
||||
wxBoxSizer* sb_content;
|
||||
sb_content = new wxBoxSizer( wxVERTICAL );
|
||||
|
||||
m_credentials = new wxPAPCredentialsConfigPanel<_Tprov>(prov, cfg, pszCredTarget, this);
|
||||
sb_content->Add(m_credentials, 0, wxEXPAND, 5);
|
||||
|
||||
this->SetSizer(sb_content);
|
||||
this->Layout();
|
||||
|
||||
// Connect Events
|
||||
this->Connect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(wxPAPConfigPanel::OnInitDialog));
|
||||
}
|
||||
wxPAPConfigPanel(const eap::config_provider &prov, eap::config_method_pap &cfg, LPCTSTR pszCredTarget, wxWindow* parent);
|
||||
|
||||
///
|
||||
/// Destructs the configuration panel
|
||||
///
|
||||
virtual ~wxPAPConfigPanel()
|
||||
{
|
||||
// Disconnect Events
|
||||
this->Disconnect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(wxPAPConfigPanel::OnInitDialog));
|
||||
}
|
||||
|
||||
virtual ~wxPAPConfigPanel();
|
||||
|
||||
protected:
|
||||
/// \cond internal
|
||||
|
||||
virtual void OnInitDialog(wxInitDialogEvent& event)
|
||||
{
|
||||
// Forward the event to child panels.
|
||||
if (m_credentials)
|
||||
m_credentials->GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
|
||||
virtual void OnInitDialog(wxInitDialogEvent& event);
|
||||
/// \endcond
|
||||
|
||||
protected:
|
||||
wxPAPCredentialsConfigPanel<_Tprov> *m_credentials; ///< Credentials configuration panel
|
||||
wxPAPCredentialsConfigPanel *m_credentials; ///< Credentials configuration panel
|
||||
};
|
||||
|
56
lib/PAP_UI/src/PAP_UI.cpp
Normal file
56
lib/PAP_UI/src/PAP_UI.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
/*
|
||||
Copyright 2015-2016 Amebis
|
||||
Copyright 2016 GÉANT
|
||||
|
||||
This file is part of GÉANTLink.
|
||||
|
||||
GÉANTLink is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GÉANTLink is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GÉANTLink. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// wxPAPConfigPanel
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
wxPAPConfigPanel::wxPAPConfigPanel(const eap::config_provider &prov, eap::config_method_pap &cfg, LPCTSTR pszCredTarget, wxWindow* parent) : wxPanel(parent)
|
||||
{
|
||||
wxBoxSizer* sb_content;
|
||||
sb_content = new wxBoxSizer( wxVERTICAL );
|
||||
|
||||
m_credentials = new wxPAPCredentialsConfigPanel(prov, cfg, pszCredTarget, this);
|
||||
sb_content->Add(m_credentials, 0, wxEXPAND, 5);
|
||||
|
||||
this->SetSizer(sb_content);
|
||||
this->Layout();
|
||||
|
||||
// Connect Events
|
||||
this->Connect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(wxPAPConfigPanel::OnInitDialog));
|
||||
}
|
||||
|
||||
|
||||
wxPAPConfigPanel::~wxPAPConfigPanel()
|
||||
{
|
||||
// Disconnect Events
|
||||
this->Disconnect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(wxPAPConfigPanel::OnInitDialog));
|
||||
}
|
||||
|
||||
|
||||
void wxPAPConfigPanel::OnInitDialog(wxInitDialogEvent& event)
|
||||
{
|
||||
// Forward the event to child panels.
|
||||
if (m_credentials)
|
||||
m_credentials->GetEventHandler()->ProcessEvent(event);
|
||||
}
|
@ -58,22 +58,22 @@ class wxFQDNListValidator;
|
||||
///
|
||||
/// TLS credential panel
|
||||
///
|
||||
template <class _Tprov> class wxTLSCredentialsPanel;
|
||||
class wxTLSCredentialsPanel;
|
||||
|
||||
///
|
||||
/// TLS server trust configuration panel
|
||||
///
|
||||
template <class _Tprov> class wxTLSServerTrustPanel;
|
||||
class wxTLSServerTrustPanel;
|
||||
|
||||
///
|
||||
/// TLS credentials configuration panel
|
||||
///
|
||||
template <class _Tprov> class wxTLSCredentialsConfigPanel;
|
||||
typedef wxEAPCredentialsConfigPanel<eap::config_method_tls, wxTLSCredentialsPanel> wxTLSCredentialsConfigPanel;
|
||||
|
||||
///
|
||||
/// TLS configuration panel
|
||||
///
|
||||
template <class _Tprov> class wxTLSConfigPanel;
|
||||
class wxTLSConfigPanel;
|
||||
|
||||
#pragma once
|
||||
|
||||
@ -248,95 +248,19 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
template <class _Tprov>
|
||||
class wxTLSCredentialsPanel : public wxEAPCredentialsPanelBase<wxTLSCredentialsPanelBase>
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Constructs a configuration panel
|
||||
///
|
||||
wxTLSCredentialsPanel(_Tprov &prov, eap::credentials &cred, LPCTSTR pszCredTarget, wxWindow* parent, bool is_config = false) :
|
||||
m_cred((eap::credentials_tls&)cred),
|
||||
wxEAPCredentialsPanelBase<wxTLSCredentialsPanelBase>(cred, pszCredTarget, parent, is_config)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(prov);
|
||||
|
||||
// Load and set icon.
|
||||
if (m_shell32.load(_T("shell32.dll"), NULL, LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE))
|
||||
wxSetIconFromResource(m_credentials_icon, m_icon, m_shell32, MAKEINTRESOURCE(269));
|
||||
}
|
||||
wxTLSCredentialsPanel(const eap::config_provider &prov, eap::credentials &cred, LPCTSTR pszCredTarget, wxWindow* parent, bool is_config = false);
|
||||
|
||||
protected:
|
||||
/// \cond internal
|
||||
|
||||
virtual bool TransferDataToWindow()
|
||||
{
|
||||
// Populate certificate list.
|
||||
bool is_found = false;
|
||||
winstd::cert_store store;
|
||||
if (store.create(CERT_STORE_PROV_SYSTEM, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, (HCRYPTPROV)NULL, CERT_SYSTEM_STORE_CURRENT_USER, _T("My"))) {
|
||||
for (PCCERT_CONTEXT cert = NULL; (cert = CertEnumCertificatesInStore(store, cert)) != NULL;) {
|
||||
DWORD dwKeySpec = 0, dwSize = sizeof(dwKeySpec);
|
||||
if (!CertGetCertificateContextProperty(cert, CERT_KEY_SPEC_PROP_ID, &dwKeySpec, &dwSize) || !dwKeySpec) {
|
||||
// Skip certificates without private key.
|
||||
continue;
|
||||
}
|
||||
|
||||
// Prepare certificate information.
|
||||
std::unique_ptr<wxCertificateClientData> data(new wxCertificateClientData(CertDuplicateCertificateContext(cert)));
|
||||
|
||||
// Add to list.
|
||||
bool is_selected =
|
||||
m_cred.m_cert &&
|
||||
m_cred.m_cert->cbCertEncoded == data->m_cert->cbCertEncoded &&
|
||||
memcmp(m_cred.m_cert->pbCertEncoded, data->m_cert->pbCertEncoded, m_cred.m_cert->cbCertEncoded) == 0;
|
||||
winstd::tstring name(std::move(eap::get_cert_title(cert)));
|
||||
int i = m_cert_select_val->Append(name, data.release());
|
||||
if (is_selected) {
|
||||
m_cert_select_val->SetSelection(i);
|
||||
is_found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (is_found) {
|
||||
m_cert_select ->SetValue(true);
|
||||
m_cert_select_val->Enable(true);
|
||||
} else {
|
||||
m_cert_none ->SetValue(true);
|
||||
m_cert_select_val->Enable(false);
|
||||
if (!m_cert_select_val->IsEmpty())
|
||||
m_cert_select_val->SetSelection(0);
|
||||
}
|
||||
|
||||
return __super::TransferDataToWindow();
|
||||
}
|
||||
|
||||
|
||||
virtual bool TransferDataFromWindow()
|
||||
{
|
||||
if (m_cert_none->GetValue())
|
||||
m_cred.clear();
|
||||
else {
|
||||
const wxCertificateClientData *data = dynamic_cast<const wxCertificateClientData*>(m_cert_select_val->GetClientObject(m_cert_select_val->GetSelection()));
|
||||
if (data)
|
||||
m_cred.m_cert.attach_duplicated(data->m_cert);
|
||||
else
|
||||
m_cred.clear();
|
||||
}
|
||||
|
||||
// Inherited TransferDataFromWindow() calls m_cred.store().
|
||||
// Therefore, call it only now, that m_cred is set.
|
||||
return __super::TransferDataFromWindow();
|
||||
}
|
||||
|
||||
|
||||
virtual void OnCertSelect(wxCommandEvent& event)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(event);
|
||||
m_cert_select_val->Enable(m_cert_select->GetValue());
|
||||
}
|
||||
|
||||
virtual bool TransferDataToWindow();
|
||||
virtual bool TransferDataFromWindow();
|
||||
virtual void OnCertSelect(wxCommandEvent& event);
|
||||
/// \endcond
|
||||
|
||||
protected:
|
||||
@ -346,147 +270,23 @@ protected:
|
||||
};
|
||||
|
||||
|
||||
template <class _Tprov>
|
||||
class wxTLSServerTrustPanel : public wxEAPTLSServerTrustConfigPanelBase
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Constructs a configuration panel
|
||||
///
|
||||
wxTLSServerTrustPanel(_Tprov &prov, eap::config_method_tls &cfg, wxWindow* parent) :
|
||||
m_prov(prov),
|
||||
m_cfg(cfg),
|
||||
wxEAPTLSServerTrustConfigPanelBase(parent)
|
||||
{
|
||||
// Load and set icon.
|
||||
if (m_certmgr.load(_T("certmgr.dll"), NULL, LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE))
|
||||
wxSetIconFromResource(m_server_trust_icon, m_icon, m_certmgr, MAKEINTRESOURCE(218));
|
||||
|
||||
// Do not use cfg.m_server_names directly, so we can decide not to store the value in case of provider-locked configuration.
|
||||
// Never rely on control disabled state alone, as they can be enabled using external tool like Spy++.
|
||||
m_server_names->SetValidator(wxFQDNListValidator(&m_server_names_val));
|
||||
}
|
||||
wxTLSServerTrustPanel(const eap::config_provider &prov, eap::config_method_tls &cfg, wxWindow* parent);
|
||||
|
||||
protected:
|
||||
/// \cond internal
|
||||
|
||||
virtual bool TransferDataToWindow()
|
||||
{
|
||||
if (m_prov.m_read_only) {
|
||||
// This is provider-locked configuration. Disable controls.
|
||||
m_root_ca_add_store->Enable(false);
|
||||
m_root_ca_add_file ->Enable(false);
|
||||
m_root_ca_remove ->Enable(false);
|
||||
m_server_names ->Enable(false);
|
||||
}
|
||||
|
||||
// Populate trusted CA list.
|
||||
for (std::list<winstd::cert_context>::const_iterator cert = m_cfg.m_trusted_root_ca.cbegin(), cert_end = m_cfg.m_trusted_root_ca.cend(); cert != cert_end; ++cert)
|
||||
m_root_ca->Append(wxString(eap::get_cert_title(*cert)), new wxCertificateClientData(cert->duplicate()));
|
||||
|
||||
// Set server acceptable names. The edit control will get populated by validator.
|
||||
m_server_names_val = m_cfg.m_server_names;
|
||||
|
||||
return wxEAPTLSServerTrustConfigPanelBase::TransferDataToWindow();
|
||||
}
|
||||
|
||||
|
||||
virtual bool TransferDataFromWindow()
|
||||
{
|
||||
wxCHECK(wxEAPTLSServerTrustConfigPanelBase::TransferDataFromWindow(), false);
|
||||
|
||||
if (!m_prov.m_read_only) {
|
||||
// This is not a provider-locked configuration. Save the data.
|
||||
|
||||
// Parse trusted CA list.
|
||||
m_cfg.m_trusted_root_ca.clear();
|
||||
for (unsigned int i = 0, i_end = m_root_ca->GetCount(); i < i_end; i++) {
|
||||
wxCertificateClientData *cert = dynamic_cast<wxCertificateClientData*>(m_root_ca->GetClientObject(i));
|
||||
if (cert)
|
||||
m_cfg.add_trusted_ca(cert->m_cert->dwCertEncodingType, cert->m_cert->pbCertEncoded, cert->m_cert->cbCertEncoded);
|
||||
}
|
||||
|
||||
// Save acceptable server names.
|
||||
m_cfg.m_server_names = m_server_names_val;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
virtual void OnUpdateUI(wxUpdateUIEvent& event)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(event);
|
||||
|
||||
if (!m_prov.m_read_only) {
|
||||
// This is not a provider-locked configuration. Selectively enable/disable controls.
|
||||
wxArrayInt selections;
|
||||
m_root_ca_remove->Enable(m_root_ca->GetSelections(selections) ? true : false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
virtual void OnRootCADClick(wxCommandEvent& event)
|
||||
{
|
||||
wxCertificateClientData *cert = dynamic_cast<wxCertificateClientData*>(event.GetClientObject());
|
||||
if (cert)
|
||||
CryptUIDlgViewContext(CERT_STORE_CERTIFICATE_CONTEXT, cert->m_cert, this->GetHWND(), NULL, 0, NULL);
|
||||
}
|
||||
|
||||
|
||||
virtual void OnRootCAAddStore(wxCommandEvent& event)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(event);
|
||||
|
||||
winstd::cert_store store;
|
||||
if (store.create(NULL, _T("ROOT"))) {
|
||||
winstd::cert_context cert;
|
||||
cert.attach(CryptUIDlgSelectCertificateFromStore(store, this->GetHWND(), NULL, NULL, 0, 0, NULL));
|
||||
if (cert)
|
||||
AddRootCA(cert);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
virtual void OnRootCAAddFile(wxCommandEvent& event)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(event);
|
||||
|
||||
const wxString separator(wxT("|"));
|
||||
wxFileDialog open_dialog(this, _("Add Certificate"), wxEmptyString, wxEmptyString,
|
||||
_("Certificate Files (*.cer;*.crt;*.der;*.p7b;*.pem)") + separator + wxT("*.cer;*.crt;*.der;*.p7b;*.pem") + separator +
|
||||
_("X.509 Certificate Files (*.cer;*.crt;*.der;*.pem)") + separator + wxT("*.cer;*.crt;*.der;*.pem") + separator +
|
||||
_("PKCS #7 Certificate Files (*.p7b)") + separator + wxT("*.p7b") + separator +
|
||||
_("All Files (*.*)") + separator + wxT("*.*"),
|
||||
wxFD_OPEN|wxFD_FILE_MUST_EXIST|wxFD_MULTIPLE);
|
||||
if (open_dialog.ShowModal() == wxID_CANCEL) {
|
||||
event.Skip();
|
||||
return;
|
||||
}
|
||||
|
||||
wxArrayString paths;
|
||||
open_dialog.GetPaths(paths);
|
||||
for (size_t i = 0, i_end = paths.GetCount(); i < i_end; i++) {
|
||||
// Load certificate(s) from file.
|
||||
winstd::cert_store cs;
|
||||
if (cs.create(CERT_STORE_PROV_FILENAME, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, NULL, CERT_STORE_OPEN_EXISTING_FLAG | CERT_STORE_READONLY_FLAG, (LPCTSTR)(paths[i]))) {
|
||||
for (PCCERT_CONTEXT cert = NULL; (cert = CertEnumCertificatesInStore(cs, cert)) != NULL;)
|
||||
AddRootCA(cert);
|
||||
} else
|
||||
wxMessageBox(wxString::Format(_("Invalid or unsupported certificate file %s"), paths[i]), _("Error"), wxOK | wxICON_EXCLAMATION, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
virtual void OnRootCARemove(wxCommandEvent& event)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(event);
|
||||
|
||||
wxArrayInt selections;
|
||||
for (int i = m_root_ca->GetSelections(selections); i--; )
|
||||
m_root_ca->Delete(selections[i]);
|
||||
}
|
||||
|
||||
virtual bool TransferDataToWindow();
|
||||
virtual bool TransferDataFromWindow();
|
||||
virtual void OnUpdateUI(wxUpdateUIEvent& event);
|
||||
virtual void OnRootCADClick(wxCommandEvent& event);
|
||||
virtual void OnRootCAAddStore(wxCommandEvent& event);
|
||||
virtual void OnRootCAAddFile(wxCommandEvent& event);
|
||||
virtual void OnRootCARemove(wxCommandEvent& event);
|
||||
/// \endcond
|
||||
|
||||
///
|
||||
@ -498,105 +298,36 @@ protected:
|
||||
/// - \c true if certificate was added;
|
||||
/// - \c false if duplicate found or an error occured.
|
||||
///
|
||||
bool AddRootCA(PCCERT_CONTEXT cert)
|
||||
{
|
||||
for (unsigned int i = 0, i_end = m_root_ca->GetCount(); i < i_end; i++) {
|
||||
wxCertificateClientData *c = dynamic_cast<wxCertificateClientData*>(m_root_ca->GetClientObject(i));
|
||||
if (c && c->m_cert &&
|
||||
c->m_cert->cbCertEncoded == cert->cbCertEncoded &&
|
||||
memcmp(c->m_cert->pbCertEncoded, cert->pbCertEncoded, cert->cbCertEncoded) == 0)
|
||||
{
|
||||
// This certificate is already on the list.
|
||||
m_root_ca->SetSelection(i);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Add certificate to the list.
|
||||
int i = m_root_ca->Append(wxString(eap::get_cert_title(cert)), new wxCertificateClientData(CertDuplicateCertificateContext(cert)));
|
||||
if (0 <= i)
|
||||
m_root_ca->SetSelection(i);
|
||||
|
||||
return true;
|
||||
}
|
||||
bool AddRootCA(PCCERT_CONTEXT cert);
|
||||
|
||||
protected:
|
||||
_Tprov &m_prov; ///< EAP provider
|
||||
eap::config_method_tls &m_cfg; ///< TLS configuration
|
||||
const eap::config_provider &m_prov; ///< EAP provider
|
||||
eap::config_method_tls &m_cfg; ///< TLS configuration
|
||||
winstd::library m_certmgr; ///< certmgr.dll resource library reference
|
||||
wxIcon m_icon; ///< Panel icon
|
||||
std::list<std::string> m_server_names_val; ///< Acceptable authenticating server names
|
||||
};
|
||||
|
||||
|
||||
template <class _Tprov>
|
||||
class wxTLSCredentialsConfigPanel : public wxEAPCredentialsConfigPanel<_Tprov, eap::config_method_tls, wxTLSCredentialsPanel<_Tprov> >
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Constructs a credential configuration panel
|
||||
///
|
||||
/// \param[inout] prov Provider configuration data
|
||||
/// \param[inout] cfg Configuration data
|
||||
/// \param[in] pszCredTarget Target name of credentials in Windows Credential Manager. Can be further decorated to create final target name.
|
||||
/// \param[in] parent Parent window
|
||||
///
|
||||
wxTLSCredentialsConfigPanel(_Tprov &prov, eap::config_method_tls &cfg, LPCTSTR pszCredTarget, wxWindow *parent) :
|
||||
wxEAPCredentialsConfigPanel<_Tprov, eap::config_method_tls, wxTLSCredentialsPanel<_Tprov> >(prov, cfg, pszCredTarget, parent)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <class _Tprov>
|
||||
class wxTLSConfigPanel : public wxPanel
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Constructs a configuration panel
|
||||
///
|
||||
wxTLSConfigPanel(_Tprov &prov, eap::config_method_tls &cfg, LPCTSTR pszCredTarget, wxWindow* parent) : wxPanel(parent)
|
||||
{
|
||||
wxBoxSizer* sb_content;
|
||||
sb_content = new wxBoxSizer( wxVERTICAL );
|
||||
|
||||
m_server_trust = new wxTLSServerTrustPanel<_Tprov>(prov, cfg, this);
|
||||
sb_content->Add(m_server_trust, 0, wxDOWN|wxEXPAND, 5);
|
||||
|
||||
m_credentials = new wxTLSCredentialsConfigPanel<_Tprov>(prov, cfg, pszCredTarget, this);
|
||||
sb_content->Add(m_credentials, 0, wxUP|wxEXPAND, 5);
|
||||
|
||||
this->SetSizer(sb_content);
|
||||
this->Layout();
|
||||
|
||||
// Connect Events
|
||||
this->Connect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(wxTLSConfigPanel::OnInitDialog));
|
||||
}
|
||||
|
||||
wxTLSConfigPanel(const eap::config_provider &prov, eap::config_method_tls &cfg, LPCTSTR pszCredTarget, wxWindow* parent);
|
||||
|
||||
///
|
||||
/// Destructs the configuration panel
|
||||
///
|
||||
virtual ~wxTLSConfigPanel()
|
||||
{
|
||||
// Disconnect Events
|
||||
this->Disconnect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(wxTLSConfigPanel::OnInitDialog));
|
||||
}
|
||||
virtual ~wxTLSConfigPanel();
|
||||
|
||||
protected:
|
||||
/// \cond internal
|
||||
|
||||
virtual void OnInitDialog(wxInitDialogEvent& event)
|
||||
{
|
||||
// Forward the event to child panels.
|
||||
m_server_trust->GetEventHandler()->ProcessEvent(event);
|
||||
if (m_credentials)
|
||||
m_credentials->GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
|
||||
virtual void OnInitDialog(wxInitDialogEvent& event);
|
||||
/// \endcond
|
||||
|
||||
protected:
|
||||
wxTLSServerTrustPanel<_Tprov> *m_server_trust; ///< Server trust configuration panel
|
||||
wxTLSCredentialsConfigPanel<_Tprov> *m_credentials; ///< Credentials configuration panel
|
||||
wxTLSServerTrustPanel *m_server_trust; ///< Server trust configuration panel
|
||||
wxTLSCredentialsConfigPanel *m_credentials; ///< Credentials configuration panel
|
||||
};
|
||||
|
@ -305,3 +305,287 @@ bool wxFQDNListValidator::Parse(const wxString &val_in, size_t i_start, size_t i
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// wxTLSCredentialsPanel
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
wxTLSCredentialsPanel::wxTLSCredentialsPanel(const eap::config_provider &prov, eap::credentials &cred, LPCTSTR pszCredTarget, wxWindow* parent, bool is_config) :
|
||||
m_cred((eap::credentials_tls&)cred),
|
||||
wxEAPCredentialsPanelBase<wxTLSCredentialsPanelBase>(cred, pszCredTarget, parent, is_config)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(prov);
|
||||
|
||||
// Load and set icon.
|
||||
if (m_shell32.load(_T("shell32.dll"), NULL, LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE))
|
||||
wxSetIconFromResource(m_credentials_icon, m_icon, m_shell32, MAKEINTRESOURCE(269));
|
||||
}
|
||||
|
||||
|
||||
bool wxTLSCredentialsPanel::TransferDataToWindow()
|
||||
{
|
||||
// Populate certificate list.
|
||||
bool is_found = false;
|
||||
winstd::cert_store store;
|
||||
if (store.create(CERT_STORE_PROV_SYSTEM, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, (HCRYPTPROV)NULL, CERT_SYSTEM_STORE_CURRENT_USER, _T("My"))) {
|
||||
for (PCCERT_CONTEXT cert = NULL; (cert = CertEnumCertificatesInStore(store, cert)) != NULL;) {
|
||||
DWORD dwKeySpec = 0, dwSize = sizeof(dwKeySpec);
|
||||
if (!CertGetCertificateContextProperty(cert, CERT_KEY_SPEC_PROP_ID, &dwKeySpec, &dwSize) || !dwKeySpec) {
|
||||
// Skip certificates without private key.
|
||||
continue;
|
||||
}
|
||||
|
||||
// Prepare certificate information.
|
||||
std::unique_ptr<wxCertificateClientData> data(new wxCertificateClientData(CertDuplicateCertificateContext(cert)));
|
||||
|
||||
// Add to list.
|
||||
bool is_selected =
|
||||
m_cred.m_cert &&
|
||||
m_cred.m_cert->cbCertEncoded == data->m_cert->cbCertEncoded &&
|
||||
memcmp(m_cred.m_cert->pbCertEncoded, data->m_cert->pbCertEncoded, m_cred.m_cert->cbCertEncoded) == 0;
|
||||
winstd::tstring name(std::move(eap::get_cert_title(cert)));
|
||||
int i = m_cert_select_val->Append(name, data.release());
|
||||
if (is_selected) {
|
||||
m_cert_select_val->SetSelection(i);
|
||||
is_found = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (is_found) {
|
||||
m_cert_select ->SetValue(true);
|
||||
m_cert_select_val->Enable(true);
|
||||
} else {
|
||||
m_cert_none ->SetValue(true);
|
||||
m_cert_select_val->Enable(false);
|
||||
if (!m_cert_select_val->IsEmpty())
|
||||
m_cert_select_val->SetSelection(0);
|
||||
}
|
||||
|
||||
return __super::TransferDataToWindow();
|
||||
}
|
||||
|
||||
|
||||
bool wxTLSCredentialsPanel::TransferDataFromWindow()
|
||||
{
|
||||
if (m_cert_none->GetValue())
|
||||
m_cred.clear();
|
||||
else {
|
||||
const wxCertificateClientData *data = dynamic_cast<const wxCertificateClientData*>(m_cert_select_val->GetClientObject(m_cert_select_val->GetSelection()));
|
||||
if (data)
|
||||
m_cred.m_cert.attach_duplicated(data->m_cert);
|
||||
else
|
||||
m_cred.clear();
|
||||
}
|
||||
|
||||
// Inherited TransferDataFromWindow() calls m_cred.store().
|
||||
// Therefore, call it only now, that m_cred is set.
|
||||
return __super::TransferDataFromWindow();
|
||||
}
|
||||
|
||||
|
||||
void wxTLSCredentialsPanel::OnCertSelect(wxCommandEvent& event)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(event);
|
||||
m_cert_select_val->Enable(m_cert_select->GetValue());
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// wxTLSServerTrustPanel
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
wxTLSServerTrustPanel::wxTLSServerTrustPanel(const eap::config_provider &prov, eap::config_method_tls &cfg, wxWindow* parent) :
|
||||
m_prov(prov),
|
||||
m_cfg(cfg),
|
||||
wxEAPTLSServerTrustConfigPanelBase(parent)
|
||||
{
|
||||
// Load and set icon.
|
||||
if (m_certmgr.load(_T("certmgr.dll"), NULL, LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE))
|
||||
wxSetIconFromResource(m_server_trust_icon, m_icon, m_certmgr, MAKEINTRESOURCE(218));
|
||||
|
||||
// Do not use cfg.m_server_names directly, so we can decide not to store the value in case of provider-locked configuration.
|
||||
// Never rely on control disabled state alone, as they can be enabled using external tool like Spy++.
|
||||
m_server_names->SetValidator(wxFQDNListValidator(&m_server_names_val));
|
||||
}
|
||||
|
||||
|
||||
bool wxTLSServerTrustPanel::TransferDataToWindow()
|
||||
{
|
||||
if (m_prov.m_read_only) {
|
||||
// This is provider-locked configuration. Disable controls.
|
||||
m_root_ca_add_store->Enable(false);
|
||||
m_root_ca_add_file ->Enable(false);
|
||||
m_root_ca_remove ->Enable(false);
|
||||
m_server_names ->Enable(false);
|
||||
}
|
||||
|
||||
// Populate trusted CA list.
|
||||
for (std::list<winstd::cert_context>::const_iterator cert = m_cfg.m_trusted_root_ca.cbegin(), cert_end = m_cfg.m_trusted_root_ca.cend(); cert != cert_end; ++cert)
|
||||
m_root_ca->Append(wxString(eap::get_cert_title(*cert)), new wxCertificateClientData(cert->duplicate()));
|
||||
|
||||
// Set server acceptable names. The edit control will get populated by validator.
|
||||
m_server_names_val = m_cfg.m_server_names;
|
||||
|
||||
return wxEAPTLSServerTrustConfigPanelBase::TransferDataToWindow();
|
||||
}
|
||||
|
||||
|
||||
bool wxTLSServerTrustPanel::TransferDataFromWindow()
|
||||
{
|
||||
wxCHECK(wxEAPTLSServerTrustConfigPanelBase::TransferDataFromWindow(), false);
|
||||
|
||||
if (!m_prov.m_read_only) {
|
||||
// This is not a provider-locked configuration. Save the data.
|
||||
|
||||
// Parse trusted CA list.
|
||||
m_cfg.m_trusted_root_ca.clear();
|
||||
for (unsigned int i = 0, i_end = m_root_ca->GetCount(); i < i_end; i++) {
|
||||
wxCertificateClientData *cert = dynamic_cast<wxCertificateClientData*>(m_root_ca->GetClientObject(i));
|
||||
if (cert)
|
||||
m_cfg.add_trusted_ca(cert->m_cert->dwCertEncodingType, cert->m_cert->pbCertEncoded, cert->m_cert->cbCertEncoded);
|
||||
}
|
||||
|
||||
// Save acceptable server names.
|
||||
m_cfg.m_server_names = m_server_names_val;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void wxTLSServerTrustPanel::OnUpdateUI(wxUpdateUIEvent& event)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(event);
|
||||
|
||||
if (!m_prov.m_read_only) {
|
||||
// This is not a provider-locked configuration. Selectively enable/disable controls.
|
||||
wxArrayInt selections;
|
||||
m_root_ca_remove->Enable(m_root_ca->GetSelections(selections) ? true : false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void wxTLSServerTrustPanel::OnRootCADClick(wxCommandEvent& event)
|
||||
{
|
||||
wxCertificateClientData *cert = dynamic_cast<wxCertificateClientData*>(event.GetClientObject());
|
||||
if (cert)
|
||||
CryptUIDlgViewContext(CERT_STORE_CERTIFICATE_CONTEXT, cert->m_cert, this->GetHWND(), NULL, 0, NULL);
|
||||
}
|
||||
|
||||
|
||||
void wxTLSServerTrustPanel::OnRootCAAddStore(wxCommandEvent& event)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(event);
|
||||
|
||||
winstd::cert_store store;
|
||||
if (store.create(NULL, _T("ROOT"))) {
|
||||
winstd::cert_context cert;
|
||||
cert.attach(CryptUIDlgSelectCertificateFromStore(store, this->GetHWND(), NULL, NULL, 0, 0, NULL));
|
||||
if (cert)
|
||||
AddRootCA(cert);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void wxTLSServerTrustPanel::OnRootCAAddFile(wxCommandEvent& event)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(event);
|
||||
|
||||
const wxString separator(wxT("|"));
|
||||
wxFileDialog open_dialog(this, _("Add Certificate"), wxEmptyString, wxEmptyString,
|
||||
_("Certificate Files (*.cer;*.crt;*.der;*.p7b;*.pem)") + separator + wxT("*.cer;*.crt;*.der;*.p7b;*.pem") + separator +
|
||||
_("X.509 Certificate Files (*.cer;*.crt;*.der;*.pem)") + separator + wxT("*.cer;*.crt;*.der;*.pem") + separator +
|
||||
_("PKCS #7 Certificate Files (*.p7b)") + separator + wxT("*.p7b") + separator +
|
||||
_("All Files (*.*)") + separator + wxT("*.*"),
|
||||
wxFD_OPEN|wxFD_FILE_MUST_EXIST|wxFD_MULTIPLE);
|
||||
if (open_dialog.ShowModal() == wxID_CANCEL) {
|
||||
event.Skip();
|
||||
return;
|
||||
}
|
||||
|
||||
wxArrayString paths;
|
||||
open_dialog.GetPaths(paths);
|
||||
for (size_t i = 0, i_end = paths.GetCount(); i < i_end; i++) {
|
||||
// Load certificate(s) from file.
|
||||
winstd::cert_store cs;
|
||||
if (cs.create(CERT_STORE_PROV_FILENAME, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, NULL, CERT_STORE_OPEN_EXISTING_FLAG | CERT_STORE_READONLY_FLAG, (LPCTSTR)(paths[i]))) {
|
||||
for (PCCERT_CONTEXT cert = NULL; (cert = CertEnumCertificatesInStore(cs, cert)) != NULL;)
|
||||
AddRootCA(cert);
|
||||
} else
|
||||
wxMessageBox(wxString::Format(_("Invalid or unsupported certificate file %s"), paths[i]), _("Error"), wxOK | wxICON_EXCLAMATION, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void wxTLSServerTrustPanel::OnRootCARemove(wxCommandEvent& event)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(event);
|
||||
|
||||
wxArrayInt selections;
|
||||
for (int i = m_root_ca->GetSelections(selections); i--; )
|
||||
m_root_ca->Delete(selections[i]);
|
||||
}
|
||||
|
||||
|
||||
bool wxTLSServerTrustPanel::AddRootCA(PCCERT_CONTEXT cert)
|
||||
{
|
||||
for (unsigned int i = 0, i_end = m_root_ca->GetCount(); i < i_end; i++) {
|
||||
wxCertificateClientData *c = dynamic_cast<wxCertificateClientData*>(m_root_ca->GetClientObject(i));
|
||||
if (c && c->m_cert &&
|
||||
c->m_cert->cbCertEncoded == cert->cbCertEncoded &&
|
||||
memcmp(c->m_cert->pbCertEncoded, cert->pbCertEncoded, cert->cbCertEncoded) == 0)
|
||||
{
|
||||
// This certificate is already on the list.
|
||||
m_root_ca->SetSelection(i);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Add certificate to the list.
|
||||
int i = m_root_ca->Append(wxString(eap::get_cert_title(cert)), new wxCertificateClientData(CertDuplicateCertificateContext(cert)));
|
||||
if (0 <= i)
|
||||
m_root_ca->SetSelection(i);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// wxTLSConfigPanel
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
wxTLSConfigPanel::wxTLSConfigPanel(const eap::config_provider &prov, eap::config_method_tls &cfg, LPCTSTR pszCredTarget, wxWindow* parent) : wxPanel(parent)
|
||||
{
|
||||
wxBoxSizer* sb_content;
|
||||
sb_content = new wxBoxSizer( wxVERTICAL );
|
||||
|
||||
m_server_trust = new wxTLSServerTrustPanel(prov, cfg, this);
|
||||
sb_content->Add(m_server_trust, 0, wxDOWN|wxEXPAND, 5);
|
||||
|
||||
m_credentials = new wxTLSCredentialsConfigPanel(prov, cfg, pszCredTarget, this);
|
||||
sb_content->Add(m_credentials, 0, wxUP|wxEXPAND, 5);
|
||||
|
||||
this->SetSizer(sb_content);
|
||||
this->Layout();
|
||||
|
||||
// Connect Events
|
||||
this->Connect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(wxTLSConfigPanel::OnInitDialog));
|
||||
}
|
||||
|
||||
|
||||
wxTLSConfigPanel::~wxTLSConfigPanel()
|
||||
{
|
||||
// Disconnect Events
|
||||
this->Disconnect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(wxTLSConfigPanel::OnInitDialog));
|
||||
}
|
||||
|
||||
|
||||
void wxTLSConfigPanel::OnInitDialog(wxInitDialogEvent& event)
|
||||
{
|
||||
// Forward the event to child panels.
|
||||
m_server_trust->GetEventHandler()->ProcessEvent(event);
|
||||
if (m_credentials)
|
||||
m_credentials->GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
|
@ -75,13 +75,13 @@ namespace eap
|
||||
/// - \c false otherwise. See \p ppEapError for details.
|
||||
///
|
||||
virtual bool get_identity(
|
||||
_In_ DWORD dwFlags,
|
||||
_In_ const config_providers_type &cfg,
|
||||
_Inout_ credentials_type &cred,
|
||||
_In_ HANDLE hTokenImpersonateUser,
|
||||
_Out_ BOOL *pfInvokeUI,
|
||||
_Out_ WCHAR **ppwszIdentity,
|
||||
_Out_ EAP_ERROR **ppEapError);
|
||||
_In_ DWORD dwFlags,
|
||||
_In_ const config_providers &cfg,
|
||||
_Inout_ credentials_type &cred,
|
||||
_In_ HANDLE hTokenImpersonateUser,
|
||||
_Out_ BOOL *pfInvokeUI,
|
||||
_Out_ WCHAR **ppwszIdentity,
|
||||
_Out_ EAP_ERROR **ppEapError);
|
||||
|
||||
///
|
||||
/// Defines the implementation of an EAP method-specific function that retrieves the properties of an EAP method given the connection and user data.
|
||||
@ -96,7 +96,7 @@ namespace eap
|
||||
_In_ DWORD dwVersion,
|
||||
_In_ DWORD dwFlags,
|
||||
_In_ HANDLE hUserImpersonationToken,
|
||||
_In_ const config_providers_type &cfg,
|
||||
_In_ const config_providers &cfg,
|
||||
_In_ const credentials_type &cred,
|
||||
_Out_ EAP_METHOD_PROPERTY_ARRAY *pMethodPropertyArray,
|
||||
_Out_ EAP_ERROR **ppEapError) const;
|
||||
|
@ -59,13 +59,13 @@ bool eap::peer_ttls::shutdown(_Out_ EAP_ERROR **ppEapError)
|
||||
|
||||
|
||||
bool eap::peer_ttls::get_identity(
|
||||
_In_ DWORD dwFlags,
|
||||
_In_ const config_providers_type &cfg,
|
||||
_Inout_ credentials_type &cred,
|
||||
_In_ HANDLE hTokenImpersonateUser,
|
||||
_Out_ BOOL *pfInvokeUI,
|
||||
_Out_ WCHAR **ppwszIdentity,
|
||||
_Out_ EAP_ERROR **ppEapError)
|
||||
_In_ DWORD dwFlags,
|
||||
_In_ const config_providers &cfg,
|
||||
_Inout_ credentials_type &cred,
|
||||
_In_ HANDLE hTokenImpersonateUser,
|
||||
_Out_ BOOL *pfInvokeUI,
|
||||
_Out_ WCHAR **ppwszIdentity,
|
||||
_Out_ EAP_ERROR **ppEapError)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(dwFlags);
|
||||
UNREFERENCED_PARAMETER(cfg);
|
||||
@ -84,7 +84,7 @@ bool eap::peer_ttls::get_method_properties(
|
||||
_In_ DWORD dwVersion,
|
||||
_In_ DWORD dwFlags,
|
||||
_In_ HANDLE hUserImpersonationToken,
|
||||
_In_ const config_providers_type &cfg,
|
||||
_In_ const config_providers &cfg,
|
||||
_In_ const credentials_type &cred,
|
||||
_Out_ EAP_METHOD_PROPERTY_ARRAY *pMethodPropertyArray,
|
||||
_Out_ EAP_ERROR **ppEapError) const
|
||||
|
@ -93,6 +93,7 @@
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\TTLS_UI.cpp" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\res\wxTTLS_UI.fbp" />
|
||||
|
@ -38,6 +38,9 @@
|
||||
<ClCompile Include="..\src\Module.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\TTLS_UI.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\res\wxTTLS_UI.fbp">
|
||||
|
@ -57,9 +57,9 @@ namespace eap
|
||||
/// - \c false otherwise. See \p ppEapError for details.
|
||||
///
|
||||
virtual bool invoke_config_ui(
|
||||
_In_ HWND hwndParent,
|
||||
_Inout_ config_providers_type &cfg,
|
||||
_Out_ EAP_ERROR **ppEapError);
|
||||
_In_ HWND hwndParent,
|
||||
_Inout_ config_providers &cfg,
|
||||
_Out_ EAP_ERROR **ppEapError);
|
||||
|
||||
///
|
||||
/// Raises a custom interactive user interface dialog to obtain user identity information for the EAP method on the client.
|
||||
@ -78,12 +78,12 @@ namespace eap
|
||||
/// - \c false otherwise. See \p ppEapError for details.
|
||||
///
|
||||
virtual bool invoke_identity_ui(
|
||||
_In_ HWND hwndParent,
|
||||
_In_ DWORD dwFlags,
|
||||
_Inout_ config_providers_type &cfg,
|
||||
_Inout_ credentials_type &cred,
|
||||
_Out_ LPWSTR *ppwszIdentity,
|
||||
_Out_ EAP_ERROR **ppEapError);
|
||||
_In_ HWND hwndParent,
|
||||
_In_ DWORD dwFlags,
|
||||
_Inout_ config_providers &cfg,
|
||||
_Inout_ credentials_type &cred,
|
||||
_Out_ LPWSTR *ppwszIdentity,
|
||||
_Out_ EAP_ERROR **ppEapError);
|
||||
|
||||
///
|
||||
/// Raises a custom interactive user interface dialog for the EAP method on the client.
|
||||
|
@ -21,12 +21,12 @@
|
||||
///
|
||||
/// TTLS configuration panel
|
||||
///
|
||||
template <class _Tprov> class wxTTLSConfigPanel;
|
||||
class wxTTLSConfigPanel;
|
||||
|
||||
///
|
||||
/// TTLS configuration scrollable window
|
||||
///
|
||||
template <class _Tprov> class wxTTLSConfigWindow;
|
||||
class wxTTLSConfigWindow;
|
||||
|
||||
#pragma once
|
||||
|
||||
@ -46,89 +46,29 @@ template <class _Tprov> class wxTTLSConfigWindow;
|
||||
#include <Windows.h>
|
||||
|
||||
|
||||
template <class _Tprov>
|
||||
class wxTTLSConfigPanel : public wxTTLSConfigPanelBase
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Constructs a configuration panel
|
||||
///
|
||||
wxTTLSConfigPanel(_Tprov &prov, eap::config_method_ttls &cfg, wxWindow* parent) :
|
||||
m_prov(prov),
|
||||
m_cfg(cfg),
|
||||
wxTTLSConfigPanelBase(parent)
|
||||
{
|
||||
// Load and set icon.
|
||||
if (m_shell32.load(_T("shell32.dll"), NULL, LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE))
|
||||
wxSetIconFromResource(m_outer_identity_icon, m_icon, m_shell32, MAKEINTRESOURCE(265));
|
||||
}
|
||||
wxTTLSConfigPanel(const eap::config_provider &prov, eap::config_method_ttls &cfg, wxWindow* parent);
|
||||
|
||||
protected:
|
||||
/// \cond internal
|
||||
|
||||
virtual bool TransferDataToWindow()
|
||||
{
|
||||
if (m_prov.m_read_only) {
|
||||
// This is provider-locked configuration. Disable controls.
|
||||
m_outer_identity_same ->Enable(false);
|
||||
m_outer_identity_empty ->Enable(false);
|
||||
m_outer_identity_custom ->Enable(false);
|
||||
m_outer_identity_custom_val->Enable(false);
|
||||
}
|
||||
|
||||
// Populate identity controls.
|
||||
if (m_cfg.m_anonymous_identity.empty()) {
|
||||
m_outer_identity_same->SetValue(true);
|
||||
} else if (m_cfg.m_anonymous_identity == L"@") {
|
||||
m_outer_identity_empty->SetValue(true);
|
||||
} else {
|
||||
m_outer_identity_custom->SetValue(true);
|
||||
m_outer_identity_custom_val->SetValue(m_cfg.m_anonymous_identity);
|
||||
}
|
||||
|
||||
return wxTTLSConfigPanelBase::TransferDataToWindow();
|
||||
}
|
||||
|
||||
|
||||
virtual bool TransferDataFromWindow()
|
||||
{
|
||||
wxCHECK(wxTTLSConfigPanelBase::TransferDataFromWindow(), false);
|
||||
|
||||
if (!m_prov.m_read_only) {
|
||||
// This is not a provider-locked configuration. Save the data.
|
||||
if (m_outer_identity_same->GetValue())
|
||||
m_cfg.m_anonymous_identity.clear();
|
||||
else if (m_outer_identity_empty->GetValue())
|
||||
m_cfg.m_anonymous_identity = L"@";
|
||||
else
|
||||
m_cfg.m_anonymous_identity = m_outer_identity_custom_val->GetValue();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
virtual void OnUpdateUI(wxUpdateUIEvent& event)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(event);
|
||||
|
||||
if (!m_prov.m_read_only) {
|
||||
// This is not a provider-locked configuration. Selectively enable/disable controls.
|
||||
m_outer_identity_custom_val->Enable(m_outer_identity_custom->GetValue());
|
||||
}
|
||||
}
|
||||
|
||||
virtual bool TransferDataToWindow();
|
||||
virtual bool TransferDataFromWindow();
|
||||
virtual void OnUpdateUI(wxUpdateUIEvent& event);
|
||||
/// \endcond
|
||||
|
||||
protected:
|
||||
_Tprov &m_prov; ///< EAP provider
|
||||
eap::config_method_ttls &m_cfg; ///< TTLS configuration
|
||||
winstd::library m_shell32; ///< shell32.dll resource library reference
|
||||
wxIcon m_icon; ///< Panel icon
|
||||
const eap::config_provider &m_prov; ///< EAP provider
|
||||
eap::config_method_ttls &m_cfg; ///< TTLS configuration
|
||||
winstd::library m_shell32; ///< shell32.dll resource library reference
|
||||
wxIcon m_icon; ///< Panel icon
|
||||
};
|
||||
|
||||
|
||||
template <class _Tprov>
|
||||
class wxTTLSConfigWindow : public wxScrolledWindow
|
||||
{
|
||||
public:
|
||||
@ -139,135 +79,28 @@ public:
|
||||
/// \param[in] pszCredTarget Target name of credentials in Windows Credential Manager. Can be further decorated to create final target name.
|
||||
/// \param[in] parent Parent window
|
||||
///
|
||||
wxTTLSConfigWindow(_Tprov &prov, eap::config_method &cfg, LPCTSTR pszCredTarget, wxWindow* parent) :
|
||||
m_prov(prov),
|
||||
m_cfg((eap::config_method_ttls&)cfg),
|
||||
m_cfg_pap(cfg.m_module),
|
||||
wxScrolledWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL)
|
||||
{
|
||||
wxBoxSizer* sb_content;
|
||||
sb_content = new wxBoxSizer( wxVERTICAL );
|
||||
|
||||
if (prov.m_read_only)
|
||||
sb_content->Add(new wxEAPProviderLockedPanel<_Tprov>(prov, this), 0, wxALL|wxEXPAND, 5);
|
||||
|
||||
m_inner_title = new wxStaticText(this, wxID_ANY, _("Inner Authentication"), wxDefaultPosition, wxDefaultSize, 0);
|
||||
m_inner_title->SetFont(wxFont(18, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxEmptyString));
|
||||
m_inner_title->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_INACTIVECAPTION ) );
|
||||
sb_content->Add(m_inner_title, 0, wxALL|wxALIGN_RIGHT, 5);
|
||||
|
||||
m_inner_type = new wxChoicebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxCHB_DEFAULT);
|
||||
m_inner_type->SetToolTip( _("Select inner authentication method from the list") );
|
||||
m_inner_type->AddPage(new wxPAPConfigPanel<_Tprov>(prov, m_cfg_pap, pszCredTarget, m_inner_type), _("PAP"));
|
||||
sb_content->Add(m_inner_type, 0, wxALL|wxEXPAND, 5);
|
||||
|
||||
sb_content->Add(20, 20, 1, wxALL|wxEXPAND, 5);
|
||||
|
||||
m_outer_title = new wxStaticText(this, wxID_ANY, _("Outer Authentication"), wxDefaultPosition, wxDefaultSize, 0);
|
||||
m_outer_title->SetFont(wxFont(18, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxEmptyString));
|
||||
m_outer_title->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_INACTIVECAPTION ) );
|
||||
sb_content->Add(m_outer_title, 0, wxALL|wxALIGN_RIGHT, 5);
|
||||
|
||||
m_outer_identity = new wxTTLSConfigPanel<_Tprov>(prov, m_cfg, this);
|
||||
sb_content->Add(m_outer_identity, 0, wxALL|wxEXPAND, 5);
|
||||
|
||||
m_tls = new wxTLSConfigPanel<_Tprov>(prov, m_cfg, pszCredTarget, this);
|
||||
sb_content->Add(m_tls, 0, wxALL|wxEXPAND, 5);
|
||||
|
||||
wxSize size = sb_content->CalcMin();
|
||||
if (size.y > 500) {
|
||||
// Increase the width to allow space for vertical scroll bar (to prevent horizontal one) and truncate the height.
|
||||
size.x += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X, this);
|
||||
size.y = 500;
|
||||
}
|
||||
this->SetMinSize(size);
|
||||
this->SetScrollRate(5, 5);
|
||||
|
||||
this->SetSizer(sb_content);
|
||||
this->Layout();
|
||||
|
||||
m_inner_type->SetFocusFromKbd();
|
||||
|
||||
// Connect Events
|
||||
this->Connect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(wxTTLSConfigWindow::OnInitDialog));
|
||||
}
|
||||
|
||||
wxTTLSConfigWindow(const eap::config_provider &prov, eap::config_method &cfg, LPCTSTR pszCredTarget, wxWindow* parent);
|
||||
|
||||
///
|
||||
/// Destructs the configuration panel
|
||||
///
|
||||
virtual ~wxTTLSConfigWindow()
|
||||
{
|
||||
// Disconnect Events
|
||||
this->Disconnect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(wxTTLSConfigWindow::OnInitDialog));
|
||||
}
|
||||
|
||||
virtual ~wxTTLSConfigWindow();
|
||||
|
||||
protected:
|
||||
/// \cond internal
|
||||
|
||||
virtual bool TransferDataToWindow()
|
||||
{
|
||||
if (m_prov.m_read_only) {
|
||||
// This is provider-locked configuration. Disable controls.
|
||||
m_inner_type->GetChoiceCtrl()->Enable(false);
|
||||
}
|
||||
|
||||
eap::config_method_pap *cfg_pap = dynamic_cast<eap::config_method_pap*>(m_cfg.m_inner.get());
|
||||
if (cfg_pap) {
|
||||
m_cfg_pap = *cfg_pap;
|
||||
m_inner_type->SetSelection(0); // 0=PAP
|
||||
} else
|
||||
wxFAIL_MSG(wxT("Unsupported inner authentication method type."));
|
||||
|
||||
// Do not invoke inherited TransferDataToWindow(), as it will call others TransferDataToWindow().
|
||||
// This will handle wxTTLSConfigWindow::OnInitDialog() via wxEVT_INIT_DIALOG forwarding.
|
||||
return true /*wxScrolledWindow::TransferDataToWindow()*/;
|
||||
}
|
||||
|
||||
|
||||
virtual bool TransferDataFromWindow()
|
||||
{
|
||||
wxCHECK(wxScrolledWindow::TransferDataFromWindow(), false);
|
||||
|
||||
if (!m_prov.m_read_only) {
|
||||
// This is not a provider-locked configuration. Save the data.
|
||||
switch (m_inner_type->GetSelection()) {
|
||||
case 0: // 0=PAP
|
||||
m_cfg.m_inner.reset(new eap::config_method_pap(m_cfg_pap));
|
||||
break;
|
||||
|
||||
default:
|
||||
wxFAIL_MSG(wxT("Unsupported inner authentication method type."));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
virtual void OnInitDialog(wxInitDialogEvent& event)
|
||||
{
|
||||
// Call TransferDataToWindow() manually, as wxScrolledWindow somehow skips that.
|
||||
TransferDataToWindow();
|
||||
|
||||
// Forward the event to child panels.
|
||||
m_outer_identity->GetEventHandler()->ProcessEvent(event);
|
||||
m_tls->GetEventHandler()->ProcessEvent(event);
|
||||
for (wxWindowList::compatibility_iterator inner = m_inner_type->GetChildren().GetFirst(); inner; inner = inner->GetNext())
|
||||
inner->GetData()->GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
|
||||
virtual bool TransferDataToWindow();
|
||||
virtual bool TransferDataFromWindow();
|
||||
virtual void OnInitDialog(wxInitDialogEvent& event);
|
||||
/// \endcond
|
||||
|
||||
protected:
|
||||
_Tprov &m_prov; ///< EAP provider
|
||||
eap::config_method_ttls &m_cfg; ///< TTLS configuration
|
||||
wxStaticText *m_outer_title; ///< Outer authentication title
|
||||
wxTTLSConfigPanel<_Tprov> *m_outer_identity; ///< Outer identity configuration panel
|
||||
wxTLSConfigPanel<_Tprov> *m_tls; ///< TLS configuration panel
|
||||
wxStaticText *m_inner_title; ///< Inner authentication title
|
||||
wxChoicebook *m_inner_type; ///< Inner authentication type
|
||||
const eap::config_provider &m_prov; ///< EAP provider
|
||||
eap::config_method_ttls &m_cfg; ///< TTLS configuration
|
||||
wxStaticText *m_outer_title; ///< Outer authentication title
|
||||
wxTTLSConfigPanel *m_outer_identity; ///< Outer identity configuration panel
|
||||
wxTLSConfigPanel *m_tls; ///< TLS configuration panel
|
||||
wxStaticText *m_inner_title; ///< Inner authentication title
|
||||
wxChoicebook *m_inner_type; ///< Inner authentication type
|
||||
|
||||
// Temprary inner method configurations to hold data until applied
|
||||
eap::config_method_pap m_cfg_pap; ///< PAP configuration
|
||||
|
@ -31,9 +31,9 @@ eap::peer_ttls_ui::peer_ttls_ui() : peer_ui<eap::config_method_ttls, eap::creden
|
||||
|
||||
|
||||
bool eap::peer_ttls_ui::invoke_config_ui(
|
||||
_In_ HWND hwndParent,
|
||||
_Inout_ config_providers_type &cfg,
|
||||
_Out_ EAP_ERROR **ppEapError)
|
||||
_In_ HWND hwndParent,
|
||||
_Inout_ config_providers &cfg,
|
||||
_Out_ EAP_ERROR **ppEapError)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(ppEapError);
|
||||
|
||||
@ -50,7 +50,7 @@ bool eap::peer_ttls_ui::invoke_config_ui(
|
||||
wxTopLevelWindows.Append(&parent);
|
||||
|
||||
// Create and launch configuration dialog.
|
||||
wxEAPConfigDialog<config_method_ttls, wxTTLSConfigWindow<config_provider_type> > dlg(cfg, &parent);
|
||||
wxEAPConfigDialog<config_method_ttls, wxTTLSConfigWindow> dlg(cfg, &parent);
|
||||
result = dlg.ShowModal();
|
||||
|
||||
wxTopLevelWindows.DeleteObject(&parent);
|
||||
@ -69,12 +69,12 @@ bool eap::peer_ttls_ui::invoke_config_ui(
|
||||
|
||||
|
||||
bool eap::peer_ttls_ui::invoke_identity_ui(
|
||||
_In_ HWND hwndParent,
|
||||
_In_ DWORD dwFlags,
|
||||
_Inout_ config_providers_type &cfg,
|
||||
_Inout_ credentials_type &cred,
|
||||
_Out_ LPWSTR *ppwszIdentity,
|
||||
_Out_ EAP_ERROR **ppEapError)
|
||||
_In_ HWND hwndParent,
|
||||
_In_ DWORD dwFlags,
|
||||
_Inout_ config_providers &cfg,
|
||||
_Inout_ credentials_type &cred,
|
||||
_Out_ LPWSTR *ppwszIdentity,
|
||||
_Out_ EAP_ERROR **ppEapError)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(dwFlags);
|
||||
UNREFERENCED_PARAMETER(cfg);
|
||||
|
207
lib/TTLS_UI/src/TTLS_UI.cpp
Normal file
207
lib/TTLS_UI/src/TTLS_UI.cpp
Normal file
@ -0,0 +1,207 @@
|
||||
/*
|
||||
Copyright 2015-2016 Amebis
|
||||
Copyright 2016 GÉANT
|
||||
|
||||
This file is part of GÉANTLink.
|
||||
|
||||
GÉANTLink is free software: you can redistribute it and/or modify it
|
||||
under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GÉANTLink is distributed in the hope that it will be useful, but
|
||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GÉANTLink. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// wxTTLSConfigPanel
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
wxTTLSConfigPanel::wxTTLSConfigPanel(const eap::config_provider &prov, eap::config_method_ttls &cfg, wxWindow* parent) :
|
||||
m_prov(prov),
|
||||
m_cfg(cfg),
|
||||
wxTTLSConfigPanelBase(parent)
|
||||
{
|
||||
// Load and set icon.
|
||||
if (m_shell32.load(_T("shell32.dll"), NULL, LOAD_LIBRARY_AS_DATAFILE | LOAD_LIBRARY_AS_IMAGE_RESOURCE))
|
||||
wxSetIconFromResource(m_outer_identity_icon, m_icon, m_shell32, MAKEINTRESOURCE(265));
|
||||
}
|
||||
|
||||
|
||||
bool wxTTLSConfigPanel::TransferDataToWindow()
|
||||
{
|
||||
if (m_prov.m_read_only) {
|
||||
// This is provider-locked configuration. Disable controls.
|
||||
m_outer_identity_same ->Enable(false);
|
||||
m_outer_identity_empty ->Enable(false);
|
||||
m_outer_identity_custom ->Enable(false);
|
||||
m_outer_identity_custom_val->Enable(false);
|
||||
}
|
||||
|
||||
// Populate identity controls.
|
||||
if (m_cfg.m_anonymous_identity.empty()) {
|
||||
m_outer_identity_same->SetValue(true);
|
||||
} else if (m_cfg.m_anonymous_identity == L"@") {
|
||||
m_outer_identity_empty->SetValue(true);
|
||||
} else {
|
||||
m_outer_identity_custom->SetValue(true);
|
||||
m_outer_identity_custom_val->SetValue(m_cfg.m_anonymous_identity);
|
||||
}
|
||||
|
||||
return wxTTLSConfigPanelBase::TransferDataToWindow();
|
||||
}
|
||||
|
||||
|
||||
bool wxTTLSConfigPanel::TransferDataFromWindow()
|
||||
{
|
||||
wxCHECK(wxTTLSConfigPanelBase::TransferDataFromWindow(), false);
|
||||
|
||||
if (!m_prov.m_read_only) {
|
||||
// This is not a provider-locked configuration. Save the data.
|
||||
if (m_outer_identity_same->GetValue())
|
||||
m_cfg.m_anonymous_identity.clear();
|
||||
else if (m_outer_identity_empty->GetValue())
|
||||
m_cfg.m_anonymous_identity = L"@";
|
||||
else
|
||||
m_cfg.m_anonymous_identity = m_outer_identity_custom_val->GetValue();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void wxTTLSConfigPanel::OnUpdateUI(wxUpdateUIEvent& event)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(event);
|
||||
|
||||
if (!m_prov.m_read_only) {
|
||||
// This is not a provider-locked configuration. Selectively enable/disable controls.
|
||||
m_outer_identity_custom_val->Enable(m_outer_identity_custom->GetValue());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// wxTTLSConfigWindow
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
wxTTLSConfigWindow::wxTTLSConfigWindow(const eap::config_provider &prov, eap::config_method &cfg, LPCTSTR pszCredTarget, wxWindow* parent) :
|
||||
m_prov(prov),
|
||||
m_cfg((eap::config_method_ttls&)cfg),
|
||||
m_cfg_pap(cfg.m_module),
|
||||
wxScrolledWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL)
|
||||
{
|
||||
wxBoxSizer* sb_content;
|
||||
sb_content = new wxBoxSizer( wxVERTICAL );
|
||||
|
||||
if (prov.m_read_only)
|
||||
sb_content->Add(new wxEAPProviderLockedPanel(prov, this), 0, wxALL|wxEXPAND, 5);
|
||||
|
||||
m_inner_title = new wxStaticText(this, wxID_ANY, _("Inner Authentication"), wxDefaultPosition, wxDefaultSize, 0);
|
||||
m_inner_title->SetFont(wxFont(18, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxEmptyString));
|
||||
m_inner_title->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_INACTIVECAPTION ) );
|
||||
sb_content->Add(m_inner_title, 0, wxALL|wxALIGN_RIGHT, 5);
|
||||
|
||||
m_inner_type = new wxChoicebook(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxCHB_DEFAULT);
|
||||
m_inner_type->SetToolTip( _("Select inner authentication method from the list") );
|
||||
m_inner_type->AddPage(new wxPAPConfigPanel(prov, m_cfg_pap, pszCredTarget, m_inner_type), _("PAP"));
|
||||
sb_content->Add(m_inner_type, 0, wxALL|wxEXPAND, 5);
|
||||
|
||||
sb_content->Add(20, 20, 1, wxALL|wxEXPAND, 5);
|
||||
|
||||
m_outer_title = new wxStaticText(this, wxID_ANY, _("Outer Authentication"), wxDefaultPosition, wxDefaultSize, 0);
|
||||
m_outer_title->SetFont(wxFont(18, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL, false, wxEmptyString));
|
||||
m_outer_title->SetForegroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_INACTIVECAPTION ) );
|
||||
sb_content->Add(m_outer_title, 0, wxALL|wxALIGN_RIGHT, 5);
|
||||
|
||||
m_outer_identity = new wxTTLSConfigPanel(prov, m_cfg, this);
|
||||
sb_content->Add(m_outer_identity, 0, wxALL|wxEXPAND, 5);
|
||||
|
||||
m_tls = new wxTLSConfigPanel(prov, m_cfg, pszCredTarget, this);
|
||||
sb_content->Add(m_tls, 0, wxALL|wxEXPAND, 5);
|
||||
|
||||
wxSize size = sb_content->CalcMin();
|
||||
if (size.y > 500) {
|
||||
// Increase the width to allow space for vertical scroll bar (to prevent horizontal one) and truncate the height.
|
||||
size.x += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X, this);
|
||||
size.y = 500;
|
||||
}
|
||||
this->SetMinSize(size);
|
||||
this->SetScrollRate(5, 5);
|
||||
|
||||
this->SetSizer(sb_content);
|
||||
this->Layout();
|
||||
|
||||
m_inner_type->SetFocusFromKbd();
|
||||
|
||||
// Connect Events
|
||||
this->Connect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(wxTTLSConfigWindow::OnInitDialog));
|
||||
}
|
||||
|
||||
|
||||
wxTTLSConfigWindow::~wxTTLSConfigWindow()
|
||||
{
|
||||
// Disconnect Events
|
||||
this->Disconnect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(wxTTLSConfigWindow::OnInitDialog));
|
||||
}
|
||||
|
||||
|
||||
bool wxTTLSConfigWindow::TransferDataToWindow()
|
||||
{
|
||||
if (m_prov.m_read_only) {
|
||||
// This is provider-locked configuration. Disable controls.
|
||||
m_inner_type->GetChoiceCtrl()->Enable(false);
|
||||
}
|
||||
|
||||
eap::config_method_pap *cfg_pap = dynamic_cast<eap::config_method_pap*>(m_cfg.m_inner.get());
|
||||
if (cfg_pap) {
|
||||
m_cfg_pap = *cfg_pap;
|
||||
m_inner_type->SetSelection(0); // 0=PAP
|
||||
} else
|
||||
wxFAIL_MSG(wxT("Unsupported inner authentication method type."));
|
||||
|
||||
// Do not invoke inherited TransferDataToWindow(), as it will call others TransferDataToWindow().
|
||||
// This will handle wxTTLSConfigWindow::OnInitDialog() via wxEVT_INIT_DIALOG forwarding.
|
||||
return true /*wxScrolledWindow::TransferDataToWindow()*/;
|
||||
}
|
||||
|
||||
|
||||
bool wxTTLSConfigWindow::TransferDataFromWindow()
|
||||
{
|
||||
wxCHECK(wxScrolledWindow::TransferDataFromWindow(), false);
|
||||
|
||||
if (!m_prov.m_read_only) {
|
||||
// This is not a provider-locked configuration. Save the data.
|
||||
switch (m_inner_type->GetSelection()) {
|
||||
case 0: // 0=PAP
|
||||
m_cfg.m_inner.reset(new eap::config_method_pap(m_cfg_pap));
|
||||
break;
|
||||
|
||||
default:
|
||||
wxFAIL_MSG(wxT("Unsupported inner authentication method type."));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void wxTTLSConfigWindow::OnInitDialog(wxInitDialogEvent& event)
|
||||
{
|
||||
// Call TransferDataToWindow() manually, as wxScrolledWindow somehow skips that.
|
||||
TransferDataToWindow();
|
||||
|
||||
// Forward the event to child panels.
|
||||
m_outer_identity->GetEventHandler()->ProcessEvent(event);
|
||||
m_tls->GetEventHandler()->ProcessEvent(event);
|
||||
for (wxWindowList::compatibility_iterator inner = m_inner_type->GetChildren().GetFirst(); inner; inner = inner->GetNext())
|
||||
inner->GetData()->GetEventHandler()->ProcessEvent(event);
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user