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

This commit is contained in:
Simon Rozman 2016-08-28 17:43:06 +02:00
parent fc5e54db05
commit 6c66862eed
3 changed files with 25 additions and 40 deletions

View File

@ -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;
}

View File

@ -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) {
// <InnerAuthenticationMethod>
winstd::com_obj<IXMLDOMElement> pXmlElInnerAuthenticationMethod;
if (FAILED(hr = eapxml::create_element(pDoc, winstd::bstr(L"InnerAuthenticationMethod"), bstrNamespace, &pXmlElInnerAuthenticationMethod)))
throw com_runtime_error(hr, __FUNCTION__ " Error creating <InnerAuthenticationMethod> element.");
// <InnerAuthenticationMethod>
winstd::com_obj<IXMLDOMElement> pXmlElInnerAuthenticationMethod;
if (FAILED(hr = eapxml::create_element(pDoc, winstd::bstr(L"InnerAuthenticationMethod"), bstrNamespace, &pXmlElInnerAuthenticationMethod)))
throw com_runtime_error(hr, __FUNCTION__ " Error creating <InnerAuthenticationMethod> 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 <InnerAuthenticationMethod> element.");
}
if (FAILED(hr = pConfigRoot->appendChild(pXmlElInnerAuthenticationMethod, NULL)))
throw com_runtime_error(hr, __FUNCTION__ " Error appending <InnerAuthenticationMethod> 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<IXMLDOMNode> pXmlElInnerAuthenticationMethod;
if (FAILED(hr = eapxml::select_node(pConfigRoot, bstr(L"eap-metadata:InnerAuthenticationMethod"), &pXmlElInnerAuthenticationMethod)))
throw com_runtime_error(hr, __FUNCTION__ " Error selecting <InnerAuthenticationMethod> element.");
// Load inner credentials.
com_obj<IXMLDOMNode> pXmlElInnerAuthenticationMethod;
if (SUCCEEDED(hr = eapxml::select_node(pConfigRoot, bstr(L"eap-metadata:InnerAuthenticationMethod"), &pXmlElInnerAuthenticationMethod)))
m_inner->load(pXmlElInnerAuthenticationMethod);
}
else
m_inner->clear();
}

View File

@ -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<config_method_ttls> 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);