From 6c66862eed71a0af4f59cceb8cf2f07a40cb9200 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Sun, 28 Aug 2016 17:43:06 +0200 Subject: [PATCH] TTLS config and credentials are now expected to always have inner config and credentials object present; it can be blank, but it must not be nullptr --- lib/TTLS/src/Config.cpp | 26 ++++++-------------------- lib/TTLS/src/Credentials.cpp | 33 ++++++++++++++------------------- lib/TTLS_UI/src/Module.cpp | 6 +++++- 3 files changed, 25 insertions(+), 40 deletions(-) diff --git a/lib/TTLS/src/Config.cpp b/lib/TTLS/src/Config.cpp index 7f7608b..7be6242 100644 --- a/lib/TTLS/src/Config.cpp +++ b/lib/TTLS/src/Config.cpp @@ -168,30 +168,18 @@ void eap::config_method_ttls::load(_In_ IXMLDOMNode *pConfigRoot) void eap::config_method_ttls::operator<<(_Inout_ cursor_out &cursor) const { config_method_tls::operator<<(cursor); - - if (m_inner) { - cursor << m_inner->get_method_id(); - cursor << *m_inner; - } else - cursor << eap_type_undefined; - + cursor << m_inner->get_method_id(); + cursor << *m_inner; cursor << m_anonymous_identity; } size_t eap::config_method_ttls::get_pk_size() const { - size_t size_inner; - if (m_inner) { - size_inner = - pksizeof(m_inner->get_method_id()) + - pksizeof(*m_inner); - } else - size_inner = pksizeof(eap_type_undefined); - return config_method_tls::get_pk_size() + - size_inner + + pksizeof(m_inner->get_method_id()) + + pksizeof(*m_inner) + pksizeof(m_anonymous_identity); } @@ -202,10 +190,8 @@ void eap::config_method_ttls::operator>>(_Inout_ cursor_in &cursor) eap_type_t eap_type; cursor >> eap_type; - if (eap_type != eap_type_undefined) { - m_inner.reset(make_config_method(eap_type)); - cursor >> *m_inner; - } + m_inner.reset(make_config_method(eap_type)); + cursor >> *m_inner; cursor >> m_anonymous_identity; } diff --git a/lib/TTLS/src/Credentials.cpp b/lib/TTLS/src/Credentials.cpp index dec87e8..5c2c2f4 100644 --- a/lib/TTLS/src/Credentials.cpp +++ b/lib/TTLS/src/Credentials.cpp @@ -79,14 +79,13 @@ eap::config* eap::credentials_ttls::clone() const void eap::credentials_ttls::clear() { credentials_tls::clear(); - if (m_inner) - m_inner->clear(); + m_inner->clear(); } bool eap::credentials_ttls::empty() const { - return credentials_tls::empty() && (!m_inner || m_inner->empty()); + return credentials_tls::empty() && m_inner->empty(); } @@ -100,17 +99,15 @@ void eap::credentials_ttls::save(_In_ IXMLDOMDocument *pDoc, _In_ IXMLDOMNode *p const bstr bstrNamespace(L"urn:ietf:params:xml:ns:yang:ietf-eap-metadata"); HRESULT hr; - if (m_inner) { - // - winstd::com_obj pXmlElInnerAuthenticationMethod; - if (FAILED(hr = eapxml::create_element(pDoc, winstd::bstr(L"InnerAuthenticationMethod"), bstrNamespace, &pXmlElInnerAuthenticationMethod))) - throw com_runtime_error(hr, __FUNCTION__ " Error creating element."); + // + winstd::com_obj pXmlElInnerAuthenticationMethod; + if (FAILED(hr = eapxml::create_element(pDoc, winstd::bstr(L"InnerAuthenticationMethod"), bstrNamespace, &pXmlElInnerAuthenticationMethod))) + throw com_runtime_error(hr, __FUNCTION__ " Error creating element."); - m_inner->save(pDoc, pXmlElInnerAuthenticationMethod); + m_inner->save(pDoc, pXmlElInnerAuthenticationMethod); - if (FAILED(hr = pConfigRoot->appendChild(pXmlElInnerAuthenticationMethod, NULL))) - throw com_runtime_error(hr, __FUNCTION__ " Error appending element."); - } + if (FAILED(hr = pConfigRoot->appendChild(pXmlElInnerAuthenticationMethod, NULL))) + throw com_runtime_error(hr, __FUNCTION__ " Error appending element."); } @@ -121,14 +118,12 @@ void eap::credentials_ttls::load(_In_ IXMLDOMNode *pConfigRoot) credentials_tls::load(pConfigRoot); - if (m_inner) { - // Load inner credentials. - com_obj pXmlElInnerAuthenticationMethod; - if (FAILED(hr = eapxml::select_node(pConfigRoot, bstr(L"eap-metadata:InnerAuthenticationMethod"), &pXmlElInnerAuthenticationMethod))) - throw com_runtime_error(hr, __FUNCTION__ " Error selecting element."); - + // Load inner credentials. + com_obj pXmlElInnerAuthenticationMethod; + if (SUCCEEDED(hr = eapxml::select_node(pConfigRoot, bstr(L"eap-metadata:InnerAuthenticationMethod"), &pXmlElInnerAuthenticationMethod))) m_inner->load(pXmlElInnerAuthenticationMethod); - } + else + m_inner->clear(); } diff --git a/lib/TTLS_UI/src/Module.cpp b/lib/TTLS_UI/src/Module.cpp index 0e215d4..b80c22e 100644 --- a/lib/TTLS_UI/src/Module.cpp +++ b/lib/TTLS_UI/src/Module.cpp @@ -105,11 +105,15 @@ void eap::peer_ttls_ui::invoke_config_ui( // This is a blank network profile. Create default configuraton. // Start with PAP inner configuration. + 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)); + unique_ptr cfg_method(new config_method_ttls(*this)); - cfg_method->m_inner.reset(new config_method_pap(*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. config_provider cfg_provider(*this);