From cb24fbd6a3b2e777af18233f6770332b6a53edb0 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Wed, 3 Aug 2016 13:50:12 +0200 Subject: [PATCH] eap::peer_ttls::get_method_properties() implemented --- EAPMethods/src/Main.cpp | 2 +- lib/EAPBase/include/Module.h | 56 +++++++++++++++++++++++++++++++++++- lib/TTLS/include/Module.h | 2 +- lib/TTLS/src/Module.cpp | 45 +++++++++++++++++++++++++---- 4 files changed, 97 insertions(+), 8 deletions(-) diff --git a/EAPMethods/src/Main.cpp b/EAPMethods/src/Main.cpp index 46de3d6..ed74a76 100644 --- a/EAPMethods/src/Main.cpp +++ b/EAPMethods/src/Main.cpp @@ -296,7 +296,7 @@ DWORD APIENTRY EapPeerBeginSession( // Allocate new session. unique_ptr<_EAPMETHOD_SESSION> session(new _EAPMETHOD_SESSION(g_peer)); if (!session) { - g_peer.log_error(*ppEapError = g_peer.make_error(dwResult = ERROR_OUTOFMEMORY, _T(" Error allocating memory for EAP session."))); + g_peer.log_error(*ppEapError = g_peer.make_error(dwResult = ERROR_OUTOFMEMORY, _T(__FUNCTION__) _T(" Error allocating memory for EAP session."))); return dwResult; } diff --git a/lib/EAPBase/include/Module.h b/lib/EAPBase/include/Module.h index 8e78b08..e507e16 100644 --- a/lib/EAPBase/include/Module.h +++ b/lib/EAPBase/include/Module.h @@ -40,6 +40,11 @@ namespace eap /// A group of methods all EAP peers must or should implement. /// template class peer; + + /// + /// EAP_METHOD_PROPERTY helper + /// + class method_property; } #pragma once @@ -763,7 +768,7 @@ namespace eap _In_ const config_providers &cfg, _In_ const credentials_type &cred, _Out_ EAP_METHOD_PROPERTY_ARRAY *pMethodPropertyArray, - _Out_ EAP_ERROR **ppEapError) const = 0; + _Out_ EAP_ERROR **ppEapError) = 0; /// /// Defines the implementation of an EAP method-specific function that obtains the EAP Single-Sign-On (SSO) credential input fields for an EAP method. @@ -889,4 +894,53 @@ namespace eap return false; } }; + + + class method_property : public EAP_METHOD_PROPERTY + { + public: + /// + /// Constructs a BOOL method property + /// + /// \param[in] type EAP method property type + /// \param[in] value Property value + /// + inline method_property(_In_ EAP_METHOD_PROPERTY_TYPE type, _In_ BOOL value) + { + eapMethodPropertyType = type; + eapMethodPropertyValueType = empvtBool; + eapMethodPropertyValue.empvBool.length = sizeof(BOOL); + eapMethodPropertyValue.empvBool.value = value; + } + + + /// + /// Constructs a DWORD method property + /// + /// \param[in] type EAP method property type + /// \param[in] value Property value + /// + inline method_property(_In_ EAP_METHOD_PROPERTY_TYPE type, _In_ DWORD value) + { + eapMethodPropertyType = type; + eapMethodPropertyValueType = empvtDword; + eapMethodPropertyValue.empvDword.length = sizeof(DWORD); + eapMethodPropertyValue.empvDword.value = value; + } + + + /// + /// Constructs a Unicode string method property + /// + /// \param[in] type EAP method property type + /// \param[in] value Property value + /// + inline method_property(_In_ EAP_METHOD_PROPERTY_TYPE type, _In_z_ LPCWSTR value) + { + eapMethodPropertyType = type; + eapMethodPropertyValueType = empvtString; + eapMethodPropertyValue.empvString.length = (DWORD)(sizeof(WCHAR)*(wcslen(value) + 1)); + eapMethodPropertyValue.empvString.value = (BYTE*)value; + } + }; } diff --git a/lib/TTLS/include/Module.h b/lib/TTLS/include/Module.h index fe3b7c8..c21693d 100644 --- a/lib/TTLS/include/Module.h +++ b/lib/TTLS/include/Module.h @@ -100,6 +100,6 @@ namespace eap _In_ const config_providers &cfg, _In_ const credentials_type &cred, _Out_ EAP_METHOD_PROPERTY_ARRAY *pMethodPropertyArray, - _Out_ EAP_ERROR **ppEapError) const; + _Out_ EAP_ERROR **ppEapError); }; } diff --git a/lib/TTLS/src/Module.cpp b/lib/TTLS/src/Module.cpp index f89769c..473f601 100644 --- a/lib/TTLS/src/Module.cpp +++ b/lib/TTLS/src/Module.cpp @@ -209,16 +209,51 @@ bool eap::peer_ttls::get_method_properties( _In_ const config_providers &cfg, _In_ const credentials_type &cred, _Out_ EAP_METHOD_PROPERTY_ARRAY *pMethodPropertyArray, - _Out_ EAP_ERROR **ppEapError) const + _Out_ EAP_ERROR **ppEapError) { UNREFERENCED_PARAMETER(dwVersion); UNREFERENCED_PARAMETER(dwFlags); UNREFERENCED_PARAMETER(hUserImpersonationToken); UNREFERENCED_PARAMETER(cfg); UNREFERENCED_PARAMETER(cred); - UNREFERENCED_PARAMETER(pMethodPropertyArray); - UNREFERENCED_PARAMETER(ppEapError); + assert(pMethodPropertyArray); + assert(ppEapError); - *ppEapError = make_error(ERROR_NOT_SUPPORTED, _T(__FUNCTION__) _T(" Not supported.")); - return false; + vector properties; + properties.reserve(20); + + properties.push_back(eap::method_property(emptPropCipherSuiteNegotiation, TRUE)); + properties.push_back(eap::method_property(emptPropMutualAuth, TRUE)); + properties.push_back(eap::method_property(emptPropIntegrity, TRUE)); + properties.push_back(eap::method_property(emptPropReplayProtection, TRUE)); + properties.push_back(eap::method_property(emptPropConfidentiality, TRUE)); + properties.push_back(eap::method_property(emptPropKeyDerivation, TRUE)); + properties.push_back(eap::method_property(emptPropKeyStrength128, TRUE)); + properties.push_back(eap::method_property(emptPropDictionaryAttackResistance, TRUE)); + properties.push_back(eap::method_property(emptPropFastReconnect, TRUE)); + properties.push_back(eap::method_property(emptPropCryptoBinding, TRUE)); + properties.push_back(eap::method_property(emptPropSessionIndependence, TRUE)); + properties.push_back(eap::method_property(emptPropFragmentation, TRUE)); + properties.push_back(eap::method_property(emptPropStandalone, TRUE)); + properties.push_back(eap::method_property(emptPropMppeEncryption, TRUE)); + properties.push_back(eap::method_property(emptPropTunnelMethod, TRUE)); + properties.push_back(eap::method_property(emptPropSupportsConfig, TRUE)); + properties.push_back(eap::method_property(emptPropMachineAuth, TRUE)); + properties.push_back(eap::method_property(emptPropUserAuth, TRUE)); + properties.push_back(eap::method_property(emptPropIdentityPrivacy, TRUE)); + properties.push_back(eap::method_property(emptPropSharedStateEquivalence, TRUE)); + + // Allocate property array. + DWORD dwCount = (DWORD)properties.size(); + pMethodPropertyArray->pMethodProperty = (EAP_METHOD_PROPERTY*)alloc_memory(sizeof(EAP_METHOD_PROPERTY) * dwCount); + if (!pMethodPropertyArray->pMethodProperty) { + *ppEapError = make_error(ERROR_OUTOFMEMORY, _T(__FUNCTION__) _T(" Error allocating memory for propery array.")); + return false; + } + + // Copy properties. + memcpy(pMethodPropertyArray->pMethodProperty, properties.data(), sizeof(EAP_METHOD_PROPERTY) * dwCount); + pMethodPropertyArray->dwNumberOfProperties = dwCount; + + return true; }