diff --git a/lib/EAPBase/include/Config.h b/lib/EAPBase/include/Config.h index 30dfc1f..d0c76d8 100644 --- a/lib/EAPBase/include/Config.h +++ b/lib/EAPBase/include/Config.h @@ -227,6 +227,12 @@ namespace eap template class config_method : public config { + public: + /// + /// Configuration credentials type + /// + typedef _Tcred credentials_type; + public: /// /// Constructs configuration @@ -420,13 +426,21 @@ namespace eap template class config_provider : public config { + public: + /// + /// Provider method configuration type + /// + typedef _Tmeth config_method_type; + public: /// /// Constructs configuration /// /// \param[in] mod Reference of the EAP module to use for global services /// - config_provider(_In_ module &mod) : config(mod) + config_provider(_In_ module &mod) : + m_read_only(false), + config(mod) { } @@ -436,7 +450,9 @@ namespace eap /// \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_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), @@ -451,7 +467,9 @@ namespace eap /// \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_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)), @@ -471,7 +489,9 @@ namespace eap { if (this != &other) { (config&)*this = other; + m_read_only = other.m_read_only; m_id = other.m_id; + m_name = other.m_name; 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; @@ -492,7 +512,9 @@ namespace eap { 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_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); @@ -529,6 +551,12 @@ namespace eap DWORD dwResult; HRESULT hr; + // + 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, 0, NULL, NULL, NULL, _T(__FUNCTION__) _T(" Error creating element."), NULL); + return false; + } + // if (!m_id.empty()) if ((dwResult = eapxml::put_element_value(pDoc, pConfigRoot, winstd::bstr(L"ID"), bstrNamespace, winstd::bstr(m_id))) != ERROR_SUCCESS) { @@ -543,6 +571,13 @@ namespace eap return false; } + // / + 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, 0, NULL, NULL, NULL, _T(__FUNCTION__) _T(" Error creating element."), NULL); + return false; + } + // / 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) { @@ -611,16 +646,24 @@ namespace eap std::wstring lang; LoadString(m_module.m_instance, 2, lang); + // + if ((dwResult = eapxml::get_element_value(pConfigRoot, winstd::bstr(L"eap-metadata:read-only"), &m_read_only)) != ERROR_SUCCESS) + m_read_only = true; + // m_id.clear(); eapxml::get_element_value(pConfigRoot, winstd::bstr(L"eap-metadata:ID"), m_id); // + m_name.clear(); m_lbl_alt_credential.clear(); m_lbl_alt_identity.clear(); m_lbl_alt_password.clear(); winstd::com_obj pXmlElProviderInfo; if (eapxml::select_element(pConfigRoot, winstd::bstr(L"eap-metadata:ProviderInfo"), &pXmlElProviderInfo) == ERROR_SUCCESS) { + // + eapxml::get_element_localized(pXmlElProviderInfo, winstd::bstr(L"eap-metadata:DisplayName"), lang.c_str(), m_name); + // eapxml::get_element_localized(pXmlElProviderInfo, winstd::bstr(L"eap-metadata:CredentialPrompt"), lang.c_str(), m_lbl_alt_credential); @@ -669,7 +712,9 @@ namespace eap /// @} public: + bool m_read_only; ///< Is profile read-only std::wstring m_id; ///< Profile ID + winstd::tstring m_name; ///< Provider name winstd::tstring m_lbl_alt_credential; ///< Alternative label for credential prompt winstd::tstring m_lbl_alt_identity; ///< Alternative label for identity prompt winstd::tstring m_lbl_alt_password; ///< Alternative label for password prompt @@ -887,7 +932,9 @@ namespace eapserial template inline void pack(_Inout_ unsigned char *&cursor, _In_ const eap::config_provider<_Tmeth> &val) { + pack(cursor, val.m_read_only ); pack(cursor, val.m_id ); + pack(cursor, val.m_name ); pack(cursor, val.m_lbl_alt_credential); pack(cursor, val.m_lbl_alt_identity ); pack(cursor, val.m_lbl_alt_password ); @@ -899,7 +946,9 @@ namespace eapserial inline size_t get_pk_size(const eap::config_provider<_Tmeth> &val) { return + get_pk_size(val.m_read_only ) + get_pk_size(val.m_id ) + + get_pk_size(val.m_name ) + get_pk_size(val.m_lbl_alt_credential) + get_pk_size(val.m_lbl_alt_identity ) + get_pk_size(val.m_lbl_alt_password ) + @@ -910,7 +959,9 @@ namespace eapserial template inline void unpack(_Inout_ const unsigned char *&cursor, _Out_ eap::config_provider<_Tmeth> &val) { + unpack(cursor, val.m_read_only ); unpack(cursor, val.m_id ); + unpack(cursor, val.m_name ); unpack(cursor, val.m_lbl_alt_credential); unpack(cursor, val.m_lbl_alt_identity ); unpack(cursor, val.m_lbl_alt_password ); diff --git a/lib/EAPBase/include/Module.h b/lib/EAPBase/include/Module.h index 557433e..2545e53 100644 --- a/lib/EAPBase/include/Module.h +++ b/lib/EAPBase/include/Module.h @@ -441,10 +441,15 @@ namespace eap class peer_base : public module { public: + /// + /// Provider configuration data type + /// + typedef config_provider<_Tcfg> provider_config_type; + /// /// Configuration data type /// - typedef config_providers > config_type; + typedef config_providers config_type; /// /// Identity data type diff --git a/lib/EAPBase/src/Credentials.cpp b/lib/EAPBase/src/Credentials.cpp index 5230c47..11098a8 100644 --- a/lib/EAPBase/src/Credentials.cpp +++ b/lib/EAPBase/src/Credentials.cpp @@ -280,7 +280,10 @@ bool eap::credentials_pass::retrieve(_In_ LPCTSTR pszTargetName, _Out_ EAP_ERROR return false; } - m_identity = cred->UserName; + if (cred->UserName) + m_identity = cred->UserName; + else + m_identity.clear(); // Decrypt the password using user's key. string password_base64; diff --git a/lib/EAPBase/src/Module.cpp b/lib/EAPBase/src/Module.cpp index d6645d4..589aee1 100644 --- a/lib/EAPBase/src/Module.cpp +++ b/lib/EAPBase/src/Module.cpp @@ -150,7 +150,7 @@ bool eap::module::encrypt(_In_ HCRYPTPROV hProv, _In_bytecount_(size) const void vector > buf(size); memcpy(buf.data(), data, size); if (!CryptGetKeyParam(key, KP_BLOCKLEN, dwBlockLen, 0)) dwBlockLen = 0; - buf.reserve((size + dwBlockLen - 1) / dwBlockLen * dwBlockLen); + buf.reserve(std::max((size + dwBlockLen - 1) / dwBlockLen, 1) * dwBlockLen); // Encrypt the data using our public key. if (!CryptEncrypt(key, hHash, TRUE, 0, buf)) { diff --git a/lib/EAPBase_UI/include/EAP_UI.h b/lib/EAPBase_UI/include/EAP_UI.h index bee7b67..3d955b5 100644 --- a/lib/EAPBase_UI/include/EAP_UI.h +++ b/lib/EAPBase_UI/include/EAP_UI.h @@ -26,7 +26,7 @@ /// /// EAP configuration dialog /// -template class wxEAPConfigDialog; +template class wxEAPConfigDialog; /// /// EAP credentials dialog @@ -38,15 +38,20 @@ class wxEAPCredentialsDialog; /// class wxEAPBannerPanel; +/// +/// EAP Provider-locked congifuration note +/// +template class wxEAPProviderLocked; + /// /// Base template for credentials configuration panel /// -template class wxEAPCredentialsConfigPanel; +template class wxEAPCredentialsConfigPanel; /// /// Base template for all credential panels /// -template class wxCredentialsPanel; +template class wxCredentialsPanel; /// /// Password credentials panel @@ -115,6 +120,7 @@ public: for (; method != method_end; ++method, count++) m_providers->AddPage( new _wxT( + *provider, provider->m_methods.front(), provider->m_id.c_str(), m_providers), @@ -182,18 +188,51 @@ protected: }; -template +template +class wxEAPProviderLocked : public wxEAPProviderLockedBase +{ +public: + /// + /// Constructs a notice pannel and set the title text + /// + wxEAPProviderLocked(_Tprov &prov, wxWindow* parent) : wxEAPProviderLockedBase(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."), + !prov.m_name.empty() ? prov.m_name.c_str() : + !prov.m_id .empty() ? winstd::string_printf(_("Your %ls provider"), prov.m_id.c_str()).c_str() : _("Your provider"))); + m_provider_locked_label->Wrap(452); + } + +protected: + /// \cond internal + virtual bool AcceptsFocusFromKeyboard() const { return false; } + /// \endcond + +protected: + winstd::library m_shell32; ///< shell32.dll resource library reference + wxIcon m_icon; ///< Panel icon +}; + + +template class wxEAPCredentialsConfigPanel : public wxEAPCredentialsConfigPanelBase { 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 /// - wxEAPCredentialsConfigPanel(_Tcfg &cfg, LPCTSTR pszCredTarget, wxWindow *parent) : + wxEAPCredentialsConfigPanel(_Tprov &prov, _Tmeth &cfg, LPCTSTR pszCredTarget, wxWindow *parent) : + m_prov(prov), m_cfg(cfg), m_target(pszCredTarget), m_cred(m_cfg.m_module), @@ -201,7 +240,7 @@ public: { // 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(48)); + wxSetIconFromResource(m_credentials_icon, m_icon, m_shell32, MAKEINTRESOURCE(/*16770*/269)); } protected: @@ -209,29 +248,41 @@ protected: virtual bool TransferDataToWindow() { - wxCHECK(wxEAPCredentialsConfigPanelBase::TransferDataToWindow(), false); + if (m_prov.m_read_only) { + // This is provider-locked configuration. Disable controls. + m_own ->Enable(false); + m_preshared ->Enable(false); + m_preshared_identity->Enable(false); + m_preshared_set ->Enable(false); + } if (!m_cfg.m_use_preshared) { m_own->SetValue(true); + m_cred.clear(); } else { m_preshared->SetValue(true); m_cred = m_cfg.m_preshared; } - return true; + return wxEAPCredentialsConfigPanelBase::TransferDataToWindow(); } virtual bool TransferDataFromWindow() { - if (m_own->GetValue()) { - m_cfg.m_use_preshared = false; - } else { - m_cfg.m_use_preshared = true; - m_cfg.m_preshared = m_cred; + wxCHECK(wxEAPCredentialsConfigPanelBase::TransferDataFromWindow(), false); + + if (!m_prov.m_read_only) { + // This is not a provider-locked configuration. Save the data. + if (m_own->GetValue()) { + m_cfg.m_use_preshared = false; + } else { + m_cfg.m_use_preshared = true; + m_cfg.m_preshared = m_cred; + } } - return wxEAPCredentialsConfigPanelBase::TransferDataFromWindow(); + return true; } @@ -240,33 +291,48 @@ protected: UNREFERENCED_PARAMETER(event); DWORD dwResult; - bool has_own; - std::unique_ptr > cred; - if (CredRead(m_cred.target_name(m_target.c_str()).c_str(), CRED_TYPE_GENERIC, 0, (PCREDENTIAL*)&cred)) { - m_identity_own->SetValue(cred->UserName && cred->UserName[0] != 0 ? cred->UserName : _("")); - has_own = true; - } else if ((dwResult = GetLastError()) == ERROR_NOT_FOUND) { - m_identity_own->Clear(); - has_own = false; + if (m_cfg.m_allow_save) { + bool has_own; + std::unique_ptr > cred; + if (CredRead(m_cred.target_name(m_target.c_str()).c_str(), CRED_TYPE_GENERIC, 0, (PCREDENTIAL*)&cred)) { + m_own_identity->SetValue(cred->UserName && cred->UserName[0] != 0 ? cred->UserName : _("")); + has_own = true; + } else if ((dwResult = GetLastError()) == ERROR_NOT_FOUND) { + m_own_identity->Clear(); + has_own = false; + } else { + m_own_identity->SetValue(wxString::Format(_(""), dwResult)); + has_own = true; + } + + if (m_own->GetValue()) { + m_own_identity->Enable(true); + m_own_set ->Enable(true); + m_own_clear ->Enable(has_own); + } else { + m_own_identity->Enable(false); + m_own_set ->Enable(false); + m_own_clear ->Enable(false); + } } else { - m_identity_own->SetValue(wxString::Format(_(""), dwResult)); - has_own = true; + m_own_identity->Clear(); + + m_own_identity->Enable(false); + m_own_set ->Enable(false); + m_own_clear ->Enable(false); } - if (m_own->GetValue()) { - m_identity_own ->Enable(true); - m_set_own ->Enable(true); - m_clear_own ->Enable(has_own); - m_identity_preshared->Enable(false); - m_identity_preshared->SetValue(wxEmptyString); - m_set_preshared ->Enable(false); - } else { - m_identity_own ->Enable(false); - m_set_own ->Enable(false); - m_clear_own ->Enable(false); - m_identity_preshared->Enable(true); - m_identity_preshared->SetValue(!m_cred.empty() ? m_cred.m_identity : _("")); - m_set_preshared ->Enable(true); + m_preshared_identity->SetValue(!m_cred.empty() ? m_cred.m_identity : _("")); + + if (!m_prov.m_read_only) { + // This is not a provider-locked configuration. Selectively enable/disable controls. + if (m_own->GetValue()) { + m_preshared_identity->Enable(false); + m_preshared_set ->Enable(false); + } else { + m_preshared_identity->Enable(true); + m_preshared_set ->Enable(true); + } } } @@ -277,7 +343,7 @@ protected: wxEAPCredentialsDialog dlg(this); - _Tpanel *panel = new _Tpanel(m_cred, m_target.c_str(), &dlg, true); + _wxT *panel = new _wxT(m_cred, m_target.c_str(), &dlg, true); dlg.AddContents((wxPanel**)&panel, 1); dlg.ShowModal(); @@ -299,7 +365,7 @@ protected: wxEAPCredentialsDialog dlg(this); - _Tpanel *panel = new _Tpanel(m_cred, _T(""), &dlg, true); + _wxT *panel = new _wxT(m_cred, _T(""), &dlg, true); dlg.AddContents((wxPanel**)&panel, 1); dlg.ShowModal(); @@ -308,17 +374,18 @@ protected: /// \endcond protected: - _Tcfg &m_cfg; ///< EAP configuration - winstd::library m_shell32; ///< shell32.dll resource library reference - wxIcon m_icon; ///< Panel icon - winstd::tstring m_target; ///< Credential Manager target + _Tprov &m_prov; ///< EAP provider + _Tmeth &m_cfg; ///< EAP configuration + winstd::library m_shell32; ///< shell32.dll resource library reference + wxIcon m_icon; ///< Panel icon + winstd::tstring m_target; ///< Credential Manager target private: - _Tcred m_cred; ///< Temporary credential data + typename _Tmeth::credentials_type m_cred; ///< Temporary credential data }; -template +template class wxCredentialsPanel : public _Tbase { public: @@ -348,8 +415,6 @@ protected: virtual bool TransferDataToWindow() { - wxCHECK(_Tbase::TransferDataToWindow(), false); - if (!m_target.empty()) { // Read credentials from Credential Manager EAP_ERROR *pEapError; @@ -363,12 +428,14 @@ protected: wxLogError(_("Reading credentials failed.")); } - return true; + return _Tbase::TransferDataToWindow(); } virtual bool TransferDataFromWindow() { + wxCHECK(_Tbase::TransferDataFromWindow(), false); + if (!m_target.empty()) { // Write credentials to credential manager. if (m_remember->GetValue()) { @@ -383,7 +450,7 @@ protected: } } - return _Tbase::TransferDataFromWindow(); + return true; } /// \endcond @@ -394,7 +461,7 @@ protected: }; -class wxPasswordCredentialsPanel : public wxCredentialsPanel +class wxPasswordCredentialsPanel : public wxCredentialsPanel { public: /// diff --git a/lib/EAPBase_UI/res/wxEAP_UI.cpp b/lib/EAPBase_UI/res/wxEAP_UI.cpp index 7e9f508..6082252 100644 --- a/lib/EAPBase_UI/res/wxEAP_UI.cpp +++ b/lib/EAPBase_UI/res/wxEAP_UI.cpp @@ -119,6 +119,35 @@ wxEAPBannerPanelBase::~wxEAPBannerPanelBase() { } +wxEAPProviderLockedBase::wxEAPProviderLockedBase( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) : wxPanel( parent, id, pos, size, style ) +{ + this->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_INFOBK ) ); + + wxBoxSizer* sb_provider_locked_horiz; + sb_provider_locked_horiz = new wxBoxSizer( wxHORIZONTAL ); + + m_provider_locked_icon = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 ); + sb_provider_locked_horiz->Add( m_provider_locked_icon, 0, wxALL, 5 ); + + wxBoxSizer* sb_provider_locked_vert; + sb_provider_locked_vert = new wxBoxSizer( wxVERTICAL ); + + m_provider_locked_label = new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 ); + m_provider_locked_label->Wrap( 452 ); + sb_provider_locked_vert->Add( m_provider_locked_label, 0, wxALL|wxEXPAND, 5 ); + + + sb_provider_locked_horiz->Add( sb_provider_locked_vert, 1, wxEXPAND, 5 ); + + + this->SetSizer( sb_provider_locked_horiz ); + this->Layout(); +} + +wxEAPProviderLockedBase::~wxEAPProviderLockedBase() +{ +} + wxEAPCredentialsConfigPanelBase::wxEAPCredentialsConfigPanelBase( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) : wxPanel( parent, id, pos, size, style ) { wxStaticBoxSizer* sb_credentials; @@ -151,10 +180,10 @@ wxEAPCredentialsConfigPanelBase::wxEAPCredentialsConfigPanelBase( wxWindow* pare sz_own_inner->Add( m_own, 2, wxEXPAND, 5 ); - m_identity_own = new wxTextCtrl( sb_credentials->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY ); - m_identity_own->SetToolTip( _("Enter your user name here (user@domain.org, DOMAINUser, etc.)") ); + m_own_identity = new wxTextCtrl( sb_credentials->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY ); + m_own_identity->SetToolTip( _("Enter your user name here (user@domain.org, DOMAINUser, etc.)") ); - sz_own_inner->Add( m_identity_own, 3, wxEXPAND|wxALIGN_CENTER_VERTICAL, 5 ); + sz_own_inner->Add( m_own_identity, 3, wxEXPAND|wxALIGN_CENTER_VERTICAL, 5 ); sz_own->Add( sz_own_inner, 1, wxEXPAND|wxBOTTOM, 5 ); @@ -162,15 +191,15 @@ wxEAPCredentialsConfigPanelBase::wxEAPCredentialsConfigPanelBase( wxWindow* pare wxBoxSizer* sb_buttons_own; sb_buttons_own = new wxBoxSizer( wxHORIZONTAL ); - m_clear_own = new wxButton( sb_credentials->GetStaticBox(), wxID_ANY, _("&Clear Credentials"), wxDefaultPosition, wxDefaultSize, 0 ); - m_clear_own->SetToolTip( _("Click to clear your credentials from Credential Manager.\nNote: You will be prompted to enter credentials when connecting.") ); + m_own_clear = new wxButton( sb_credentials->GetStaticBox(), wxID_ANY, _("&Clear Credentials"), wxDefaultPosition, wxDefaultSize, 0 ); + m_own_clear->SetToolTip( _("Click to clear your credentials from Credential Manager.\nNote: You will be prompted to enter credentials when connecting.") ); - sb_buttons_own->Add( m_clear_own, 0, wxRIGHT, 5 ); + sb_buttons_own->Add( m_own_clear, 0, wxRIGHT, 5 ); - m_set_own = new wxButton( sb_credentials->GetStaticBox(), wxID_ANY, _("&Set Credentials..."), wxDefaultPosition, wxDefaultSize, 0 ); - m_set_own->SetToolTip( _("Click here to set or modify your credentials") ); + m_own_set = new wxButton( sb_credentials->GetStaticBox(), wxID_ANY, _("&Set Credentials..."), wxDefaultPosition, wxDefaultSize, 0 ); + m_own_set->SetToolTip( _("Click here to set or modify your credentials") ); - sb_buttons_own->Add( m_set_own, 0, wxLEFT, 5 ); + sb_buttons_own->Add( m_own_set, 0, wxLEFT, 5 ); sz_own->Add( sb_buttons_own, 0, wxALIGN_RIGHT, 5 ); @@ -189,10 +218,10 @@ wxEAPCredentialsConfigPanelBase::wxEAPCredentialsConfigPanelBase( wxWindow* pare sz_preshared_inner->Add( m_preshared, 2, wxEXPAND, 5 ); - m_identity_preshared = new wxTextCtrl( sb_credentials->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY ); - m_identity_preshared->SetToolTip( _("Enter your user name here (user@domain.org, DOMAINUser, etc.)") ); + m_preshared_identity = new wxTextCtrl( sb_credentials->GetStaticBox(), wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_READONLY ); + m_preshared_identity->SetToolTip( _("Enter your user name here (user@domain.org, DOMAINUser, etc.)") ); - sz_preshared_inner->Add( m_identity_preshared, 3, wxEXPAND|wxALIGN_CENTER_VERTICAL, 5 ); + sz_preshared_inner->Add( m_preshared_identity, 3, wxEXPAND|wxALIGN_CENTER_VERTICAL, 5 ); sz_preshared->Add( sz_preshared_inner, 1, wxEXPAND|wxBOTTOM, 5 ); @@ -200,10 +229,10 @@ wxEAPCredentialsConfigPanelBase::wxEAPCredentialsConfigPanelBase( wxWindow* pare wxBoxSizer* sb_buttons_preshared; sb_buttons_preshared = new wxBoxSizer( wxHORIZONTAL ); - m_set_preshared = new wxButton( sb_credentials->GetStaticBox(), wxID_ANY, _("&Set Credentials..."), wxDefaultPosition, wxDefaultSize, 0 ); - m_set_preshared->SetToolTip( _("Click here to set or modify your credentials") ); + m_preshared_set = new wxButton( sb_credentials->GetStaticBox(), wxID_ANY, _("&Set Credentials..."), wxDefaultPosition, wxDefaultSize, 0 ); + m_preshared_set->SetToolTip( _("Click here to set or modify your credentials") ); - sb_buttons_preshared->Add( m_set_preshared, 0, 0, 5 ); + sb_buttons_preshared->Add( m_preshared_set, 0, 0, 5 ); sz_preshared->Add( sb_buttons_preshared, 0, wxALIGN_RIGHT, 5 ); @@ -226,18 +255,18 @@ wxEAPCredentialsConfigPanelBase::wxEAPCredentialsConfigPanelBase( wxWindow* pare // Connect Events this->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( wxEAPCredentialsConfigPanelBase::OnUpdateUI ) ); - m_clear_own->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxEAPCredentialsConfigPanelBase::OnClearOwn ), NULL, this ); - m_set_own->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxEAPCredentialsConfigPanelBase::OnSetOwn ), NULL, this ); - m_set_preshared->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxEAPCredentialsConfigPanelBase::OnSetPreshared ), NULL, this ); + m_own_clear->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxEAPCredentialsConfigPanelBase::OnClearOwn ), NULL, this ); + m_own_set->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxEAPCredentialsConfigPanelBase::OnSetOwn ), NULL, this ); + m_preshared_set->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxEAPCredentialsConfigPanelBase::OnSetPreshared ), NULL, this ); } wxEAPCredentialsConfigPanelBase::~wxEAPCredentialsConfigPanelBase() { // Disconnect Events this->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( wxEAPCredentialsConfigPanelBase::OnUpdateUI ) ); - m_clear_own->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxEAPCredentialsConfigPanelBase::OnClearOwn ), NULL, this ); - m_set_own->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxEAPCredentialsConfigPanelBase::OnSetOwn ), NULL, this ); - m_set_preshared->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxEAPCredentialsConfigPanelBase::OnSetPreshared ), NULL, this ); + m_own_clear->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxEAPCredentialsConfigPanelBase::OnClearOwn ), NULL, this ); + m_own_set->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxEAPCredentialsConfigPanelBase::OnSetOwn ), NULL, this ); + m_preshared_set->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxEAPCredentialsConfigPanelBase::OnSetPreshared ), NULL, this ); } diff --git a/lib/EAPBase_UI/res/wxEAP_UI.fbp b/lib/EAPBase_UI/res/wxEAP_UI.fbp index b3a8f98..58fd3a0 100644 --- a/lib/EAPBase_UI/res/wxEAP_UI.fbp +++ b/lib/EAPBase_UI/res/wxEAP_UI.fbp @@ -623,6 +623,240 @@ + + 0 + wxAUI_MGR_DEFAULT + wxSYS_COLOUR_INFOBK + + 1 + 1 + impl_virtual + + + 0 + wxID_ANY + + + wxEAPProviderLockedBase + + 500,-1 + + + + + wxSIMPLE_BORDER|wxTAB_TRAVERSAL + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + sb_provider_locked_horiz + wxHORIZONTAL + none + + 5 + wxALL + 0 + + 1 + 1 + 1 + 1 + + + + + + + Load From Icon Resource; ; [32; 32] + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + 0 + + + 0 + + 1 + m_provider_locked_icon + 1 + + + protected + 1 + + Resizable + 1 + + + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxEXPAND + 1 + + + sb_provider_locked_vert + wxVERTICAL + none + + 5 + wxALL|wxEXPAND + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + 1 + + 1 + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + + + 0 + + + 0 + + 1 + m_provider_locked_label + 1 + + + protected + 1 + + Resizable + 1 + + + + 0 + + + + + 452 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 wxAUI_MGR_DEFAULT @@ -1020,7 +1254,7 @@ 0 1 - m_identity_own + m_own_identity 1 @@ -1123,7 +1357,7 @@ 0 1 - m_clear_own + m_own_clear 1 @@ -1211,7 +1445,7 @@ 0 1 - m_set_own + m_own_set 1 @@ -1408,7 +1642,7 @@ 0 1 - m_identity_preshared + m_preshared_identity 1 @@ -1511,7 +1745,7 @@ 0 1 - m_set_preshared + m_preshared_set 1 @@ -1622,7 +1856,7 @@ - + wxID_ANY Client Credentials @@ -1630,11 +1864,11 @@ wxVERTICAL none - + 5 wxEXPAND 0 - + sb_credentials_horiz wxHORIZONTAL @@ -1720,11 +1954,11 @@ - + 5 wxEXPAND 1 - + sb_credentials_vert wxVERTICAL @@ -1812,11 +2046,11 @@ - + 5 wxEXPAND|wxALL 0 - + 2 wxBOTH 1 @@ -1828,11 +2062,11 @@ none 0 5 - + 5 wxEXPAND|wxALIGN_CENTER_VERTICAL 0 - + 1 1 1 @@ -1911,11 +2145,11 @@ - + 5 wxEXPAND|wxALIGN_CENTER_VERTICAL 2 - + 1 1 1 @@ -2002,11 +2236,11 @@ - + 5 wxEXPAND|wxALIGN_CENTER_VERTICAL 0 - + 1 1 1 @@ -2085,11 +2319,11 @@ - + 5 wxEXPAND|wxALIGN_CENTER_VERTICAL 2 - + 1 1 1 @@ -2178,11 +2412,11 @@ - + 5 wxALL|wxEXPAND 0 - + 1 1 1 diff --git a/lib/EAPBase_UI/res/wxEAP_UI.h b/lib/EAPBase_UI/res/wxEAP_UI.h index 4f04853..8513c0c 100644 --- a/lib/EAPBase_UI/res/wxEAP_UI.h +++ b/lib/EAPBase_UI/res/wxEAP_UI.h @@ -101,6 +101,24 @@ class wxEAPBannerPanelBase : public wxPanel }; +/////////////////////////////////////////////////////////////////////////////// +/// Class wxEAPProviderLockedBase +/////////////////////////////////////////////////////////////////////////////// +class wxEAPProviderLockedBase : public wxPanel +{ + private: + + protected: + wxStaticBitmap* m_provider_locked_icon; + wxStaticText* m_provider_locked_label; + + public: + + wxEAPProviderLockedBase( wxWindow* parent, wxWindowID id = wxID_ANY, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxSize( 500,-1 ), long style = wxSIMPLE_BORDER|wxTAB_TRAVERSAL ); + ~wxEAPProviderLockedBase(); + +}; + /////////////////////////////////////////////////////////////////////////////// /// Class wxEAPCredentialsConfigPanelBase /////////////////////////////////////////////////////////////////////////////// @@ -112,12 +130,12 @@ class wxEAPCredentialsConfigPanelBase : public wxPanel wxStaticBitmap* m_credentials_icon; wxStaticText* m_credentials_label; wxRadioButton* m_own; - wxTextCtrl* m_identity_own; - wxButton* m_clear_own; - wxButton* m_set_own; + wxTextCtrl* m_own_identity; + wxButton* m_own_clear; + wxButton* m_own_set; wxRadioButton* m_preshared; - wxTextCtrl* m_identity_preshared; - wxButton* m_set_preshared; + wxTextCtrl* m_preshared_identity; + wxButton* m_preshared_set; // Virtual event handlers, overide them in your derived class virtual void OnUpdateUI( wxUpdateUIEvent& event ) { event.Skip(); } diff --git a/lib/EAPBase_UI/src/EAP_UI.cpp b/lib/EAPBase_UI/src/EAP_UI.cpp index e6805b0..7cc45db 100644 --- a/lib/EAPBase_UI/src/EAP_UI.cpp +++ b/lib/EAPBase_UI/src/EAP_UI.cpp @@ -72,7 +72,7 @@ const wxStringCharType *wxPasswordCredentialsPanel::s_dummy_password = wxT("dumm wxPasswordCredentialsPanel::wxPasswordCredentialsPanel(eap::credentials_pass &cred, LPCTSTR pszCredTarget, wxWindow* parent, bool is_config) : - wxCredentialsPanel(cred, pszCredTarget, parent, is_config) + wxCredentialsPanel(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)) @@ -82,6 +82,8 @@ wxPasswordCredentialsPanel::wxPasswordCredentialsPanel(eap::credentials_pass &cr 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); @@ -102,5 +104,7 @@ bool wxPasswordCredentialsPanel::TransferDataFromWindow() pass.assign(pass.length(), wxT('*')); } + // Inherited TransferDataFromWindow() calls m_cred.store(). + // Therefore, call it only now, that m_cred is set. return __super::TransferDataFromWindow(); } diff --git a/lib/PAP_UI/build/PAP_UI.vcxproj b/lib/PAP_UI/build/PAP_UI.vcxproj index 9f128e9..b76f688 100644 --- a/lib/PAP_UI/build/PAP_UI.vcxproj +++ b/lib/PAP_UI/build/PAP_UI.vcxproj @@ -83,7 +83,6 @@ - Create Create diff --git a/lib/PAP_UI/build/PAP_UI.vcxproj.filters b/lib/PAP_UI/build/PAP_UI.vcxproj.filters index 9b71eac..a9d5f39d 100644 --- a/lib/PAP_UI/build/PAP_UI.vcxproj.filters +++ b/lib/PAP_UI/build/PAP_UI.vcxproj.filters @@ -26,8 +26,5 @@ Source Files - - Source Files - \ No newline at end of file diff --git a/lib/PAP_UI/include/PAP_UI.h b/lib/PAP_UI/include/PAP_UI.h index 8713136..62c61fb 100644 --- a/lib/PAP_UI/include/PAP_UI.h +++ b/lib/PAP_UI/include/PAP_UI.h @@ -25,12 +25,12 @@ /// /// PAP credentials configuration panel /// -typedef wxEAPCredentialsConfigPanel wxPAPCredentialsConfigPanel; +template class wxPAPCredentialsConfigPanel; /// /// PAP configuration panel /// -class wxPAPConfigPanel; +template class wxPAPConfigPanel; #pragma once @@ -40,25 +40,69 @@ class wxPAPConfigPanel; #include +template +class wxPAPCredentialsConfigPanel : public wxEAPCredentialsConfigPanel<_Tprov, eap::config_pap, wxPasswordCredentialsPanel> +{ +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_pap &cfg, LPCTSTR pszCredTarget, wxWindow *parent) : + wxEAPCredentialsConfigPanel<_Tprov, eap::config_pap, wxPasswordCredentialsPanel>(prov, cfg, pszCredTarget, parent) + { + } +}; + + +template class wxPAPConfigPanel : public wxPanel { public: /// /// Constructs a configuration panel /// - wxPAPConfigPanel(eap::config_pap &cfg, LPCTSTR pszCredTarget, wxWindow* parent); + wxPAPConfigPanel(_Tprov &prov, eap::config_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)); + } /// /// Destructs the configuration panel /// - virtual ~wxPAPConfigPanel(); + virtual ~wxPAPConfigPanel() + { + // Disconnect Events + this->Disconnect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(wxPAPConfigPanel::OnInitDialog)); + } + protected: /// \cond internal - virtual void OnInitDialog(wxInitDialogEvent& event); + + virtual void OnInitDialog(wxInitDialogEvent& event) + { + // Forward the event to child panels. + if (m_credentials) + m_credentials->GetEventHandler()->ProcessEvent(event); + } + /// \endcond protected: - wxPAPCredentialsConfigPanel *m_credentials; ///< Credentials configuration panel - wxStaticText *m_label; ///< No-configuration notice + wxPAPCredentialsConfigPanel<_Tprov> *m_credentials; ///< Credentials configuration panel }; diff --git a/lib/PAP_UI/src/PAP_UI.cpp b/lib/PAP_UI/src/PAP_UI.cpp deleted file mode 100644 index 1f617a0..0000000 --- a/lib/PAP_UI/src/PAP_UI.cpp +++ /dev/null @@ -1,66 +0,0 @@ -/* - 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 . -*/ - -#include "StdAfx.h" - - -////////////////////////////////////////////////////////////////////// -// wxPAPConfigPanel -////////////////////////////////////////////////////////////////////// - -wxPAPConfigPanel::wxPAPConfigPanel(eap::config_pap &cfg, LPCTSTR pszCredTarget, wxWindow* parent) : wxPanel(parent) -{ - wxBoxSizer* sb_content; - sb_content = new wxBoxSizer( wxVERTICAL ); - - if (cfg.m_allow_save) { - m_credentials = new wxPAPCredentialsConfigPanel(cfg, pszCredTarget, this); - sb_content->Add(m_credentials, 0, wxEXPAND, 5); - - m_label = NULL; - } else { - m_credentials = NULL; - - m_label = new wxStaticText(this, wxID_ANY, _("This method requires no additional settings."), wxDefaultPosition, wxDefaultSize, 0); - m_label->Wrap(-1); - sb_content->Add(m_label, 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); -} diff --git a/lib/TLS_UI/include/TLS_UI.h b/lib/TLS_UI/include/TLS_UI.h index d1c8c4a..3fac909 100644 --- a/lib/TLS_UI/include/TLS_UI.h +++ b/lib/TLS_UI/include/TLS_UI.h @@ -24,9 +24,16 @@ #include +#include +#include + +#include #include #include // Must include after +#include +#include + /// /// Helper class for auto-destroyable certificates used in wxWidget's item containers @@ -56,17 +63,17 @@ class wxEAPTLSCredentialsPanel; /// /// EAPTLS server trust configuration panel /// -class wxEAPTLSServerTrustPanel; +template class wxEAPTLSServerTrustPanel; /// /// TLS credentials configuration panel /// -typedef wxEAPCredentialsConfigPanel wxEAPTLSCredentialsConfigPanel; +template class wxEAPTLSCredentialsConfigPanel; /// /// EAPTLS configuration panel /// -class wxEAPTLSConfigPanel; +template class wxEAPTLSConfigPanel; namespace eap { @@ -249,7 +256,7 @@ protected: }; -class wxEAPTLSCredentialsPanel : public wxCredentialsPanel +class wxEAPTLSCredentialsPanel : public wxCredentialsPanel { public: /// @@ -270,23 +277,150 @@ protected: }; +template class wxEAPTLSServerTrustPanel : public wxEAPTLSServerTrustConfigPanelBase { public: /// /// Constructs a configuration panel /// - wxEAPTLSServerTrustPanel(eap::config_tls &cfg, wxWindow* parent); + wxEAPTLSServerTrustPanel(_Tprov &prov, eap::config_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)); + } protected: /// \cond internal - virtual bool TransferDataToWindow(); - virtual bool TransferDataFromWindow(); - virtual void OnRootCA(wxCommandEvent& event); - virtual void OnRootCADClick(wxCommandEvent& event); - virtual void OnRootCAAddStore(wxCommandEvent& event); - virtual void OnRootCAAddFile(wxCommandEvent& event); - virtual void OnRootCARemove(wxCommandEvent& event); + + 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::const_iterator cert = m_cfg.m_trusted_root_ca.cbegin(), cert_end = m_cfg.m_trusted_root_ca.cend(); cert != cert_end; ++cert) { + winstd::tstring name; + if (CertGetNameString(*cert, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, NULL, name) > 0) + m_root_ca->Append(wxString(name), 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(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(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]); + } + /// \endcond /// @@ -298,34 +432,110 @@ protected: /// - \c true if certificate was added; /// - \c false if duplicate found or an error occured. /// - bool AddRootCA(PCCERT_CONTEXT cert); + bool AddRootCA(PCCERT_CONTEXT cert) + { + for (unsigned int i = 0, i_end = m_root_ca->GetCount(); i < i_end; i++) { + wxCertificateClientData *c = dynamic_cast(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. + winstd::tstring name; + if (CertGetNameString(cert, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, NULL, name) > 0) { + int i = m_root_ca->Append(wxString(name), new wxCertificateClientData(CertDuplicateCertificateContext(cert))); + if (0 <= i) { + m_root_ca->SetSelection(i); + } + return true; + } + + return false; + } protected: - eap::config_tls &m_cfg; ///< TLS configuration - winstd::library m_certmgr; ///< certmgr.dll resource library reference - wxIcon m_icon; ///< Panel icon + _Tprov &m_prov; ///< EAP provider + eap::config_tls &m_cfg; ///< TLS configuration + winstd::library m_certmgr; ///< certmgr.dll resource library reference + wxIcon m_icon; ///< Panel icon + std::list m_server_names_val; ///< Acceptable authenticating server names }; +template +class wxEAPTLSCredentialsConfigPanel : public wxEAPCredentialsConfigPanel<_Tprov, eap::config_tls, wxEAPTLSCredentialsPanel> +{ +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 + /// + wxEAPTLSCredentialsConfigPanel(_Tprov &prov, eap::config_tls &cfg, LPCTSTR pszCredTarget, wxWindow *parent) : + wxEAPCredentialsConfigPanel<_Tprov, eap::config_tls, wxEAPTLSCredentialsPanel>(prov, cfg, pszCredTarget, parent) + { + } +}; + + +template class wxEAPTLSConfigPanel : public wxPanel { public: /// /// Constructs a configuration panel /// - wxEAPTLSConfigPanel(eap::config_tls &cfg, LPCTSTR pszCredTarget, wxWindow* parent); + wxEAPTLSConfigPanel(_Tprov &prov, eap::config_tls &cfg, LPCTSTR pszCredTarget, wxWindow* parent) : wxPanel(parent) + { + wxBoxSizer* sb_content; + sb_content = new wxBoxSizer( wxVERTICAL ); + + m_server_trust = new wxEAPTLSServerTrustPanel<_Tprov>(prov, cfg, this); + sb_content->Add(m_server_trust, 0, wxDOWN|wxEXPAND, 5); + + m_credentials = new wxEAPTLSCredentialsConfigPanel<_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(wxEAPTLSConfigPanel::OnInitDialog)); + } + /// /// Destructs the configuration panel /// - virtual ~wxEAPTLSConfigPanel(); + virtual ~wxEAPTLSConfigPanel() + { + // Disconnect Events + this->Disconnect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(wxEAPTLSConfigPanel::OnInitDialog)); + } protected: /// \cond internal - virtual void OnInitDialog(wxInitDialogEvent& event); + + 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); + } + /// \endcond protected: - wxEAPTLSServerTrustPanel *m_server_trust; ///< Server trust configuration panel - wxEAPTLSCredentialsConfigPanel *m_credentials; ///< Credentials configuration panel + wxEAPTLSServerTrustPanel<_Tprov> *m_server_trust; ///< Server trust configuration panel + wxEAPTLSCredentialsConfigPanel<_Tprov> *m_credentials; ///< Credentials configuration panel }; diff --git a/lib/TLS_UI/res/wxTLS_UI.cpp b/lib/TLS_UI/res/wxTLS_UI.cpp index 04ac84e..756f072 100644 --- a/lib/TLS_UI/res/wxTLS_UI.cpp +++ b/lib/TLS_UI/res/wxTLS_UI.cpp @@ -96,7 +96,7 @@ wxEAPTLSServerTrustConfigPanelBase::wxEAPTLSServerTrustConfigPanelBase( wxWindow this->Layout(); // Connect Events - m_root_ca->Connect( wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler( wxEAPTLSServerTrustConfigPanelBase::OnRootCA ), NULL, this ); + this->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( wxEAPTLSServerTrustConfigPanelBase::OnUpdateUI ) ); m_root_ca->Connect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEventHandler( wxEAPTLSServerTrustConfigPanelBase::OnRootCADClick ), NULL, this ); m_root_ca_add_store->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxEAPTLSServerTrustConfigPanelBase::OnRootCAAddStore ), NULL, this ); m_root_ca_add_file->Connect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxEAPTLSServerTrustConfigPanelBase::OnRootCAAddFile ), NULL, this ); @@ -106,7 +106,7 @@ wxEAPTLSServerTrustConfigPanelBase::wxEAPTLSServerTrustConfigPanelBase( wxWindow wxEAPTLSServerTrustConfigPanelBase::~wxEAPTLSServerTrustConfigPanelBase() { // Disconnect Events - m_root_ca->Disconnect( wxEVT_COMMAND_LISTBOX_SELECTED, wxCommandEventHandler( wxEAPTLSServerTrustConfigPanelBase::OnRootCA ), NULL, this ); + this->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( wxEAPTLSServerTrustConfigPanelBase::OnUpdateUI ) ); m_root_ca->Disconnect( wxEVT_COMMAND_LISTBOX_DOUBLECLICKED, wxCommandEventHandler( wxEAPTLSServerTrustConfigPanelBase::OnRootCADClick ), NULL, this ); m_root_ca_add_store->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxEAPTLSServerTrustConfigPanelBase::OnRootCAAddStore ), NULL, this ); m_root_ca_add_file->Disconnect( wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler( wxEAPTLSServerTrustConfigPanelBase::OnRootCAAddFile ), NULL, this ); diff --git a/lib/TLS_UI/res/wxTLS_UI.fbp b/lib/TLS_UI/res/wxTLS_UI.fbp index e2baaaf..5b886bf 100644 --- a/lib/TLS_UI/res/wxTLS_UI.fbp +++ b/lib/TLS_UI/res/wxTLS_UI.fbp @@ -77,7 +77,7 @@ - + OnUpdateUI wxID_ANY Server Trust @@ -431,7 +431,7 @@ - OnRootCA + OnRootCADClick diff --git a/lib/TLS_UI/res/wxTLS_UI.h b/lib/TLS_UI/res/wxTLS_UI.h index 8a98e75..c83fa76 100644 --- a/lib/TLS_UI/res/wxTLS_UI.h +++ b/lib/TLS_UI/res/wxTLS_UI.h @@ -53,7 +53,7 @@ class wxEAPTLSServerTrustConfigPanelBase : public wxPanel wxStaticText* m_server_names_note; // Virtual event handlers, overide them in your derived class - virtual void OnRootCA( wxCommandEvent& event ) { event.Skip(); } + virtual void OnUpdateUI( wxUpdateUIEvent& event ) { event.Skip(); } virtual void OnRootCADClick( wxCommandEvent& event ) { event.Skip(); } virtual void OnRootCAAddStore( wxCommandEvent& event ) { event.Skip(); } virtual void OnRootCAAddFile( wxCommandEvent& event ) { event.Skip(); } diff --git a/lib/TLS_UI/src/StdAfx.h b/lib/TLS_UI/src/StdAfx.h index 28e370b..082f7c3 100644 --- a/lib/TLS_UI/src/StdAfx.h +++ b/lib/TLS_UI/src/StdAfx.h @@ -25,8 +25,3 @@ #include "../../../include/Version.h" #include "../include/TLS_UI.h" - -#include -#include - -#include diff --git a/lib/TLS_UI/src/TLS_UI.cpp b/lib/TLS_UI/src/TLS_UI.cpp index b82a9f2..a6c015a 100644 --- a/lib/TLS_UI/src/TLS_UI.cpp +++ b/lib/TLS_UI/src/TLS_UI.cpp @@ -332,7 +332,7 @@ bool wxFQDNListValidator::Parse(const wxString &val_in, size_t i_start, size_t i // Skip trailing white-space. for (; i < i_end && _istspace(buf[i_end - 1]); i_end--); - if (wxHostNameValidator::Parse(val_in, i, i_end, ctrl, parent, fqdn)) { + if (wxFQDNValidator::Parse(val_in, i, i_end, ctrl, parent, fqdn)) { // The rest of the FQDN list parsed succesfully. if (fqdn && !fqdn->empty()) _val_out.push_back(std::move(*fqdn)); if (val_out) *val_out = std::move(_val_out); @@ -349,7 +349,7 @@ bool wxFQDNListValidator::Parse(const wxString &val_in, size_t i_start, size_t i ////////////////////////////////////////////////////////////////////// wxEAPTLSCredentialsPanel::wxEAPTLSCredentialsPanel(eap::credentials_tls &cred, LPCTSTR pszCredTarget, wxWindow* parent, bool is_config) : - wxCredentialsPanel(cred, pszCredTarget, parent, is_config) + wxCredentialsPanel(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)) @@ -359,8 +359,6 @@ wxEAPTLSCredentialsPanel::wxEAPTLSCredentialsPanel(eap::credentials_tls &cred, L bool wxEAPTLSCredentialsPanel::TransferDataToWindow() { - wxCHECK(__super::TransferDataToWindow(), false); - // Populate certificate list. bool is_found = false; winstd::cert_store store; @@ -400,7 +398,7 @@ bool wxEAPTLSCredentialsPanel::TransferDataToWindow() m_cert_select_val->SetSelection(0); } - return true; + return __super::TransferDataToWindow(); } @@ -419,6 +417,8 @@ bool wxEAPTLSCredentialsPanel::TransferDataFromWindow() m_cred.clear(); } + // Inherited TransferDataFromWindow() calls m_cred.store(). + // Therefore, call it only now, that m_cred is set. return __super::TransferDataFromWindow(); } @@ -428,192 +428,3 @@ void wxEAPTLSCredentialsPanel::OnCertSelect(wxCommandEvent& event) UNREFERENCED_PARAMETER(event); m_cert_select_val->Enable(m_cert_select->GetValue()); } - - -////////////////////////////////////////////////////////////////////// -// wxEAPTLSServerTrustPanel -////////////////////////////////////////////////////////////////////// - -wxEAPTLSServerTrustPanel::wxEAPTLSServerTrustPanel(eap::config_tls &cfg, wxWindow* parent) : - 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)); - - m_server_names->SetValidator(wxFQDNListValidator(&(m_cfg.m_server_names))); -} - - -bool wxEAPTLSServerTrustPanel::TransferDataToWindow() -{ - wxCHECK(wxEAPTLSServerTrustConfigPanelBase::TransferDataToWindow(), false); - - // Populate trusted CA list. - for (std::list::const_iterator cert = m_cfg.m_trusted_root_ca.cbegin(), cert_end = m_cfg.m_trusted_root_ca.cend(); cert != cert_end; ++cert) { - winstd::tstring name; - if (CertGetNameString(*cert, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, NULL, name) > 0) - m_root_ca->Append(wxString(name), new wxCertificateClientData(cert->duplicate())); - } - - return true; -} - - -bool wxEAPTLSServerTrustPanel::TransferDataFromWindow() -{ - // 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(m_root_ca->GetClientObject(i)); - if (cert) - m_cfg.add_trusted_ca(cert->m_cert->dwCertEncodingType, cert->m_cert->pbCertEncoded, cert->m_cert->cbCertEncoded); - } - - return wxEAPTLSServerTrustConfigPanelBase::TransferDataFromWindow(); -} - - -void wxEAPTLSServerTrustPanel::OnRootCA(wxCommandEvent& event) -{ - wxCertificateClientData *cert = dynamic_cast(event.GetClientObject()); - m_root_ca_remove->Enable(cert ? true : false); -} - - -void wxEAPTLSServerTrustPanel::OnRootCADClick(wxCommandEvent& event) -{ - wxCertificateClientData *cert = dynamic_cast(event.GetClientObject()); - if (cert) - CryptUIDlgViewContext(CERT_STORE_CERTIFICATE_CONTEXT, cert->m_cert, this->GetHWND(), NULL, 0, NULL); -} - - -void wxEAPTLSServerTrustPanel::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 wxEAPTLSServerTrustPanel::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 wxEAPTLSServerTrustPanel::OnRootCARemove(wxCommandEvent& event) -{ - UNREFERENCED_PARAMETER(event); - - wxArrayInt selections; - for (int i = m_root_ca->GetSelections(selections); i--; ) - m_root_ca->Delete(selections[i]); - - m_root_ca_remove->Enable(false); -} - - -bool wxEAPTLSServerTrustPanel::AddRootCA(PCCERT_CONTEXT cert) -{ - for (unsigned int i = 0, i_end = m_root_ca->GetCount(); i < i_end; i++) { - wxCertificateClientData *c = dynamic_cast(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); - m_root_ca_remove->Enable(); - return false; - } - } - - // Add certificate to the list. - winstd::tstring name; - if (CertGetNameString(cert, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, NULL, name) > 0) { - int i = m_root_ca->Append(wxString(name), new wxCertificateClientData(CertDuplicateCertificateContext(cert))); - if (0 <= i) { - m_root_ca->SetSelection(i); - m_root_ca_remove->Enable(); - } - return true; - } - - return false; -} - - -////////////////////////////////////////////////////////////////////// -// wxEAPTLSConfigPanel -////////////////////////////////////////////////////////////////////// - -wxEAPTLSConfigPanel::wxEAPTLSConfigPanel(eap::config_tls &cfg, LPCTSTR pszCredTarget, wxWindow* parent) : wxPanel(parent) -{ - wxBoxSizer* sb_content; - sb_content = new wxBoxSizer( wxVERTICAL ); - - m_server_trust = new wxEAPTLSServerTrustPanel(cfg, this); - if (cfg.m_allow_save) { - sb_content->Add(m_server_trust, 0, wxDOWN|wxEXPAND, 5); - m_credentials = new wxEAPTLSCredentialsConfigPanel(cfg, pszCredTarget, this); - sb_content->Add(m_credentials, 0, wxUP|wxEXPAND, 5); - } else { - sb_content->Add(m_server_trust, 0, wxEXPAND, 5); - m_credentials = NULL; - } - - this->SetSizer(sb_content); - this->Layout(); - - // Connect Events - this->Connect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(wxEAPTLSConfigPanel::OnInitDialog)); -} - - -wxEAPTLSConfigPanel::~wxEAPTLSConfigPanel() -{ - // Disconnect Events - this->Disconnect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(wxEAPTLSConfigPanel::OnInitDialog)); -} - - -void wxEAPTLSConfigPanel::OnInitDialog(wxInitDialogEvent& event) -{ - // Forward the event to child panels. - m_server_trust->GetEventHandler()->ProcessEvent(event); - if (m_credentials) - m_credentials->GetEventHandler()->ProcessEvent(event); -} diff --git a/lib/TTLS_UI/build/TTLS_UI.vcxproj b/lib/TTLS_UI/build/TTLS_UI.vcxproj index 38e4e11..e485454 100644 --- a/lib/TTLS_UI/build/TTLS_UI.vcxproj +++ b/lib/TTLS_UI/build/TTLS_UI.vcxproj @@ -87,7 +87,6 @@ - Create Create diff --git a/lib/TTLS_UI/build/TTLS_UI.vcxproj.filters b/lib/TTLS_UI/build/TTLS_UI.vcxproj.filters index 3378275..ccf0a8a 100644 --- a/lib/TTLS_UI/build/TTLS_UI.vcxproj.filters +++ b/lib/TTLS_UI/build/TTLS_UI.vcxproj.filters @@ -32,9 +32,6 @@ Source Files - - Source Files - Source Files diff --git a/lib/TTLS_UI/include/TTLS_UI.h b/lib/TTLS_UI/include/TTLS_UI.h index 599db2d..138cffb 100644 --- a/lib/TTLS_UI/include/TTLS_UI.h +++ b/lib/TTLS_UI/include/TTLS_UI.h @@ -21,12 +21,12 @@ /// /// EAPTTLS configuration panel /// -class wxEAPTTLSConfigPanel; +template class wxEAPTTLSConfigPanel; /// /// EAPTTLS configuration /// -class wxEAPTTLSConfig; +template class wxEAPTTLSConfig; #pragma once @@ -46,28 +46,89 @@ class wxEAPTTLSConfig; #include +template class wxEAPTTLSConfigPanel : public wxEAPTTLSConfigPanelBase { public: /// /// Constructs a configuration panel /// - wxEAPTTLSConfigPanel(eap::config_ttls &cfg, wxWindow* parent); + wxEAPTTLSConfigPanel(_Tprov &prov, eap::config_ttls &cfg, wxWindow* parent) : + m_prov(prov), + m_cfg(cfg), + wxEAPTTLSConfigPanelBase(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)); + } protected: /// \cond internal - virtual bool TransferDataToWindow(); - virtual bool TransferDataFromWindow(); - virtual void OnOuterIdentityCustom(wxCommandEvent& event); + + 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 wxEAPTTLSConfigPanelBase::TransferDataToWindow(); + } + + + virtual bool TransferDataFromWindow() + { + wxCHECK(wxEAPTTLSConfigPanelBase::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()); + } + } + /// \endcond protected: - eap::config_ttls &m_cfg; ///< TLS configuration + _Tprov &m_prov; ///< EAP provider + eap::config_ttls &m_cfg; ///< TTLS configuration winstd::library m_shell32; ///< shell32.dll resource library reference wxIcon m_icon; ///< Panel icon }; +template class wxEAPTTLSConfig : public wxScrolledWindow { public: @@ -78,25 +139,134 @@ 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 /// - wxEAPTTLSConfig(eap::config_ttls &cfg, LPCTSTR pszCredTarget, wxWindow* parent); + wxEAPTTLSConfig(_Tprov &prov, eap::config_ttls &cfg, LPCTSTR pszCredTarget, wxWindow* parent) : + m_prov(prov), + m_cfg(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 wxEAPProviderLocked<_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 wxEAPTTLSConfigPanel<_Tprov>(prov, m_cfg, this); + sb_content->Add(m_outer_identity, 0, wxALL|wxEXPAND, 5); + + m_tls = new wxEAPTLSConfigPanel<_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(wxEAPTTLSConfig::OnInitDialog)); + } + /// /// Destructs the configuration panel /// - virtual ~wxEAPTTLSConfig(); + virtual ~wxEAPTTLSConfig() + { + // Disconnect Events + this->Disconnect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(wxEAPTTLSConfig::OnInitDialog)); + } + protected: /// \cond internal - virtual bool TransferDataToWindow(); - virtual bool TransferDataFromWindow(); - virtual void OnInitDialog(wxInitDialogEvent& event); + + virtual bool TransferDataToWindow() + { + if (m_prov.m_read_only) { + // This is provider-locked configuration. Disable controls. + m_inner_type->GetChoiceCtrl()->Enable(false); + } + + eap::config_pap *cfg_pap = dynamic_cast(m_cfg.m_inner); + 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 wxEAPTTLSConfig::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 + delete m_cfg.m_inner; + m_cfg.m_inner = new eap::config_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); + } + /// \endcond protected: + _Tprov &m_prov; ///< EAP provider eap::config_ttls &m_cfg; ///< TTLS configuration wxStaticText *m_outer_title; ///< Outer authentication title - wxEAPTTLSConfigPanel *m_outer_identity; ///< Outer identity configuration panel - wxEAPTLSConfigPanel *m_tls; ///< TLS configuration panel + wxEAPTTLSConfigPanel<_Tprov> *m_outer_identity; ///< Outer identity configuration panel + wxEAPTLSConfigPanel<_Tprov> *m_tls; ///< TLS configuration panel wxStaticText *m_inner_title; ///< Inner authentication title wxChoicebook *m_inner_type; ///< Inner authentication type diff --git a/lib/TTLS_UI/res/wxTTLS_UI.cpp b/lib/TTLS_UI/res/wxTTLS_UI.cpp index ea00db4..2740691 100644 --- a/lib/TTLS_UI/res/wxTTLS_UI.cpp +++ b/lib/TTLS_UI/res/wxTTLS_UI.cpp @@ -72,12 +72,12 @@ wxEAPTTLSConfigPanelBase::wxEAPTTLSConfigPanelBase( wxWindow* parent, wxWindowID this->Layout(); // Connect Events - m_outer_identity_custom->Connect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( wxEAPTTLSConfigPanelBase::OnOuterIdentityCustom ), NULL, this ); + this->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( wxEAPTTLSConfigPanelBase::OnUpdateUI ) ); } wxEAPTTLSConfigPanelBase::~wxEAPTTLSConfigPanelBase() { // Disconnect Events - m_outer_identity_custom->Disconnect( wxEVT_COMMAND_RADIOBUTTON_SELECTED, wxCommandEventHandler( wxEAPTTLSConfigPanelBase::OnOuterIdentityCustom ), NULL, this ); + this->Disconnect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( wxEAPTTLSConfigPanelBase::OnUpdateUI ) ); } diff --git a/lib/TTLS_UI/res/wxTTLS_UI.fbp b/lib/TTLS_UI/res/wxTTLS_UI.fbp index 1d26854..ffbe92d 100644 --- a/lib/TTLS_UI/res/wxTTLS_UI.fbp +++ b/lib/TTLS_UI/res/wxTTLS_UI.fbp @@ -77,7 +77,7 @@ - + OnUpdateUI wxID_ANY Outer Identity @@ -541,7 +541,7 @@ - OnOuterIdentityCustom + diff --git a/lib/TTLS_UI/res/wxTTLS_UI.h b/lib/TTLS_UI/res/wxTTLS_UI.h index 2f7e513..27d8bd3 100644 --- a/lib/TTLS_UI/res/wxTTLS_UI.h +++ b/lib/TTLS_UI/res/wxTTLS_UI.h @@ -45,7 +45,7 @@ class wxEAPTTLSConfigPanelBase : public wxPanel wxTextCtrl* m_outer_identity_custom_val; // Virtual event handlers, overide them in your derived class - virtual void OnOuterIdentityCustom( wxCommandEvent& event ) { event.Skip(); } + virtual void OnUpdateUI( wxUpdateUIEvent& event ) { event.Skip(); } public: diff --git a/lib/TTLS_UI/src/Module.cpp b/lib/TTLS_UI/src/Module.cpp index 906718c..466ef9c 100644 --- a/lib/TTLS_UI/src/Module.cpp +++ b/lib/TTLS_UI/src/Module.cpp @@ -50,7 +50,7 @@ bool eap::peer_ttls_ui::invoke_config_ui( wxTopLevelWindows.Append(&parent); // Create and launch configuration dialog. - wxEAPConfigDialog dlg(cfg, &parent); + wxEAPConfigDialog > dlg(cfg, &parent); result = dlg.ShowModal(); wxTopLevelWindows.DeleteObject(&parent); diff --git a/lib/TTLS_UI/src/TTLS_UI.cpp b/lib/TTLS_UI/src/TTLS_UI.cpp deleted file mode 100644 index 9e5350d..0000000 --- a/lib/TTLS_UI/src/TTLS_UI.cpp +++ /dev/null @@ -1,184 +0,0 @@ -/* - 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 . -*/ - -#include "StdAfx.h" - - -////////////////////////////////////////////////////////////////////// -// wxEAPTTLSConfigPanel -////////////////////////////////////////////////////////////////////// - -wxEAPTTLSConfigPanel::wxEAPTTLSConfigPanel(eap::config_ttls &cfg, wxWindow* parent) : - m_cfg(cfg), - wxEAPTTLSConfigPanelBase(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 wxEAPTTLSConfigPanel::TransferDataToWindow() -{ - wxCHECK(wxEAPTTLSConfigPanelBase::TransferDataToWindow(), false); - - // Populate identity controls. - if (m_cfg.m_anonymous_identity.empty()) { - m_outer_identity_same->SetValue(true); - m_outer_identity_custom_val->Enable(false); - } else if (m_cfg.m_anonymous_identity == L"@") { - m_outer_identity_empty->SetValue(true); - m_outer_identity_custom_val->Enable(false); - } else { - m_outer_identity_custom->SetValue(true); - m_outer_identity_custom_val->Enable(true); - m_outer_identity_custom_val->SetValue(m_cfg.m_anonymous_identity); - } - - return true; -} - - -bool wxEAPTTLSConfigPanel::TransferDataFromWindow() -{ - 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 wxEAPTTLSConfigPanelBase::TransferDataFromWindow(); -} - - -void wxEAPTTLSConfigPanel::OnOuterIdentityCustom(wxCommandEvent& event) -{ - UNREFERENCED_PARAMETER(event); - - m_outer_identity_custom_val->Enable(m_outer_identity_custom->GetValue()); -} - - -////////////////////////////////////////////////////////////////////// -// wxEAPTTLSConfig -////////////////////////////////////////////////////////////////////// - -wxEAPTTLSConfig::wxEAPTTLSConfig(eap::config_ttls &cfg, LPCTSTR pszCredTarget, wxWindow* parent) : - m_cfg(cfg), - m_cfg_pap(cfg.m_module), - wxScrolledWindow(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxVSCROLL) -{ - wxBoxSizer* sb_content; - sb_content = new wxBoxSizer( wxVERTICAL ); - - 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(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 wxEAPTTLSConfigPanel(m_cfg, this); - sb_content->Add(m_outer_identity, 0, wxALL|wxEXPAND, 5); - - m_tls = new wxEAPTLSConfigPanel(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_outer_identity->SetFocusFromKbd(); - - // Connect Events - this->Connect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(wxEAPTTLSConfig::OnInitDialog)); -} - - -wxEAPTTLSConfig::~wxEAPTTLSConfig() -{ - // Disconnect Events - this->Disconnect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(wxEAPTTLSConfig::OnInitDialog)); -} - - -bool wxEAPTTLSConfig::TransferDataToWindow() -{ - eap::config_pap *cfg_pap = dynamic_cast(m_cfg.m_inner); - 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 wxEAPTTLSConfig::OnInitDialog() via wxEVT_INIT_DIALOG forwarding. - return true /*wxScrolledWindow::TransferDataToWindow()*/; -} - - -bool wxEAPTTLSConfig::TransferDataFromWindow() -{ - wxCHECK(wxScrolledWindow::TransferDataFromWindow(), false); - - switch (m_inner_type->GetSelection()) { - case 0: // 0=PAP - delete m_cfg.m_inner; - m_cfg.m_inner = new eap::config_pap(m_cfg_pap); - break; - - default: - wxFAIL_MSG(wxT("Unsupported inner authentication method type.")); - } - - return true; -} - - -void wxEAPTTLSConfig::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); -} diff --git a/lib/WinStd b/lib/WinStd index 7510410..5d47a19 160000 --- a/lib/WinStd +++ b/lib/WinStd @@ -1 +1 @@ -Subproject commit 7510410b5660ba9027feb432f8f18940e000f376 +Subproject commit 5d47a19972d64b7f537b675fcbf435759d9c95e5