Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
trudyhood committed Mar 19, 2023
2 parents ef29b10 + 6bf666c commit 75e8ca3
Show file tree
Hide file tree
Showing 31 changed files with 159 additions and 91 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v2.8.361
### Server
* Feature: Enable hot reconfig for VpnHood Server TCP listener to avoid unnecessary restarts on unchanged endpoints
* Update: Replace AllowIpV6 to BlockIpV6
* Update: Improve server security

# v2.8.360
### Client
* Fix: Used traffic was not displayed correctly
Expand Down
4 changes: 2 additions & 2 deletions Pub/Version.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"Version": "2.8.360",
"BumpTime": "2023-03-12T01:19:57.7771871Z",
"Version": "2.8.361",
"BumpTime": "2023-03-17T20:04:49.4236941Z",
"Prerelease": false,
"DeprecatedVersion": "2.0.0"
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="VpnHood.Client">
<Version>2.8.360</Version>
<Version>2.8.361</Version>
</PackageReference>
<PackageReference Include="VpnHood.Client.Device.Android">
<Version>2.8.360</Version>
<Version>2.8.361</Version>
</PackageReference>
<PackageReference Include="Xamarin.Essentials" Version="1.7.5" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="VpnHood.Client" Version="2.8.360" />
<PackageReference Include="VpnHood.Client.Device.WinDivert" Version="2.8.360" />
<PackageReference Include="VpnHood.Client" Version="2.8.361" />
<PackageReference Include="VpnHood.Client.Device.WinDivert" Version="2.8.361" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions VpnHood.Client.App.UI/VpnHood.Client.App.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<PackageIcon>VpnHood.png</PackageIcon>
<Description>Tiny internal webserver to server your single-page application (SPA). You need this only if you want to create a UI for your VpnHood client by single-page application (SPA).</Description>
<PackageId>VpnHood.Client.App.UI</PackageId>
<Version>2.8.360</Version>
<AssemblyVersion>2.8.360</AssemblyVersion>
<Version>2.8.361</Version>
<AssemblyVersion>2.8.361</AssemblyVersion>
<FileVersion>$([System.DateTime]::Now.ToString("yyyy.M.d.HHmm"))</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down
4 changes: 2 additions & 2 deletions VpnHood.Client.App.Win/VpnHood.Client.App.Win.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<PackageIcon>VpnHood.png</PackageIcon>
<PackageId>VpnHood.Client.App.Win</PackageId>
<StartupObject></StartupObject>
<Version>2.8.360</Version>
<AssemblyVersion>2.8.360</AssemblyVersion>
<Version>2.8.361</Version>
<AssemblyVersion>2.8.361</AssemblyVersion>
<FileVersion>$([System.DateTime]::Now.ToString("yyyy.M.d.HHmm"))</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>11</LangVersion>
Expand Down
4 changes: 2 additions & 2 deletions VpnHood.Client.App/VpnHood.Client.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
<RepositoryUrl>https://github.com/vpnhood/vpnhood</RepositoryUrl>
<Description>Readymade Vpn App skeleton for VpnHood clients. You just need to create a UI on it.</Description>
<PackageId>VpnHood.Client.App</PackageId>
<Version>2.8.360</Version>
<AssemblyVersion>2.8.360</AssemblyVersion>
<Version>2.8.361</Version>
<AssemblyVersion>2.8.361</AssemblyVersion>
<FileVersion>$([System.DateTime]::Now.ToString("yyyy.M.d.HHmm"))</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
<RepositoryUrl>https://github.com/vpnhood/vpnhood</RepositoryUrl>
<PackageIcon>VpnHood.png</PackageIcon>
<Description>VpnHood client device provider for Windows using WinDivert.</Description>
<Version>2.8.360</Version>
<Version>2.8.361</Version>
<PackageId>VpnHood.Client.Device.WinDivert</PackageId>
<Version>1.1.226</Version>
<AssemblyVersion>2.8.360</AssemblyVersion>
<AssemblyVersion>2.8.361</AssemblyVersion>
<FileVersion>$([System.DateTime]::Now.ToString("yyyy.M.d.HHmm"))</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down
4 changes: 2 additions & 2 deletions VpnHood.Client.Device/VpnHood.Client.Device.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
<RepositoryType></RepositoryType>
<PackageId>VpnHood.Client.Device</PackageId>
<RootNamespace>VpnHood.Client.Device</RootNamespace>
<Version>2.8.360</Version>
<AssemblyVersion>2.8.360</AssemblyVersion>
<Version>2.8.361</Version>
<AssemblyVersion>2.8.361</AssemblyVersion>
<FileVersion>$([System.DateTime]::Now.ToString("yyyy.M.d.HHmm"))</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down
4 changes: 2 additions & 2 deletions VpnHood.Client/VpnHood.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<Copyright>2022 VpnHood</Copyright>
<PackageId>VpnHood.Client</PackageId>
<PackageTags>VPN VpnClient Proxy</PackageTags>
<Version>2.8.360</Version>
<AssemblyVersion>2.8.360</AssemblyVersion>
<Version>2.8.361</Version>
<AssemblyVersion>2.8.361</AssemblyVersion>
<FileVersion>$([System.DateTime]::Now.ToString("yyyy.M.d.HHmm"))</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down
2 changes: 1 addition & 1 deletion VpnHood.Client/VpnHoodClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -715,8 +715,8 @@ private async Task ConnectInternal(CancellationToken cancellationToken, bool red
_helloTraffic = sessionResponse.AccessUsage?.Traffic ?? new Traffic();
SessionStatus.SuppressedTo = sessionResponse.SuppressedTo;
PublicAddress = sessionResponse.ClientPublicAddress;
IsIpV6Supported = sessionResponse.IsIpV6Supported;
ServerVersion = Version.Parse(sessionResponse.ServerVersion);
IsIpV6Supported = sessionResponse.IsIpV6Supported;

// PacketCaptureIpRanges
if (!VhUtil.IsNullOrEmpty(sessionResponse.PacketCaptureIncludeIpRanges))
Expand Down
5 changes: 5 additions & 0 deletions VpnHood.Common/Net/IpNetwork.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,11 @@ public static IOrderedEnumerable<IpNetwork> Intersect(IEnumerable<IpNetwork> ipN
return FromIpRange(IpRange.Intersect(ToIpRange(ipNetworks1), ToIpRange(ipNetworks2)));
}

public static IOrderedEnumerable<IpNetwork> Union(IEnumerable<IpNetwork> ipNetworks1, IEnumerable<IpNetwork> ipNetworks2)
{
return FromIpRange(IpRange.Union(ToIpRange(ipNetworks1), ToIpRange(ipNetworks2)));
}

public static IOrderedEnumerable<IpNetwork> Exclude(IEnumerable<IpNetwork> ipNetworks, IEnumerable<IpNetwork> excludeIpNetworks)
{
return FromIpRange(IpRange.Exclude(ToIpRange(ipNetworks), ToIpRange(excludeIpNetworks)));
Expand Down
10 changes: 10 additions & 0 deletions VpnHood.Common/Net/IpNetworkExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ public static IOrderedEnumerable<IpNetwork> Intersect(this IEnumerable<IpNetwork
return IpNetwork.Intersect(ipNetworks1, ipNetworks2);
}

public static IOrderedEnumerable<IpNetwork> Union(IEnumerable<IpNetwork> ipNetworks1, IEnumerable<IpNetwork> ipNetworks2)
{
return IpNetwork.Union(ipNetworks1, ipNetworks2);
}

public static IOrderedEnumerable<IpNetwork> Exclude(this IEnumerable<IpNetwork> ipNetworks, IEnumerable<IpNetwork> excludeIpNetworks)
{
return IpNetwork.Exclude(ipNetworks, excludeIpNetworks);
Expand Down Expand Up @@ -77,4 +82,9 @@ public static IOrderedEnumerable<IpRange> Intersect(this IEnumerable<IpRange> ip
{
return IpRange.Intersect(ipRanges1, ipRanges2);
}

public static IOrderedEnumerable<IpRange> Union(this IEnumerable<IpRange> ipRanges1, IEnumerable<IpRange> ipRanges2)
{
return IpRange.Union(ipRanges1, ipRanges2);
}
}
5 changes: 5 additions & 0 deletions VpnHood.Common/Net/IpRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,11 @@ public static bool IsInSortedRanges(IpRange[] sortedIpRanges, IPAddress ipAddres
return res >= 0 && res < sortedIpRanges.Length ? sortedIpRanges[res] : null;
}

public static IOrderedEnumerable<IpRange> Union(IEnumerable<IpRange> ipRanges1, IEnumerable<IpRange> ipRanges2)
{
return Sort(ipRanges1.Concat(ipRanges2));
}

public static IOrderedEnumerable<IpRange> Exclude(IEnumerable<IpRange> ipRanges, IEnumerable<IpRange> excludeIpRanges)
{
return Intersect(ipRanges, Invert(excludeIpRanges));
Expand Down
4 changes: 2 additions & 2 deletions VpnHood.Common/VpnHood.Common.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<PackageId>VpnHood.Common</PackageId>
<PackageIcon>VpnHood.png</PackageIcon>
<Description>VpnHood Common Library is shared among all other VpnHood modules.</Description>
<Version>2.8.360</Version>
<AssemblyVersion>2.8.360</AssemblyVersion>
<Version>2.8.361</Version>
<AssemblyVersion>2.8.361</AssemblyVersion>
<FileVersion>$([System.DateTime]::Now.ToString("yyyy.M.d.HHmm"))</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down
52 changes: 47 additions & 5 deletions VpnHood.Server.Access/Configurations/NetFilterOptions.cs
Original file line number Diff line number Diff line change
@@ -1,29 +1,71 @@
using System.Text.Json.Serialization;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using VpnHood.Common.Net;
using VpnHood.Common.Utils;

namespace VpnHood.Server.Configurations;

public class NetFilterOptions
{
public bool? ExcludeLocalNetwork { get; set; }
public bool? IncludeLocalNetwork { get; set; }
public IpRange[]? PacketCaptureIncludeIpRanges { get; set; }
public IpRange[]? PacketCaptureExcludeIpRanges { get; set; }
public IpRange[]? IncludeIpRanges { get; set; }
public IpRange[]? ExcludeIpRanges { get; set; }
public bool? BlockIpV6 { get; set; }

[JsonIgnore] public bool ExcludeLocalNetworkValue => ExcludeLocalNetwork ?? true;
[JsonIgnore] public bool IncludeLocalNetworkValue => IncludeLocalNetwork ?? false;
[JsonIgnore] public bool BlockIpV6Value => BlockIpV6 ?? false;

public void Merge(NetFilterOptions obj)
{
if (obj.ExcludeLocalNetwork != null) ExcludeLocalNetwork = obj.ExcludeLocalNetwork;
if (obj.IncludeLocalNetwork != null) IncludeLocalNetwork = obj.IncludeLocalNetwork;
if (obj.PacketCaptureIncludeIpRanges != null) PacketCaptureIncludeIpRanges = obj.PacketCaptureIncludeIpRanges;
if (obj.PacketCaptureExcludeIpRanges != null) PacketCaptureExcludeIpRanges = obj.PacketCaptureExcludeIpRanges;
if (obj.IncludeIpRanges != null) IncludeIpRanges = obj.IncludeIpRanges;
if (obj.ExcludeIpRanges != null) ExcludeIpRanges = obj.ExcludeIpRanges;
if (obj.BlockIpV6 != null) BlockIpV6 = obj.BlockIpV6;
}
public void ApplyDefaults()
{
ExcludeLocalNetwork = ExcludeLocalNetworkValue;
IncludeLocalNetwork = IncludeLocalNetworkValue;
BlockIpV6 = BlockIpV6Value;
}

public IEnumerable<IpRange> GetFinalIncludeIpRanges()
{
var includeIpRanges = IpNetwork.All.ToIpRanges();
if (!VhUtil.IsNullOrEmpty(IncludeIpRanges))
includeIpRanges = includeIpRanges.Intersect(IncludeIpRanges);

if (!VhUtil.IsNullOrEmpty(ExcludeIpRanges))
includeIpRanges = includeIpRanges.Exclude(ExcludeIpRanges);

return includeIpRanges;
}

public IEnumerable<IpRange> GetFinalPacketCaptureIncludeIpRanges()
{
var packetCaptureIncludeIpRanges = IpNetwork.All.ToIpRanges();
if (!IncludeLocalNetworkValue)
packetCaptureIncludeIpRanges = packetCaptureIncludeIpRanges.Exclude(IpNetwork.LocalNetworks.ToIpRanges());

if (!VhUtil.IsNullOrEmpty(PacketCaptureIncludeIpRanges))
packetCaptureIncludeIpRanges = packetCaptureIncludeIpRanges.Intersect(PacketCaptureIncludeIpRanges);

if (!VhUtil.IsNullOrEmpty(PacketCaptureExcludeIpRanges))
packetCaptureIncludeIpRanges = packetCaptureIncludeIpRanges.Exclude(PacketCaptureExcludeIpRanges);

return packetCaptureIncludeIpRanges;
}

public IEnumerable<IpRange> GetBlockedIpRanges()
{
var includeIpRanges = GetFinalIncludeIpRanges().Intersect(GetFinalPacketCaptureIncludeIpRanges());
if (BlockIpV6Value)
includeIpRanges = includeIpRanges.Exclude(new[] { IpNetwork.AllV6.ToIpRange() });

return includeIpRanges.Invert();
}

}
4 changes: 0 additions & 4 deletions VpnHood.Server.Access/Configurations/ServerConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class ServerConfig
[JsonConverter(typeof(TimeSpanConverter))]
public TimeSpan? UpdateStatusInterval { get; set; }
public bool? LogAnonymizer { get; set; }
public bool? AllowIpV6 { get; set; }
public string ConfigCode { get; set; } = string.Empty;
public int? MinCompletionPortThreads { get; set; }
public int? MaxCompletionPortThreads { get; set; }
Expand All @@ -31,7 +30,6 @@ public class ServerConfig
[JsonIgnore] public IPEndPoint[] TcpEndPointsValue => TcpEndPoints ?? new IPEndPoint[] { new(IPAddress.Any, 443), new(IPAddress.IPv6Any, 443) };
[JsonIgnore] public TimeSpan UpdateStatusIntervalValue => UpdateStatusInterval ?? TimeSpan.FromSeconds(120);
[JsonIgnore] public bool LogAnonymizerValue => LogAnonymizer ?? true;
[JsonIgnore] public bool AllowIpV6Value => AllowIpV6 ?? true;

public void Merge(ServerConfig obj)
{
Expand All @@ -41,7 +39,6 @@ public void Merge(ServerConfig obj)
if (obj.TcpEndPoints != null) TcpEndPoints = obj.TcpEndPoints;
if (obj.UpdateStatusInterval != null) UpdateStatusInterval = obj.UpdateStatusInterval;
if (obj.LogAnonymizer != null) LogAnonymizer = obj.LogAnonymizer;
if (obj.AllowIpV6 != null) AllowIpV6 = obj.AllowIpV6;
if (obj.MinCompletionPortThreads != null) MinCompletionPortThreads = obj.MinCompletionPortThreads;
if (obj.MaxCompletionPortThreads != null) MaxCompletionPortThreads = obj.MaxCompletionPortThreads;
}
Expand All @@ -54,6 +51,5 @@ public void ApplyDefaults()
TcpEndPoints = TcpEndPointsValue;
UpdateStatusInterval = UpdateStatusIntervalValue;
LogAnonymizer = LogAnonymizerValue;
AllowIpV6 = AllowIpV6Value;
}
}
4 changes: 2 additions & 2 deletions VpnHood.Server.Access/VpnHood.Server.Access.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<PackageId>VpnHood.Server.Access</PackageId>
<PackageIcon>VpnHood.png</PackageIcon>
<Description>Stores, and retrieves end users' access and usage. Provides required interfaces and classes to use or create an access server and accounting.</Description>
<Version>2.8.360</Version>
<AssemblyVersion>2.8.360</AssemblyVersion>
<Version>2.8.361</Version>
<AssemblyVersion>2.8.361</AssemblyVersion>
<FileVersion>$([System.DateTime]::Now.ToString("yyyy.M.d.HHmm"))</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down
4 changes: 2 additions & 2 deletions VpnHood.Server.App.Net/VpnHood.Server.App.Net.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
<RepositoryUrl>https://github.com/vpnhood/vpnhood</RepositoryUrl>
<PackageLicenseExpression>LGPL-2.1-only</PackageLicenseExpression>
<PackageIcon>VpnHood.png</PackageIcon>
<Version>2.8.360</Version>
<AssemblyVersion>2.8.360</AssemblyVersion>
<Version>2.8.361</Version>
<AssemblyVersion>2.8.361</AssemblyVersion>
<FileVersion>$([System.DateTime]::Now.ToString("yyyy.M.d.HHmm"))</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down
12 changes: 7 additions & 5 deletions VpnHood.Server/TcpHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,22 @@ internal class TcpHost : IAsyncDisposable
private readonly SessionManager _sessionManager;
private readonly SslCertificateManager _sslCertificateManager;
private readonly List<TcpListener> _tcpListeners = new();
private bool _isIpV6Supported;
private Task? _startTask;
private bool _disposed;

public bool IsIpV6Supported { get; set; }
public IpRange[]? NetFilterPacketCaptureIncludeIpRanges { get; set; }
public IpRange[]? NetFilterIncludeIpRanges { get; set; }
public bool IsStarted { get; private set; }
public IPEndPoint[] TcpEndPoints { get; private set; } = Array.Empty<IPEndPoint>();

public TcpHost(SessionManager sessionManager, SslCertificateManager sslCertificateManager)
{
_sslCertificateManager = sslCertificateManager ?? throw new ArgumentNullException(nameof(sslCertificateManager));
_sessionManager = sessionManager;
}

public void Start(IPEndPoint[] tcpEndPoints, bool isIpV6Supported)
public void Start(IPEndPoint[] tcpEndPoints)
{
if (_disposed) throw new ObjectDisposedException(GetType().Name);
if (IsStarted) throw new Exception($"{nameof(TcpHost)} is already Started!");
Expand All @@ -50,7 +51,6 @@ public void Start(IPEndPoint[] tcpEndPoints, bool isIpV6Supported)
_cancellationTokenSource = new CancellationTokenSource();
var cancellationToken = _cancellationTokenSource.Token;
IsStarted = true;
_isIpV6Supported = isIpV6Supported;

try
{
Expand All @@ -59,14 +59,16 @@ public void Start(IPEndPoint[] tcpEndPoints, bool isIpV6Supported)
{
foreach (var tcpEndPoint in tcpEndPoints)
{
VhLogger.Instance.LogInformation($"Start listening on {VhLogger.Format(tcpEndPoint)}");
VhLogger.Instance.LogInformation("Start listening on TcpEndPoint: {TcpEndPoint}", VhLogger.Format(tcpEndPoint));
cancellationToken.ThrowIfCancellationRequested();
var tcpListener = new TcpListener(tcpEndPoint);
tcpListener.Start();
_tcpListeners.Add(tcpListener);
tasks.Add(ListenTask(tcpListener, cancellationToken));
}
}

TcpEndPoints = tcpEndPoints;
_startTask = Task.WhenAll(tasks);
}
catch
Expand Down Expand Up @@ -337,9 +339,9 @@ private async Task ProcessHello(TcpClientStream tcpClientStream, CancellationTok
AccessUsage = sessionResponse.AccessUsage,
MaxDatagramChannelCount = session.Tunnel.MaxDatagramChannelCount,
ClientPublicAddress = ipEndPointPair.RemoteEndPoint.Address,
IsIpV6Supported = _isIpV6Supported,
IncludeIpRanges = NetFilterIncludeIpRanges,
PacketCaptureIncludeIpRanges = NetFilterPacketCaptureIncludeIpRanges,
IsIpV6Supported = IsIpV6Supported,
ErrorCode = SessionErrorCode.Ok
};
await StreamUtil.WriteJsonAsync(tcpClientStream.Stream, helloResponse, cancellationToken);
Expand Down
4 changes: 2 additions & 2 deletions VpnHood.Server/VpnHood.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
<PackageIcon>VpnHood.png</PackageIcon>
<Description>The core of VpnHood server. It can listen and accept connections from VpnHood clients.</Description>
<PackageId>VpnHood.Server</PackageId>
<Version>2.8.360</Version>
<AssemblyVersion>2.8.360</AssemblyVersion>
<Version>2.8.361</Version>
<AssemblyVersion>2.8.361</AssemblyVersion>
<FileVersion>$([System.DateTime]::Now.ToString("yyyy.M.d.HHmm"))</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
Expand Down
Loading

0 comments on commit 75e8ca3

Please sign in to comment.