From e66a7eb9ba0ccf0f4f0bb31cac16af2d8f34933e Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Sun, 28 Aug 2016 20:04:45 +0200 Subject: [PATCH] dePAPization continues to pave the road for seamless MSCHAPv2 integration --- lib/EAPBase/include/Credentials.h | 2 +- lib/EAPBase_UI/build/EAPBase_UI.vcxproj | 1 + .../build/EAPBase_UI.vcxproj.filters | 3 ++ lib/EAPBase_UI/include/EAP_UI.h | 26 +++++----- lib/EAPBase_UI/include/wxEAP_UIBase.h | 48 +++++++++++++++++++ lib/EAPBase_UI/res/wxEAP_UI.cpp | 2 +- lib/EAPBase_UI/res/wxEAP_UI.fbp | 2 +- lib/EAPBase_UI/res/wxEAP_UI.h | 5 +- lib/TLS_UI/include/TLS_UI.h | 2 +- lib/TLS_UI/src/TLS_UI.cpp | 8 ++-- lib/TTLS/include/Credentials.h | 5 -- lib/TTLS/src/Credentials.cpp | 21 ++------ lib/TTLS_UI/include/TTLS_UI.h | 12 ++--- lib/TTLS_UI/src/Module.cpp | 28 ++++------- 14 files changed, 97 insertions(+), 68 deletions(-) create mode 100644 lib/EAPBase_UI/include/wxEAP_UIBase.h diff --git a/lib/EAPBase/include/Credentials.h b/lib/EAPBase/include/Credentials.h index cc3f50e..5e89b56 100644 --- a/lib/EAPBase/include/Credentials.h +++ b/lib/EAPBase/include/Credentials.h @@ -58,7 +58,7 @@ namespace eap /// /// Credential source when combined /// - enum source_t { + enum source_t { source_unknown = -1, ///< Unknown source source_cache = 0, ///< Credentials were obtained from EapHost cache source_preshared, ///< Credentials were set by method configuration diff --git a/lib/EAPBase_UI/build/EAPBase_UI.vcxproj b/lib/EAPBase_UI/build/EAPBase_UI.vcxproj index 529879a..8b13bd9 100644 --- a/lib/EAPBase_UI/build/EAPBase_UI.vcxproj +++ b/lib/EAPBase_UI/build/EAPBase_UI.vcxproj @@ -81,6 +81,7 @@ + diff --git a/lib/EAPBase_UI/build/EAPBase_UI.vcxproj.filters b/lib/EAPBase_UI/build/EAPBase_UI.vcxproj.filters index bdc70fe..c6ed288 100644 --- a/lib/EAPBase_UI/build/EAPBase_UI.vcxproj.filters +++ b/lib/EAPBase_UI/build/EAPBase_UI.vcxproj.filters @@ -27,6 +27,9 @@ Header Files + + Header Files + diff --git a/lib/EAPBase_UI/include/EAP_UI.h b/lib/EAPBase_UI/include/EAP_UI.h index a252af5..125b3e1 100644 --- a/lib/EAPBase_UI/include/EAP_UI.h +++ b/lib/EAPBase_UI/include/EAP_UI.h @@ -81,9 +81,9 @@ class wxEAPConfigProvider; template class wxEAPCredentialsConfigPanel; /// -/// Base template for all credential entry panels +/// Helper template for all credential entry panels /// -template class wxEAPCredentialsPanelBase; +template class wxEAPCredentialsPanel; /// /// Generic password credential entry panel @@ -637,11 +637,11 @@ private: template -class wxEAPCredentialsPanelBase : public _Tbase +class wxEAPCredentialsPanel : public _Tbase { private: /// \cond internal - typedef wxEAPCredentialsPanelBase<_Tcred, _Tbase> _Tthis; + typedef wxEAPCredentialsPanel<_Tcred, _Tbase> _Tthis; /// \endcond public: @@ -655,7 +655,7 @@ public: /// \param[in] parent Parent window /// \param[in] is_config Is this panel used to pre-enter credentials? When \c true, the "Remember" checkbox is always selected and disabled. /// - wxEAPCredentialsPanelBase(const eap::config_provider &prov, const eap::config_method_with_cred &cfg, _Tcred &cred, LPCTSTR pszCredTarget, wxWindow* parent, bool is_config = false) : + wxEAPCredentialsPanel(const eap::config_provider &prov, const eap::config_method_with_cred &cfg, _Tcred &cred, LPCTSTR pszCredTarget, wxWindow* parent, bool is_config = false) : m_prov(prov), m_cfg(cfg), m_cred(cred), @@ -666,17 +666,17 @@ public: this->Connect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(_Tthis::OnUpdateUI)); } - virtual ~wxEAPCredentialsPanelBase() + virtual ~wxEAPCredentialsPanel() { this->Disconnect(wxEVT_UPDATE_UI, wxUpdateUIEventHandler(_Tthis::OnUpdateUI)); } - inline void SetRememberValue(bool val) + virtual void SetRemember(bool val) { return m_remember->SetValue(val); } - inline bool GetRememberValue() const + virtual bool GetRemember() const { return m_remember->GetValue(); } @@ -716,7 +716,7 @@ protected: template -class wxPasswordCredentialsPanel : public wxEAPCredentialsPanelBase<_Tcred, _Tbase> +class wxPasswordCredentialsPanel : public wxEAPCredentialsPanel<_Tcred, _Tbase> { public: /// @@ -730,7 +730,7 @@ public: /// \param[in] is_config Is this panel used to pre-enter credentials? When \c true, the "Remember" checkbox is always selected and disabled. /// wxPasswordCredentialsPanel(const eap::config_provider &prov, const eap::config_method_with_cred &cfg, _Tcred &cred, LPCTSTR pszCredTarget, wxWindow* parent, bool is_config = false) : - wxEAPCredentialsPanelBase<_Tcred, _Tbase>(prov, cfg, cred, pszCredTarget, parent, is_config) + wxEAPCredentialsPanel<_Tcred, _Tbase>(prov, cfg, cred, pszCredTarget, parent, is_config) { // Load and set icon. winstd::library lib_shell32; @@ -767,12 +767,12 @@ protected: m_identity->SetSelection(0, -1); m_password->SetValue(m_cred.m_password.empty() ? wxEmptyString : s_dummy_password); - return wxEAPCredentialsPanelBase<_Tcred, wxEAPCredentialsPassPanelBase>::TransferDataToWindow(); + return wxEAPCredentialsPanel<_Tcred, wxEAPCredentialsPassPanelBase>::TransferDataToWindow(); } virtual bool TransferDataFromWindow() { - if (!wxEAPCredentialsPanelBase<_Tcred, wxEAPCredentialsPassPanelBase>::TransferDataFromWindow()) + if (!wxEAPCredentialsPanel<_Tcred, wxEAPCredentialsPassPanelBase>::TransferDataFromWindow()) return false; m_cred.m_identity = m_identity->GetValue(); @@ -795,7 +795,7 @@ protected: m_password ->Enable(false); } - wxEAPCredentialsPanelBase<_Tcred, wxEAPCredentialsPassPanelBase>::OnUpdateUI(event); + wxEAPCredentialsPanel<_Tcred, wxEAPCredentialsPassPanelBase>::OnUpdateUI(event); } /// \endcond diff --git a/lib/EAPBase_UI/include/wxEAP_UIBase.h b/lib/EAPBase_UI/include/wxEAP_UIBase.h new file mode 100644 index 0000000..c24803d --- /dev/null +++ b/lib/EAPBase_UI/include/wxEAP_UIBase.h @@ -0,0 +1,48 @@ +/* + 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 . +*/ + +/// +/// Base class for all credential entry panel that must provide "Remember" credentials checkbox +/// +class wxEAPCredentialsPanelBase; + +#pragma once + +#include + + +class wxEAPCredentialsPanelBase : public wxPanel +{ +public: + /// + /// Constructs a wxPanel with "Remember" credentials checkbox + /// + wxEAPCredentialsPanelBase(wxWindow *parent, + wxWindowID winid = wxID_ANY, + const wxPoint& pos = wxDefaultPosition, + const wxSize& size = wxDefaultSize, + long style = wxTAB_TRAVERSAL | wxNO_BORDER, + const wxString& name = wxPanelNameStr) : wxPanel(parent, winid, pos, size, style, name) + { + } + + virtual void SetRemember(bool val) = 0; + virtual bool GetRemember() const = 0; +}; diff --git a/lib/EAPBase_UI/res/wxEAP_UI.cpp b/lib/EAPBase_UI/res/wxEAP_UI.cpp index 1f6362c..3c08310 100644 --- a/lib/EAPBase_UI/res/wxEAP_UI.cpp +++ b/lib/EAPBase_UI/res/wxEAP_UI.cpp @@ -290,7 +290,7 @@ wxEAPCredentialsConfigPanelBase::~wxEAPCredentialsConfigPanelBase() } -wxEAPCredentialsPassPanelBase::wxEAPCredentialsPassPanelBase( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) : wxPanel( parent, id, pos, size, style ) +wxEAPCredentialsPassPanelBase::wxEAPCredentialsPassPanelBase( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style ) : wxEAPCredentialsPanelBase( parent, id, pos, size, style ) { wxStaticBoxSizer* sb_credentials; sb_credentials = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, _("Client Credentials") ), wxVERTICAL ); diff --git a/lib/EAPBase_UI/res/wxEAP_UI.fbp b/lib/EAPBase_UI/res/wxEAP_UI.fbp index 88d2eb9..ec9f918 100644 --- a/lib/EAPBase_UI/res/wxEAP_UI.fbp +++ b/lib/EAPBase_UI/res/wxEAP_UI.fbp @@ -1931,7 +1931,7 @@ wxEAPCredentialsPassPanelBase 500,-1 - + wxEAPCredentialsPanelBase; ../include/wxEAP_UIBase.h diff --git a/lib/EAPBase_UI/res/wxEAP_UI.h b/lib/EAPBase_UI/res/wxEAP_UI.h index 6eef1b6..076aad2 100644 --- a/lib/EAPBase_UI/res/wxEAP_UI.h +++ b/lib/EAPBase_UI/res/wxEAP_UI.h @@ -11,6 +11,9 @@ #include #include #include +class wxEAPCredentialsPanelBase; + +#include "../include/wxEAP_UIBase.h" class wxEAPBannerPanel; #include #include @@ -158,7 +161,7 @@ class wxEAPCredentialsConfigPanelBase : public wxPanel /////////////////////////////////////////////////////////////////////////////// /// Class wxEAPCredentialsPassPanelBase /////////////////////////////////////////////////////////////////////////////// -class wxEAPCredentialsPassPanelBase : public wxPanel +class wxEAPCredentialsPassPanelBase : public wxEAPCredentialsPanelBase { private: diff --git a/lib/TLS_UI/include/TLS_UI.h b/lib/TLS_UI/include/TLS_UI.h index f62da7e..f0073cc 100644 --- a/lib/TLS_UI/include/TLS_UI.h +++ b/lib/TLS_UI/include/TLS_UI.h @@ -248,7 +248,7 @@ protected: }; -class wxTLSCredentialsPanel : public wxEAPCredentialsPanelBase +class wxTLSCredentialsPanel : public wxEAPCredentialsPanel { public: /// diff --git a/lib/TLS_UI/src/TLS_UI.cpp b/lib/TLS_UI/src/TLS_UI.cpp index bb1c91a..8638548 100644 --- a/lib/TLS_UI/src/TLS_UI.cpp +++ b/lib/TLS_UI/src/TLS_UI.cpp @@ -312,7 +312,7 @@ bool wxFQDNListValidator::Parse(const wxString &val_in, size_t i_start, size_t i ////////////////////////////////////////////////////////////////////// wxTLSCredentialsPanel::wxTLSCredentialsPanel(const eap::config_provider &prov, const eap::config_method_with_cred &cfg, eap::credentials_tls &cred, LPCTSTR pszCredTarget, wxWindow* parent, bool is_config) : - wxEAPCredentialsPanelBase(prov, cfg, cred, pszCredTarget, parent, is_config) + wxEAPCredentialsPanel(prov, cfg, cred, pszCredTarget, parent, is_config) { // Load and set icon. winstd::library lib_shell32; @@ -361,7 +361,7 @@ bool wxTLSCredentialsPanel::TransferDataToWindow() m_identity->SetValue(m_cred.m_identity); - return wxEAPCredentialsPanelBase::TransferDataToWindow(); + return wxEAPCredentialsPanel::TransferDataToWindow(); } @@ -381,7 +381,7 @@ bool wxTLSCredentialsPanel::TransferDataFromWindow() // Inherited TransferDataFromWindow() calls m_cred.store(). // Therefore, call it only now, that m_cred is set. - return wxEAPCredentialsPanelBase::TransferDataFromWindow(); + return wxEAPCredentialsPanel::TransferDataFromWindow(); } @@ -405,7 +405,7 @@ void wxTLSCredentialsPanel::OnUpdateUI(wxUpdateUIEvent& event) m_identity->Enable(true); } - wxEAPCredentialsPanelBase::OnUpdateUI(event); + wxEAPCredentialsPanel::OnUpdateUI(event); } diff --git a/lib/TTLS/include/Credentials.h b/lib/TTLS/include/Credentials.h index 370def2..7060ee7 100644 --- a/lib/TTLS/include/Credentials.h +++ b/lib/TTLS/include/Credentials.h @@ -159,11 +159,6 @@ namespace eap /// virtual void retrieve(_In_z_ LPCTSTR pszTargetName); - /// - /// Return target suffix for Windows Credential Manager credential name - /// - virtual LPCTSTR target_suffix() const; - /// /// Returns credential identity. /// diff --git a/lib/TTLS/src/Credentials.cpp b/lib/TTLS/src/Credentials.cpp index 5c2c2f4..790591f 100644 --- a/lib/TTLS/src/Credentials.cpp +++ b/lib/TTLS/src/Credentials.cpp @@ -169,13 +169,6 @@ void eap::credentials_ttls::retrieve(_In_z_ LPCTSTR pszTargetName) } -LPCTSTR eap::credentials_ttls::target_suffix() const -{ - assert(0); // Not that we would ever store inner&outer credentials to Windows Credential Manager joined, but for completness sake... Here we go: - return _T("TTLS"); -} - - wstring eap::credentials_ttls::get_identity() const { // Outer identity has the right-of-way. @@ -193,21 +186,17 @@ eap::credentials::source_t eap::credentials_ttls::combine( _In_ const config_method_with_cred &cfg, _In_opt_z_ LPCTSTR pszTargetName) { - source_t src; - - // Combine outer credentials first. - src = credentials_tls::combine( + // Combine outer credentials. + source_t src_outer = credentials_tls::combine( cred_cached, cfg, pszTargetName); - if (src == source_unknown) { - // Outer credentials are unknown. Enough unknowness. - return source_unknown; - } // Combine inner credentials. - return m_inner->combine( + source_t src_inner = m_inner->combine( cred_cached ? ((const credentials_ttls*)cred_cached)->m_inner.get() : NULL, *((const config_method_ttls&)cfg).m_inner, pszTargetName); + + return std::min(src_outer, src_inner); } diff --git a/lib/TTLS_UI/include/TTLS_UI.h b/lib/TTLS_UI/include/TTLS_UI.h index 8840c06..0ffc6bf 100644 --- a/lib/TTLS_UI/include/TTLS_UI.h +++ b/lib/TTLS_UI/include/TTLS_UI.h @@ -132,12 +132,12 @@ protected: /// \endcond public: - wxTLSCredentialsPanel *m_outer_cred; ///< Outer credentials panel - wxPanel *m_inner_cred; ///< Inner credentials panel + 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 + 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 }; diff --git a/lib/TTLS_UI/src/Module.cpp b/lib/TTLS_UI/src/Module.cpp index b80c22e..1f07ac5 100644 --- a/lib/TTLS_UI/src/Module.cpp +++ b/lib/TTLS_UI/src/Module.cpp @@ -104,22 +104,23 @@ void eap::peer_ttls_ui::invoke_config_ui( } else { // This is a blank network profile. Create default configuraton. - // Start with PAP inner configuration. + // Inner configuration: PAP config_method_pap *cfg_method_inner = new config_method_pap(*this); cfg_method_inner->m_use_preshared = false; cfg_method_inner->m_preshared(new credentials_pap(*this)); + // Outer configuration unique_ptr cfg_method(new config_method_ttls(*this)); cfg_method->m_anonymous_identity = L"@"; cfg_method->m_use_preshared = true; cfg_method->m_preshared.reset(new credentials_tls(*this)); cfg_method->m_inner.reset(cfg_method_inner); - // Start with one method. + // One method config_provider cfg_provider(*this); cfg_provider.m_methods.push_back(std::move(cfg_method)); - // Start with one provider. + // One provider cfg.m_providers.push_back(std::move(cfg_provider)); } @@ -189,16 +190,7 @@ void eap::peer_ttls_ui::invoke_identity_ui( #endif credentials_ttls cred_out(*this); - - // Determine inner credential type. - eap_type_t type_inner; - if (dynamic_cast(cfg_method->m_inner.get())) { - cred_out.m_inner.reset(new credentials_pap(*this)); - type_inner = eap_type_pap; - } else { - assert(0); // Unsupported inner authentication method type. - type_inner = eap_type_undefined; - } + cred_out.m_inner.reset(cfg_method->m_inner->make_credentials()); // Combine credentials. Outer and inner separately to get the idea which one is missing. eap::credentials::source_t cred_source = cred_out.credentials_tls::combine( @@ -242,17 +234,15 @@ void eap::peer_ttls_ui::invoke_identity_ui( dlg.AddContent(panel); // Set "Remember" checkboxes according to credential source, - panel->m_outer_cred->SetRememberValue(cred_source == eap::credentials::source_storage); - wxPAPCredentialsPanel *panel_inner_cred_pap = dynamic_cast(panel->m_inner_cred); - if (panel_inner_cred_pap) - panel_inner_cred_pap->SetRememberValue(cred_source_inner == eap::credentials::source_storage); + panel->m_outer_cred->SetRemember(cred_source == eap::credentials::source_storage); + panel->m_inner_cred->SetRemember(cred_source_inner == eap::credentials::source_storage); // Centre and display dialog. dlg.Centre(wxBOTH); result = dlg.ShowModal(); if (result == wxID_OK) { // Write credentials to credential manager. - if (panel->m_outer_cred->GetRememberValue()) { + if (panel->m_outer_cred->GetRemember()) { try { cred_out.credentials_tls::store(cfg_prov.m_id.c_str()); } catch (winstd::win_runtime_error &err) { @@ -262,7 +252,7 @@ void eap::peer_ttls_ui::invoke_identity_ui( } } - if (panel_inner_cred_pap && panel_inner_cred_pap->GetRememberValue()) { + if (panel->m_inner_cred->GetRemember()) { try { cred_out.m_inner->store(cfg_prov.m_id.c_str()); } catch (winstd::win_runtime_error &err) {