Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
trudyhood committed Sep 22, 2021
2 parents 82fe4ee + 14ed49a commit cce4909
Show file tree
Hide file tree
Showing 46 changed files with 687 additions and 304 deletions.
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# v2.0.271
# v2.0.272
* Feature: Block all IPv6 Global Unicast to prevent leak
* Fix: Android: Vpn Connection keeps open after disconnecting
* Fix: Android: Crash in android 5.1
* Fix: IpFilter miss some IPs of countries
* Update: Improve the speed of establishing the connection

# v2.0.271
### Client
* Feature: Server Redirection
* Feature: Server Maintenance mode detection
Expand Down Expand Up @@ -267,3 +274,4 @@




Binary file modified Pub/Version.json
Binary file not shown.
6 changes: 3 additions & 3 deletions VpnHood.App.Launcher/VpnHood.App.Launcher.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<PackageIcon>VpnHood.png</PackageIcon>
<Product>VpnHood.App.Launcher</Product>
<ApplicationIcon>Resources\VpnHood.ico</ApplicationIcon>
<Version>2.0.271</Version>
<AssemblyVersion>2.0.271</AssemblyVersion>
<FileVersion>2.0.271</FileVersion>
<Version>2.0.272</Version>
<AssemblyVersion>2.0.272</AssemblyVersion>
<FileVersion>2.0.272</FileVersion>
<LangVersion>9.0</LangVersion>
<Nullable>enable</Nullable>
</PropertyGroup>
Expand Down
8 changes: 6 additions & 2 deletions VpnHood.Client.App.Android/AndroidApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ public AndroidApp(IntPtr javaReference, JniHandleOwnership transfer)
}


private readonly object stateLock = new();
private readonly object _stateLock = new();
private void UpdateNotification()
{
lock (stateLock)
lock (_stateLock)
{
if (_notifyBuilder == null)
return; // _notifyBuilder has not been initialized yet
Expand Down Expand Up @@ -143,6 +143,10 @@ private void InitNotification()
#pragma warning restore CS0618 // Type or member is obsolete
}

// for android 5.1 (no subtext will be shown if we don't call SetContentText)
if (Build.VERSION.SdkInt < BuildVersionCodes.N)
_notifyBuilder.SetContentText(Resources?.GetString(Resource.String.app_name) ?? "VpnHood!");

_notifyBuilder.SetVisibility(NotificationVisibility.Secret); //VPN icon is already showed by the system
_notifyBuilder.SetContentIntent(pendingOpenIntent);
_notifyBuilder.AddAction(new Notification.Action(0, Resources?.GetText(Resource.String.disconnect) ?? "Disconnect", CreatePendingIntent("disconnect")));
Expand Down
25 changes: 19 additions & 6 deletions VpnHood.Client.App.Android/MainActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,22 @@ public class MainActivity : Activity
private const int RequestVpnPermission = 10;
private VpnHoodAppUi? _appUi;

private AndroidDevice Device => (AndroidDevice?) AndroidApp.Current?.Device ??
throw new InvalidOperationException($"{nameof(Device)} is not initialized!");
private AndroidDevice Device =>
(AndroidDevice?)AndroidApp.Current?.Device ?? throw new InvalidOperationException($"{nameof(Device)} is not initialized!");

public WebView? WebView { get; private set; }
public Color BackgroundColor => Resources?.GetColor(Resource.Color.colorBackground, null) ?? Color.DarkBlue;
public Color BackgroundColor
{
get
{
if (Build.VERSION.SdkInt >= BuildVersionCodes.M)
return Resources?.GetColor(Resource.Color.colorBackground, Theme) ?? Color.DarkBlue;

#pragma warning disable 618
return Resources?.GetColor(Resource.Color.colorBackground) ?? Color.DarkBlue;
#pragma warning restore 618
}
}

protected override void OnCreate(Bundle? savedInstanceState)
{
Expand All @@ -44,10 +55,12 @@ protected override void OnCreate(Bundle? savedInstanceState)

// manage VpnPermission
Device.OnRequestVpnPermission += Device_OnRequestVpnPermission;

//var item = VpnHoodApp.Instance.ClientProfileStore.ClientProfileItems[0]; //todo
//VpnHoodApp.Instance.Connect(item.Id); //todo

// Initialize UI
var zipStream = Resources?.Assets?.Open("SPA.zip") ??
throw new Exception("Could not load SPA.zip resource!");
var zipStream = Resources?.Assets?.Open("SPA.zip") ?? throw new Exception("Could not load SPA.zip resource!");
_appUi = VpnHoodAppUi.Init(zipStream);
InitWebUi();
}
Expand Down Expand Up @@ -90,7 +103,7 @@ private void InitSplashScreen()
imageView.SetImageResource(Resource.Mipmap.ic_launcher_round);
imageView.LayoutParameters = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent);
imageView.SetScaleType(ImageView.ScaleType.CenterInside);
//imageView.SetBackgroundColor(Color);
imageView.SetBackgroundColor(BackgroundColor);
SetContentView(imageView);
}

Expand Down
2 changes: 1 addition & 1 deletion VpnHood.Client.App.Android/Properties/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="271" package="com.vpnhood.client.android" android:installLocation="auto" android:versionName="2.0.271">
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="272" package="com.vpnhood.client.android" android:installLocation="auto" android:versionName="2.0.272">
<uses-sdk android:minSdkVersion="22" android:targetSdkVersion="30" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 10 additions & 2 deletions VpnHood.Client.App.Android/VpnHood.Client.App.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
<Nullable>enable</Nullable>
<LangVersion>9.0</LangVersion>
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
Expand Down Expand Up @@ -102,7 +102,9 @@
<AndroidResource Include="Resources\values\styles.xml" />
<AndroidResource Include="Resources\values\colors.xml" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<AndroidResource Include="Resources\mipmap-ldpi\ic_launcher_foreground.png" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\VpnHood.Client.App.UI\VpnHood.Client.App.UI.csproj">
<Project>{18d028c5-3056-457f-9286-f469bee59bbe}</Project>
Expand Down Expand Up @@ -259,5 +261,11 @@
<Generator>MSBuild:UpdateGeneratedFiles</Generator>
</AndroidResource>
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\mipmap-ldpi\ic_launcher_round.png" />
</ItemGroup>
<ItemGroup>
<AndroidResource Include="Resources\mipmap-ldpi\ic_notification.png" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />
</Project>
6 changes: 3 additions & 3 deletions VpnHood.Client.App.UI/VpnHood.Client.App.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
<PackageIcon>VpnHood.png</PackageIcon>
<Description>Readymade Vpn App skeleton for VpnHood clients. You just need to add build a UI on it.</Description>
<PackageId>VpnHood.Client.App.UI</PackageId>
<Version>2.0.271</Version>
<AssemblyVersion>2.0.271</AssemblyVersion>
<FileVersion>2.0.271</FileVersion>
<Version>2.0.272</Version>
<AssemblyVersion>2.0.272</AssemblyVersion>
<FileVersion>2.0.272</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>9.0</LangVersion>
</PropertyGroup>
Expand Down
6 changes: 3 additions & 3 deletions VpnHood.Client.App.Win.Setup/VpnHood.Client.App.Win.Setup.aip
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<DOCUMENT Type="Advanced Installer" CreateVersion="17.7" version="18.3" Modules="professional" RootPath="." Language="en" Id="{F5BEDA55-1847-4909-B85B-443D6C887C92}">
<DOCUMENT Type="Advanced Installer" CreateVersion="17.7" version="18.6.1" Modules="professional" RootPath="." Language="en" Id="{F5BEDA55-1847-4909-B85B-443D6C887C92}">
<COMPONENT cid="caphyon.advinst.msicomp.MsiPropsComponent">
<ROW Property="AI_BITMAP_DISPLAY_MODE" Value="0"/>
<ROW Property="AI_COLOR_DISABLED_TEXT" Value="3026478" MultiBuildValue="DefaultBuild:15461355" MsiKey="AI_COLOR_DISABLED_TEXT"/>
Expand All @@ -22,10 +22,10 @@
<ROW Property="CTRLS" Value="2"/>
<ROW Property="DOTNET" Value="dotnet"/>
<ROW Property="Manufacturer" Value="VpnHood"/>
<ROW Property="ProductCode" Value="1033:{58FA7AB2-71DF-44F9-9B08-F91849D7A080} " Type="16"/>
<ROW Property="ProductCode" Value="1033:{1C229520-CA65-408A-9921-9FCD92B7F2F6} " Type="16"/>
<ROW Property="ProductLanguage" Value="1033"/>
<ROW Property="ProductName" Value="VpnHood"/>
<ROW Property="ProductVersion" Value="2.0.271.0" Type="32" TargetFile="VpnHoodClient.dll"/>
<ROW Property="ProductVersion" Value="2.0.272.0" Type="32" TargetFile="VpnHoodClient.dll"/>
<ROW Property="SecureCustomProperties" Value="OLDPRODUCTS;AI_NEWERPRODUCTFOUND;AI_SETUPEXEPATH;SETUPEXEDIR"/>
<ROW Property="UpgradeCode" Value="{38FCFAB0-A40C-4840-A9F9-B7A06A5BC552}"/>
<ROW Property="WindowsType9X" MultiBuildValue="DefaultBuild:Windows 9x/ME" ValueLocId="-"/>
Expand Down
8 changes: 4 additions & 4 deletions VpnHood.Client.App.Win/VpnHood.Client.App.Win.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
<ApplicationManifest>app.manifest</ApplicationManifest>
<PackageId>VpnHood.Client.App.Win</PackageId>
<StartupObject></StartupObject>
<Version>2.0.271</Version>
<AssemblyVersion>2.0.271</AssemblyVersion>
<FileVersion>2.0.271</FileVersion>
<Version>2.0.272</Version>
<AssemblyVersion>2.0.272</AssemblyVersion>
<FileVersion>2.0.272</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>9.0</LangVersion>
<EnforceCodeStyleInBuild>false</EnforceCodeStyleInBuild>
Expand Down Expand Up @@ -58,7 +58,7 @@

<ItemGroup>
<PackageReference Include=" " Version="1.0.664.37" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.902.49" />
<PackageReference Include="Microsoft.Web.WebView2" Version="1.0.961.33" />
</ItemGroup>

<ItemGroup>
Expand Down
30 changes: 16 additions & 14 deletions VpnHood.Client.App/ClientProfileStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,44 +50,46 @@ public ClientProfileItem[] ClientProfileItems
}
}

public Token GetToken(Guid tokenId, bool autoUpdate = false)
public Token GetToken(Guid tokenId)
{
return GetToken(tokenId, false, autoUpdate);
return GetToken(tokenId, false);
}

internal Token GetToken(Guid tokenId, bool withSecret, bool autoUpdate)
internal Token GetToken(Guid tokenId, bool withSecret)
{
var token = _tokens.FirstOrDefault(x => x.TokenId == tokenId);
if (token == null) throw new KeyNotFoundException($"{nameof(tokenId)} does not exists. TokenId {tokenId}");

// clone token
token = (Token) token.Clone();

// update token
if (token.Url != null && autoUpdate)
token = UpdateTokenFromUrl(token).Result;

if (!withSecret)
token.Secret = Array.Empty<byte>();
return token;
}

private async Task<Token> UpdateTokenFromUrl(Token token)
public async Task<Token> UpdateTokenFromUrl(Token token)
{
if (string.IsNullOrEmpty(token.Url))
return token;

// update token
VhLogger.Instance.LogInformation($"Trying to get new token from token url, Url: {token.Url}");
try
{
using var client = new HttpClient();
var accessKey = await client.GetStringAsync(token.Url);
AddAccessKey(accessKey); //update store
token = Token.FromAccessKey(accessKey);
VhLogger.Instance.LogInformation(
$"Updated TokenId: {VhLogger.FormatId(token.TokenId)}, SupportId: {VhLogger.FormatId(token.SupportId)}");
var accessKey = await Util.RunTask(client.GetStringAsync(token.Url), TimeSpan.FromSeconds(20));
var newToken = Token.FromAccessKey(accessKey);
if (newToken.TokenId != token.TokenId)
throw new InvalidOperationException($"Could not updated Token because {nameof(token.TokenId)} has been changed! TokenId: {VhLogger.FormatId(token.TokenId)}");

//update store
AddAccessKey(accessKey);
VhLogger.Instance.LogInformation($"Updated TokenId: {VhLogger.FormatId(token.TokenId)}, SupportId: {VhLogger.FormatId(token.SupportId)}");
}
catch (Exception ex)
{
VhLogger.Instance.LogInformation($"Could not update token from token url, Error: {ex.Message}");
VhLogger.Instance.LogError($"Could not update token from token url, Error: {ex.Message}");
}

return token;
Expand Down
6 changes: 3 additions & 3 deletions VpnHood.Client.App/VpnHood.Client.App.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
<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.0.271</Version>
<AssemblyVersion>2.0.271</AssemblyVersion>
<FileVersion>2.0.271</FileVersion>
<Version>2.0.272</Version>
<AssemblyVersion>2.0.272</AssemblyVersion>
<FileVersion>2.0.272</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>9.0</LangVersion>
</PropertyGroup>
Expand Down
4 changes: 3 additions & 1 deletion VpnHood.Client.App/VpnHoodApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ private async Task ConnectInternal(IPacketCapture packetCapture, Guid tokenId, s
VhLogger.Instance.LogInformation($"UserAgent: {userAgent}");

// get token
var token = ClientProfileStore.GetToken(tokenId, true, true);
var token = ClientProfileStore.GetToken(tokenId, true);
_ = ClientProfileStore.UpdateTokenFromUrl(token);

VhLogger.Instance.LogInformation($"TokenId: {VhLogger.FormatId(token.TokenId)}, SupportId: {VhLogger.FormatId(token.SupportId)}");

// Create Client
Expand Down
36 changes: 24 additions & 12 deletions VpnHood.Client.Device.Android/AppVpnService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
using PacketDotNet;
using VpnHood.Common;
using VpnHood.Common.Logging;
using Exception = System.Exception;

namespace VpnHood.Client.Device.Android
{
[Service(Label = VpnServiceName, Permission = Manifest.Permission.BindVpnService)]
[IntentFilter(new[] {"android.net.VpnService"})]
[IntentFilter(new[] { "android.net.VpnService" })]
internal class AppVpnService : VpnService, IPacketCapture
{
public const string VpnServiceName = "VpnHood";
private IPAddress[]? _dnsServers = {IPAddress.Parse("8.8.8.8"), IPAddress.Parse("8.8.4.4")};
private IPAddress[]? _dnsServers = { IPAddress.Parse("8.8.8.8"), IPAddress.Parse("8.8.4.4") };
private FileInputStream? _inStream; // Packets to be sent are queued in this input stream.
private ParcelFileDescriptor? _mInterface;
private int _mtu;
Expand Down Expand Up @@ -68,10 +69,11 @@ public void StartCapture()
var builder = new Builder(this)
.SetBlocking(true)
.SetSession(VpnServiceName)
.AddAddress("192.168.0.100", 24);
.AddAddress("192.168.0.100", 24)
.AddAddress("fe80::64", 120);

// dnsServers
if (DnsServers is {Length: > 0})
if (DnsServers is { Length: > 0 })
foreach (var dnsServer in DnsServers)
builder.AddDnsServer(dnsServer.ToString());
else
Expand Down Expand Up @@ -210,7 +212,7 @@ private Task ReadingPacketTask()
var buf = new byte[short.MaxValue];
while (_inStream.Read(buf) > 0)
{
var ipPacket = Packet.ParsePacket(LinkLayers.Raw, buf)?.Extract<IPv4Packet>();
var ipPacket = Packet.ParsePacket(LinkLayers.Raw, buf)?.Extract<IPPacket>();
if (ipPacket != null)
ProcessPacket(ipPacket);
}
Expand All @@ -234,7 +236,7 @@ protected virtual void ProcessPacket(IPPacket ipPacket)
{
try
{
OnPacketReceivedFromInbound?.Invoke(this, new PacketReceivedEventArgs(new[] {ipPacket}, this));
OnPacketReceivedFromInbound?.Invoke(this, new PacketReceivedEventArgs(new[] { ipPacket }, this));
}
catch (Exception ex)
{
Expand All @@ -257,13 +259,23 @@ private void Close()
return;

VhLogger.Instance.LogTrace("Closing VpnService...");
StopSelf();

_inStream?.Dispose();
_outStream?.Dispose();
_mInterface?.Close(); //required to close the vpn. dispose is not enough
_mInterface?.Dispose();
_mInterface = null;
try
{
_inStream?.Dispose();
_outStream?.Dispose();
_mInterface?.Close(); //required to close the vpn. dispose is not enough
_mInterface?.Dispose();
_mInterface = null;

}
catch (Exception ex)
{
VhLogger.Instance.LogError(ex, "Error while closing the VpnService!");
}

// it must be after _mInterface.Close
StopSelf();
}

#region Application Filter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
<RepositoryUrl>https://github.com/vpnhood/vpnhood</RepositoryUrl>
<PackageIcon>VpnHood.png</PackageIcon>
<Description>VpnHood client device provider for Windows using WinDivert.</Description>
<Version>2.0.271</Version>
<Version>2.0.272</Version>
<PackageId>VpnHood.Client.Device.WinDivert</PackageId>
<Version>1.1.226</Version>
<AssemblyVersion>2.0.271</AssemblyVersion>
<FileVersion>2.0.271</FileVersion>
<AssemblyVersion>2.0.272</AssemblyVersion>
<FileVersion>2.0.272</FileVersion>
<Nullable>enable</Nullable>
<LangVersion>9.0</LangVersion>
</PropertyGroup>
Expand All @@ -29,7 +29,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="SharpPcap" Version="6.0.0" />
<PackageReference Include="SharpPcap" Version="6.1.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading

0 comments on commit cce4909

Please sign in to comment.