Skip to content

Commit

Permalink
add cyrillic password support (#37)
Browse files Browse the repository at this point in the history
Co-authored-by: Vladimir Zimin <v.zimin@multifactor.ru>
  • Loading branch information
gelatincrypto and Vladimir Zimin authored Apr 22, 2024
1 parent c8c8439 commit be1ccbb
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 32 deletions.
13 changes: 0 additions & 13 deletions README.ru.md
Original file line number Diff line number Diff line change
Expand Up @@ -350,19 +350,6 @@ sudo systemctl enable multifactor-radius
}
```

### Дополнительные RADIUS атрибуты

```xml
<RadiusReply>
<Attributes>
<!--Это пример, можно использовать любые атрибуты-->
<add name="Class" value="Super" />
<add name="Fortinet-Group-Name" value="Users" when="UserGroup=VPN Users"/>
<add name="Fortinet-Group-Name" value="Admins" when="UserGroup=VPN Admins"/>
</Attributes>
</RadiusReply>
```

## Запуск компонента

После настройки конфигурации запустите компонент:
Expand Down
30 changes: 30 additions & 0 deletions src/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/azds.yaml
**/bin
**/charts
**/docker-compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
LICENSE
README.md
!**/.gitignore
!.git/HEAD
!.git/config
!.git/packed-refs
!.git/refs/heads/**
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@
<ProjectReference Include="..\MultiFactor.Radius.Adapter\MultiFactor.Radius.Adapter.csproj" />
</ItemGroup>

<ItemGroup>
<Reference Include="LdapForNet">
<HintPath>..\libs\LdapForNet.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<None Update="Assets\clients\pre-auth-method\client-pre-auth-method-otp-with-no-cred-delay.config">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand Down
26 changes: 26 additions & 0 deletions src/MultiFactor.Radius.Adapter/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
RUN apt-get update && apt-get install -y libldap-2.4-2
RUN ln -s libldap-2.4.so.2 /usr/lib/x86_64-linux-gnu/libldap.so.2
EXPOSE 80
EXPOSE 443
EXPOSE 1812/udp

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["MultiFactor.Radius.Adapter/MultiFactor.Radius.Adapter.csproj", "MultiFactor.Radius.Adapter/"]
RUN dotnet restore "./MultiFactor.Radius.Adapter/MultiFactor.Radius.Adapter.csproj"
COPY . .
WORKDIR "/src/MultiFactor.Radius.Adapter"
RUN dotnet build "./MultiFactor.Radius.Adapter.csproj" -c $BUILD_CONFIGURATION -o /app/build

FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./MultiFactor.Radius.Adapter.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "multifactor-radius-adapter.dll"]
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ public static RadiusHostApplicationBuilder AddLogging(this RadiusHostApplication
var services = new ServiceCollection();

var appVarDescriptor = builder.InternalHostApplicationBuilder.Services.FirstOrDefault(x => x.ServiceType == typeof(ApplicationVariables))
?? throw new System.Exception($"Service type '{typeof(ApplicationVariables)}' was not found in the RadiusHostApplicationBuilder services");
?? throw new Exception($"Service type '{typeof(ApplicationVariables)}' was not found in the RadiusHostApplicationBuilder services");
services.Add(appVarDescriptor);

var rootConfigProvDescriptor = builder.InternalHostApplicationBuilder.Services.FirstOrDefault(x => x.ServiceType == typeof(IRootConfigurationProvider))
?? throw new System.Exception($"Service type '{typeof(IRootConfigurationProvider)}' was not found in the RadiusHostApplicationBuilder services");
?? throw new Exception($"Service type '{typeof(IRootConfigurationProvider)}' was not found in the RadiusHostApplicationBuilder services");
services.Add(rootConfigProvDescriptor);

services.AddSingleton<SerilogLoggerFactory>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ namespace MultiFactor.Radius.Adapter.Framework.Context
/// </summary>
public class RadiusContext
{
public RadiusContext(IRadiusPacket request,
public RadiusContext(
IRadiusPacket request,
IClientConfiguration clientConfiguration,
IServiceProvider provider)
{
RequestPacket = request ?? throw new ArgumentNullException(nameof(request));
ReceivedAt = DateTime.Now;
Configuration = clientConfiguration ?? throw new ArgumentNullException(nameof(clientConfiguration));
RequestServices = provider ?? throw new ArgumentNullException(nameof(provider));
Authentication = new();
Expand All @@ -40,10 +40,11 @@ public RadiusContext(IRadiusPacket request,
/// Current request packet.
/// </summary>
public IRadiusPacket RequestPacket { get; }
public DateTime ReceivedAt { get; }

public RadiusPacketHeader Header => RequestPacket.Header;

public IRadiusPacket ResponsePacket { get; set; }

public PacketCode ResponseCode => Authentication.ToPacketCode();

/// <summary>
Expand All @@ -55,7 +56,6 @@ public RadiusContext(IRadiusPacket request,
/// Challenge state.
/// </summary>
public string State { get; private set; }

public string ReplyMessage { get; private set; }

/// <summary>
Expand Down
15 changes: 13 additions & 2 deletions src/MultiFactor.Radius.Adapter/MultiFactor.Radius.Adapter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<AssemblyName>multifactor-radius-adapter</AssemblyName>
<Authors>Multifactor</Authors>
<Description>Multifactor Radus Adapter</Description>
<Version>2.0.0</Version>
<Version>2.1.0</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
Expand All @@ -18,13 +18,15 @@

<PropertyGroup>
<ServerGarbageCollection>true</ServerGarbageCollection>
<UserSecretsId>f07ad043-43df-44e3-965d-beb88a9eac86</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Elastic.CommonSchema.Serilog" Version="8.6.1" />
<PackageReference Include="IPAddressRange" Version="6.0.0" />
<PackageReference Include="LdapForNet" Version="2.7.11" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.6" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
<PackageReference Include="Serilog.Formatting.Compact" Version="2.0.0" />
Expand Down Expand Up @@ -52,6 +54,9 @@
<None Update="content\radius.dictionary">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="libs\LdapForNet.dll">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

<ItemGroup>
Expand All @@ -62,4 +67,10 @@
<InternalsVisibleTo Include="MultiFactor.Radius.Adapter.Tests" />
</ItemGroup>

<ItemGroup>
<Reference Include="LdapForNet">
<HintPath>..\libs\LdapForNet.dll</HintPath>
</Reference>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
},
"Docker": {
"commandName": "Docker",
"launchBrowser": false,
"launchUrl": "{Scheme}://{ServiceHost}:{ServicePort}",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "localhost",
"LD_DEBUG": "libs"
},
"publishAllPorts": true,
"useSSL": false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@ namespace MultiFactor.Radius.Adapter.Server.Pipeline.FirstFactorAuthentication
public class FirstFactorAuthenticationMiddleware : IRadiusMiddleware
{
private readonly IFirstFactorAuthenticationProcessorProvider _firstAuthFactorProcessorProvider;
private readonly IRadiusRequestPostProcessor _requestPostProcessor;

public FirstFactorAuthenticationMiddleware(IFirstFactorAuthenticationProcessorProvider firstAuthFactorProcessorProvider, IRadiusRequestPostProcessor requestPostProcessor)
public FirstFactorAuthenticationMiddleware(IFirstFactorAuthenticationProcessorProvider firstAuthFactorProcessorProvider)
{
_firstAuthFactorProcessorProvider = firstAuthFactorProcessorProvider ?? throw new ArgumentNullException(nameof(firstAuthFactorProcessorProvider));
_requestPostProcessor = requestPostProcessor ?? throw new ArgumentNullException(nameof(requestPostProcessor));
}

public async Task InvokeAsync(RadiusContext context, RadiusRequestDelegate next)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
using Microsoft.Extensions.Logging;
using MultiFactor.Radius.Adapter.Configuration.Core;
using MultiFactor.Radius.Adapter.Core.Radius;
using System;
using System.Net;

namespace MultiFactor.Radius.Adapter.Server
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public string FormatIdentity(LdapIdentity user, string ldapUri)
return _clientConfiguration.FirstFactorAuthenticationSource switch
{
Configuration.AuthenticationSource.None or Configuration.AuthenticationSource.ActiveDirectory => FormatIdentityAD(user, ldapUri),
Configuration.AuthenticationSource.Ldap => FormatIdentityLdap(user, ldapUri),
Configuration.AuthenticationSource.Ldap => FormatIdentityLdap(user),
_ => user.Name,
};
}
Expand All @@ -59,7 +59,7 @@ private static string FormatIdentityAD(LdapIdentity user, string ldapUri)
return user.Name;
}

private string FormatIdentityLdap(LdapIdentity user, string ldapUri)
private string FormatIdentityLdap(LdapIdentity user)
{
if (user.Type == IdentityType.UserPrincipalName)
{
Expand Down
Binary file added src/libs/LdapForNet.dll
Binary file not shown.
8 changes: 4 additions & 4 deletions src/multifactor-radius-adapter.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ VisualStudioVersion = 17.4.33103.184
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{1FDA0815-14C7-4C4A-B632-52BFF4AF7788}"
ProjectSection(SolutionItems) = preProject
LICENSE.md = LICENSE.md
LICENSE.ru.md = LICENSE.ru.md
README.md = README.md
README.ru.md = README.ru.md
..\LICENSE.md = ..\LICENSE.md
..\LICENSE.ru.md = ..\LICENSE.ru.md
..\README.md = ..\README.md
..\README.ru.md = ..\README.ru.md
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MultiFactor.Radius.Adapter.Tests", "MultiFactor.Radius.Adapter.Tests\MultiFactor.Radius.Adapter.Tests.csproj", "{E8A7518C-A622-4343-A594-46EE5869EE96}"
Expand Down

0 comments on commit be1ccbb

Please sign in to comment.