EAPMsg >> EapHost
This commit is contained in:
2
lib/EapHost/build/.gitignore
vendored
Normal file
2
lib/EapHost/build/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/temp
|
||||
/*.user
|
12
lib/EapHost/build/EapHost.props
Normal file
12
lib/EapHost/build/EapHost.props
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ImportGroup Label="PropertySheets" />
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup />
|
||||
<ItemDefinitionGroup>
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>..\..\Events\build\temp\Events.$(Platform).$(Configuration).$(PlatformToolset);..\..\WinStd\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup />
|
||||
</Project>
|
106
lib/EapHost/build/EapHost.vcxproj
Normal file
106
lib/EapHost/build/EapHost.vcxproj
Normal file
@@ -0,0 +1,106 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{B385EC2B-C3F4-48BB-9BAC-8B996DE7F754}</ProjectGuid>
|
||||
<RootNamespace>EapHost</RootNamespace>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>StaticLibrary</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\..\..\include\Win32.props" />
|
||||
<Import Project="..\..\..\include\Debug.props" />
|
||||
<Import Project="EapHost.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\..\..\include\x64.props" />
|
||||
<Import Project="..\..\..\include\Debug.props" />
|
||||
<Import Project="EapHost.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\..\..\include\Win32.props" />
|
||||
<Import Project="..\..\..\include\Release.props" />
|
||||
<Import Project="EapHost.props" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\..\..\include\x64.props" />
|
||||
<Import Project="..\..\..\include\Release.props" />
|
||||
<Import Project="EapHost.props" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\include\Config.h" />
|
||||
<ClInclude Include="..\include\Credentials.h" />
|
||||
<ClInclude Include="..\include\Method.h" />
|
||||
<ClInclude Include="..\src\StdAfx.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\src\Config.cpp" />
|
||||
<ClCompile Include="..\src\Credentials.cpp" />
|
||||
<ClCompile Include="..\src\Method.cpp" />
|
||||
<ClCompile Include="..\src\StdAfx.cpp">
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Create</PrecompiledHeader>
|
||||
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Create</PrecompiledHeader>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\Events\build\Events.vcxproj">
|
||||
<Project>{d63f24bd-92a0-4d6b-8b69-ed947e4d2b1b}</Project>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
41
lib/EapHost/build/EapHost.vcxproj.filters
Normal file
41
lib/EapHost/build/EapHost.vcxproj.filters
Normal file
@@ -0,0 +1,41 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="Source Files">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="Header Files">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\src\StdAfx.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\Config.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\Method.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\include\Credentials.h">
|
||||
<Filter>Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\src\StdAfx.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\Config.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\Method.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\src\Credentials.cpp">
|
||||
<Filter>Source Files</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
157
lib/EapHost/include/Config.h
Normal file
157
lib/EapHost/include/Config.h
Normal file
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <sal.h>
|
||||
|
||||
namespace eap
|
||||
{
|
||||
///
|
||||
/// EapHost peer method configuration
|
||||
///
|
||||
class config_method_eaphost;
|
||||
}
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../../EAPBase/include/Config.h"
|
||||
|
||||
#include <Windows.h>
|
||||
#include <sal.h>
|
||||
#include <tchar.h>
|
||||
|
||||
|
||||
namespace eap
|
||||
{
|
||||
class config_method_eaphost : public config_method
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Constructs configuration
|
||||
///
|
||||
/// \param[in] mod EAP module to use for global services
|
||||
/// \param[in] level Config level (0=outer, 1=inner, 2=inner-inner...)
|
||||
///
|
||||
config_method_eaphost(_In_ module &mod, _In_ unsigned int level);
|
||||
|
||||
///
|
||||
/// Copies configuration
|
||||
///
|
||||
/// \param[in] other Configuration to copy from
|
||||
///
|
||||
config_method_eaphost(_In_ const config_method_eaphost &other);
|
||||
|
||||
///
|
||||
/// Moves configuration
|
||||
///
|
||||
/// \param[in] other Configuration to move from
|
||||
///
|
||||
config_method_eaphost(_Inout_ config_method_eaphost &&other);
|
||||
|
||||
///
|
||||
/// Copies configuration
|
||||
///
|
||||
/// \param[in] other Configuration to copy from
|
||||
///
|
||||
/// \returns Reference to this object
|
||||
///
|
||||
config_method_eaphost& operator=(_In_ const config_method_eaphost &other);
|
||||
|
||||
///
|
||||
/// Moves configuration
|
||||
///
|
||||
/// \param[in] other Configuration to move from
|
||||
///
|
||||
/// \returns Reference to this object
|
||||
///
|
||||
config_method_eaphost& operator=(_Inout_ config_method_eaphost &&other);
|
||||
|
||||
///
|
||||
/// Clones configuration
|
||||
///
|
||||
/// \returns Pointer to cloned configuration
|
||||
///
|
||||
virtual config* clone() const;
|
||||
|
||||
/// \name XML configuration management
|
||||
/// @{
|
||||
|
||||
///
|
||||
/// Save to XML document
|
||||
///
|
||||
/// \param[in] pDoc XML document
|
||||
/// \param[in] pConfigRoot Suggested root element for saving
|
||||
///
|
||||
virtual void save(_In_ IXMLDOMDocument *pDoc, _In_ IXMLDOMNode *pConfigRoot) const;
|
||||
|
||||
///
|
||||
/// Load from XML document
|
||||
///
|
||||
/// \param[in] pConfigRoot Root element for loading
|
||||
///
|
||||
virtual void load(_In_ IXMLDOMNode *pConfigRoot);
|
||||
|
||||
/// @}
|
||||
|
||||
/// \name BLOB management
|
||||
/// @{
|
||||
|
||||
///
|
||||
/// Packs a configuration
|
||||
///
|
||||
/// \param[inout] cursor Memory cursor
|
||||
///
|
||||
virtual void operator<<(_Inout_ cursor_out &cursor) const;
|
||||
|
||||
///
|
||||
/// Returns packed size of a configuration
|
||||
///
|
||||
/// \returns Size of data when packed (in bytes)
|
||||
///
|
||||
virtual size_t get_pk_size() const;
|
||||
|
||||
///
|
||||
/// Unpacks a configuration
|
||||
///
|
||||
/// \param[inout] cursor Memory cursor
|
||||
///
|
||||
virtual void operator>>(_Inout_ cursor_in &cursor);
|
||||
|
||||
/// @}
|
||||
|
||||
///
|
||||
/// Returns EAP method type of this configuration
|
||||
///
|
||||
virtual winstd::eap_type_t get_method_id() const;
|
||||
|
||||
///
|
||||
/// Returns EAP method type as a string
|
||||
///
|
||||
virtual const wchar_t* get_method_str() const;
|
||||
|
||||
///
|
||||
/// Creates a blank set of credentials suitable for this method
|
||||
///
|
||||
virtual credentials* make_credentials() const;
|
||||
|
||||
public:
|
||||
EAP_METHOD_TYPE m_type; ///< EapHost method type: (EAP type, vendor ID, vendor type, author ID) tuple
|
||||
sanitizing_blob m_cfg_blob; ///< Method configuration BLOB
|
||||
};
|
||||
}
|
218
lib/EapHost/include/Credentials.h
Normal file
218
lib/EapHost/include/Credentials.h
Normal file
@@ -0,0 +1,218 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <sal.h>
|
||||
|
||||
namespace eap
|
||||
{
|
||||
///
|
||||
/// EapHost peer method credentials
|
||||
///
|
||||
class credentials_eaphost;
|
||||
}
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Config.h"
|
||||
|
||||
#include "../../EAPBase/include/Credentials.h"
|
||||
|
||||
#include <WinStd/Crypt.h>
|
||||
|
||||
#include <Windows.h>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace eap
|
||||
{
|
||||
class credentials_eaphost : public credentials
|
||||
{
|
||||
public:
|
||||
///
|
||||
/// Constructs credentials
|
||||
///
|
||||
/// \param[in] mod EAP module to use for global services
|
||||
///
|
||||
credentials_eaphost(_In_ module &mod);
|
||||
|
||||
///
|
||||
/// Copies credentials
|
||||
///
|
||||
/// \param[in] other Credentials to copy from
|
||||
///
|
||||
credentials_eaphost(_In_ const credentials_eaphost &other);
|
||||
|
||||
///
|
||||
/// Moves credentials
|
||||
///
|
||||
/// \param[in] other Credentials to move from
|
||||
///
|
||||
credentials_eaphost(_Inout_ credentials_eaphost &&other);
|
||||
|
||||
///
|
||||
/// Copies credentials
|
||||
///
|
||||
/// \param[in] other Credentials to copy from
|
||||
///
|
||||
/// \returns Reference to this object
|
||||
///
|
||||
credentials_eaphost& operator=(_In_ const credentials_eaphost &other);
|
||||
|
||||
///
|
||||
/// Moves credentials
|
||||
///
|
||||
/// \param[in] other Credentials to move from
|
||||
///
|
||||
/// \returns Reference to this object
|
||||
///
|
||||
credentials_eaphost& operator=(_Inout_ credentials_eaphost &&other);
|
||||
|
||||
///
|
||||
/// Clones credentials
|
||||
///
|
||||
/// \returns Pointer to cloned credentials
|
||||
///
|
||||
virtual config* clone() const;
|
||||
|
||||
///
|
||||
/// Resets credentials
|
||||
///
|
||||
virtual void clear();
|
||||
|
||||
///
|
||||
/// Test credentials if blank
|
||||
///
|
||||
/// \returns
|
||||
/// - \c true if blank
|
||||
/// - \c false otherwise
|
||||
///
|
||||
virtual bool empty() const;
|
||||
|
||||
/// \name XML credentials management
|
||||
/// @{
|
||||
|
||||
///
|
||||
/// Save to XML document
|
||||
///
|
||||
/// \param[in] pDoc XML document
|
||||
/// \param[in] pConfigRoot Suggested root element for saving
|
||||
///
|
||||
virtual void save(_In_ IXMLDOMDocument *pDoc, _In_ IXMLDOMNode *pConfigRoot) const;
|
||||
|
||||
///
|
||||
/// Load from XML document
|
||||
///
|
||||
/// \param[in] pConfigRoot Root element for loading
|
||||
///
|
||||
virtual void load(_In_ IXMLDOMNode *pConfigRoot);
|
||||
|
||||
/// @}
|
||||
|
||||
/// \name BLOB management
|
||||
/// @{
|
||||
|
||||
///
|
||||
/// Packs a configuration
|
||||
///
|
||||
/// \param[inout] cursor Memory cursor
|
||||
///
|
||||
virtual void operator<<(_Inout_ cursor_out &cursor) const;
|
||||
|
||||
///
|
||||
/// Returns packed size of a configuration
|
||||
///
|
||||
/// \returns Size of data when packed (in bytes)
|
||||
///
|
||||
virtual size_t get_pk_size() const;
|
||||
|
||||
///
|
||||
/// Unpacks a configuration
|
||||
///
|
||||
/// \param[inout] cursor Memory cursor
|
||||
///
|
||||
virtual void operator>>(_Inout_ cursor_in &cursor);
|
||||
|
||||
/// @}
|
||||
|
||||
/// \name Storage
|
||||
/// @{
|
||||
|
||||
///
|
||||
/// Save credentials to Windows Credential Manager
|
||||
///
|
||||
/// \param[in] pszTargetName The name in Windows Credential Manager to store credentials as
|
||||
/// \param[in] level Credential level (0=outer, 1=inner, 2=inner-inner...)
|
||||
///
|
||||
virtual void store(_In_z_ LPCTSTR pszTargetName, _In_ unsigned int level) const;
|
||||
|
||||
///
|
||||
/// Retrieve credentials from Windows Credential Manager
|
||||
///
|
||||
/// \param[in] pszTargetName The name in Windows Credential Manager to retrieve credentials from
|
||||
/// \param[in] level Credential level (0=outer, 1=inner, 2=inner-inner...)
|
||||
///
|
||||
virtual void retrieve(_In_z_ LPCTSTR pszTargetName, _In_ unsigned int level);
|
||||
|
||||
///
|
||||
/// Return target suffix for Windows Credential Manager credential name
|
||||
///
|
||||
virtual LPCTSTR target_suffix() const;
|
||||
|
||||
/// @}
|
||||
|
||||
///
|
||||
/// Returns credential identity.
|
||||
///
|
||||
virtual std::wstring get_identity() const;
|
||||
|
||||
///
|
||||
/// Combine credentials in the following order:
|
||||
///
|
||||
/// 1. Cached credentials
|
||||
/// 2. Configured credentials (if \p cfg is derived from config_method_with_cred)
|
||||
/// 3. Stored credentials
|
||||
///
|
||||
/// \param[in] dwFlags A combination of [EAP flags](https://msdn.microsoft.com/en-us/library/windows/desktop/bb891975.aspx) that describe the EAP authentication session behavior
|
||||
/// \param[in] hTokenImpersonateUser Impersonation token for a logged-on user to collect user-related information
|
||||
/// \param[in] cred_cached Cached credentials (optional, can be \c NULL, must be credentials_eaphost* type)
|
||||
/// \param[in] cfg Method configuration (unused, as must be as config_method_eaphost is not derived from config_method_with_cred)
|
||||
/// \param[in] pszTargetName The name in Windows Credential Manager to retrieve credentials from (optional, can be \c NULL)
|
||||
///
|
||||
/// \returns
|
||||
/// - \c source_cache Credentials were obtained from EapHost cache
|
||||
/// - \c source_config Credentials were set by method configuration
|
||||
/// - \c source_storage Credentials were loaded from Windows Credential Manager
|
||||
///
|
||||
virtual source_t combine(
|
||||
_In_ DWORD dwFlags,
|
||||
_In_ HANDLE hTokenImpersonateUser,
|
||||
_In_opt_ const credentials *cred_cached,
|
||||
_In_ const config_method &cfg,
|
||||
_In_opt_z_ LPCTSTR pszTargetName);
|
||||
|
||||
public:
|
||||
sanitizing_blob m_cred_blob; ///< Credentials BLOB
|
||||
|
||||
private:
|
||||
/// \cond internal
|
||||
static const unsigned char s_entropy[1024];
|
||||
/// \endcond
|
||||
};
|
||||
}
|
200
lib/EapHost/include/Method.h
Normal file
200
lib/EapHost/include/Method.h
Normal file
@@ -0,0 +1,200 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
namespace eap
|
||||
{
|
||||
///
|
||||
/// EapHost peer method
|
||||
///
|
||||
class method_eaphost;
|
||||
}
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Config.h"
|
||||
#include "Credentials.h"
|
||||
|
||||
#include "../../EAPBase/include/Method.h"
|
||||
|
||||
|
||||
namespace eap
|
||||
{
|
||||
class method_eaphost : public method_noneap
|
||||
{
|
||||
WINSTD_NONCOPYABLE(method_eaphost)
|
||||
|
||||
public:
|
||||
///
|
||||
/// Constructs an EAP method
|
||||
///
|
||||
/// \param[in] mod EAP module to use for global services
|
||||
/// \param[in] cfg Method configuration
|
||||
/// \param[in] cred User credentials
|
||||
///
|
||||
method_eaphost(_In_ module &module, _In_ config_method_eaphost &cfg, _In_ credentials_eaphost &cred);
|
||||
|
||||
///
|
||||
/// Moves an EAP method
|
||||
///
|
||||
/// \param[in] other EAP method to move from
|
||||
///
|
||||
method_eaphost(_Inout_ method_eaphost &&other);
|
||||
|
||||
///
|
||||
/// Moves an EAP method
|
||||
///
|
||||
/// \param[in] other EAP method to move from
|
||||
///
|
||||
/// \returns Reference to this object
|
||||
///
|
||||
method_eaphost& operator=(_Inout_ method_eaphost &&other);
|
||||
|
||||
/// \name Packet processing
|
||||
/// @{
|
||||
|
||||
///
|
||||
/// Starts an EAP authentication session on the peer EapHost using the EAP method.
|
||||
///
|
||||
/// \sa [EapPeerBeginSession function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363600.aspx)
|
||||
///
|
||||
virtual void begin_session(
|
||||
_In_ DWORD dwFlags,
|
||||
_In_ const EapAttributes *pAttributeArray,
|
||||
_In_ HANDLE hTokenImpersonateUser,
|
||||
_In_opt_ DWORD dwMaxSendPacketSize = MAXDWORD);
|
||||
|
||||
///
|
||||
/// Ends an EAP authentication session for the EAP method.
|
||||
///
|
||||
/// \sa [EapPeerEndSession function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363604.aspx)
|
||||
///
|
||||
virtual void end_session();
|
||||
|
||||
///
|
||||
/// Processes a packet received by EapHost from a supplicant.
|
||||
///
|
||||
/// \sa [EapPeerProcessRequestPacket function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363621.aspx)
|
||||
///
|
||||
virtual void process_request_packet(
|
||||
_In_bytecount_(dwReceivedPacketSize) const void *pReceivedPacket,
|
||||
_In_ DWORD dwReceivedPacketSize,
|
||||
_Out_ EapPeerMethodOutput *pEapOutput);
|
||||
|
||||
///
|
||||
/// Obtains a response packet from the EAP method.
|
||||
///
|
||||
/// \sa [EapPeerGetResponsePacket function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363610.aspx)
|
||||
///
|
||||
virtual void get_response_packet(
|
||||
_Inout_bytecap_(*dwSendPacketSize) void *pSendPacket,
|
||||
_Inout_ DWORD *pdwSendPacketSize);
|
||||
|
||||
///
|
||||
/// Obtains the result of an authentication session from the EAP method.
|
||||
///
|
||||
/// \sa [EapPeerGetResult function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363611.aspx)
|
||||
///
|
||||
virtual void get_result(
|
||||
_In_ EapPeerMethodResultReason reason,
|
||||
_Inout_ EapPeerMethodResult *pResult);
|
||||
|
||||
/// @}
|
||||
|
||||
/// \name User Interaction
|
||||
/// @{
|
||||
|
||||
///
|
||||
/// Obtains the user interface context from the EAP method.
|
||||
///
|
||||
/// \note This function is always followed by the `EapPeerInvokeInteractiveUI()` function, which is followed by the `EapPeerSetUIContext()` function.
|
||||
///
|
||||
/// \sa [EapPeerGetUIContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363612.aspx)
|
||||
///
|
||||
virtual void get_ui_context(
|
||||
_Inout_ BYTE **ppUIContextData,
|
||||
_Inout_ DWORD *pdwUIContextDataSize);
|
||||
|
||||
///
|
||||
/// Provides a user interface context to the EAP method.
|
||||
///
|
||||
/// \note This function is called after the UI has been raised through the `EapPeerGetUIContext()` function.
|
||||
///
|
||||
/// \sa [EapPeerSetUIContext function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363626.aspx)
|
||||
///
|
||||
virtual void set_ui_context(
|
||||
_In_count_(dwUIContextDataSize) const BYTE *pUIContextData,
|
||||
_In_ DWORD dwUIContextDataSize,
|
||||
_Out_ EapPeerMethodOutput *pEapOutput);
|
||||
|
||||
/// @}
|
||||
|
||||
/// \name EAP Response Attributes
|
||||
/// @{
|
||||
|
||||
///
|
||||
/// Obtains an array of EAP response attributes from the EAP method.
|
||||
///
|
||||
/// \sa [EapPeerGetResponseAttributes function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363609.aspx)
|
||||
///
|
||||
virtual void get_response_attributes(_Inout_ EapAttributes *pAttribs);
|
||||
|
||||
///
|
||||
/// Provides an updated array of EAP response attributes to the EAP method.
|
||||
///
|
||||
/// \sa [EapPeerSetResponseAttributes function](https://msdn.microsoft.com/en-us/library/windows/desktop/aa363625.aspx)
|
||||
///
|
||||
virtual void set_response_attributes(
|
||||
_In_ const EapAttributes *pAttribs,
|
||||
_Out_ EapPeerMethodOutput *pEapOutput);
|
||||
|
||||
/// @}
|
||||
|
||||
protected:
|
||||
///
|
||||
/// Converts EapHost peer action to output structure.
|
||||
///
|
||||
/// \param[in ] action EapHost peer action
|
||||
/// \param[out] pEapOutput EAP method output structure
|
||||
///
|
||||
inline void action_to_output(
|
||||
_In_ EapHostPeerResponseAction action,
|
||||
_Out_ EapPeerMethodOutput *pEapOutput)
|
||||
{
|
||||
switch (action) {
|
||||
case EapHostPeerResponseDiscard : pEapOutput->action = EapPeerMethodResponseActionDiscard ; break;
|
||||
case EapHostPeerResponseSend : pEapOutput->action = EapPeerMethodResponseActionSend ; break;
|
||||
case EapHostPeerResponseResult : pEapOutput->action = EapPeerMethodResponseActionResult ; break;
|
||||
case EapHostPeerResponseInvokeUi : pEapOutput->action = EapPeerMethodResponseActionInvokeUI; break;
|
||||
case EapHostPeerResponseRespond : pEapOutput->action = EapPeerMethodResponseActionRespond ; break;
|
||||
case EapHostPeerResponseStartAuthentication: pEapOutput->action = EapPeerMethodResponseActionDiscard ; break; // The session could not be found. So the supplicant either needs to start session again with the same packet or discard the packet.
|
||||
case EapHostPeerResponseNone : pEapOutput->action = EapPeerMethodResponseActionNone ; break;
|
||||
default : throw std::invalid_argument(winstd::string_printf(__FUNCTION__ " Unknown action (%u).", action).c_str());
|
||||
}
|
||||
pEapOutput->fAllowNotifications = TRUE;
|
||||
}
|
||||
|
||||
protected:
|
||||
EAP_SESSIONID m_session_id; ///< EAP session ID
|
||||
|
||||
sanitizing_blob m_ctx_req_blob; ///< Inner UI context request
|
||||
sanitizing_blob m_ctx_res_blob; ///< Inner UI context response
|
||||
};
|
||||
}
|
177
lib/EapHost/src/Config.cpp
Normal file
177
lib/EapHost/src/Config.cpp
Normal file
@@ -0,0 +1,177 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace winstd;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// eap::config_method_eaphost
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
eap::config_method_eaphost::config_method_eaphost(_In_ module &mod, _In_ unsigned int level) : config_method(mod, level)
|
||||
{
|
||||
memset(&m_type, 0, sizeof(EAP_METHOD_TYPE));
|
||||
}
|
||||
|
||||
|
||||
eap::config_method_eaphost::config_method_eaphost(_In_ const config_method_eaphost &other) :
|
||||
m_type (other.m_type ),
|
||||
m_cfg_blob (other.m_cfg_blob),
|
||||
config_method(other )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
eap::config_method_eaphost::config_method_eaphost(_Inout_ config_method_eaphost &&other) :
|
||||
m_type (std::move(other.m_type )),
|
||||
m_cfg_blob (std::move(other.m_cfg_blob)),
|
||||
config_method(std::move(other ))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
eap::config_method_eaphost& eap::config_method_eaphost::operator=(_In_ const config_method_eaphost &other)
|
||||
{
|
||||
if (this != &other) {
|
||||
(config_method&)*this = other;
|
||||
m_type = other.m_type;
|
||||
m_cfg_blob = other.m_cfg_blob;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
eap::config_method_eaphost& eap::config_method_eaphost::operator=(_Inout_ config_method_eaphost &&other)
|
||||
{
|
||||
if (this != &other) {
|
||||
(config_method&&)*this = std::move(other );
|
||||
m_type = std::move(other.m_type );
|
||||
m_cfg_blob = std::move(other.m_cfg_blob);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
eap::config* eap::config_method_eaphost::clone() const
|
||||
{
|
||||
return new config_method_eaphost(*this);
|
||||
}
|
||||
|
||||
|
||||
void eap::config_method_eaphost::save(_In_ IXMLDOMDocument *pDoc, _In_ IXMLDOMNode *pConfigRoot) const
|
||||
{
|
||||
assert(pDoc);
|
||||
assert(pConfigRoot);
|
||||
|
||||
config_method::save(pDoc, pConfigRoot);
|
||||
|
||||
// Convert configuration BLOB to XML using EapHost (and ultimately method peer's EapPeerConfigBlob2Xml).
|
||||
com_obj<IXMLDOMDocument2> pConfigDoc;
|
||||
eap_error error;
|
||||
DWORD dwResult = EapHostPeerConfigBlob2Xml(0, m_type, (DWORD)m_cfg_blob.size(), const_cast<BYTE*>(m_cfg_blob.data()), &pConfigDoc, &error._Myptr);
|
||||
if (dwResult == ERROR_SUCCESS) {
|
||||
HRESULT hr;
|
||||
|
||||
com_obj<IXMLDOMElement> pXmlElConfigDoc;
|
||||
if (FAILED(hr = pConfigDoc->get_documentElement(&pXmlElConfigDoc)))
|
||||
throw com_runtime_error(hr, __FUNCTION__ " Error getting XML document element.");
|
||||
|
||||
// Insert method configuration into our XML configuration.
|
||||
if (FAILED(hr = pConfigRoot->appendChild(pXmlElConfigDoc, NULL)))
|
||||
throw com_runtime_error(hr, __FUNCTION__ " Error appending configuration document element.");
|
||||
} else if (error)
|
||||
throw eap_runtime_error(*error , __FUNCTION__ " EapHostPeerConfigBlob2Xml failed.");
|
||||
else
|
||||
throw win_runtime_error(dwResult, __FUNCTION__ " EapHostPeerConfigBlob2Xml failed.");
|
||||
}
|
||||
|
||||
|
||||
void eap::config_method_eaphost::load(_In_ IXMLDOMNode *pConfigRoot)
|
||||
{
|
||||
assert(pConfigRoot);
|
||||
|
||||
config_method::load(pConfigRoot);
|
||||
|
||||
// <EapHostConfig>
|
||||
winstd::com_obj<IXMLDOMElement> pXmlElEapHostConfig;
|
||||
if (SUCCEEDED(eapxml::select_element(pConfigRoot, winstd::bstr(L"eaphostconfig:EapHostConfig"), pXmlElEapHostConfig))) {
|
||||
// Convert configuration XML to BLOB using EapHost (and ultimately method peer's EapPeerConfigXml2Blob).
|
||||
DWORD cfg_data_size = 0;
|
||||
eap_blob cfg_data;
|
||||
eap_error error;
|
||||
DWORD dwResult = EapHostPeerConfigXml2Blob(0, pXmlElEapHostConfig, &cfg_data_size, &cfg_data._Myptr, &m_type, &error._Myptr);
|
||||
if (dwResult == ERROR_SUCCESS) {
|
||||
const BYTE *_cfg_data = cfg_data.get();
|
||||
m_cfg_blob.assign(_cfg_data, _cfg_data + cfg_data_size);
|
||||
} else if (error)
|
||||
throw eap_runtime_error(*error , __FUNCTION__ " EapHostPeerConfigBlob2Xml failed.");
|
||||
else
|
||||
throw win_runtime_error(dwResult, __FUNCTION__ " EapHostPeerConfigBlob2Xml failed.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void eap::config_method_eaphost::operator<<(_Inout_ cursor_out &cursor) const
|
||||
{
|
||||
config_method::operator<<(cursor);
|
||||
cursor << m_type ;
|
||||
cursor << m_cfg_blob;
|
||||
}
|
||||
|
||||
|
||||
size_t eap::config_method_eaphost::get_pk_size() const
|
||||
{
|
||||
return
|
||||
config_method::get_pk_size() +
|
||||
pksizeof(m_type ) +
|
||||
pksizeof(m_cfg_blob);
|
||||
}
|
||||
|
||||
|
||||
void eap::config_method_eaphost::operator>>(_Inout_ cursor_in &cursor)
|
||||
{
|
||||
config_method::operator>>(cursor);
|
||||
cursor >> m_type ;
|
||||
cursor >> m_cfg_blob;
|
||||
}
|
||||
|
||||
|
||||
eap_type_t eap::config_method_eaphost::get_method_id() const
|
||||
{
|
||||
return (eap_type_t)m_type.eapType.type;
|
||||
}
|
||||
|
||||
|
||||
const wchar_t* eap::config_method_eaphost::get_method_str() const
|
||||
{
|
||||
// TODO: Query registry for EAP method name (PeerFriendlyName using RegLoadMUIString()).
|
||||
return L"EapHost";
|
||||
}
|
||||
|
||||
|
||||
eap::credentials* eap::config_method_eaphost::make_credentials() const
|
||||
{
|
||||
return new credentials_eaphost(m_module);
|
||||
}
|
387
lib/EapHost/src/Credentials.cpp
Normal file
387
lib/EapHost/src/Credentials.cpp
Normal file
@@ -0,0 +1,387 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#pragma comment(lib, "Eappprxy.lib")
|
||||
|
||||
using namespace std;
|
||||
using namespace winstd;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// eap::credentials_eaphost
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
eap::credentials_eaphost::credentials_eaphost(_In_ module &mod) : credentials(mod)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
eap::credentials_eaphost::credentials_eaphost(_In_ const credentials_eaphost &other) :
|
||||
m_cred_blob(other.m_cred_blob),
|
||||
credentials(other )
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
eap::credentials_eaphost::credentials_eaphost(_Inout_ credentials_eaphost &&other) :
|
||||
m_cred_blob(std::move(other.m_cred_blob)),
|
||||
credentials(std::move(other ))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
eap::credentials_eaphost& eap::credentials_eaphost::operator=(_In_ const credentials_eaphost &other)
|
||||
{
|
||||
if (this != &other) {
|
||||
(credentials&)*this = other;
|
||||
m_cred_blob = other.m_cred_blob;
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
eap::credentials_eaphost& eap::credentials_eaphost::operator=(_Inout_ credentials_eaphost &&other)
|
||||
{
|
||||
if (this != &other) {
|
||||
(credentials&)*this = std::move(other);
|
||||
m_cred_blob = std::move(other.m_cred_blob);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
eap::config* eap::credentials_eaphost::clone() const
|
||||
{
|
||||
return new credentials_eaphost(*this);
|
||||
}
|
||||
|
||||
|
||||
void eap::credentials_eaphost::clear()
|
||||
{
|
||||
credentials::clear();
|
||||
m_cred_blob.clear();
|
||||
}
|
||||
|
||||
|
||||
bool eap::credentials_eaphost::empty() const
|
||||
{
|
||||
return m_cred_blob.empty();
|
||||
}
|
||||
|
||||
|
||||
void eap::credentials_eaphost::save(_In_ IXMLDOMDocument *pDoc, _In_ IXMLDOMNode *pConfigRoot) const
|
||||
{
|
||||
assert(pDoc);
|
||||
assert(pConfigRoot);
|
||||
|
||||
credentials::save(pDoc, pConfigRoot);
|
||||
|
||||
HRESULT hr;
|
||||
|
||||
// <Credentials>
|
||||
if (FAILED(hr = eapxml::put_element_base64(pDoc, pConfigRoot, bstr(L"Credentials"), namespace_eapmetadata, m_cred_blob.data(), m_cred_blob.size())))
|
||||
throw com_runtime_error(hr, __FUNCTION__ " Error creating <Credentials> element.");
|
||||
}
|
||||
|
||||
|
||||
void eap::credentials_eaphost::load(_In_ IXMLDOMNode *pConfigRoot)
|
||||
{
|
||||
assert(pConfigRoot);
|
||||
HRESULT hr;
|
||||
|
||||
credentials::load(pConfigRoot);
|
||||
|
||||
std::wstring xpath(eapxml::get_xpath(pConfigRoot));
|
||||
|
||||
m_cred_blob.clear();
|
||||
if (FAILED(hr = eapxml::get_element_base64(pConfigRoot, bstr(L"eap-metadata:Credentials"), m_cred_blob)))
|
||||
throw com_runtime_error(hr, __FUNCTION__ " Error reading <Credentials> element.");
|
||||
|
||||
// TODO: Finish log output!
|
||||
//m_module.log_config((xpath + L"/Credentials").c_str(), get_name().c_str());
|
||||
}
|
||||
|
||||
|
||||
void eap::credentials_eaphost::operator<<(_Inout_ cursor_out &cursor) const
|
||||
{
|
||||
credentials::operator<<(cursor);
|
||||
cursor << m_cred_blob;
|
||||
}
|
||||
|
||||
|
||||
size_t eap::credentials_eaphost::get_pk_size() const
|
||||
{
|
||||
return
|
||||
credentials::get_pk_size() +
|
||||
pksizeof(m_cred_blob);
|
||||
}
|
||||
|
||||
|
||||
void eap::credentials_eaphost::operator>>(_Inout_ cursor_in &cursor)
|
||||
{
|
||||
credentials::operator>>(cursor);
|
||||
cursor >> m_cred_blob;
|
||||
}
|
||||
|
||||
|
||||
void eap::credentials_eaphost::store(_In_z_ LPCTSTR pszTargetName, _In_ unsigned int level) const
|
||||
{
|
||||
// TODO: Finish!
|
||||
UNREFERENCED_PARAMETER(pszTargetName);
|
||||
UNREFERENCED_PARAMETER(level);
|
||||
|
||||
//assert(pszTargetName);
|
||||
|
||||
//data_blob cred_enc;
|
||||
//if (m_cred_blob) {
|
||||
// // Encrypt the certificate using user's key.
|
||||
// DATA_BLOB cred_blob = { m_cred_blob->cbCertEncoded, m_cred_blob->pbCertEncoded };
|
||||
// DATA_BLOB entropy_blob = { sizeof(s_entropy) , (LPBYTE)s_entropy };
|
||||
// if (!CryptProtectData(&cred_blob, NULL, &entropy_blob, NULL, NULL, CRYPTPROTECT_UI_FORBIDDEN, &cred_enc))
|
||||
// throw win_runtime_error(__FUNCTION__ " CryptProtectData failed.");
|
||||
//}
|
||||
|
||||
//tstring target(target_name(pszTargetName, level));
|
||||
|
||||
//// Write credentials.
|
||||
//assert(cred_enc.cbData < CRED_MAX_CREDENTIAL_BLOB_SIZE);
|
||||
//assert(m_identity.length() < CRED_MAX_USERNAME_LENGTH );
|
||||
//CREDENTIAL cred = {
|
||||
// 0, // Flags
|
||||
// CRED_TYPE_GENERIC, // Type
|
||||
// (LPTSTR)target.c_str(), // TargetName
|
||||
// _T(""), // Comment
|
||||
// { 0, 0 }, // LastWritten
|
||||
// cred_enc.cbData, // CredentialBlobSize
|
||||
// cred_enc.pbData, // CredentialBlob
|
||||
// CRED_PERSIST_ENTERPRISE, // Persist
|
||||
// 0, // AttributeCount
|
||||
// NULL, // Attributes
|
||||
// NULL, // TargetAlias
|
||||
// (LPTSTR)m_identity.c_str() // UserName
|
||||
//};
|
||||
//if (!CredWrite(&cred, 0))
|
||||
// throw win_runtime_error(__FUNCTION__ " CredWrite failed.");
|
||||
}
|
||||
|
||||
|
||||
void eap::credentials_eaphost::retrieve(_In_z_ LPCTSTR pszTargetName, _In_ unsigned int level)
|
||||
{
|
||||
// TODO: Finish!
|
||||
UNREFERENCED_PARAMETER(pszTargetName);
|
||||
UNREFERENCED_PARAMETER(level);
|
||||
|
||||
//assert(pszTargetName);
|
||||
|
||||
//// Read credentials.
|
||||
//unique_ptr<CREDENTIAL, CredFree_delete<CREDENTIAL> > cred;
|
||||
//if (!CredRead(target_name(pszTargetName, level).c_str(), CRED_TYPE_GENERIC, 0, (PCREDENTIAL*)&cred))
|
||||
// throw win_runtime_error(__FUNCTION__ " CredRead failed.");
|
||||
|
||||
//if (cred->CredentialBlobSize) {
|
||||
// // Decrypt the certificate using user's key.
|
||||
// DATA_BLOB cred_enc = { cred->CredentialBlobSize, cred->CredentialBlob };
|
||||
// DATA_BLOB entropy_blob = { sizeof(s_entropy) , (LPBYTE)s_entropy };
|
||||
// data_blob cred_int;
|
||||
// if (!CryptUnprotectData(&cred_enc, NULL, &entropy_blob, NULL, NULL, CRYPTPROTECT_UI_FORBIDDEN | CRYPTPROTECT_VERIFY_PROTECTION, &cred_int))
|
||||
// throw win_runtime_error(__FUNCTION__ " CryptUnprotectData failed.");
|
||||
|
||||
// bool bResult = m_cred_blob.create(X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, cred_int.pbData, cred_int.cbData);
|
||||
// SecureZeroMemory(cred_int.pbData, cred_int.cbData);
|
||||
// if (!bResult)
|
||||
// throw win_runtime_error(__FUNCTION__ " Error loading certificate.");
|
||||
//} else
|
||||
// m_cred_blob.free();
|
||||
|
||||
//if (cred->UserName)
|
||||
// m_identity = cred->UserName;
|
||||
//else
|
||||
// m_identity.clear();
|
||||
|
||||
//wstring xpath(pszTargetName);
|
||||
//m_module.log_config((xpath + L"/Identity").c_str(), m_identity.c_str());
|
||||
//m_module.log_config((xpath + L"/Certificate").c_str(), get_name().c_str());
|
||||
}
|
||||
|
||||
|
||||
LPCTSTR eap::credentials_eaphost::target_suffix() const
|
||||
{
|
||||
return _T("BLOB");
|
||||
}
|
||||
|
||||
|
||||
std::wstring eap::credentials_eaphost::get_identity() const
|
||||
{
|
||||
if (!m_identity.empty()) {
|
||||
return m_identity;
|
||||
} else if (!m_cred_blob.empty()) {
|
||||
// TODO: Use EapHostPeerGetIdentity() to obtain user identity.
|
||||
assert(0);
|
||||
}
|
||||
|
||||
return L"";
|
||||
}
|
||||
|
||||
|
||||
eap::credentials::source_t eap::credentials_eaphost::combine(
|
||||
_In_ DWORD dwFlags,
|
||||
_In_ HANDLE hTokenImpersonateUser,
|
||||
_In_opt_ const credentials *cred_cached,
|
||||
_In_ const config_method &cfg,
|
||||
_In_opt_z_ LPCTSTR pszTargetName)
|
||||
{
|
||||
// When cached credentials are available, EapHost calls EapPeerGetIdentity() anyway.
|
||||
// This allows each peer to decide to reuse or drop cached credentials itself.
|
||||
// To mimic that behaviour, we do the same:
|
||||
// 1. Retrieve credentials from cache (or store)
|
||||
// 2. Call EapHostPeerGetIdentity()
|
||||
source_t src = source_unknown;
|
||||
|
||||
if (cred_cached) {
|
||||
// Using EAP service cached credentials.
|
||||
*this = *(credentials_eaphost*)cred_cached;
|
||||
m_module.log_event(&EAPMETHOD_TRACE_EVT_CRED_CACHED2, event_data((unsigned int)cfg.get_method_id()), event_data(get_name()), event_data(pszTargetName), event_data::blank);
|
||||
src = source_cache;
|
||||
}
|
||||
|
||||
//if (src == source_unknown && pszTargetName) {
|
||||
// try {
|
||||
// credentials_eaphost cred_loaded(m_module);
|
||||
// cred_loaded.retrieve(pszTargetName, cfg.m_level);
|
||||
|
||||
// // Using stored credentials.
|
||||
// *this = std::move(cred_loaded);
|
||||
// m_module.log_event(&EAPMETHOD_TRACE_EVT_CRED_STORED2, event_data((unsigned int)cfg.get_method_id()), event_data(get_name()), event_data(pszTargetName), event_data::blank);
|
||||
// src = source_storage;
|
||||
// } catch (...) {
|
||||
// // Not actually an error.
|
||||
// }
|
||||
//}
|
||||
|
||||
auto cfg_eaphost = dynamic_cast<const config_method_eaphost*>(&cfg);
|
||||
BOOL fInvokeUI = FALSE;
|
||||
DWORD cred_data_size = 0;
|
||||
eap_blob_runtime cred_data;
|
||||
unique_ptr<WCHAR[], EapHostPeerFreeRuntimeMemory_delete> identity;
|
||||
eap_error error;
|
||||
DWORD dwResult = EapHostPeerGetIdentity(
|
||||
0,
|
||||
dwFlags,
|
||||
cfg_eaphost->m_type,
|
||||
(DWORD)cfg_eaphost->m_cfg_blob.size(), cfg_eaphost->m_cfg_blob.data(),
|
||||
src != source_unknown ? (DWORD)m_cred_blob.size() : 0, src != source_unknown ? m_cred_blob.data() : NULL,
|
||||
hTokenImpersonateUser,
|
||||
&fInvokeUI,
|
||||
&cred_data_size, &cred_data._Myptr,
|
||||
&identity._Myptr,
|
||||
&error._Myptr,
|
||||
NULL);
|
||||
if (dwResult == ERROR_SUCCESS) {
|
||||
if (identity && !fInvokeUI) {
|
||||
// Inner EAP method provided identity and does not require additional UI prompt.
|
||||
m_identity = identity.get();
|
||||
m_cred_blob.assign(cred_data.get(), cred_data.get() + cred_data_size);
|
||||
SecureZeroMemory(cred_data.get(), cred_data_size);
|
||||
m_module.log_event(&EAPMETHOD_TRACE_EVT_CRED_EAPHOST, event_data((unsigned int)cfg.get_method_id()), event_data(get_name()), event_data(pszTargetName), event_data::blank);
|
||||
return source_lower;
|
||||
} else
|
||||
SecureZeroMemory(cred_data.get(), cred_data_size);
|
||||
} else if (error) {
|
||||
// An EAP error in inner EAP method occurred.
|
||||
m_module.log_error(error.get());
|
||||
} else {
|
||||
// A runtime error in inner EAP method occurred.
|
||||
m_module.log_event(&EAPMETHOD_TRACE_EVT_WIN_ERROR, event_data((unsigned int)dwResult), event_data(__FUNCTION__ " EapHostPeerGetIdentity failed."), event_data::blank);
|
||||
}
|
||||
|
||||
return source_unknown;
|
||||
}
|
||||
|
||||
|
||||
const unsigned char eap::credentials_eaphost::s_entropy[1024] = {
|
||||
0xe6, 0x01, 0x7b, 0x5f, 0xe5, 0x32, 0xee, 0x8c, 0x57, 0x41, 0x52, 0x95, 0xab, 0xe5, 0x65, 0xdd,
|
||||
0xb3, 0x12, 0x7c, 0xcb, 0xdb, 0x37, 0x03, 0x76, 0xfc, 0x53, 0x4a, 0xf9, 0x3f, 0xf1, 0xd8, 0x7e,
|
||||
0x60, 0x9a, 0x49, 0x93, 0xeb, 0x2e, 0x18, 0xd0, 0xfb, 0x40, 0xa9, 0x95, 0x66, 0x8a, 0xdd, 0x99,
|
||||
0x51, 0x1c, 0xfb, 0x73, 0xa9, 0x7c, 0x31, 0x2b, 0xe6, 0x54, 0x61, 0x64, 0x25, 0x86, 0x36, 0xd4,
|
||||
0xde, 0xc8, 0x6d, 0x3e, 0x6f, 0x47, 0x40, 0x6f, 0xd6, 0x5b, 0xe2, 0x0c, 0x92, 0x16, 0xe2, 0xdc,
|
||||
0x45, 0x2f, 0x44, 0xf4, 0x87, 0x64, 0x6d, 0x4e, 0x5c, 0x24, 0x8a, 0x10, 0xb1, 0x2f, 0xa7, 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fa, 0x02, 0x9f, 0x2a, 0xbf, 0x8b, 0xe7,
|
||||
0x87, 0xd4, 0xc2, 0x72, 0x46, 0xd4, 0xf7, 0x57, 0xbe, 0x9a, 0x4e, 0xd4, 0xb5, 0x0f, 0x8d, 0x46,
|
||||
0x81, 0x6e, 0x1b, 0xe2, 0x85, 0x3b, 0x78, 0x78, 0x9f, 0xa1, 0xd7, 0x27, 0x2d, 0x92, 0x28, 0x62,
|
||||
0x6d, 0xcd, 0xfe, 0x48, 0x18, 0x19, 0x6c, 0x61, 0x6c, 0x8b, 0xbe, 0xe5, 0xb0, 0xff, 0x80, 0x4d,
|
||||
0x60, 0x71, 0x89, 0x79, 0x41, 0x08, 0x8e, 0x81, 0x84, 0x71, 0xb8, 0xcd, 0x00, 0x27, 0x37, 0xa2,
|
||||
0xad, 0x47, 0xc5, 0x6a, 0xf9, 0xb3, 0x00, 0x67, 0x11, 0x60, 0x93, 0xd1, 0xe1, 0x89, 0x9f, 0xec,
|
||||
0x92, 0xb4, 0x48, 0xa6, 0x11, 0x5f, 0xc1, 0x62, 0xb9, 0xd2, 0x3f, 0xb0, 0x4e, 0xd2, 0xdb, 0x1d,
|
||||
0x80, 0xd6, 0x02, 0x82, 0x39, 0xb4, 0xbb, 0x3b, 0x51, 0x26, 0xb5, 0x0c, 0xb9, 0xff, 0x9a, 0x38,
|
||||
0xa8, 0x49, 0x58, 0x70, 0xdd, 0xec, 0x71, 0x27, 0xec, 0x3c, 0x13, 0x8b, 0x2f, 0xf3, 0x38, 0xa8,
|
||||
0x6e, 0xf2, 0xe2, 0xa0, 0xcd, 0xa4, 0x2a, 0x8b, 0xd4, 0xaa, 0x31, 0x83, 0x4c, 0xe6, 0x98, 0xf5,
|
||||
0x11, 0xea, 0x40, 0xf9, 0x22, 0xf8, 0x30, 0x56, 0x58, 0xe6, 0xe2, 0x69, 0x49, 0xec, 0x50, 0xbf,
|
||||
0x39, 0x10, 0x77, 0xa1, 0x54, 0xf8, 0x82, 0x19, 0x7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f2, 0xc6, 0x31, 0x7e, 0xb8, 0x29, 0x9b, 0xa4, 0xe9, 0x9d,
|
||||
0x6b, 0x95, 0xae, 0x37, 0xdf, 0x1d, 0x8c, 0xea, 0xc2, 0x50, 0x14, 0x48, 0x05, 0xd0, 0xcd, 0xd1,
|
||||
0x25, 0x25, 0x10, 0xa2, 0x85, 0x6f, 0x88, 0xe1, 0x22, 0x9d, 0xd2, 0xbe, 0x59, 0x88, 0x86, 0x20,
|
||||
0x93, 0x6a, 0x44, 0xed, 0xc8, 0xee, 0x73, 0xe7, 0x1a, 0xc3, 0x16, 0x23, 0xff, 0x69, 0x8c, 0xd0,
|
||||
};
|
60
lib/EapHost/src/EapHost.cpp
Normal file
60
lib/EapHost/src/EapHost.cpp
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// eap::credentials_eaphost
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
eap::credentials_eaphost::credentials_eaphost(_In_ module &mod) : credentials_pass(mod)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
eap::credentials_eaphost::credentials_eaphost(_In_ const credentials_eaphost &other) :
|
||||
credentials_pass(other)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
eap::credentials_eaphost::credentials_eaphost(_Inout_ credentials_eaphost &&other) :
|
||||
credentials_pass(std::move(other))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
eap::credentials_eaphost& eap::credentials_eaphost::operator=(_In_ const credentials_eaphost &other)
|
||||
{
|
||||
if (this != &other)
|
||||
(credentials_pass&)*this = other;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
eap::credentials_eaphost& eap::credentials_eaphost::operator=(_Inout_ credentials_eaphost &&other)
|
||||
{
|
||||
if (this != &other)
|
||||
(credentials_pass&&)*this = std::move(other);
|
||||
|
||||
return *this;
|
||||
}
|
277
lib/EapHost/src/Method.cpp
Normal file
277
lib/EapHost/src/Method.cpp
Normal file
@@ -0,0 +1,277 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace winstd;
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// eap::method_eaphost
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
eap::method_eaphost::method_eaphost(_In_ module &module, _In_ config_method_eaphost &cfg, _In_ credentials_eaphost &cred) :
|
||||
m_session_id(0),
|
||||
method_noneap(module, cfg, cred)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
eap::method_eaphost::method_eaphost(_Inout_ method_eaphost &&other) :
|
||||
m_session_id (std::move(other.m_session_id)),
|
||||
method_noneap(std::move(other ))
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
eap::method_eaphost& eap::method_eaphost::operator=(_Inout_ method_eaphost &&other)
|
||||
{
|
||||
if (this != std::addressof(other)) {
|
||||
(method_noneap&)*this = std::move(other );
|
||||
m_session_id = std::move(other.m_session_id);
|
||||
}
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
void eap::method_eaphost::begin_session(
|
||||
_In_ DWORD dwFlags,
|
||||
_In_ const EapAttributes *pAttributeArray,
|
||||
_In_ HANDLE hTokenImpersonateUser,
|
||||
_In_opt_ DWORD dwMaxSendPacketSize)
|
||||
{
|
||||
// Create EapHost peer session using available connection data (m_cfg) and user data (m_cred).
|
||||
auto &cfg = dynamic_cast<config_method_eaphost&>(m_cfg);
|
||||
auto &cred = dynamic_cast<credentials_eaphost &>(m_cred);
|
||||
eap_error_runtime error;
|
||||
DWORD dwResult = EapHostPeerBeginSession(
|
||||
dwFlags,
|
||||
cfg.m_type,
|
||||
pAttributeArray,
|
||||
hTokenImpersonateUser,
|
||||
(DWORD)cfg.m_cfg_blob.size(),
|
||||
cfg.m_cfg_blob.data(),
|
||||
(DWORD)cred.m_cred_blob.size(),
|
||||
cred.m_cred_blob.data(),
|
||||
dwMaxSendPacketSize,
|
||||
NULL, NULL, NULL,
|
||||
&m_session_id,
|
||||
&error._Myptr);
|
||||
if (dwResult == ERROR_SUCCESS) {
|
||||
// Session succesfully created.
|
||||
method_noneap::begin_session(dwFlags, pAttributeArray, hTokenImpersonateUser, dwMaxSendPacketSize);
|
||||
|
||||
m_module.log_event(&EAPMETHOD_METHOD_HANDSHAKE_START2, event_data((unsigned int)m_cfg.get_method_id()), event_data::blank);
|
||||
} else if (error)
|
||||
throw eap_runtime_error(*error , __FUNCTION__ " EapHostPeerBeginSession failed.");
|
||||
else
|
||||
throw win_runtime_error(dwResult, __FUNCTION__ " EapHostPeerBeginSession failed.");
|
||||
}
|
||||
|
||||
|
||||
void eap::method_eaphost::end_session()
|
||||
{
|
||||
// End EapHost peer session.
|
||||
eap_error_runtime error;
|
||||
DWORD dwResult = EapHostPeerEndSession(m_session_id, &error._Myptr);
|
||||
if (dwResult == ERROR_SUCCESS) {
|
||||
// Session successfuly ended.
|
||||
} else if (error)
|
||||
throw eap_runtime_error(*error , __FUNCTION__ " EapHostPeerEndSession failed.");
|
||||
else
|
||||
throw win_runtime_error(dwResult, __FUNCTION__ " EapHostPeerEndSession failed.");
|
||||
}
|
||||
|
||||
|
||||
void eap::method_eaphost::process_request_packet(
|
||||
_In_bytecount_(dwReceivedPacketSize) const void *pReceivedPacket,
|
||||
_In_ DWORD dwReceivedPacketSize,
|
||||
_Out_ EapPeerMethodOutput *pEapOutput)
|
||||
{
|
||||
assert(pReceivedPacket || dwReceivedPacketSize == 0);
|
||||
assert(pEapOutput);
|
||||
|
||||
m_module.log_event(&EAPMETHOD_PACKET_RECV, event_data((unsigned int)m_cfg.get_method_id()), event_data((unsigned int)dwReceivedPacketSize), event_data::blank);
|
||||
|
||||
// Let EapHost peer process the packet.
|
||||
EapHostPeerResponseAction action;
|
||||
eap_error_runtime error;
|
||||
DWORD dwResult = EapHostPeerProcessReceivedPacket(
|
||||
m_session_id,
|
||||
dwReceivedPacketSize,
|
||||
reinterpret_cast<const BYTE*>(pReceivedPacket),
|
||||
&action,
|
||||
&error._Myptr);
|
||||
if (dwResult == ERROR_SUCCESS) {
|
||||
// Packet successfuly processed.
|
||||
action_to_output(action, pEapOutput);
|
||||
} else if (error)
|
||||
throw eap_runtime_error(*error , __FUNCTION__ " EapHostPeerProcessReceivedPacket failed.");
|
||||
else
|
||||
throw win_runtime_error(dwResult, __FUNCTION__ " EapHostPeerProcessReceivedPacket failed.");
|
||||
}
|
||||
|
||||
|
||||
void eap::method_eaphost::get_response_packet(
|
||||
_Inout_bytecap_(*dwSendPacketSize) void *pSendPacket,
|
||||
_Inout_ DWORD *pdwSendPacketSize)
|
||||
{
|
||||
assert(pdwSendPacketSize);
|
||||
assert(pSendPacket || !*pdwSendPacketSize);
|
||||
|
||||
// Let EapHost peer prepare response packet.
|
||||
DWORD size_max = *pdwSendPacketSize;
|
||||
eap_blob_runtime packet;
|
||||
eap_error_runtime error;
|
||||
DWORD dwResult = EapHostPeerGetSendPacket(
|
||||
m_session_id,
|
||||
pdwSendPacketSize,
|
||||
&packet._Myptr,
|
||||
&error._Myptr);
|
||||
if (dwResult == ERROR_SUCCESS) {
|
||||
// Packet successfuly prepared.
|
||||
memcpy_s(pSendPacket, size_max, packet.get(), *pdwSendPacketSize);
|
||||
} else if (error)
|
||||
throw eap_runtime_error(*error , __FUNCTION__ " EapHostPeerGetSendPacket failed.");
|
||||
else
|
||||
throw win_runtime_error(dwResult, __FUNCTION__ " EapHostPeerGetSendPacket failed.");
|
||||
}
|
||||
|
||||
|
||||
void eap::method_eaphost::get_result(
|
||||
_In_ EapPeerMethodResultReason reason,
|
||||
_Inout_ EapPeerMethodResult *pResult)
|
||||
{
|
||||
assert(pResult);
|
||||
|
||||
if (reason == EapPeerMethodResultSuccess) {
|
||||
// Let EapHost peer return result.
|
||||
eap_error_runtime error;
|
||||
EapHostPeerMethodResult result = {};
|
||||
DWORD dwResult = EapHostPeerGetResult(
|
||||
m_session_id,
|
||||
EapHostPeerMethodResultFromMethod,
|
||||
&result,
|
||||
&error._Myptr);
|
||||
if (dwResult == ERROR_SUCCESS) {
|
||||
// Result successfuly returned.
|
||||
pResult->fIsSuccess = result.fIsSuccess;
|
||||
pResult->dwFailureReasonCode = result.dwFailureReasonCode;
|
||||
pResult->pAttribArray = result.pAttribArray;
|
||||
pResult->pEapError = result.pEapError;
|
||||
|
||||
if (result.fSaveConnectionData)
|
||||
dynamic_cast<config_method_eaphost&>(m_cfg).m_cfg_blob.assign(result.pConnectionData, result.pConnectionData + result.dwSizeofConnectionData);
|
||||
|
||||
if (result.fSaveUserData)
|
||||
dynamic_cast<credentials_eaphost &>(m_cred).m_cred_blob.assign(result.pUserData, result.pUserData + result.dwSizeofUserData);
|
||||
} else if (error)
|
||||
throw eap_runtime_error(*error , __FUNCTION__ " EapHostPeerGetResult failed.");
|
||||
else
|
||||
throw win_runtime_error(dwResult, __FUNCTION__ " EapHostPeerGetResult failed.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void eap::method_eaphost::get_ui_context(
|
||||
_Inout_ BYTE **ppUIContextData,
|
||||
_Inout_ DWORD *pdwUIContextDataSize)
|
||||
{
|
||||
// Get EapHost peer UI context data.
|
||||
eap_error_runtime error;
|
||||
DWORD dwResult = EapHostPeerGetUIContext(
|
||||
m_session_id,
|
||||
pdwUIContextDataSize,
|
||||
ppUIContextData,
|
||||
&error._Myptr);
|
||||
if (dwResult == ERROR_SUCCESS) {
|
||||
// UI context data successfuly returned.
|
||||
} else if (error)
|
||||
throw eap_runtime_error(*error , __FUNCTION__ " EapHostPeerGetUIContext failed.");
|
||||
else
|
||||
throw win_runtime_error(dwResult, __FUNCTION__ " EapHostPeerGetUIContext failed.");
|
||||
}
|
||||
|
||||
|
||||
void eap::method_eaphost::set_ui_context(
|
||||
_In_count_(dwUIContextDataSize) const BYTE *pUIContextData,
|
||||
_In_ DWORD dwUIContextDataSize,
|
||||
_Out_ EapPeerMethodOutput *pEapOutput)
|
||||
{
|
||||
assert(pEapOutput);
|
||||
|
||||
// Set EapHost peer UI context data.
|
||||
EapHostPeerResponseAction action;
|
||||
eap_error_runtime error;
|
||||
DWORD dwResult = EapHostPeerSetUIContext(
|
||||
m_session_id,
|
||||
dwUIContextDataSize,
|
||||
pUIContextData,
|
||||
&action,
|
||||
&error._Myptr);
|
||||
if (dwResult == ERROR_SUCCESS) {
|
||||
// UI context data successfuly returned.
|
||||
action_to_output(action, pEapOutput);
|
||||
} else if (error)
|
||||
throw eap_runtime_error(*error , __FUNCTION__ " EapHostPeerSetUIContext failed.");
|
||||
else
|
||||
throw win_runtime_error(dwResult, __FUNCTION__ " EapHostPeerSetUIContext failed.");
|
||||
}
|
||||
|
||||
|
||||
void eap::method_eaphost::get_response_attributes(_Inout_ EapAttributes *pAttribs)
|
||||
{
|
||||
// Get response attributes from EapHost peer.
|
||||
eap_error_runtime error;
|
||||
DWORD dwResult = EapHostPeerGetResponseAttributes(
|
||||
m_session_id,
|
||||
pAttribs,
|
||||
&error._Myptr);
|
||||
if (dwResult == ERROR_SUCCESS) {
|
||||
// Response attributes successfuly returned.
|
||||
} else if (error)
|
||||
throw eap_runtime_error(*error , __FUNCTION__ " EapHostPeerGetResponseAttributes failed.");
|
||||
else
|
||||
throw win_runtime_error(dwResult, __FUNCTION__ " EapHostPeerGetResponseAttributes failed.");
|
||||
}
|
||||
|
||||
|
||||
void eap::method_eaphost::set_response_attributes(
|
||||
_In_ const EapAttributes *pAttribs,
|
||||
_Out_ EapPeerMethodOutput *pEapOutput)
|
||||
{
|
||||
// Set response attributes for EapHost peer.
|
||||
EapHostPeerResponseAction action;
|
||||
eap_error_runtime error;
|
||||
DWORD dwResult = EapHostPeerSetResponseAttributes(
|
||||
m_session_id,
|
||||
pAttribs,
|
||||
&action,
|
||||
&error._Myptr);
|
||||
if (dwResult == ERROR_SUCCESS) {
|
||||
// Response attributes successfuly set.
|
||||
action_to_output(action, pEapOutput);
|
||||
} else if (error)
|
||||
throw eap_runtime_error(*error , __FUNCTION__ " EapHostPeerGetResponseAttributes failed.");
|
||||
else
|
||||
throw win_runtime_error(dwResult, __FUNCTION__ " EapHostPeerGetResponseAttributes failed.");
|
||||
}
|
21
lib/EapHost/src/StdAfx.cpp
Normal file
21
lib/EapHost/src/StdAfx.cpp
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "StdAfx.h"
|
30
lib/EapHost/src/StdAfx.h
Normal file
30
lib/EapHost/src/StdAfx.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "../include/Config.h"
|
||||
#include "../include/Credentials.h"
|
||||
#include "../include/Method.h"
|
||||
|
||||
#include <Windows.h>
|
||||
#include <EapHostError.h> // include after Windows.h
|
||||
#include <EapHostPeerTypes.h>
|
||||
#include <eappapis.h>
|
Reference in New Issue
Block a user