From de2506bcc45fa73efe8a1b5a216fc3aa947e389c Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Mon, 17 Oct 2016 15:54:17 +0200 Subject: [PATCH] Unified credential TTLS prompt replaced with separate prompts for identity provider, outer credentials and inner credentials EapHost peers provide credential dialogs only and cannot be integrated into unified credential prompt as a panel, requiring additional clicking and pop-ups for user to enter credentials. --- lib/EAPBase_UI/include/EAP_UI.h | 47 ++++--- lib/EAPBase_UI/res/wxEAP_UI.cpp | 40 ++++++ lib/EAPBase_UI/res/wxEAP_UI.fbp | 191 +++++++++++++++++++++++++++ lib/EAPBase_UI/res/wxEAP_UI.h | 24 ++++ lib/EAPBase_UI/src/EAP_UI.cpp | 73 +++++------ lib/EAPBase_UI/src/StdAfx.h | 2 + lib/EAPMsg/src/Credentials.cpp | 1 + lib/TTLS_UI/include/TTLS_UI.h | 41 ------ lib/TTLS_UI/src/Module.cpp | 222 ++++++++++++++++++++------------ lib/TTLS_UI/src/StdAfx.h | 3 + lib/TTLS_UI/src/TTLS_UI.cpp | 73 ----------- lib/WinStd | 2 +- 12 files changed, 462 insertions(+), 257 deletions(-) diff --git a/lib/EAPBase_UI/include/EAP_UI.h b/lib/EAPBase_UI/include/EAP_UI.h index eeb0c04..2d63893 100644 --- a/lib/EAPBase_UI/include/EAP_UI.h +++ b/lib/EAPBase_UI/include/EAP_UI.h @@ -47,11 +47,6 @@ class wxEAPGeneralDialog; /// class wxEAPCredentialsDialog; -/// -/// EAP connection credential dialog -/// -class wxEAPCredentialsConnectionDialog; - /// /// EAP general note /// @@ -102,6 +97,11 @@ template class wxEAPCredentialsPanel; /// template class wxPasswordCredentialsPanel; +/// +/// EAP provider select dialog +/// +class wxEAPProviderSelectDialog; + /// /// Loads icon from resource /// @@ -361,18 +361,32 @@ public: }; -class wxEAPCredentialsConnectionDialog : public wxEAPCredentialsConnectionDialogBase +class wxEAPProviderSelectDialog : public wxEAPProviderSelectDialogBase { public: /// - /// Constructs a credential dialog + /// Constructs a provider select dialog /// - wxEAPCredentialsConnectionDialog(wxWindow *parent, wxWindowID id = wxID_ANY, const wxString &title = _("EAP Credentials"), const wxPoint &pos = wxDefaultPosition, const wxSize &size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE); + /// \param[inout] cfg Connection configuration + /// \param[in] parent Parent window + /// + wxEAPProviderSelectDialog(eap::config_connection &cfg, wxWindow* parent); + + /// + /// Returns pointer to selected provider or NULL if no provider is selected. + /// + inline eap::config_provider* GetSelection() const + { + return m_selected; + } protected: /// \cond internal - virtual void OnInitDialog(wxInitDialogEvent& event); + virtual void OnProvSelect(wxCommandEvent& event); /// \endcond + +protected: + eap::config_provider* m_selected; ///< Pointer to selected provider (or NULL if none selected). }; @@ -809,20 +823,15 @@ private: template class wxEAPCredentialsPanel : public _Tbase { -private: - /// \cond internal - typedef wxEAPCredentialsPanel<_Tcred, _Tbase> _Tthis; - /// \endcond - public: /// /// Constructs a credentials panel /// - /// \param[in] prov Provider configuration data - /// \param[in] cfg Configuration data - /// \param[inout] cred Credentials data - /// \param[in] parent Parent window - /// \param[in] is_config Is this panel used to config credentials? + /// \param[in] prov Provider configuration data + /// \param[in] cfg Configuration data + /// \param[inout] cred Credentials data + /// \param[in] parent Parent window + /// \param[in] is_config Is this panel used to config credentials? /// wxEAPCredentialsPanel(const eap::config_provider &prov, const eap::config_method_with_cred &cfg, _Tcred &cred, wxWindow* parent, bool is_config = false) : m_prov(prov), diff --git a/lib/EAPBase_UI/res/wxEAP_UI.cpp b/lib/EAPBase_UI/res/wxEAP_UI.cpp index 6ac6e59..a6f8dbe 100644 --- a/lib/EAPBase_UI/res/wxEAP_UI.cpp +++ b/lib/EAPBase_UI/res/wxEAP_UI.cpp @@ -607,3 +607,43 @@ wxEAPProviderLockPanelBase::wxEAPProviderLockPanelBase( wxWindow* parent, wxWind wxEAPProviderLockPanelBase::~wxEAPProviderLockPanelBase() { } + +wxEAPProviderSelectDialogBase::wxEAPProviderSelectDialogBase( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxDialog( parent, id, title, pos, size, style ) +{ + this->SetSizeHints( wxDefaultSize, wxDefaultSize ); + + wxBoxSizer* sb_content; + sb_content = new wxBoxSizer( wxVERTICAL ); + + m_banner = new wxEAPBannerPanel( this ); + + sb_content->Add( m_banner, 0, wxEXPAND|wxBOTTOM, 5 ); + + m_providers = new wxBoxSizer( wxVERTICAL ); + + m_providers->SetMinSize( wxSize( 350,-1 ) ); + + sb_content->Add( m_providers, 1, wxEXPAND|wxALL, 5 ); + + m_buttons = new wxStdDialogButtonSizer(); + m_buttonsCancel = new wxButton( this, wxID_CANCEL ); + m_buttons->AddButton( m_buttonsCancel ); + m_buttons->Realize(); + + sb_content->Add( m_buttons, 0, wxEXPAND|wxALL, 5 ); + + + this->SetSizer( sb_content ); + this->Layout(); + sb_content->Fit( this ); + + // Connect Events + this->Connect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( wxEAPProviderSelectDialogBase::OnInitDialog ) ); +} + +wxEAPProviderSelectDialogBase::~wxEAPProviderSelectDialogBase() +{ + // Disconnect Events + this->Disconnect( wxEVT_INIT_DIALOG, wxInitDialogEventHandler( wxEAPProviderSelectDialogBase::OnInitDialog ) ); + +} diff --git a/lib/EAPBase_UI/res/wxEAP_UI.fbp b/lib/EAPBase_UI/res/wxEAP_UI.fbp index cc7dff7..38a3761 100644 --- a/lib/EAPBase_UI/res/wxEAP_UI.fbp +++ b/lib/EAPBase_UI/res/wxEAP_UI.fbp @@ -5139,5 +5139,196 @@ + + 0 + wxAUI_MGR_DEFAULT + + + + 1 + 1 + impl_virtual + + + + 0 + wxID_ANY + + + wxEAPProviderSelectDialogBase + + + wxDEFAULT_DIALOG_STYLE + + EAP Identity Provider + + + + + + + + + + + + + + + + + + + + OnInitDialog + + + + + + + + + + + + + + + + + + + + + + + sb_content + wxVERTICAL + none + + 5 + wxEXPAND|wxBOTTOM + 0 + + 1 + 1 + 1 + 1 + + + + + + + + 1 + 0 + wxEAPBannerPanel + 1 + m_banner = new wxEAPBannerPanel( this ); + + 1 + wxEAPBannerPanel *m_banner; + 0 + Dock + 0 + Left + 1 + + 1 + + 0 + 0 + wxID_ANY + class wxEAPBannerPanel; + + 0 + + + 0 + + 1 + m_banner + 1 + + + protected + 1 + + Resizable + + 1 + -1,-1 + ; ../include/EAP_UI.h + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + wxEXPAND|wxALL + 1 + + 350,-1 + m_providers + wxVERTICAL + protected + + + + 5 + wxEXPAND|wxALL + 0 + + 0 + 1 + 0 + 0 + 0 + 0 + 0 + 0 + + m_buttons + protected + + + + + + + + + + + + diff --git a/lib/EAPBase_UI/res/wxEAP_UI.h b/lib/EAPBase_UI/res/wxEAP_UI.h index 06a001a..f549a75 100644 --- a/lib/EAPBase_UI/res/wxEAP_UI.h +++ b/lib/EAPBase_UI/res/wxEAP_UI.h @@ -290,4 +290,28 @@ class wxEAPProviderLockPanelBase : public wxPanel }; +/////////////////////////////////////////////////////////////////////////////// +/// Class wxEAPProviderSelectDialogBase +/////////////////////////////////////////////////////////////////////////////// +class wxEAPProviderSelectDialogBase : public wxDialog +{ + private: + + protected: + wxEAPBannerPanel *m_banner; + wxBoxSizer* m_providers; + wxStdDialogButtonSizer* m_buttons; + wxButton* m_buttonsCancel; + + // Virtual event handlers, overide them in your derived class + virtual void OnInitDialog( wxInitDialogEvent& event ) { event.Skip(); } + + + public: + + wxEAPProviderSelectDialogBase( wxWindow* parent, wxWindowID id = wxID_ANY, const wxString& title = _("EAP Identity Provider"), const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxDEFAULT_DIALOG_STYLE ); + ~wxEAPProviderSelectDialogBase(); + +}; + #endif //__WXEAP_UI_H__ diff --git a/lib/EAPBase_UI/src/EAP_UI.cpp b/lib/EAPBase_UI/src/EAP_UI.cpp index 717e3a7..867ad1c 100644 --- a/lib/EAPBase_UI/src/EAP_UI.cpp +++ b/lib/EAPBase_UI/src/EAP_UI.cpp @@ -100,46 +100,6 @@ wxEAPCredentialsDialog::wxEAPCredentialsDialog(const eap::config_provider &prov, } -////////////////////////////////////////////////////////////////////// -// wxEAPCredentialsConnectionDialog -////////////////////////////////////////////////////////////////////// - -wxEAPCredentialsConnectionDialog::wxEAPCredentialsConnectionDialog(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &pos, const wxSize &size, long style) : - wxEAPCredentialsConnectionDialogBase(parent, id, title, pos, size, style) -{ - // Set extra style here, as wxFormBuilder overrides all default flags. - this->SetExtraStyle(this->GetExtraStyle() | wxWS_EX_VALIDATE_RECURSIVELY); - - // Load window icons. -#ifdef __WINDOWS__ - wxIconBundle icons; - icons.AddIcon(wxIcon(wxT("product.ico"), wxBITMAP_TYPE_ICO_RESOURCE, ::GetSystemMetrics(SM_CXSMICON), ::GetSystemMetrics(SM_CYSMICON))); - icons.AddIcon(wxIcon(wxT("product.ico"), wxBITMAP_TYPE_ICO_RESOURCE, ::GetSystemMetrics(SM_CXICON ), ::GetSystemMetrics(SM_CYICON ))); - this->SetIcons(icons); -#else - this->SetIcon(wxIcon(wxICON(product.ico))); -#endif - - // Set banner title. - m_banner->m_title->SetLabel(_("EAP Credentials")); - - m_buttonsOK->SetDefault(); -} - - -void wxEAPCredentialsConnectionDialog::OnInitDialog(wxInitDialogEvent& event) -{ - wxEAPCredentialsConnectionDialogBase::OnInitDialog(event); - - // Forward the event to child panels. - for (wxWindowList::compatibility_iterator provider = m_providers->GetChildren().GetFirst(); provider; provider = provider->GetNext()) { - wxWindow *prov = wxDynamicCast(provider->GetData(), wxWindow); - if (prov) - prov->GetEventHandler()->ProcessEvent(event); - } -} - - ////////////////////////////////////////////////////////////////////// // wxEAPNotePanel ////////////////////////////////////////////////////////////////////// @@ -426,6 +386,39 @@ wxEAPConfigProvider::wxEAPConfigProvider(eap::config_provider &prov, wxWindow *p } +////////////////////////////////////////////////////////////////////// +// wxEAPProviderSelectDialog +////////////////////////////////////////////////////////////////////// + +wxEAPProviderSelectDialog::wxEAPProviderSelectDialog(eap::config_connection &cfg, wxWindow *parent) : + m_selected(NULL), + wxEAPProviderSelectDialogBase(parent) +{ + // Set banner title. + std::unique_ptr cfg_dummy(cfg.m_module.make_config_method()); + m_banner->m_title->SetLabel(wxString::Format("%s %s", wxT(PRODUCT_NAME_STR), cfg_dummy->get_method_str())); + + for (auto prov = cfg.m_providers.cbegin(), prov_end = cfg.m_providers.cend(); prov != prov_end; ++prov) { + wxCommandLinkButton *btn = new wxCommandLinkButton(this, wxID_ANY, wxEAPGetProviderName(prov->m_name)); + m_providers->Add(btn, 0, wxALL|wxEXPAND, 5); + + btn->Connect(wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(wxEAPProviderSelectDialog::OnProvSelect), new wxVariant((void*)&*prov), this); + } + + this->Layout(); + this->GetSizer()->Fit(this); +} + + +void wxEAPProviderSelectDialog::OnProvSelect(wxCommandEvent& event) +{ + // Set selected provider and dismiss dialog. + m_selected = static_cast(dynamic_cast(event.GetEventUserData())->GetVoidPtr()); + this->EndModal(wxID_OK); + event.Skip(); +} + + using namespace std; using namespace winstd; diff --git a/lib/EAPBase_UI/src/StdAfx.h b/lib/EAPBase_UI/src/StdAfx.h index 5a4804e..509255d 100644 --- a/lib/EAPBase_UI/src/StdAfx.h +++ b/lib/EAPBase_UI/src/StdAfx.h @@ -24,3 +24,5 @@ #include "../include/EAP_UI.h" #include "../include/Module.h" + +#include diff --git a/lib/EAPMsg/src/Credentials.cpp b/lib/EAPMsg/src/Credentials.cpp index 23f7036..be20d7b 100644 --- a/lib/EAPMsg/src/Credentials.cpp +++ b/lib/EAPMsg/src/Credentials.cpp @@ -237,6 +237,7 @@ std::wstring eap::credentials_eapmsg::get_identity() const return m_identity; } else if (!m_cred_blob.empty()) { // TODO: Use EapHostPeerGetIdentity() to obtain user identity. + assert(0); } return L""; diff --git a/lib/TTLS_UI/include/TTLS_UI.h b/lib/TTLS_UI/include/TTLS_UI.h index bfc64e4..fd6f9e2 100644 --- a/lib/TTLS_UI/include/TTLS_UI.h +++ b/lib/TTLS_UI/include/TTLS_UI.h @@ -18,11 +18,6 @@ along with GÉANTLink. If not, see . */ -/// -/// TTLS credential panel -/// -class wxTTLSCredentialsPanel; - /// /// TTLS configuration panel /// @@ -53,42 +48,6 @@ class wxTTLSConfigWindow; #include -class wxTTLSCredentialsPanel : public wxPanel -{ -public: - /// - /// Constructs a configuration panel - /// - /// \param[in] prov Provider configuration data - /// \param[in] cfg Configuration data - /// \param[inout] cred Credentials data - /// \param[in] parent Parent window - /// \param[in] is_config Is this panel used to config credentials? - /// - wxTTLSCredentialsPanel(const eap::config_provider &prov, const eap::config_method_ttls &cfg, eap::credentials_ttls &cred, wxWindow* parent, bool is_config = false); - - /// - /// Destructs the configuration panel - /// - virtual ~wxTTLSCredentialsPanel(); - -protected: - /// \cond internal - virtual void OnInitDialog(wxInitDialogEvent& event); - /// \endcond - -public: - wxTLSCredentialsPanel *m_outer_cred; ///< Outer credentials panel - wxEAPCredentialsPanelBase *m_inner_cred; ///< Inner credentials panel - -protected: - const eap::config_provider &m_prov; ///< EAP provider - const eap::config_method_ttls &m_cfg; ///< TTLS configuration - wxStaticText *m_outer_title; ///< Outer authentication title - wxStaticText *m_inner_title; ///< Inner authentication title -}; - - class wxTTLSConfigPanel : public wxTTLSConfigPanelBase { public: diff --git a/lib/TTLS_UI/src/Module.cpp b/lib/TTLS_UI/src/Module.cpp index 16e3e90..728ccec 100644 --- a/lib/TTLS_UI/src/Module.cpp +++ b/lib/TTLS_UI/src/Module.cpp @@ -164,11 +164,9 @@ void eap::peer_ttls_ui::invoke_identity_ui( #endif credentials_connection cred_out(*this, cfg); + config_provider *cfg_prov = NULL; config_method_ttls *cfg_method = NULL; - vector > cred_method_store; - cred_method_store.reserve(cfg.m_providers.size()); - int result; { // Initialize application. @@ -181,26 +179,35 @@ void eap::peer_ttls_ui::invoke_identity_ui( parent.AdoptAttributesFromHWND(); wxTopLevelWindows.Append(&parent); - // Create credentials dialog and populate it with providers. - bool combined = false; - wxEAPCredentialsConnectionDialog dlg(&parent); - for (auto cfg_prov = cfg.m_providers.begin(), cfg_prov_end = cfg.m_providers.end(); cfg_prov != cfg_prov_end; ++cfg_prov) { - wstring target_name(std::move(cfg_prov->get_id())); + if (cfg.m_providers.size() > 1) { + // Multiple identity providers: User has to select one first. + wxEAPProviderSelectDialog dlg(cfg, &parent); - // Get method configuration. - if (cfg_prov->m_methods.empty()) { - log_event(&EAPMETHOD_TRACE_EVT_CRED_NO_METHOD, event_data(target_name), event_data::blank); - continue; + // Centre and display dialog. + dlg.Centre(wxBOTH); + if ((result = dlg.ShowModal()) == wxID_OK) { + cfg_prov = dlg.GetSelection(); + assert(cfg_prov); } - config_method_ttls *cfg_method = dynamic_cast(cfg_prov->m_methods.front().get()); + } else if (!cfg.m_providers.empty()) { + // Single identity provider. No need to ask user to select one. + result = wxID_OK; + cfg_prov = &cfg.m_providers.front(); + } else { + // No identity provider. Bail out. + result = wxID_CANCEL; + } + + if (cfg_prov) { + // The identity provider is selected. + cfg_method = dynamic_cast(cfg_prov->m_methods.front().get()); assert(cfg_method); - // Prepare new set of credentials for given provider. - credentials_connection cred_method(*this, cfg); - cred_method.m_namespace = cfg_prov->m_namespace; - cred_method.m_id = cfg_prov->m_id; - credentials_ttls *_cred_method = dynamic_cast(cfg_method->make_credentials()); - cred_method.m_cred.reset(_cred_method); + // Configure output credentials. + cred_out.m_namespace = cfg_prov->m_namespace; + cred_out.m_id = cfg_prov->m_id; + auto cred = dynamic_cast(cfg_method->make_credentials()); + cred_out.m_cred.reset(cred); #ifdef EAP_USE_NATIVE_CREDENTIAL_CACHE bool has_cached = cred_in.m_cred && cred_in.match(*cfg_prov); #endif @@ -212,7 +219,8 @@ void eap::peer_ttls_ui::invoke_identity_ui( } // Combine outer credentials. - eap::credentials::source_t src_outer = _cred_method->credentials_tls::combine( + wstring target_name(std::move(cfg_prov->get_id())); + eap::credentials::source_t src_outer = cred->credentials_tls::combine( dwFlags, NULL, #ifdef EAP_USE_NATIVE_CREDENTIAL_CACHE @@ -222,76 +230,124 @@ void eap::peer_ttls_ui::invoke_identity_ui( #endif *cfg_method, cfg_method->m_allow_save ? target_name.c_str() : NULL); + if (src_outer == eap::credentials::source_unknown || + src_outer != eap::credentials::source_config && eap::config_method::status_cred_begin <= cfg_method->m_last_status && cfg_method->m_last_status < eap::config_method::status_cred_end) + { + // Build dialog to prompt for outer credentials. + wxEAPCredentialsDialog dlg(*cfg_prov, &parent); + if (eap::config_method::status_cred_begin <= cfg_method->m_last_status && cfg_method->m_last_status < eap::config_method::status_cred_end) + dlg.AddContent(new wxEAPCredentialWarningPanel(*cfg_prov, cfg_method->m_last_status, &dlg)); + auto panel = new wxTLSCredentialsPanel(*cfg_prov, *cfg_method, *cred, &dlg, false); + panel->SetRemember(src_outer == eap::credentials::source_storage); + dlg.AddContent(panel); - // Combine inner credentials. - eap::credentials::source_t src_inner = _cred_method->m_inner->combine( - dwFlags, - NULL, + // Update dialog layout. + dlg.Layout(); + dlg.GetSizer()->Fit(&dlg); + + // Centre and display dialog. + dlg.Centre(wxBOTH); + if ((result = dlg.ShowModal()) == wxID_OK) { + // Write credentials to credential manager. + if (panel->GetRemember()) { + try { + cred->credentials_tls::store(target_name.c_str(), 0); + } catch (winstd::win_runtime_error &err) { + wxLogError(winstd::tstring_printf(_("Error writing credentials to Credential Manager: %hs (error %u)"), err.what(), err.number()).c_str()); + } catch (...) { + wxLogError(_("Writing credentials failed.")); + } + } + } + } else + result = wxID_OK; + + if (result == wxID_OK) { + // Combine inner credentials. + eap::credentials::source_t src_inner = cred->m_inner->combine( + dwFlags, + NULL, #ifdef EAP_USE_NATIVE_CREDENTIAL_CACHE - has_cached ? dynamic_cast(cred_in.m_cred.get())->m_inner.get() : NULL, + has_cached ? dynamic_cast(cred_in.m_cred.get())->m_inner.get() : NULL, #else - NULL, + NULL, #endif - *cfg_method->m_inner, - cfg_method->m_inner->m_allow_save ? target_name.c_str() : NULL); + *cfg_method->m_inner, + cfg_method->m_inner->m_allow_save ? target_name.c_str() : NULL); + if (src_inner == eap::credentials::source_unknown || + src_inner != eap::credentials::source_config && eap::config_method::status_cred_begin <= cfg_method->m_inner->m_last_status && cfg_method->m_inner->m_last_status < eap::config_method::status_cred_end) + { + // Prompt for inner credentials. + auto cfg_inner_eapmsg = dynamic_cast(cfg_method->m_inner.get()); + if (!cfg_inner_eapmsg) { + // Native inner methods. Build dialog to prompt for inner credentials. + wxEAPCredentialsDialog dlg(*cfg_prov, &parent); + if (eap::config_method::status_cred_begin <= cfg_method->m_inner->m_last_status && cfg_method->m_inner->m_last_status < eap::config_method::status_cred_end) + dlg.AddContent(new wxEAPCredentialWarningPanel(*cfg_prov, cfg_method->m_inner->m_last_status, &dlg)); + wxEAPCredentialsPanelBase *panel = NULL; + const eap::config_method_pap *cfg_inner_pap; + const eap::config_method_mschapv2 *cfg_inner_mschapv2; + if ((cfg_inner_pap = dynamic_cast(cfg_method->m_inner.get())) != NULL) + panel = new wxPAPCredentialsPanel(*cfg_prov, *cfg_inner_pap, *dynamic_cast(cred->m_inner.get()), &dlg, false); + else if ((cfg_inner_mschapv2 = dynamic_cast(cfg_method->m_inner.get())) != NULL) + panel = new wxMSCHAPv2CredentialsPanel(*cfg_prov, *cfg_inner_mschapv2, *dynamic_cast(cred->m_inner.get()), &dlg, false); + else + assert(0); // Unsupported inner authentication method type. + panel->SetRemember(src_inner == eap::credentials::source_storage); + dlg.AddContent(panel); - // Create method credentials panel. - wxTTLSCredentialsPanel *panel = new wxTTLSCredentialsPanel(*cfg_prov, *cfg_method, *_cred_method, dlg.m_providers); + // Update dialog layout. + dlg.Layout(); + dlg.GetSizer()->Fit(&dlg); - // Set "Remember" checkboxes according to credential source, - panel->m_outer_cred->SetRemember(src_outer == eap::credentials::source_storage); - panel->m_inner_cred->SetRemember(src_inner == eap::credentials::source_storage); - - // Add panel to choice-book. Select the first one to have known sources. - if (!combined && src_outer != eap::credentials::source_unknown && src_inner != eap::credentials::source_unknown) { - if (dlg.m_providers->AddPage(panel, wxEAPGetProviderName(cfg_prov->m_name), true)) { - cred_method_store.push_back(pair(cfg_method, std::move(cred_method))); - combined = true; - } - } else - if (dlg.m_providers->AddPage(panel, wxEAPGetProviderName(cfg_prov->m_name), false)) - cred_method_store.push_back(pair(cfg_method, std::move(cred_method))); - } - - // Update dialog layout. - dlg.Layout(); - dlg.GetSizer()->Fit(&dlg); - - // Centre and display dialog. - dlg.Centre(wxBOTH); - result = dlg.ShowModal(); - if (result == wxID_OK) { - int idx_prov = dlg.m_providers->GetSelection(); - if (idx_prov != wxNOT_FOUND) { - wxTTLSCredentialsPanel *panel = dynamic_cast(dlg.m_providers->GetPage(idx_prov)); - pair &res = cred_method_store[idx_prov]; - cfg_method = res.first; - cred_out = res.second; - credentials_ttls *_cred_out = dynamic_cast(cred_out.m_cred.get()); - wstring target_name(std::move(cred_out.get_id())); - - // Write credentials to credential manager. - if (panel->m_outer_cred->GetRemember()) { - try { - _cred_out->credentials_tls::store(target_name.c_str(), 0); - } catch (winstd::win_runtime_error &err) { - wxLogError(winstd::tstring_printf(_("Error writing credentials to Credential Manager: %hs (error %u)"), err.what(), err.number()).c_str()); - } catch (...) { - wxLogError(_("Writing credentials failed.")); + // Centre and display dialog. + dlg.Centre(wxBOTH); + if ((result = dlg.ShowModal()) == wxID_OK) { + // Write credentials to credential manager. + if (panel->GetRemember()) { + try { + cred->m_inner->store(target_name.c_str(), 1); + } catch (winstd::win_runtime_error &err) { + wxLogError(winstd::tstring_printf(_("Error writing credentials to Credential Manager: %hs (error %u)"), err.what(), err.number()).c_str()); + } catch (...) { + wxLogError(_("Writing credentials failed.")); + } + } + } + } else { + // EapHost inner method + auto cred_inner = dynamic_cast(cred->m_inner.get()); + DWORD cred_data_size = 0; + winstd::eap_blob cred_data; + unique_ptr identity; + winstd::eap_error error; + DWORD dwResult = EapHostPeerInvokeIdentityUI( + 0, + cfg_inner_eapmsg->m_type, + dwFlags, + hwndParent, + (DWORD)cfg_inner_eapmsg->m_cfg_blob.size(), cfg_inner_eapmsg->m_cfg_blob.data(), + (DWORD)cred_inner->m_cred_blob.size(), cred_inner->m_cred_blob.data(), + &cred_data_size, &cred_data._Myptr, + &identity._Myptr, + &error._Myptr, + NULL); + if (dwResult == ERROR_SUCCESS) { + // Inner EAP method provided credentials. + cred_inner->m_identity = identity.get(); + cred_inner->m_cred_blob.assign(cred_data.get(), cred_data.get() + cred_data_size); + SecureZeroMemory(cred_data.get(), cred_data_size); + } else if (dwResult == ERROR_CANCELLED) { + // Not really an error. + result = wxID_CANCEL; + } else if (error) + wxLogError(_("Invoking EAP identity failed (error %u, %s, %s)."), error->dwWinError, error->pRootCauseString, error->pRepairString); + else + wxLogError(_("Invoking EAP identity failed (error %u)."), dwResult); } - } - - if (panel->m_inner_cred->GetRemember()) { - try { - _cred_out->m_inner->store(target_name.c_str(), 1); - } catch (winstd::win_runtime_error &err) { - wxLogError(winstd::tstring_printf(_("Error writing credentials to Credential Manager: %hs (error %u)"), err.what(), err.number()).c_str()); - } catch (...) { - wxLogError(_("Writing credentials failed.")); - } - } - } else - result = wxID_CANCEL; + } else + result = wxID_OK; + } } wxTopLevelWindows.DeleteObject(&parent); diff --git a/lib/TTLS_UI/src/StdAfx.h b/lib/TTLS_UI/src/StdAfx.h index b5f516e..a80716e 100644 --- a/lib/TTLS_UI/src/StdAfx.h +++ b/lib/TTLS_UI/src/StdAfx.h @@ -29,7 +29,10 @@ #include "../../PAP_UI/include/PAP_UI.h" #include "../../MSCHAPv2_UI/include/MSCHAPv2_UI.h" +#include "../../EAPMsg/include/Credentials.h" + #include #include +#include #include diff --git a/lib/TTLS_UI/src/TTLS_UI.cpp b/lib/TTLS_UI/src/TTLS_UI.cpp index 1368b7a..3ce428d 100644 --- a/lib/TTLS_UI/src/TTLS_UI.cpp +++ b/lib/TTLS_UI/src/TTLS_UI.cpp @@ -21,79 +21,6 @@ #include "StdAfx.h" -////////////////////////////////////////////////////////////////////// -// wxTTLSCredentialsPanel -////////////////////////////////////////////////////////////////////// - -wxTTLSCredentialsPanel::wxTTLSCredentialsPanel(const eap::config_provider &prov, const eap::config_method_ttls &cfg, eap::credentials_ttls &cred, wxWindow* parent, bool is_config) : - m_prov(prov), - m_cfg(cfg), - wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize) -{ - 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); - - assert(m_cfg.m_inner); - - if (eap::config_method::status_cred_begin <= m_cfg.m_inner->m_last_status && m_cfg.m_inner->m_last_status < eap::config_method::status_cred_end) - sb_content->Add(new wxEAPCredentialWarningPanel(m_prov, m_cfg.m_inner->m_last_status, this), 0, wxALL|wxEXPAND, 5); - - const eap::config_method_pap *cfg_inner_pap; - const eap::config_method_mschapv2 *cfg_inner_mschapv2; - if ((cfg_inner_pap = dynamic_cast(m_cfg.m_inner.get())) != NULL) { - if (!cred.m_inner) cred.m_inner.reset(new eap::credentials_pass(cred.m_module)); - m_inner_cred = new wxPAPCredentialsPanel(m_prov, *cfg_inner_pap, *(eap::credentials_pass*)cred.m_inner.get(), this, is_config); - sb_content->Add(m_inner_cred, 0, wxALL|wxEXPAND, 5); - } else if ((cfg_inner_mschapv2 = dynamic_cast(m_cfg.m_inner.get())) != NULL) { - if (!cred.m_inner) cred.m_inner.reset(new eap::credentials_pass(cred.m_module)); - m_inner_cred = new wxMSCHAPv2CredentialsPanel(m_prov, *cfg_inner_mschapv2, *(eap::credentials_pass*)cred.m_inner.get(), this, is_config); - sb_content->Add(m_inner_cred, 0, wxALL|wxEXPAND, 5); - } else - assert(0); // Unsupported inner authentication method type. - - 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); - - if (eap::config_method::status_cred_begin <= m_cfg.m_last_status && m_cfg.m_last_status < eap::config_method::status_cred_end) - sb_content->Add(new wxEAPCredentialWarningPanel(m_prov, m_cfg.m_last_status, this), 0, wxALL|wxEXPAND, 5); - - m_outer_cred = new wxTLSCredentialsPanel(m_prov, m_cfg, cred, this, is_config); - sb_content->Add(m_outer_cred, 0, wxALL|wxEXPAND, 5); - - this->SetSizer(sb_content); - this->Layout(); - - m_inner_cred->SetFocusFromKbd(); - - // Connect Events - this->Connect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(wxTTLSCredentialsPanel::OnInitDialog)); -} - - -wxTTLSCredentialsPanel::~wxTTLSCredentialsPanel() -{ - // Disconnect Events - this->Disconnect(wxEVT_INIT_DIALOG, wxInitDialogEventHandler(wxTTLSCredentialsPanel::OnInitDialog)); -} - - -void wxTTLSCredentialsPanel::OnInitDialog(wxInitDialogEvent& event) -{ - // Forward the event to child panels. - m_outer_cred->GetEventHandler()->ProcessEvent(event); - m_inner_cred->GetEventHandler()->ProcessEvent(event); -} - - ////////////////////////////////////////////////////////////////////// // wxTTLSConfigPanel ////////////////////////////////////////////////////////////////////// diff --git a/lib/WinStd b/lib/WinStd index cc090e8..21ba0df 160000 --- a/lib/WinStd +++ b/lib/WinStd @@ -1 +1 @@ -Subproject commit cc090e89eb56e99382966e8f26c609e96d33bb9a +Subproject commit 21ba0dfc5f35d551d8c613751a9ea87365744cfb