Skip to content
This repository has been archived by the owner on Jul 6, 2020. It is now read-only.

Commit

Permalink
Added Basic Authentication support.
Browse files Browse the repository at this point in the history
  • Loading branch information
VahidN committed Jul 8, 2017
1 parent 7e396b4 commit c6ae3c5
Show file tree
Hide file tree
Showing 9 changed files with 7,411 additions and 6,535 deletions.
13,731 changes: 7,259 additions & 6,472 deletions Libs/DotNet4/FiddlerCore4.XML

Large diffs are not rendered by default.

Binary file modified Libs/DotNet4/FiddlerCore4.dll
Binary file not shown.
5 changes: 5 additions & 0 deletions ProcessProxifier/Core/ProcessesListManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public static AsyncObservableCollection<Process> UpdateProcesses(
foreach (var systemProcess in newSystemProcesses)
{
var path = systemProcess.GetPath();
if(string.IsNullOrWhiteSpace(path)) // TODO: improve
{
continue;
}

var newProcess = new Process
{
Name = systemProcess.ProcessName,
Expand Down
56 changes: 41 additions & 15 deletions ProcessProxifier/Core/ProxyRouter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using System.Linq;
using System;
using System.Linq;
using System.Net.Security;
using System.Text;
using System.Threading;
using Fiddler;
using ProcessProxifier.Models;
Expand All @@ -19,7 +21,6 @@ public class ProxyRouter

public AsyncObservableCollection<RoutedConnection> RoutedConnectionsList { set; get; }

// Public Methods (2) 

public void Shutdown()
{
Expand All @@ -44,22 +45,55 @@ public void Start()
FiddlerCoreStartupFlags.MonitorAllConnections |
FiddlerCoreStartupFlags.CaptureFTP);
}
// Private Methods (3) 

void beforeRequest(Session oSession)

private static void onValidateServerCertificate(object sender, ValidateServerCertificateEventArgs e)
{
if (SslPolicyErrors.None == e.CertificatePolicyErrors)
return;

e.ValidityState = CertificateValidity.ForceValid;
}

private static void setBasicAuthenticationHeaders(Session oSession, string userCredentials)
{
var base64UserCredentials = Convert.ToBase64String(Encoding.UTF8.GetBytes(userCredentials));
oSession.RequestHeaders["Proxy-Authorization"] = $"Basic {base64UserCredentials}";
}

private void beforeRequest(Session oSession)
{
var process = ProcessesList.FirstOrDefault(p => p.Pid == oSession.LocalProcessID && p.IsEnabled);
if (process == null)
{
return;
}

var useDefaultServerInfo = string.IsNullOrWhiteSpace(process.ServerInfo.ServerIP);
var processServerInfo = process.ServerInfo;
var useDefaultServerInfo = string.IsNullOrWhiteSpace(processServerInfo.ServerIP);
if (useDefaultServerInfo)
{
oSession["X-OverrideGateway"] = (DefaultServerInfo.ServerType == ServerType.Socks ? "socks=" : "") + DefaultServerInfo.ServerIP + ":" + DefaultServerInfo.ServerPort;
var serverType = DefaultServerInfo.ServerType == ServerType.Socks ? "socks=" : "";
oSession["X-OverrideGateway"] = $"{serverType}{DefaultServerInfo.ServerIP}:{DefaultServerInfo.ServerPort}";

if (!string.IsNullOrWhiteSpace(DefaultServerInfo.Username) &&
!string.IsNullOrWhiteSpace(DefaultServerInfo.Password))
{
var userCredentials = $"{DefaultServerInfo.Username}:{DefaultServerInfo.Password}";
setBasicAuthenticationHeaders(oSession, userCredentials);
}
}
else
{
oSession["X-OverrideGateway"] = (process.ServerInfo.ServerType == ServerType.Socks ? "socks=" : "") + process.ServerInfo.ServerIP + ":" + process.ServerInfo.ServerPort;
var serverType = processServerInfo.ServerType == ServerType.Socks ? "socks=" : "";
oSession["X-OverrideGateway"] = $"{serverType}{processServerInfo.ServerIP}:{processServerInfo.ServerPort}";

if (!string.IsNullOrWhiteSpace(processServerInfo.Username) &&
!string.IsNullOrWhiteSpace(processServerInfo.Password))
{
var userCredentials = $"{processServerInfo.Username}:{processServerInfo.Password}";
setBasicAuthenticationHeaders(oSession, userCredentials);
}
}

RoutedConnectionsList.Add(new RoutedConnection
Expand All @@ -76,13 +110,5 @@ private string getProcessName(Session oSession)
var process = ProcessesList.FirstOrDefault(x => x.Pid == oSession.LocalProcessID);
return process == null ? oSession.LocalProcessID.ToString(CultureInfo.InvariantCulture) : process.Name;
}

static void onValidateServerCertificate(object sender, ValidateServerCertificateEventArgs e)
{
if (SslPolicyErrors.None == e.CertificatePolicyErrors)
return;

e.ValidityState = CertificateValidity.ForceValid;
}
}
}
106 changes: 70 additions & 36 deletions ProcessProxifier/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:b="clr-namespace:ProcessProxifier.Behaviors"
xmlns:c="clr-namespace:ProcessProxifier.Converters"
xmlns:vm="clr-namespace:ProcessProxifier.ViewModels"
Title="ProcessProxifier V1.2" Height="615" Width="731">
Title="ProcessProxifier V1.3" Height="715" Width="731">
<Window.Resources>
<vm:MainWindowViewModel x:Key="VmMainWindowViewModel" />
<c:FileToImageIconConverter x:Key="CFileToImageIconConverter" />
Expand All @@ -21,8 +21,8 @@

<StackPanel VerticalAlignment="Stretch" Orientation="Horizontal" Grid.Row="0" Margin="5">
<Button x:Name="BtnStart" IsEnabled="{Binding GuiModelData.IsEnabled}"
Command="{Binding DoStart}" Width="30" Height="30"
ToolTip="Start">
Command="{Binding DoStart}" Width="30" Height="30"
ToolTip="Start">
<Rectangle Width="10" Height="10">
<Rectangle.Fill>
<VisualBrush Stretch="Fill" Visual="{StaticResource appbar_play}" />
Expand All @@ -31,8 +31,8 @@
</Button>

<Button Width="30" Height="30"
Command="{Binding DoStop}"
ToolTip="Stop">
Command="{Binding DoStop}"
ToolTip="Stop">
<Rectangle Width="10" Height="10">
<Rectangle.Fill>
<VisualBrush Stretch="Fill" Visual="{StaticResource appbar_stop}" />
Expand All @@ -41,26 +41,26 @@
</Button>
<Rectangle Name="Rectangle" Height="23" Width="1" Fill="Gray" VerticalAlignment="Stretch" Margin="2,0" />
<Button Width="30" Height="30"
Command="{Binding DoSave}"
ToolTip="Save Settings">
Command="{Binding DoSave}"
ToolTip="Save Settings">
<Rectangle Width="10" Height="10">
<Rectangle.Fill>
<VisualBrush Stretch="Fill" Visual="{StaticResource appbar_disk}" />
</Rectangle.Fill>
</Rectangle>
</Button>
<Button Width="30" Height="30"
Command="{Binding DoRefresh}"
ToolTip="Refresh Processes List">
Command="{Binding DoRefresh}"
ToolTip="Refresh Processes List">
<Rectangle Width="10" Height="10">
<Rectangle.Fill>
<VisualBrush Stretch="Fill" Visual="{StaticResource appbar_refresh}" />
</Rectangle.Fill>
</Rectangle>
</Button>
<Button Width="30" Height="30"
Command="{Binding DoClearLogs}"
ToolTip="Clear logs">
Command="{Binding DoClearLogs}"
ToolTip="Clear logs">
<Rectangle Width="10" Height="10">
<Rectangle.Fill>
<VisualBrush Stretch="Fill" Visual="{StaticResource appbar_page_minus}" />
Expand Down Expand Up @@ -88,16 +88,16 @@
</Grid.ColumnDefinitions>
<TextBlock Margin="3" Text="Server IP" />
<TextBox Grid.Row="0" Grid.Column="1" Text="{Binding GuiModelData.DefaultServerInfo.ServerIP, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,
NotifyOnValidationError=True, ValidatesOnDataErrors=True,
ValidatesOnExceptions=True}"
NotifyOnValidationError=True, ValidatesOnDataErrors=True,
ValidatesOnExceptions=True}"
Name="TxtServerIp"
Margin="3" Width="150" HorizontalAlignment="Left" TabIndex="2" />

<TextBlock Grid.Row="1" Grid.Column="0" Margin="3" Text="Server Port" />
<TextBox Grid.Column="1" Grid.Row="1"
Text="{Binding GuiModelData.DefaultServerInfo.ServerPort, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,
NotifyOnValidationError=True, ValidatesOnDataErrors=True,
ValidatesOnExceptions=True}"
NotifyOnValidationError=True, ValidatesOnDataErrors=True,
ValidatesOnExceptions=True}"
Margin="3" Width="150" HorizontalAlignment="Left" TabIndex="3" />

<TextBlock Grid.Row="2" Grid.Column="0" Text="Server Type" Margin="3" />
Expand All @@ -106,29 +106,45 @@
<RadioButton Content="HTTP Proxy Server" IsChecked="{Binding GuiModelData.DefaultServerInfo.ServerType, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource CEnumBooleanConverter}, ConverterParameter=Proxy}" Margin="3" GroupName="G1" />
</StackPanel>

<TextBlock Grid.Row="3" Grid.Column="0" Margin="3" Text="Proxifier Port" />
<TextBlock Grid.Row="3" Grid.Column="0" Margin="3" Text="Username" />
<TextBox Grid.Column="1" Grid.Row="3"
Text="{Binding GuiModelData.DefaultServerInfo.Username, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,
NotifyOnValidationError=True, ValidatesOnDataErrors=True,
ValidatesOnExceptions=True}"
Margin="3" Width="150" HorizontalAlignment="Left" TabIndex="3" />

<TextBlock Grid.Row="4" Grid.Column="0" Margin="3" Text="Password" />
<TextBox Grid.Column="1" Grid.Row="4"
Text="{Binding GuiModelData.DefaultServerInfo.Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,
NotifyOnValidationError=True, ValidatesOnDataErrors=True,
ValidatesOnExceptions=True}"
Margin="3" Width="150" HorizontalAlignment="Left" TabIndex="3" />



<TextBlock Grid.Row="5" Grid.Column="0" Margin="3" Text="Proxifier Port" />
<TextBox Grid.Column="1" Grid.Row="5"
Text="{Binding GuiModelData.ProxifierPort, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,
NotifyOnValidationError=True, ValidatesOnDataErrors=True,
ValidatesOnExceptions=True}"
NotifyOnValidationError=True, ValidatesOnDataErrors=True,
ValidatesOnExceptions=True}"
Margin="3" Width="150" HorizontalAlignment="Left" TabIndex="3" />

<CheckBox Grid.Row="5" Grid.Column="0" TabIndex="7"
<CheckBox Grid.Row="6" Grid.Column="0" TabIndex="7"
IsChecked="{Binding GuiModelData.RunOnStartup, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged,
NotifyOnValidationError=True, ValidatesOnDataErrors=True,
ValidatesOnExceptions=True}"
NotifyOnValidationError=True, ValidatesOnDataErrors=True,
ValidatesOnExceptions=True}"
Margin="3" Content="Run on Startup" />
</Grid>
</GroupBox>

<GridSplitter
Grid.Row="3"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
ShowsPreview="true"
ResizeDirection="Rows"
Panel.ZIndex="1"
Height="3" />
Grid.Row="3"
HorizontalAlignment="Stretch"
VerticalAlignment="Top"
ShowsPreview="true"
ResizeDirection="Rows"
Panel.ZIndex="1"
Height="3" />

<GroupBox Margin="5" Grid.Row="2" Header="Proxify selected process(es)">
<Grid Margin="5">
Expand All @@ -137,9 +153,9 @@
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<TextBox Grid.Row="0"
b:TextboxHelper.Watermark="Search"
Text="{Binding GuiModelData.SearchText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Margin="0,0,0,3" />
b:TextboxHelper.Watermark="Search"
Text="{Binding GuiModelData.SearchText, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
Margin="0,0,0,3" />
<ListView IsSynchronizedWithCurrentItem="True" Grid.Row="1"
SelectedItem="{Binding GuiModelData.SelectedProcess}"
ItemsSource="{Binding GuiModelData.ProcessesListDataView}"
Expand All @@ -152,8 +168,8 @@
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel
IsVirtualizing="True"
VirtualizationMode="Recycling" />
IsVirtualizing="True"
VirtualizationMode="Recycling" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.View>
Expand Down Expand Up @@ -215,6 +231,24 @@
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>

<GridViewColumn Width="120" Header="Username" b:GridViewSortBehavior.PropertyName="ServerInfo.Username">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Margin="3" HorizontalAlignment="Stretch"
Text="{Binding ServerInfo.Username, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>

<GridViewColumn Width="120" Header="Password" b:GridViewSortBehavior.PropertyName="ServerInfo.Password">
<GridViewColumn.CellTemplate>
<DataTemplate>
<TextBox Margin="3" HorizontalAlignment="Stretch"
Text="{Binding ServerInfo.Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
</DataTemplate>
</GridViewColumn.CellTemplate>
</GridViewColumn>
</GridView>
</ListView.View>
<ListView.ContextMenu>
Expand Down Expand Up @@ -245,8 +279,8 @@
<ListView.ItemsPanel>
<ItemsPanelTemplate>
<VirtualizingStackPanel
IsVirtualizing="True"
VirtualizationMode="Recycling" />
IsVirtualizing="True"
VirtualizationMode="Recycling" />
</ItemsPanelTemplate>
</ListView.ItemsPanel>
<ListView.View>
Expand Down Expand Up @@ -280,7 +314,7 @@
</MenuItem.Icon>
</MenuItem>
<MenuItem Command="{Binding DoCopySelectedLine}"
Header="Copy selected line to clipboard">
Header="Copy selected line to clipboard">
<MenuItem.Icon>
<Image Stretch="UniformToFill" Width="16" Height="16" Source="images/CopyHS.png" HorizontalAlignment="Center" VerticalAlignment="Center" />
</MenuItem.Icon>
Expand Down
35 changes: 29 additions & 6 deletions ProcessProxifier/Models/ServerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,21 @@ namespace ProcessProxifier.Models
{
public class ServerInfo : INotifyPropertyChanged
{
ServerType _serverType;
string _password = string.Empty;
string _serverIP = string.Empty;
int _serverPort;
ServerType _serverType;
string _username = string.Empty;

public ServerType ServerType
public event PropertyChangedEventHandler PropertyChanged;

public string Password
{
get { return _serverType; }
get { return _password; }
set
{
_serverType = value;
notifyPropertyChanged("ServerType");
_password = value;
notifyPropertyChanged("Password");
}
}

Expand All @@ -38,7 +42,26 @@ public int ServerPort
}
}

public event PropertyChangedEventHandler PropertyChanged;
public ServerType ServerType
{
get { return _serverType; }
set
{
_serverType = value;
notifyPropertyChanged("ServerType");
}
}

public string Username
{
get { return _username; }
set
{
_username = value;
notifyPropertyChanged("Username");
}
}

private void notifyPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
Expand Down
4 changes: 2 additions & 2 deletions ProcessProxifier/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyVersion("1.3.0.0")]
[assembly: AssemblyFileVersion("1.3.0.0")]
Loading

0 comments on commit c6ae3c5

Please sign in to comment.