Support for pre-shared credentials introduced
This commit is contained in:
@@ -158,7 +158,7 @@ namespace eap {
|
||||
virtual eap::type_t get_method_id() const;
|
||||
|
||||
public:
|
||||
config_method *m_inner; ///< Inner authentication configuration
|
||||
config *m_inner; ///< Inner authentication configuration
|
||||
};
|
||||
}
|
||||
|
||||
@@ -170,26 +170,31 @@ namespace eapserial
|
||||
pack(cursor, (const eap::config_tls&)val);
|
||||
if (val.m_inner) {
|
||||
if (dynamic_cast<eap::config_pap*>(val.m_inner)) {
|
||||
pack(cursor, (unsigned char)eap::type_pap);
|
||||
pack(cursor, eap::type_pap);
|
||||
pack(cursor, (const eap::config_pap&)*val.m_inner);
|
||||
} else {
|
||||
assert(0); // Unsupported inner authentication method type.
|
||||
pack(cursor, (unsigned char)0);
|
||||
pack(cursor, eap::type_undefined);
|
||||
}
|
||||
} else
|
||||
pack(cursor, (unsigned char)0);
|
||||
pack(cursor, eap::type_undefined);
|
||||
}
|
||||
|
||||
|
||||
inline size_t get_pk_size(const eap::config_ttls &val)
|
||||
{
|
||||
size_t size_inner = sizeof(unsigned char);
|
||||
size_t size_inner;
|
||||
if (val.m_inner) {
|
||||
if (dynamic_cast<eap::config_pap*>(val.m_inner))
|
||||
size_inner += get_pk_size((const eap::config_pap&)*val.m_inner);
|
||||
else
|
||||
if (dynamic_cast<eap::config_pap*>(val.m_inner)) {
|
||||
size_inner =
|
||||
get_pk_size(eap::type_pap) +
|
||||
get_pk_size((const eap::config_pap&)*val.m_inner);
|
||||
} else {
|
||||
size_inner = get_pk_size(eap::type_undefined);
|
||||
assert(0); // Unsupported inner authentication method type.
|
||||
}
|
||||
}
|
||||
} else
|
||||
size_inner = get_pk_size(eap::type_undefined);
|
||||
|
||||
return
|
||||
get_pk_size((const eap::config_tls&)val) +
|
||||
@@ -201,16 +206,19 @@ namespace eapserial
|
||||
{
|
||||
unpack(cursor, (eap::config_tls&)val);
|
||||
|
||||
assert(!val.m_inner);
|
||||
unsigned char eap_type;
|
||||
if (val.m_inner)
|
||||
delete val.m_inner;
|
||||
|
||||
eap::type_t eap_type;
|
||||
unpack(cursor, eap_type);
|
||||
switch (eap_type) {
|
||||
case eap::type_pap:
|
||||
val.m_inner = new eap::config_pap(val.m_module);
|
||||
unpack(cursor, (eap::config_pap&)*val.m_inner);
|
||||
break;
|
||||
case 0 : break;
|
||||
default : assert(0); // Unsupported inner authentication method type.
|
||||
default:
|
||||
val.m_inner = NULL;
|
||||
assert(0); // Unsupported inner authentication method type.
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -124,6 +124,19 @@ namespace eap
|
||||
/// \name XML credentials management
|
||||
/// @{
|
||||
|
||||
///
|
||||
/// Save credentials to XML document
|
||||
///
|
||||
/// \param[in] pDoc XML document
|
||||
/// \param[in] pConfigRoot Suggested root element for saving credentials
|
||||
/// \param[out] ppEapError Pointer to error descriptor in case of failure. Free using `module::free_error_memory()`.
|
||||
///
|
||||
/// \returns
|
||||
/// - \c ERROR_SUCCESS if succeeded
|
||||
/// - error code otherwise
|
||||
///
|
||||
virtual DWORD save(_In_ IXMLDOMDocument *pDoc, _In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **ppEapError) const;
|
||||
|
||||
///
|
||||
/// Load credentials from XML document
|
||||
///
|
||||
|
@@ -93,6 +93,9 @@ DWORD eap::config_ttls::save(_In_ IXMLDOMDocument *pDoc, _In_ IXMLDOMNode *pConf
|
||||
const bstr bstrNamespace(L"urn:ietf:params:xml:ns:yang:ietf-eap-metadata");
|
||||
DWORD dwResult;
|
||||
|
||||
if ((dwResult = config_tls::save(pDoc, pConfigRoot, ppEapError)) != ERROR_SUCCESS)
|
||||
return dwResult;
|
||||
|
||||
// <InnerAuthenticationMethod>
|
||||
com_obj<IXMLDOMElement> pXmlElInnerAuthenticationMethod;
|
||||
if ((dwResult = eapxml::create_element(pDoc, pConfigRoot, bstr(L"eap-metadata:InnerAuthenticationMethod"), bstr(L"InnerAuthenticationMethod"), bstrNamespace, &pXmlElInnerAuthenticationMethod)) != ERROR_SUCCESS) {
|
||||
@@ -113,7 +116,7 @@ DWORD eap::config_ttls::save(_In_ IXMLDOMDocument *pDoc, _In_ IXMLDOMNode *pConf
|
||||
} else
|
||||
return dwResult = ERROR_NOT_SUPPORTED;
|
||||
|
||||
return config_tls::save(pDoc, pConfigRoot, ppEapError);
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
@@ -122,6 +125,9 @@ DWORD eap::config_ttls::load(_In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **pp
|
||||
assert(ppEapError);
|
||||
DWORD dwResult;
|
||||
|
||||
if ((dwResult = config_tls::load(pConfigRoot, ppEapError)) != ERROR_SUCCESS)
|
||||
return dwResult;
|
||||
|
||||
// Load inner authentication configuration (<InnerAuthenticationMethod>).
|
||||
com_obj<IXMLDOMElement> pXmlElInnerAuthenticationMethod;
|
||||
if ((dwResult = eapxml::select_element(pConfigRoot, bstr(L"eap-metadata:InnerAuthenticationMethod"), &pXmlElInnerAuthenticationMethod)) != ERROR_SUCCESS) {
|
||||
@@ -151,7 +157,7 @@ DWORD eap::config_ttls::load(_In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **pp
|
||||
return dwResult;
|
||||
}
|
||||
|
||||
return config_tls::load(pConfigRoot, ppEapError);
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -95,6 +95,36 @@ bool eap::credentials_ttls::empty() const
|
||||
}
|
||||
|
||||
|
||||
DWORD eap::credentials_ttls::save(_In_ IXMLDOMDocument *pDoc, _In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **ppEapError) const
|
||||
{
|
||||
const bstr bstrNamespace(L"urn:ietf:params:xml:ns:yang:ietf-eap-metadata");
|
||||
DWORD dwResult;
|
||||
HRESULT hr;
|
||||
|
||||
if ((dwResult = credentials_tls::save(pDoc, pConfigRoot, ppEapError)) != ERROR_SUCCESS)
|
||||
return dwResult;
|
||||
|
||||
if (m_inner) {
|
||||
// <InnerAuthenticationMethod>
|
||||
winstd::com_obj<IXMLDOMElement> pXmlElInnerAuthenticationMethod;
|
||||
if ((dwResult = eapxml::create_element(pDoc, winstd::bstr(L"InnerAuthenticationMethod"), bstrNamespace, &pXmlElInnerAuthenticationMethod))) {
|
||||
*ppEapError = m_module.make_error(dwResult, 0, NULL, NULL, NULL, _T(__FUNCTION__) _T(" Error creating <InnerAuthenticationMethod> element."), NULL);
|
||||
return dwResult;
|
||||
}
|
||||
|
||||
if ((dwResult = m_inner->save(pDoc, pXmlElInnerAuthenticationMethod, ppEapError)) != ERROR_SUCCESS)
|
||||
return dwResult;
|
||||
|
||||
if (FAILED(hr = pConfigRoot->appendChild(pXmlElInnerAuthenticationMethod, NULL))) {
|
||||
*ppEapError = m_module.make_error(dwResult = HRESULT_CODE(hr), 0, NULL, NULL, NULL, _T(__FUNCTION__) _T(" Error appending <InnerAuthenticationMethod> element."), NULL);
|
||||
return dwResult;
|
||||
}
|
||||
}
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
DWORD eap::credentials_ttls::load(_In_ IXMLDOMNode *pConfigRoot, _Out_ EAP_ERROR **ppEapError)
|
||||
{
|
||||
assert(pConfigRoot);
|
||||
|
Reference in New Issue
Block a user