├── .gitattributes ├── .gitignore ├── .nuget ├── NuGet.Config ├── NuGet.exe └── NuGet.targets ├── BlueDwarf.Core ├── Aspects │ └── PropertyImporter.cs ├── BlueDwarf.Core.csproj ├── Configuration │ ├── IPersistence.cs │ ├── ISetupConfiguration.cs │ ├── PersistenceExtensions.cs │ ├── Persistent.cs │ ├── RegistryPersistence.cs │ ├── SetupConfiguration.cs │ └── ShellLink │ │ ├── FileIcon.cs │ │ └── ShellLink.cs ├── CoreConfiguration.cs ├── FodyWeavers.xml ├── Net │ ├── Client │ │ ├── HttpGetAttribute.cs │ │ ├── Rest.cs │ │ ├── RestAdvice.cs │ │ └── RestCall.cs │ ├── Downloader.cs │ ├── DownloaderExtensions.cs │ ├── Geolocation │ │ ├── AddressGeolocation.cs │ │ ├── HostIP │ │ │ ├── HostIPAddressGeolocation.cs │ │ │ ├── HostIPGeolocation.cs │ │ │ └── IHostIPApi.cs │ │ ├── IGeolocation.cs │ │ └── Telize │ │ │ ├── ITelizeApi.cs │ │ │ ├── TelizeAddressGeolocation.cs │ │ │ └── TelizeGeolocation.cs │ ├── IDownloader.cs │ ├── Name │ │ ├── DnsNameResolver.cs │ │ ├── INameResolver.cs │ │ ├── MultiNameResolver.cs │ │ └── StatDns │ │ │ ├── Answer.cs │ │ │ ├── IStatDns.cs │ │ │ ├── Question.cs │ │ │ ├── Response.cs │ │ │ └── StatDnsNameResolver.cs │ └── Proxy │ │ ├── Client │ │ ├── Authentication │ │ │ └── BlueCoatHttpAuthentication.cs │ │ ├── Diagnostic │ │ │ ├── IProxyAnalyzer.cs │ │ │ ├── ISystemProxyAnalyzer.cs │ │ │ ├── ProxyAnalyzer.cs │ │ │ ├── ProxyDiagnostic.cs │ │ │ ├── ProxyPerformance.cs │ │ │ ├── RouteStatus.cs │ │ │ ├── SystemAnalysisParameters.cs │ │ │ └── SystemProxyAnalyzer.cs │ │ └── RouteExtensions.cs │ │ ├── IProxyConfiguration.cs │ │ ├── ProxyConfiguration.cs │ │ ├── Scanner │ │ ├── HostPort.cs │ │ ├── HostScanner.cs │ │ ├── IHostScanner.cs │ │ ├── IProxyPageScanner.cs │ │ ├── IProxyValidator.cs │ │ ├── ProxyPage.cs │ │ ├── ProxyPageScanner.cs │ │ ├── ProxyPageScannerExtensions.cs │ │ └── ProxyValidator.cs │ │ └── Server │ │ ├── ClientReceivedEventArgs.cs │ │ ├── HttpProxyServer.cs │ │ ├── IProxyServer.cs │ │ ├── IProxyServerFactory.cs │ │ ├── MSocksProxyServer.cs │ │ ├── MSocksServer │ │ ├── Socks4.cs │ │ └── Socks4ThreadInfo.cs │ │ ├── ProxyServerFactory.cs │ │ └── ProxyServerTransferEventArgs.cs ├── Properties │ ├── Annotations.cs │ ├── AssemblyInfo.cs │ ├── BlueDwarf.snk │ └── ProductInfo.cs ├── Reflection │ ├── CustomAttributeProviderExtensions.cs │ └── PropertyAccessor.cs ├── Serialization │ ├── ObjectReader.cs │ └── RegistrySerializer.cs ├── Utility │ ├── EnumerableExtensions.cs │ ├── EventHandlerExtensions.cs │ ├── ObjectExtensions.cs │ ├── ObjectTypeConverter.cs │ ├── StreamExtensions.cs │ ├── StringExtensions.cs │ └── TypeExtensions.cs ├── app.config └── packages.config ├── BlueDwarf.Test ├── BlueDwarf.Test.csproj ├── HostScannerTest.cs ├── Properties │ └── AssemblyInfo.cs ├── ProxyProviderTest.cs ├── ProxyServerTest.cs └── app.config ├── BlueDwarf.Tunnel ├── BlueDwarf Tunnel.nuspec ├── BlueDwarf.Tunnel.csproj ├── IO │ └── StreamExtensions.cs ├── Net │ ├── Connect.cs │ ├── HostEndPoint.cs │ ├── Http │ │ ├── HttpRequest.cs │ │ └── HttpResponse.cs │ └── Proxy │ │ ├── Client │ │ ├── IProxyClient.cs │ │ ├── ProxyRouteException.cs │ │ ├── Route.cs │ │ ├── RouteExtensions.cs │ │ ├── TunnelProxyClient.Http.cs │ │ ├── TunnelProxyClient.Socks.cs │ │ └── TunnelProxyClient.cs │ │ ├── ProxyProtocol.cs │ │ ├── ProxyProtocolUtility.cs │ │ ├── ProxyServer.Literal.cs │ │ └── ProxyServer.cs ├── Properties │ ├── Annotations.cs │ └── AssemblyInfo.cs ├── Utility │ ├── EndPointExtensions.cs │ ├── SocketExtensions.cs │ └── UriExtensions.cs └── packages.config ├── BlueDwarf.sln ├── BlueDwarf.sln.DotSettings ├── BlueDwarf ├── ApplicationOptions.cs ├── BlueDwarf.csproj ├── BlueDwarfApplication.xaml ├── BlueDwarfApplication.xaml.cs ├── Controls │ ├── BoolConverter.cs │ ├── CloseButton.cs │ ├── ExtendedWebBrowser.xaml │ ├── ExtendedWebBrowser.xaml.cs │ ├── Hider.cs │ ├── Loading.xaml │ ├── Loading.xaml.cs │ ├── LowerCaseConverter.cs │ ├── ModernUI.cs │ ├── ResultTextBlock.xaml │ ├── ResultTextBlock.xaml.cs │ ├── Status.xaml │ ├── Status.xaml.cs │ ├── StatusCode.cs │ ├── UnitConverter.cs │ ├── UrlBox.xaml │ ├── UrlBox.xaml.cs │ └── VisibilityConverter.cs ├── FodyWeavers.xml ├── Properties │ ├── AssemblyInfo.cs │ └── app.manifest ├── Resources │ ├── Locales.xaml │ ├── Localization │ │ ├── CommonLocale.Designer.cs │ │ ├── CommonLocale.resx │ │ ├── HomeLocale.Designer.cs │ │ ├── HomeLocale.resx │ │ ├── HomeWelcomeLocale.Designer.cs │ │ ├── HomeWelcomeLocale.resx │ │ ├── ProxyAnalysisLocale.Designer.cs │ │ ├── ProxyAnalysisLocale.resx │ │ ├── ProxyPickerLocale.Designer.cs │ │ └── ProxyPickerLocale.resx │ ├── Styles.xaml │ ├── key.ico │ ├── passe100.png │ └── passe300.png ├── UIConfiguration.cs ├── Utility │ ├── BindingExtensions.cs │ ├── CollectionExtensions.cs │ ├── ExclusiveUpdate.cs │ └── ServiceProviderExtensions.cs ├── View │ ├── GridViewSort.cs │ ├── HomeLocalProxyKeepaliveView.xaml │ ├── HomeLocalProxyKeepaliveView.xaml.cs │ ├── HomeProxyConfigurationView.xaml │ ├── HomeProxyConfigurationView.xaml.cs │ ├── HomeStatusView.xaml │ ├── HomeStatusView.xaml.cs │ ├── HomeTunnelConfigurationView.xaml │ ├── HomeTunnelConfigurationView.xaml.cs │ ├── HomeView.xaml │ ├── HomeView.xaml.cs │ ├── HomeWelcomeView.xaml │ ├── HomeWelcomeView.xaml.cs │ ├── ImageSource.cs │ ├── ProxyAnalysisView.xaml │ ├── ProxyAnalysisView.xaml.cs │ ├── ProxyPickerView.xaml │ ├── ProxyPickerView.xaml.cs │ ├── WebDownloaderView.xaml │ └── WebDownloaderView.xaml.cs ├── ViewModel │ ├── HomeViewModel.ProxyStatus.cs │ ├── HomeViewModel.cs │ ├── Properties │ │ ├── CategoryNotifyPropertyChanged.cs │ │ ├── CategoryPropertyChangedEventArgs.cs │ │ └── PropertyChangedEventArgsExtensions.cs │ ├── Proxy.cs │ ├── ProxyAnalysisViewModel.cs │ ├── ProxyPickerViewModel.cs │ ├── ViewModel.cs │ └── WebDownloaderViewModel.cs ├── app.config └── packages.config ├── Icon └── BlueDwarf.png ├── README.md ├── Tools └── 490fc8e027f9320a04d00960ce799809.pfx └── appveyor.yml /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # Build results 10 | [Dd]ebug/ 11 | [Dd]ebugPublic/ 12 | [Rr]elease/ 13 | [Rr]eleases/ 14 | x64/ 15 | x86/ 16 | build/ 17 | bld/ 18 | [Bb]in/ 19 | [Oo]bj/ 20 | 21 | # Roslyn cache directories 22 | *.ide/ 23 | 24 | # MSTest test Results 25 | [Tt]est[Rr]esult*/ 26 | [Bb]uild[Ll]og.* 27 | 28 | #NUNIT 29 | *.VisualState.xml 30 | TestResult.xml 31 | 32 | # Build Results of an ATL Project 33 | [Dd]ebugPS/ 34 | [Rr]eleasePS/ 35 | dlldata.c 36 | 37 | *_i.c 38 | *_p.c 39 | *_i.h 40 | *.ilk 41 | *.meta 42 | *.obj 43 | *.pch 44 | *.pdb 45 | *.pgc 46 | *.pgd 47 | *.rsp 48 | *.sbr 49 | *.tlb 50 | *.tli 51 | *.tlh 52 | *.tmp 53 | *.tmp_proj 54 | *.log 55 | *.vspscc 56 | *.vssscc 57 | .builds 58 | *.pidb 59 | *.svclog 60 | *.scc 61 | 62 | # Chutzpah Test files 63 | _Chutzpah* 64 | 65 | # Visual C++ cache files 66 | ipch/ 67 | *.aps 68 | *.ncb 69 | *.opensdf 70 | *.sdf 71 | *.cachefile 72 | 73 | # Visual Studio profiler 74 | *.psess 75 | *.vsp 76 | *.vspx 77 | 78 | # TFS 2012 Local Workspace 79 | $tf/ 80 | 81 | # Guidance Automation Toolkit 82 | *.gpState 83 | 84 | # ReSharper is a .NET coding add-in 85 | _ReSharper*/ 86 | *.[Rr]e[Ss]harper 87 | *.DotSettings.user 88 | 89 | # JustCode is a .NET coding addin-in 90 | .JustCode 91 | 92 | # TeamCity is a build add-in 93 | _TeamCity* 94 | 95 | # DotCover is a Code Coverage Tool 96 | *.dotCover 97 | 98 | # NCrunch 99 | _NCrunch_* 100 | .*crunch*.local.xml 101 | 102 | # MightyMoose 103 | *.mm.* 104 | AutoTest.Net/ 105 | 106 | # Web workbench (sass) 107 | .sass-cache/ 108 | 109 | # Installshield output folder 110 | [Ee]xpress/ 111 | 112 | # DocProject is a documentation generator add-in 113 | DocProject/buildhelp/ 114 | DocProject/Help/*.HxT 115 | DocProject/Help/*.HxC 116 | DocProject/Help/*.hhc 117 | DocProject/Help/*.hhk 118 | DocProject/Help/*.hhp 119 | DocProject/Help/Html2 120 | DocProject/Help/html 121 | 122 | # Click-Once directory 123 | publish/ 124 | 125 | # Publish Web Output 126 | *.[Pp]ublish.xml 127 | *.azurePubxml 128 | # TODO: Comment the next line if you want to checkin your web deploy settings 129 | # but database connection strings (with potential passwords) will be unencrypted 130 | *.pubxml 131 | *.publishproj 132 | 133 | # NuGet Packages 134 | *.nupkg 135 | # The packages folder can be ignored because of Package Restore 136 | **/packages/* 137 | # except build/, which is used as an MSBuild target. 138 | !**/packages/build/ 139 | # If using the old MSBuild-Integrated Package Restore, uncomment this: 140 | #!**/packages/repositories.config 141 | 142 | # Windows Azure Build Output 143 | csx/ 144 | *.build.csdef 145 | 146 | # Windows Store app package directory 147 | AppPackages/ 148 | 149 | # Others 150 | sql/ 151 | *.Cache 152 | ClientBin/ 153 | [Ss]tyle[Cc]op.* 154 | ~$* 155 | *~ 156 | *.dbmdl 157 | *.dbproj.schemaview 158 | *.pfx 159 | *.publishsettings 160 | node_modules/ 161 | 162 | # RIA/Silverlight projects 163 | Generated_Code/ 164 | 165 | # Backup & report files from converting an old project file 166 | # to a newer Visual Studio version. Backup files are not needed, 167 | # because we have git ;-) 168 | _UpgradeReport_Files/ 169 | Backup*/ 170 | UpgradeLog*.XML 171 | UpgradeLog*.htm 172 | 173 | # SQL Server files 174 | *.mdf 175 | *.ldf 176 | 177 | # Business Intelligence projects 178 | *.rdl.data 179 | *.bim.layout 180 | *.bim_*.settings 181 | 182 | # Microsoft Fakes 183 | FakesAssemblies/ 184 | -------------------------------------------------------------------------------- /.nuget/NuGet.Config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.nuget/NuGet.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/picrap/BlueDwarf/444f8306c79815e9b24a19d0cc850e5ed714501f/.nuget/NuGet.exe -------------------------------------------------------------------------------- /BlueDwarf.Core/Aspects/PropertyImporter.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.Aspects 5 | { 6 | using System; 7 | using System.Linq; 8 | using System.Reflection; 9 | using Configuration; 10 | 11 | public class PropertyImporter 12 | { 13 | private readonly PropertyInfo _propertyInfo; 14 | 15 | public PropertyImporter(Type instanceType) 16 | { 17 | var propertyInfo = instanceType.GetProperties().SingleOrDefault(p => typeof(TInterface).IsAssignableFrom(p.PropertyType)); 18 | if (propertyInfo == null) 19 | throw new NotImplementedException(string.Format("The type {0} must have a property of type {1}", instanceType.Name, typeof(IPersistence).Name)); 20 | _propertyInfo = propertyInfo; 21 | } 22 | 23 | public TInterface Get(object target) 24 | { 25 | return (TInterface)_propertyInfo.GetValue(target, new object[0]); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Configuration/IPersistence.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Configuration 4 | { 5 | /// 6 | /// Abstraction for persistent configuration 7 | /// 8 | public interface IPersistence 9 | { 10 | /// 11 | /// Gets a value, or default value. 12 | /// 13 | /// The name. 14 | /// The default value. 15 | /// 16 | object GetValue(string name, object defaultValue); 17 | 18 | /// 19 | /// Sets the value. 20 | /// 21 | /// The name. 22 | /// The value. 23 | /// if set to true persists the value immediately. 24 | void SetValue(string name, object value, bool writeNow); 25 | 26 | /// 27 | /// Writes all changes down to persistence. 28 | /// 29 | void Write(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Configuration/ISetupConfiguration.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Configuration 4 | { 5 | using System.Reflection; 6 | 7 | public interface ISetupConfiguration 8 | { 9 | /// 10 | /// Gets a value indicating whether this instance is installed using click once. 11 | /// 12 | /// 13 | /// true if this instance is click once; otherwise, false. 14 | /// 15 | bool IsClickOnce { get; } 16 | 17 | /// 18 | /// Registers the specified assembly to be launched at startup. 19 | /// 20 | /// The assembly. 21 | /// The command line. 22 | void RegisterStartup(Assembly assembly, string commandLine = null); 23 | 24 | /// 25 | /// Unregisters the specified assembly from being launched at startup. 26 | /// 27 | /// The assembly. 28 | void UnregisterStartup(Assembly assembly); 29 | 30 | /// 31 | /// Sets the uninstall icon (for click once deployment). 32 | /// 33 | /// The assembly. 34 | /// The path. 35 | void SetUninstallIcon(Assembly assembly, string path = null); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Configuration/PersistenceExtensions.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.Configuration 5 | { 6 | using System; 7 | using Serialization; 8 | 9 | public static class PersistenceExtensions 10 | { 11 | public static object GetValue(this IPersistence persistence, string name, Type type, object defaultValue) 12 | { 13 | return ObjectReader.SafeConvert(persistence.GetValue(name, defaultValue), type); 14 | } 15 | 16 | public static TValue GetValue(this IPersistence persistence, string name, TValue defaultValue) 17 | { 18 | return (TValue)persistence.GetValue(name, typeof(TValue), defaultValue); 19 | } 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Configuration/Persistent.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Configuration 4 | { 5 | using System; 6 | using ArxOne.MrAdvice.Advice; 7 | using ArxOne.MrAdvice.Annotation; 8 | using ArxOne.MrAdvice.MVVM.Properties; 9 | using Aspects; 10 | 11 | /// 12 | /// Persistent properties are saved directly as preferences 13 | /// 14 | [AttributeUsage(AttributeTargets.Property)] 15 | [Priority(AspectPriority.DataHolder)] 16 | public class Persistent : Attribute, IPropertyAdvice 17 | { 18 | /// 19 | /// Gets or sets the name under which the property is serialized. 20 | /// 21 | /// 22 | /// The name. 23 | /// 24 | public string Name { get; set; } 25 | 26 | /// 27 | /// Gets or sets a value indicating whether this property is automatically saved as soon as it changes. 28 | /// 29 | /// 30 | /// true if [automatic save]; otherwise, false. 31 | /// 32 | public bool AutoSave { get; set; } 33 | 34 | /// 35 | /// Gets or sets the default value. 36 | /// 37 | /// 38 | /// The default value. 39 | /// 40 | public object DefaultValue { get; set; } 41 | 42 | [NonSerialized] 43 | private PropertyImporter _persistenceProperty; 44 | 45 | public Persistent(string name) 46 | { 47 | Name = name; 48 | } 49 | 50 | public void Advise(PropertyAdviceContext context) 51 | { 52 | if (_persistenceProperty == null) 53 | _persistenceProperty = new PropertyImporter(context.TargetProperty.DeclaringType); 54 | var persistence = _persistenceProperty.Get(context.Target); 55 | if (context.IsGetter) 56 | context.ReturnValue = persistence.GetValue(Name, context.TargetProperty.PropertyType, DefaultValue); 57 | else 58 | persistence.SetValue(Name, context.Value, AutoSave); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Configuration/RegistryPersistence.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Configuration 4 | { 5 | using System.Collections.Generic; 6 | using Annotations; 7 | using Serialization; 8 | 9 | /// 10 | /// Implementation with registry of IPersistence 11 | /// 12 | [UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)] 13 | internal class RegistryPersistence : IPersistence 14 | { 15 | private const string Key = "BlueDwarf"; 16 | 17 | private readonly RegistrySerializer _serializer = new RegistrySerializer(); 18 | 19 | private readonly IDictionary _values = new Dictionary(); 20 | 21 | /// 22 | /// Gets a value, or default value. 23 | /// Searches in cache first, then loads from registry 24 | /// 25 | /// The name. 26 | /// The default value. 27 | /// 28 | public object GetValue(string name, object defaultValue) 29 | { 30 | lock (_values) 31 | { 32 | object value; 33 | if (!_values.TryGetValue(name, out value)) 34 | { 35 | if (!_serializer.TryDeserialize(Key, name, out value)) 36 | value = defaultValue; 37 | _values[name] = value; 38 | } 39 | return value; 40 | } 41 | } 42 | 43 | /// 44 | /// Sets the value. 45 | /// 46 | /// The name. 47 | /// The value. 48 | /// if set to true persists the value immediately. 49 | public void SetValue(string name, object value, bool writeNow) 50 | { 51 | _values[name] = value; 52 | if (writeNow) 53 | _serializer.Serialize(Key, name, value); 54 | } 55 | 56 | /// 57 | /// Writes all changes down to registry. 58 | /// 59 | public void Write() 60 | { 61 | foreach (var kv in _values) 62 | _serializer.Serialize(Key, kv.Key, kv.Value); 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /BlueDwarf.Core/CoreConfiguration.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf 4 | { 5 | using Configuration; 6 | using Microsoft.Practices.Unity; 7 | using Net; 8 | using Net.Geolocation; 9 | using Net.Geolocation.Telize; 10 | using Net.Name; 11 | using Net.Proxy; 12 | using Net.Proxy.Client; 13 | using Net.Proxy.Client.Diagnostic; 14 | using Net.Proxy.Scanner; 15 | using Net.Proxy.Server; 16 | 17 | public static class CoreConfiguration 18 | { 19 | /// 20 | /// Specifies instance as singleton (laziness follows). 21 | /// 22 | /// 23 | private static LifetimeManager AsSingleton() 24 | { 25 | return new ContainerControlledLifetimeManager(); 26 | } 27 | 28 | /// 29 | /// Configures the specified container for core. 30 | /// 31 | /// The container. 32 | public static void Configure(IUnityContainer container) 33 | { 34 | container.RegisterType(AsSingleton()); 35 | container.RegisterType(AsSingleton()); 36 | container.RegisterType(AsSingleton()); 37 | container.RegisterType(AsSingleton()); 38 | container.RegisterType(AsSingleton()); 39 | container.RegisterType(AsSingleton()); 40 | container.RegisterType(AsSingleton()); 41 | container.RegisterType(AsSingleton()); 42 | container.RegisterType(AsSingleton()); 43 | container.RegisterType(AsSingleton()); 44 | container.RegisterType(AsSingleton()); 45 | container.RegisterType(AsSingleton()); 46 | container.RegisterType(AsSingleton()); 47 | } 48 | } 49 | } -------------------------------------------------------------------------------- /BlueDwarf.Core/FodyWeavers.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Client/HttpGetAttribute.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.Net.Client 5 | { 6 | using System; 7 | 8 | [AttributeUsage(AttributeTargets.Method)] 9 | public class HttpGetAttribute : Attribute 10 | { 11 | public string UriTemplate { get; set; } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Client/Rest.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.Net.Client 5 | { 6 | using System; 7 | using ArxOne.MrAdvice.Advice; 8 | using Proxy.Client; 9 | 10 | public static class Rest 11 | { 12 | /// 13 | /// Gets a client bound for specific address. 14 | /// 15 | /// The type of the client. 16 | /// The route. 17 | /// The host address. 18 | /// 19 | public static TClient Client(Route route, Uri hostAddress = null) 20 | { 21 | var restAdvice = new RestAdvice(hostAddress, route); 22 | return restAdvice.Handle(); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Client/RestCall.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.Net.Client 5 | { 6 | using System.Reflection; 7 | using Reflection; 8 | using Utility; 9 | 10 | /// 11 | /// Represents a (very) simple REST call 12 | /// 13 | internal class RestCall 14 | { 15 | /// 16 | /// Gets the HTTP verb. 17 | /// 18 | /// 19 | /// The verb. 20 | /// 21 | public string Verb { get; private set; } 22 | /// 23 | /// Gets the URL path. 24 | /// 25 | /// 26 | /// The path. 27 | /// 28 | public string Path { get; private set; } 29 | 30 | /// 31 | /// Initializes a new instance of the class. 32 | /// 33 | /// The verb. 34 | /// The path. 35 | private RestCall(string verb, string path) 36 | { 37 | Verb = verb; 38 | Path = path; 39 | } 40 | 41 | /// 42 | /// Creates a REST call from a given method. 43 | /// If the method has no marker, a null is returned 44 | /// 45 | /// The method base. 46 | /// 47 | public static RestCall FromMethod(MethodBase methodBase) 48 | { 49 | var httpGet = methodBase.GetCustomAttribute(); 50 | if (httpGet != null) 51 | return new RestCall("GET", httpGet.UriTemplate); 52 | return null; 53 | } 54 | } 55 | } -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Downloader.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net 4 | { 5 | using System; 6 | using System.Diagnostics; 7 | using System.IO; 8 | using System.Linq; 9 | using System.Reflection; 10 | using Annotations; 11 | using Http; 12 | using Microsoft.Practices.Unity; 13 | using Name; 14 | using Proxy.Client; 15 | using Proxy.Server; 16 | using Utility; 17 | 18 | [UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)] 19 | public class Downloader : IDownloader 20 | { 21 | [Dependency] 22 | public IProxyServerFactory ProxyServerFactory { get; set; } 23 | 24 | /// 25 | /// Gets or sets the name resolver. 26 | /// 27 | /// 28 | /// The name resolver. 29 | /// 30 | [Dependency] 31 | public INameResolver NameResolver { get; set; } 32 | 33 | /// 34 | /// Downloads the page as text (extracts significant text from page) using the specified route. 35 | /// 36 | /// The URI. 37 | /// The route. 38 | /// 39 | public string DownloadText(Uri uri, Route route) 40 | { 41 | using (var proxyServer = ProxyServerFactory.CreateSocksProxyServer()) 42 | { 43 | proxyServer.Port = 0; // auto-select 44 | proxyServer.Routes = new[] { route }; 45 | var textFilePath = Path.GetTempFileName(); 46 | var path = Assembly.GetEntryAssembly().Location; 47 | var arguments = string.Format("--download={0} --save-text={1} --proxy=socks://localhost:{2}", uri, textFilePath, proxyServer.Port); 48 | var process = Process.Start(path, arguments); 49 | process.WaitForExit(); 50 | var text = File.ReadAllText(textFilePath); 51 | File.Delete(textFilePath); 52 | return text; 53 | } 54 | } 55 | 56 | /// 57 | /// Downloads the page as raw. 58 | /// 59 | /// The URI. 60 | /// The route. 61 | /// 62 | public string DownloadRaw(Uri uri, Route route) 63 | { 64 | for (; ; ) 65 | { 66 | using (var requestStream = route.Connect(uri, NameResolver)) 67 | { 68 | HttpRequest.CreateGet(uri).Write(requestStream); 69 | var response = HttpResponse.FromStream(requestStream); 70 | var rawContent = response.ReadContentString(requestStream); 71 | 72 | if (response.StatusCode == 301 || response.StatusCode == 302) 73 | { 74 | var literalNewLocation = response.Headers["Location"].Single(); 75 | var newLocation = new Uri(literalNewLocation); 76 | if (newLocation.IsAbsoluteUri) 77 | uri = newLocation; 78 | else 79 | uri = new Uri(uri, newLocation); 80 | continue; 81 | } 82 | 83 | return rawContent; 84 | } 85 | } 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/DownloaderExtensions.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net 4 | { 5 | using System; 6 | using Proxy.Client; 7 | 8 | public static class DownloaderExtensions 9 | { 10 | /// 11 | /// Downloads text from specified URI, either as text or raw (html). 12 | /// 13 | /// The downloader. 14 | /// The URI. 15 | /// if set to true [keep text only]. 16 | /// The route. 17 | /// 18 | public static string Download(this IDownloader downloader, Uri uri, bool keepTextOnly, Route route) 19 | { 20 | if (keepTextOnly) 21 | return downloader.DownloadText(uri, route); 22 | return downloader.DownloadRaw(uri, route); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Geolocation/AddressGeolocation.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.Net.Geolocation 5 | { 6 | using System.Net; 7 | 8 | /// 9 | /// Geolocation for given address 10 | /// 11 | public class AddressGeolocation 12 | { 13 | public IPAddress Address { get; private set; } 14 | public string CountryCode { get; private set; } 15 | public string CountryName { get; private set; } 16 | 17 | public AddressGeolocation(IPAddress address, string countryCode, string countryName) 18 | { 19 | Address = address; 20 | CountryCode = countryCode; 21 | CountryName = countryName; 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Geolocation/HostIP/HostIPAddressGeolocation.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.Net.Geolocation.HostIP 5 | { 6 | using System.Runtime.Serialization; 7 | 8 | [DataContract] 9 | public class HostIPAddressGeolocation 10 | { 11 | [DataMember(Name = "ip")] 12 | public string Address { get; set; } 13 | [DataMember(Name = "country_code")] 14 | public string CountryCode { get; set; } 15 | [DataMember(Name = "country_name")] 16 | public string CountryName { get; set; } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Geolocation/HostIP/HostIPGeolocation.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.Net.Geolocation.HostIP 5 | { 6 | using System; 7 | using System.Net; 8 | using Client; 9 | using Geolocation; 10 | using Proxy.Client; 11 | 12 | /// 13 | /// Geolocation implementation with HostIP 14 | /// 15 | public class HostIPGeolocation : IGeolocation 16 | { 17 | public AddressGeolocation Locate(IPAddress address, Route route) 18 | { 19 | var hostIPApi = Rest.Client(route); 20 | var result = hostIPApi.GetJson(address); 21 | return new AddressGeolocation(address, result.CountryCode, result.CountryName); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Geolocation/HostIP/IHostIPApi.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.Net.Geolocation.HostIP 5 | { 6 | using System.Net; 7 | using System.ServiceModel; 8 | using Client; 9 | 10 | [ServiceContract(Namespace = "http://api.hostip.info")] 11 | public interface IHostIPApi 12 | { 13 | [OperationContract] 14 | [HttpGet(UriTemplate = "/get_json.php?ip={ip}")] 15 | HostIPAddressGeolocation GetJson(IPAddress ip); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Geolocation/IGeolocation.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.Net.Geolocation 5 | { 6 | using System.Net; 7 | using Proxy.Client; 8 | 9 | public interface IGeolocation 10 | { 11 | AddressGeolocation Locate(IPAddress address, Route route); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Geolocation/Telize/ITelizeApi.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.Net.Geolocation.Telize 5 | { 6 | using System.Net; 7 | using System.ServiceModel; 8 | using Client; 9 | 10 | [ServiceContract(Namespace = "http://www.telize.com/")] 11 | public interface ITelizeApi 12 | { 13 | [OperationContract] 14 | [HttpGet(UriTemplate = "/geoip/{ip}")] 15 | TelizeAddressGeolocation GeoIP(IPAddress ip); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Geolocation/Telize/TelizeAddressGeolocation.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.Net.Geolocation.Telize 5 | { 6 | using System.Net; 7 | using System.Runtime.Serialization; 8 | 9 | [DataContract] 10 | public class TelizeAddressGeolocation 11 | { 12 | [DataMember(Name = "ip")] 13 | public string IP { get; set; } 14 | 15 | [DataMember(Name = "country_code")] 16 | public string CountryCode { get; set; } 17 | 18 | [DataMember(Name = "country_code3")] 19 | public string CountryCode3 { get; set; } 20 | 21 | [DataMember(Name = "country")] 22 | public string Country { get; set; } 23 | 24 | [DataMember(Name = "region_code")] 25 | public string RegionCode { get; set; } 26 | 27 | [DataMember(Name = "region")] 28 | public string Region { get; set; } 29 | 30 | [DataMember(Name = "city")] 31 | public string City { get; set; } 32 | 33 | [DataMember(Name = "postal_code")] 34 | public string PostalCode { get; set; } 35 | 36 | [DataMember(Name = "continent_code")] 37 | public string ContinentCode { get; set; } 38 | 39 | [DataMember(Name = "latitude")] 40 | public double? Latitude { get; set; } 41 | 42 | [DataMember(Name = "longitude")] 43 | public double? Longitude { get; set; } 44 | 45 | [DataMember(Name = "dma_code")] 46 | public string DmaCode { get; set; } 47 | 48 | [DataMember(Name = "area_code")] 49 | public string AreaCode { get; set; } 50 | 51 | [DataMember(Name = "asn")] 52 | public string Asn { get; set; } 53 | 54 | [DataMember(Name = "isp")] 55 | public string Isp { get; set; } 56 | 57 | [DataMember(Name = "timezone")] 58 | public string TimeZone { get; set; } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Geolocation/Telize/TelizeGeolocation.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.Net.Geolocation.Telize 5 | { 6 | using System; 7 | using System.Net; 8 | using Annotations; 9 | using Client; 10 | using Proxy.Client; 11 | 12 | /// 13 | /// Geolocation using Telize 14 | /// 15 | [UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)] 16 | internal class TelizeGeolocation : IGeolocation 17 | { 18 | public AddressGeolocation Locate(IPAddress address, Route route) 19 | { 20 | var telizeApi = Rest.Client(route); 21 | var result = telizeApi.GeoIP(address); 22 | return new AddressGeolocation(address, result.CountryCode, result.Country); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/IDownloader.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net 4 | { 5 | using System; 6 | using Proxy.Client; 7 | 8 | /// 9 | /// Interface to file download 10 | /// 11 | public interface IDownloader 12 | { 13 | /// 14 | /// Downloads the page as text (removes all tags). 15 | /// 16 | /// The URI. 17 | /// The route. 18 | /// 19 | string DownloadText(Uri uri, Route route); 20 | 21 | /// 22 | /// Downloads the page as raw. 23 | /// 24 | /// The URI. 25 | /// The route. 26 | /// 27 | string DownloadRaw(Uri uri, Route route); 28 | } 29 | } -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Name/DnsNameResolver.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Name 4 | { 5 | using System; 6 | using System.Linq; 7 | using System.Net; 8 | using System.Net.Sockets; 9 | using Annotations; 10 | using Proxy.Client; 11 | 12 | [UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)] 13 | internal class DnsNameResolver : INameResolver 14 | { 15 | /// 16 | /// Simple DNS resolution using framework. 17 | /// 18 | /// The name. 19 | /// The route. 20 | /// 21 | public IPAddress Resolve(string name, Route route) 22 | { 23 | return LocalResolve(name); 24 | } 25 | 26 | /// 27 | /// Resolves the specified name. 28 | /// 29 | /// The name. 30 | /// 31 | public static IPAddress LocalResolve(string name) 32 | { 33 | try 34 | { 35 | var address = Dns.GetHostAddresses(name).FirstOrDefault(); 36 | return address; 37 | } 38 | catch (ArgumentException) 39 | { 40 | } 41 | catch (SocketException) 42 | { 43 | } 44 | return null; 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Name/INameResolver.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Name 4 | { 5 | using System.Net; 6 | using Proxy.Client; 7 | 8 | /// 9 | /// Name resolution interface 10 | /// (yes, in other words, a simple DNS client) 11 | /// 12 | public interface INameResolver 13 | { 14 | /// 15 | /// Resolves the specified name using the given route. 16 | /// 17 | /// The name. 18 | /// The route. 19 | /// 20 | IPAddress Resolve(string name, Route route); 21 | } 22 | } -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Name/MultiNameResolver.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.Net.Name 5 | { 6 | using System.Linq; 7 | using System.Net; 8 | using Microsoft.Practices.Unity; 9 | using Proxy.Client; 10 | using StatDns; 11 | 12 | internal class MultiNameResolver : INameResolver 13 | { 14 | [Dependency] 15 | public DnsNameResolver DnsNameResolver { get; set; } 16 | 17 | [Dependency] 18 | public StatDnsNameResolver StatDnsNameResolver { get; set; } 19 | 20 | /// 21 | /// Resolves the specified name using the given route. 22 | /// 23 | /// The name. 24 | /// The route. 25 | /// 26 | public IPAddress Resolve(string name, Route route) 27 | { 28 | return Resolve(name, route, StatDnsNameResolver, DnsNameResolver); 29 | } 30 | 31 | /// 32 | /// Resolves the specified name. 33 | /// 34 | /// The name. 35 | /// The route. 36 | /// The resolvers. 37 | /// 38 | private static IPAddress Resolve(string name, Route route, params INameResolver[] resolvers) 39 | { 40 | return resolvers.Select(r => r.Resolve(name, route)).FirstOrDefault(a => a != null); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Name/StatDns/Answer.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Name.StatDns 4 | { 5 | using System.Diagnostics; 6 | using System.Runtime.Serialization; 7 | 8 | [DataContract] 9 | [DebuggerDisplay("{Name} {TTL} {Class} {Type} {RData}")] 10 | public class Answer 11 | { 12 | [DataMember(Name = "name")] 13 | public string Name { get; set; } 14 | [DataMember(Name = "type")] 15 | public string Type { get; set; } 16 | [DataMember(Name = "class")] 17 | public string Class { get; set; } 18 | [DataMember(Name = "ttl")] 19 | public int TTL { get; set; } 20 | [DataMember(Name = "rdlength")] 21 | public int RDLength { get; set; } 22 | [DataMember(Name = "rdata")] 23 | public string RData { get; set; } 24 | } 25 | } -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Name/StatDns/IStatDns.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Name.StatDns 4 | { 5 | using System.ServiceModel; 6 | using Client; 7 | 8 | [ServiceContract(Namespace = "http://api.statdns.com")] 9 | public interface IStatDns 10 | { 11 | [OperationContract] 12 | [HttpGet(UriTemplate = "/{name}/{type}")] 13 | Response Ask(string name, string type); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Name/StatDns/Question.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Name.StatDns 4 | { 5 | using System.Runtime.Serialization; 6 | 7 | [DataContract] 8 | public class Question 9 | { 10 | [DataMember(Name = "name")] 11 | public string Name { get; set; } 12 | [DataMember(Name = "type")] 13 | public string Type { get; set; } 14 | [DataMember(Name = "class")] 15 | public string Class { get; set; } 16 | } 17 | } -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Name/StatDns/Response.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Name.StatDns 4 | { 5 | using System.Runtime.Serialization; 6 | 7 | [DataContract] 8 | public class Response 9 | { 10 | [DataMember(Name = "question")] 11 | public Question[] Questions { get; set; } 12 | [DataMember(Name = "answer")] 13 | public Answer[] Answers { get; set; } 14 | [DataMember(Name = "authority")] 15 | public Answer[] Authorities { get; set; } 16 | } 17 | } -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Name/StatDns/StatDnsNameResolver.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Name.StatDns 4 | { 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Net; 8 | using Annotations; 9 | using Client; 10 | using Proxy.Client; 11 | 12 | /// 13 | /// DNS resolution using the excellent statdns.com resolution 14 | /// 15 | [UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)] 16 | internal class StatDnsNameResolver : INameResolver 17 | { 18 | private readonly IDictionary> _entries = new Dictionary>(); 19 | 20 | /// 21 | /// Resolves the specified name using the given route. 22 | /// 23 | /// The name. 24 | /// The route. 25 | /// 26 | public IPAddress Resolve(string name, Route route) 27 | { 28 | IPAddress address; 29 | if (IPAddress.TryParse(name, out address)) 30 | return address; 31 | 32 | var now = DateTime.UtcNow; 33 | lock (_entries) 34 | { 35 | Tuple entry; 36 | if (_entries.TryGetValue(name, out entry)) 37 | { 38 | if (entry.Item2 > now) 39 | return entry.Item1; 40 | } 41 | 42 | var resolvedAddress = RequestionResolution(name, route); 43 | if (resolvedAddress == null) 44 | return null; 45 | entry = Tuple.Create(resolvedAddress.Item1, now + TimeSpan.FromSeconds(resolvedAddress.Item2)); 46 | _entries[name] = entry; 47 | return entry.Item1; 48 | } 49 | } 50 | 51 | /// 52 | /// Requestions the resolution. 53 | /// This can be done by following multiple resolutions (since CNAME may lead to other CNAME or A) 54 | /// 55 | /// The name. 56 | /// The route. 57 | /// 58 | private static Tuple RequestionResolution(string name, Route route) 59 | { 60 | for (int hop = 0; hop < 100; hop++) 61 | { 62 | var answer = Ask(name, "A", route) ?? Ask(name, "CNAME", route); 63 | if (answer == null) 64 | return null; 65 | 66 | IPAddress address; 67 | if (IPAddress.TryParse(answer.RData, out address)) 68 | return Tuple.Create(address, answer.TTL); 69 | 70 | name = answer.RData; 71 | } 72 | return null; 73 | } 74 | 75 | /// 76 | /// Query to . 77 | /// 78 | /// The name. 79 | /// The type. 80 | /// The route. 81 | /// 82 | private static Answer Ask(string name, string type, Route route) 83 | { 84 | try 85 | { 86 | var client = Rest.Client(route); 87 | var response = client.Ask(name, type); 88 | if (response.Answers == null) 89 | return null; 90 | return response.Answers[0]; 91 | } 92 | // TODO: something better here 93 | catch { } 94 | return null; 95 | } 96 | } 97 | } -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Proxy/Client/Authentication/BlueCoatHttpAuthentication.cs: -------------------------------------------------------------------------------- 1 |  2 | using System; 3 | using System.IO; 4 | using System.Net; 5 | using System.Text.RegularExpressions; 6 | using BlueDwarf.Net.Http; 7 | 8 | namespace BlueDwarf.Net.Proxy.Client.Authentication 9 | { 10 | public class BlueCoatHttpAuthentication 11 | { 12 | private readonly Regex _redirectEx = new Regex(@"\[a-zA-Z0-9\:\/\.]+)"); 13 | 14 | public bool Handle(Stream proxyStream, HttpResponse httpResponse, string responseContent, NetworkCredential networkCredential, ProxyRoute routeUntilHere) 15 | { 16 | var match = _redirectEx.Match(responseContent); 17 | if (!match.Success) 18 | return false; 19 | 20 | var url = match.Groups["url"].Value; 21 | var uri = new Uri(url); 22 | 23 | using (var redirectStream = routeUntilHere.GetPrevious().Connect(uri.Host, uri.Port, true)) 24 | { 25 | new HttpRequest("GET", uri.PathAndQuery).Write(redirectStream); 26 | var redirectResponse = new HttpResponse().Read(redirectStream); 27 | var redirectResponseContent = redirectResponse.ReadContentString(redirectStream); 28 | } 29 | 30 | return true; 31 | } 32 | } 33 | } 34 | /* 35 | 36 | 37 | Redirector 38 | 39 | Your request will now be redirected to your requested site. 40 | 46 | 47 | */ -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Proxy/Client/Diagnostic/IProxyAnalyzer.cs: -------------------------------------------------------------------------------- 1 | namespace BlueDwarf.Net.Proxy.Client.Diagnostic 2 | { 3 | using System; 4 | 5 | public interface IProxyAnalyzer 6 | { 7 | /// 8 | /// Measures the performance. 9 | /// 10 | /// The route. 11 | /// The test target. 12 | /// The tests. 13 | /// 14 | ProxyPerformance MeasurePerformance(Route route, Uri testTarget, int tests = 3); 15 | } 16 | } -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Proxy/Client/Diagnostic/ISystemProxyAnalyzer.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Proxy.Client.Diagnostic 4 | { 5 | /// 6 | /// System proxy analyzer interface 7 | /// 8 | public interface ISystemProxyAnalyzer 9 | { 10 | /// 11 | /// Diagnoses the system proxy. 12 | /// 13 | /// The parameters. 14 | /// 15 | ProxyDiagnostic Diagnose(SystemAnalysisParameters parameters = null); 16 | } 17 | } -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Proxy/Client/Diagnostic/ProxyAnalyzer.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.Net.Proxy.Client.Diagnostic 5 | { 6 | using System; 7 | using System.Diagnostics; 8 | using System.IO; 9 | using System.Net.Sockets; 10 | using Http; 11 | using Microsoft.Practices.Unity; 12 | using Name; 13 | 14 | /// 15 | /// Proxy analyzer implementation 16 | /// 17 | internal class ProxyAnalyzer : IProxyAnalyzer 18 | { 19 | /// 20 | /// Gets or sets the name resolver. 21 | /// 22 | /// 23 | /// The name resolver. 24 | /// 25 | [Dependency] 26 | public INameResolver NameResolver { get; set; } 27 | 28 | /// 29 | /// Measures the performance. 30 | /// 31 | /// The route. 32 | /// The test target. 33 | /// The tests. 34 | /// A performance value or null if performance could not be measured 35 | public ProxyPerformance MeasurePerformance(Route route, Uri testTarget, int tests = 3) 36 | { 37 | try 38 | { 39 | var ping = TimeSpan.Zero; 40 | var downloadTime = TimeSpan.Zero; 41 | var downloadSize = 0; 42 | var timer = new Stopwatch(); 43 | timer.Start(); 44 | for (int test = 0; test < tests; test++) 45 | { 46 | var t0 = timer.Elapsed; 47 | using (var stream = route.Connect(testTarget, NameResolver)) 48 | { 49 | var t1 = timer.Elapsed; 50 | ping += t1 - t0; 51 | HttpRequest.CreateGet(testTarget).Write(stream); 52 | var t2 = timer.Elapsed; 53 | var httpResponse = HttpResponse.FromStream(stream); 54 | downloadSize += httpResponse.ReadContent(stream).Length; 55 | var t3 = timer.Elapsed; 56 | downloadTime += t3 - t2; 57 | } 58 | } 59 | return new ProxyPerformance(TimeSpan.FromTicks(ping.Ticks / tests), downloadSize / downloadTime.TotalSeconds); 60 | } 61 | catch (ProxyRouteException) 62 | { } 63 | catch (IOException) 64 | { } 65 | catch (SocketException) 66 | { } 67 | return null; 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Proxy/Client/Diagnostic/ProxyDiagnostic.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Proxy.Client.Diagnostic 4 | { 5 | using System; 6 | 7 | public class ProxyDiagnostic 8 | { 9 | /// 10 | /// If the system uses a proxy, it is set here 11 | /// 12 | /// 13 | /// The default proxy. 14 | /// 15 | public Uri DefaultProxy { get; set; } 16 | /// 17 | /// The route diagnostic to a safe (==commonly allowed) site by HTTP 18 | /// 19 | /// 20 | /// The safe HTTP get route. 21 | /// 22 | public RouteStatus SafeHttpGetRoute { get; set; } 23 | /// 24 | /// The route diagnostic to a safe (==commonly allowed) site by HTTPS 25 | /// 26 | /// 27 | /// The safe HTTPS connect route. 28 | /// 29 | public RouteStatus SafeHttpsConnectRoute { get; set; } 30 | /// 31 | /// The route diagnostic to a safe (==commonly allowed) site by HTTP, but with a HTTP CONNECT verb 32 | /// 33 | /// 34 | /// The safe HTTP connect route. 35 | /// 36 | public RouteStatus SafeHttpConnectRoute { get; set; } 37 | /// 38 | /// The route diagnostic to an unsafe (==commonly denied) site by HTTP 39 | /// 40 | /// 41 | /// The safe HTTP get route. 42 | /// 43 | public RouteStatus SensitiveHttpGetRoute { get; set; } 44 | /// 45 | /// The route diagnostic to an unsafe (==commonly denied) site by HTTPS 46 | /// 47 | /// 48 | /// The sensitive HTTPS connect route. 49 | /// 50 | public RouteStatus SensitiveHttpsConnectRoute { get; set; } 51 | /// 52 | /// The route diagnostic to an unsafe (==commonly denied) site by HTTP, but with a HTTP CONNECT verb 53 | /// 54 | /// 55 | /// The sensitive HTTP connect route. 56 | /// 57 | public RouteStatus SensitiveHttpConnectRoute { get; set; } 58 | /// 59 | /// Tells if the local DNS resolver works directly 60 | /// 61 | /// 62 | /// true if [safe local DNS]; otherwise, false. 63 | /// 64 | public bool SafeLocalDns { get; set; } 65 | /// 66 | /// Tells if the local DNS resolver works for sensitive (==commonly denied) sites 67 | /// 68 | /// 69 | /// true if [sensitive local DNS]; otherwise, false. 70 | /// 71 | public bool SensitiveLocalDns { get; set; } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Proxy/Client/Diagnostic/ProxyPerformance.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Proxy.Client.Diagnostic 4 | { 5 | using System; 6 | 7 | public class ProxyPerformance 8 | { 9 | /// 10 | /// Gets the ping. 11 | /// 12 | /// 13 | /// The ping. 14 | /// 15 | public TimeSpan Ping { get; private set; } 16 | 17 | /// 18 | /// Gets the download speed (in bytes/s). 19 | /// 20 | /// 21 | /// The download speed. 22 | /// 23 | public double DownloadSpeed { get; private set; } 24 | 25 | /// 26 | /// Initializes a new instance of the class. 27 | /// 28 | /// The ping. 29 | /// The download speed. 30 | public ProxyPerformance(TimeSpan ping, double downloadSpeed) 31 | { 32 | Ping = ping; 33 | DownloadSpeed = downloadSpeed; 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Proxy/Client/Diagnostic/RouteStatus.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Proxy.Client.Diagnostic 4 | { 5 | using System; 6 | 7 | [Flags] 8 | public enum RouteStatus 9 | { 10 | /// 11 | /// A proxy is required for this route (if this flag is missing, then we don't need any proxy) 12 | /// 13 | HasProxy = 0x0001, 14 | /// 15 | /// The proxy accepts to connect using DNS 16 | /// 17 | ProxyAcceptsName = 0x0002, 18 | /// 19 | /// The proxy accepts to connect using IP 20 | /// If this flag is set and not ProxyAcceptsName, then we are behind a proxy filtering by DNS 21 | /// 22 | ProxyAcceptsAddress = 0x0004, 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Proxy/Client/Diagnostic/SystemAnalysisParameters.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Proxy.Client.Diagnostic 4 | { 5 | using System; 6 | 7 | public class SystemAnalysisParameters 8 | { 9 | public Uri SafeHttpTarget { get; set; } 10 | public Uri SafeHttpsTarget { get; set; } 11 | public Uri SensitiveHttpTarget { get; set; } 12 | public Uri SensitiveHttpsTarget { get; set; } 13 | 14 | public SystemAnalysisParameters() 15 | { 16 | SafeHttpTarget = new Uri("http://google.fr"); 17 | SafeHttpsTarget = new Uri("https://google.fr"); 18 | SensitiveHttpTarget = new Uri("http://isohunt.to/"); 19 | SensitiveHttpsTarget = new Uri("https://isohunt.to/"); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Proxy/Client/RouteExtensions.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.Net.Proxy.Client 5 | { 6 | using System; 7 | using System.IO; 8 | using System.Net.Sockets; 9 | using Name; 10 | using Utility; 11 | 12 | /// 13 | /// Extensions to 14 | /// 15 | public static class RouteExtensions 16 | { 17 | /// 18 | /// Connects to specified target host/port. 19 | /// 20 | /// The route. 21 | /// The target host. 22 | /// The target port. 23 | /// The name resolver. 24 | /// 25 | public static Socket Connect(this Route route, string targetHost, int targetPort, INameResolver nameResolver) 26 | { 27 | var targetAddress = nameResolver.Resolve(targetHost, route); 28 | if (targetAddress == null) 29 | throw new ProxyRouteException(targetHost); 30 | return route.Connect(targetAddress, targetPort); 31 | } 32 | 33 | /// 34 | /// Connects the specified route. 35 | /// 36 | /// The route. 37 | /// The URI. 38 | /// The name resolver. 39 | /// 40 | public static Stream Connect(this Route route, Uri uri, INameResolver nameResolver) 41 | { 42 | Stream stream = Connect(route, uri.Host, uri.Port, nameResolver).ToNetworkStream(); 43 | try 44 | { 45 | if (stream != null && string.Equals(uri.Scheme, Uri.UriSchemeHttps, StringComparison.InvariantCultureIgnoreCase)) 46 | stream = stream.AsSsl(uri.Host); 47 | } 48 | catch (IOException) 49 | { 50 | throw new ProxyRouteException(uri.Host); 51 | } 52 | return stream; 53 | } 54 | 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Proxy/IProxyConfiguration.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Proxy 4 | { 5 | using System; 6 | 7 | public interface IProxyConfiguration 8 | { 9 | /// 10 | /// Sets the application-wide proxy. 11 | /// 12 | /// The proxy. 13 | void SetApplicationProxy(Uri proxy); 14 | } 15 | } -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Proxy/ProxyConfiguration.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Proxy 4 | { 5 | using System; 6 | using System.Runtime.InteropServices; 7 | using Annotations; 8 | 9 | [UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)] 10 | internal class ProxyConfiguration : IDisposable, IProxyConfiguration 11 | { 12 | const int INTERNET_OPEN_TYPE_PRECONFIG = 0; // use registry configuration 13 | const int INTERNET_OPEN_TYPE_DIRECT = 1; // direct to net 14 | const int INTERNET_OPEN_TYPE_PROXY = 3; // via named proxy 15 | const int INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY = 4; // prevent using java/script/INS 16 | 17 | public struct INTERNET_PROXY_INFO 18 | { 19 | public int dwAccessType; 20 | public IntPtr proxy; 21 | public IntPtr proxyBypass; 22 | }; 23 | 24 | [DllImport("wininet", SetLastError = true)] 25 | private static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength); 26 | 27 | [DllImport("wininet", SetLastError = true)] 28 | private static extern IntPtr InternetOpen(string lpszAgent, int dwAccessType, string lpszProxyName, string lpszProxyBypass, int dwFlags); 29 | 30 | [DllImport("wininet")] 31 | private static extern long InternetCloseHandle(IntPtr hInet); 32 | 33 | [DllImport("urlmon")] 34 | private static extern int UrlMkSetSessionOption(int dwOption, IntPtr pBuffer, int dwBufferLength, int dwReserved); 35 | 36 | private IntPtr _internet; 37 | private IntPtr Internet 38 | { 39 | get 40 | { 41 | if (_internet == IntPtr.Zero) 42 | _internet = InternetOpen("BlueDwarf", INTERNET_OPEN_TYPE_PRECONFIG, null, null, 0); 43 | return _internet; 44 | } 45 | } 46 | 47 | public void Dispose() 48 | { 49 | if (_internet != IntPtr.Zero) 50 | { 51 | InternetCloseHandle(_internet); 52 | _internet = IntPtr.Zero; 53 | } 54 | } 55 | 56 | private static void SetProxy(string strProxy, IntPtr hInternet) 57 | { 58 | const int INTERNET_OPTION_PROXY = 38; 59 | const int INTERNET_OPEN_TYPE_PROXY = 3; 60 | 61 | INTERNET_PROXY_INFO ipi; 62 | 63 | // Filling in structure 64 | ipi.dwAccessType = INTERNET_OPEN_TYPE_PROXY; 65 | ipi.proxy = Marshal.StringToHGlobalAnsi(strProxy); 66 | ipi.proxyBypass = Marshal.StringToHGlobalAnsi("local"); 67 | 68 | // Allocating memory 69 | var intptrStruct = Marshal.AllocCoTaskMem(Marshal.SizeOf(ipi)); 70 | 71 | // Converting structure to IntPtr 72 | Marshal.StructureToPtr(ipi, intptrStruct, true); 73 | 74 | bool iReturn = InternetSetOption(hInternet, INTERNET_OPTION_PROXY, intptrStruct, Marshal.SizeOf(ipi)); 75 | //var v = UrlMkSetSessionOption(INTERNET_OPTION_PROXY, intptrStruct, Marshal.SizeOf(ipi), 0); 76 | var e = Marshal.GetLastWin32Error(); 77 | } 78 | 79 | /// 80 | /// Sets the application-wide proxy. 81 | /// 82 | /// The proxy. 83 | public void SetApplicationProxy(Uri proxy) 84 | { 85 | SetProxy(string.Format("{0}={1}:{2}", proxy.Scheme, proxy.Host, proxy.Port), IntPtr.Zero); 86 | } 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Proxy/Scanner/HostPort.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.Net.Proxy.Scanner 5 | { 6 | public static class HostPort 7 | { 8 | // A literal decimal byte, from 0 to 255 9 | private const string ByteRangeEx = @"(\d{1,2}|([0-1]\d{2})|(2[0-4]\d)|(25[0-5]))"; 10 | // so an IP v4 is 4 literal bytes, separated by a dot 11 | public const string IPv4Ex = @"(?
(" + ByteRangeEx + @"\." + ByteRangeEx + @"\." + ByteRangeEx + @"\." + ByteRangeEx + @"))"; 12 | // A port from 0 to 65535 13 | public const string PortEx = @"(?(([0-5]\d{4})|(6[0-4]\d{3})|(65[0-4]\d{2})|(655[0-2]\d)|(6553[0-5])|\d{1,4}))"; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Proxy/Scanner/HostScanner.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Proxy.Scanner 4 | { 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Net; 8 | using System.Text.RegularExpressions; 9 | using Annotations; 10 | using Utility; 11 | 12 | [UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)] 13 | internal class HostScanner : IHostScanner 14 | { 15 | internal const string AfterDigitEx = @"(\D|$)"; 16 | 17 | // A host here is an IP separated with a colon and optional spaces 18 | internal const string IPColonPortEx = @"(" + HostPort.IPv4Ex + @"\s*\:\s*" + HostPort.PortEx + AfterDigitEx + ")"; 19 | // In some cases, the port my follow the IP without colon 20 | internal const string IPSpacePortEx = @"(" + HostPort.IPv4Ex + @"\s+" + HostPort.PortEx + AfterDigitEx + ")"; 21 | 22 | private const string AnyEx = IPColonPortEx + "|" + IPSpacePortEx; 23 | 24 | /// 25 | /// Scans the specified page text. 26 | /// 27 | /// The page text. 28 | /// The host port regular expression, or null to use internal capture. 29 | /// 30 | public IEnumerable Scan(string pageText, string hostPortEx = null) 31 | { 32 | return CreateHostEndPoints(pageText, hostPortEx ?? AnyEx); 33 | } 34 | 35 | /// 36 | /// Creates the HostPort instances, given a full text and an regex. 37 | /// 38 | /// The page text. 39 | /// The host port ex. 40 | /// 41 | internal static IEnumerable CreateHostEndPoints(string pageText, string hostPortEx) 42 | { 43 | var hostPortRegex = new Regex(hostPortEx, RegexOptions.Singleline); 44 | return hostPortRegex.Matches(pageText).Cast().SelectNonNull(CreateProxyServer); 45 | } 46 | 47 | /// 48 | /// Creates a signel HostPort, or null if the match does not give all information. 49 | /// 50 | /// The match. 51 | /// 52 | private static ProxyServer CreateProxyServer(Match match) 53 | { 54 | var literalProtocol = match.Groups["protocol"].Value; 55 | if (literalProtocol.IsNullOrEmpty()) 56 | literalProtocol = "http"; 57 | var proxyProtocol = ProxyProtocolUtility.FromLiteral(literalProtocol); 58 | 59 | var literalPort = match.Groups["port"].Value; 60 | int port; 61 | // if port is not provided or invalid, no HostPort is created 62 | if (!int.TryParse(literalPort, out port)) 63 | return null; 64 | var host = match.Groups["host"].Value; 65 | if (!string.IsNullOrEmpty(host)) 66 | return new ProxyServer(proxyProtocol, host, port); 67 | 68 | var literalAddress = match.Groups["address"].Value; 69 | IPAddress address; 70 | if (IPAddress.TryParse(literalAddress, out address)) 71 | return new ProxyServer(proxyProtocol, address, port); 72 | 73 | // no host or address was captured 74 | return null; 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Proxy/Scanner/IHostScanner.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Proxy.Scanner 4 | { 5 | using System.Collections.Generic; 6 | 7 | /// 8 | /// Scans a given text for host+port, given a regex 9 | /// 10 | public interface IHostScanner 11 | { 12 | /// 13 | /// Scans the specified page text. 14 | /// 15 | /// The page text. 16 | /// The host port regular expression, or null to use internal capture. 17 | /// 18 | IEnumerable Scan(string pageText, string hostPortEx = null); 19 | } 20 | } -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Proxy/Scanner/IProxyPageScanner.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Proxy.Scanner 4 | { 5 | using System; 6 | using System.Collections.Generic; 7 | using Client; 8 | 9 | /// 10 | /// Scans pages for proxy servers and validates them 11 | /// 12 | public interface IProxyPageScanner 13 | { 14 | /// 15 | /// Scans a given page for proxy servers. 16 | /// 17 | /// The proxy listing page. 18 | /// If the page must be parsed as raw text (no HTML tags) 19 | /// The custom parsing expression (providing "address" or "host" and "port" tags) or null to use default 20 | /// 21 | /// 22 | /// 23 | IEnumerable ScanPage(Uri proxyListingPage, bool parseAsRawText, string hostPortEx, Route route, Uri testTarget); 24 | 25 | /// 26 | /// Scans a given page for proxy servers. 27 | /// 28 | /// 29 | /// The proxy listing page. 30 | /// if set to true [parse as raw text]. 31 | /// The host port ex. 32 | /// 33 | /// 34 | void ScanPage(IList proxyServers, Uri proxyListingPage, bool parseAsRawText, string hostPortEx, Route route, Uri testTarget); 35 | } 36 | } -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Proxy/Scanner/IProxyValidator.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Proxy.Scanner 4 | { 5 | using System; 6 | using Client; 7 | 8 | /// 9 | /// Proxy validation 10 | /// 11 | public interface IProxyValidator 12 | { 13 | /// 14 | /// Validates the specified proxy host port as a HTTP CONNECT proxy. 15 | /// Given a route to get to the proxy and a test target to be reached after proxy 16 | /// 17 | /// 18 | /// 19 | /// 20 | /// The try count to fully validate the route 21 | /// 22 | bool Validate(ProxyServer proxyServer, Uri testTarget, Route routeToProxy, int tryCount = 3); 23 | 24 | /// 25 | /// Validates the specified route, using the test target. 26 | /// 27 | /// The route. 28 | /// The test target. 29 | /// The try count to fully validate the route 30 | /// 31 | void Validate(Route route, Uri testTarget, int tryCount = 3); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Proxy/Scanner/ProxyPageScannerExtensions.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Proxy.Scanner 4 | { 5 | using System; 6 | using System.Collections.Generic; 7 | using Client; 8 | 9 | public static class ProxyPageScannerExtensions 10 | { 11 | /// 12 | /// Scans a given page for proxy servers. 13 | /// 14 | /// The proxy page scanner. 15 | /// The proxy page provider. 16 | /// The route. 17 | /// 18 | /// 19 | public static IEnumerable ScanPage(this IProxyPageScanner proxyPageScanner, ProxyPage proxyPage, Route route, Uri testTarget) 20 | { 21 | return proxyPageScanner.ScanPage(proxyPage.PageUri, proxyPage.ParseAsText, proxyPage.HostPortEx, route, testTarget); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Proxy/Scanner/ProxyValidator.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Proxy.Scanner 4 | { 5 | using System; 6 | using System.IO; 7 | using Annotations; 8 | using Client; 9 | using Http; 10 | using Microsoft.Practices.Unity; 11 | using Name; 12 | 13 | [UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)] 14 | public class ProxyValidator : IProxyValidator 15 | { 16 | /// 17 | /// Gets or sets the name resolver. 18 | /// 19 | /// 20 | /// The name resolver. 21 | /// 22 | [Dependency] 23 | public INameResolver NameResolver { get; set; } 24 | 25 | /// 26 | /// Validates the specified proxy host port as a HTTP CONNECT proxy. 27 | /// 28 | /// 29 | /// 30 | /// 31 | /// 32 | /// 33 | public bool Validate(ProxyServer proxyServer, Uri testTarget, Route routeToProxy, int tryCount = 3) 34 | { 35 | try 36 | { 37 | Validate(routeToProxy + proxyServer, testTarget, tryCount); 38 | return true; 39 | } 40 | catch (IOException) 41 | { 42 | } 43 | catch (ProxyRouteException) 44 | { 45 | } 46 | return false; 47 | } 48 | 49 | /// 50 | /// Validates the specified route, using the test target. 51 | /// 52 | /// The route. 53 | /// The test target. 54 | /// 55 | /// 56 | /// If proxy connection fails. 57 | public void Validate(Route route, Uri testTarget, int tryCount) 58 | { 59 | for (int tryIndex = 0; tryIndex < tryCount; tryIndex++) 60 | { 61 | // result does not matter 62 | using (var httpStream = route.Connect(testTarget, NameResolver)) 63 | { 64 | HttpRequest.CreateGet(testTarget).Write(httpStream); 65 | var httpResponse = HttpResponse.FromStream(httpStream); 66 | if (httpResponse.StatusCode > 0 && httpResponse.StatusCode < 400) 67 | return; 68 | #if DEBUG 69 | var content = httpResponse.ReadContentString(httpStream); 70 | #endif 71 | } 72 | } 73 | throw new ProxyRouteException(testTarget.Host); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Proxy/Server/ClientReceivedEventArgs.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Proxy.Server 4 | { 5 | using System; 6 | 7 | /// 8 | /// Sent when data is received from server 9 | /// 10 | public class ClientReceivedEventArgs : EventArgs 11 | { 12 | /// 13 | /// Amount of data received. 14 | /// 15 | /// 16 | /// The received. 17 | /// 18 | public int Received { get; private set; } 19 | 20 | public ClientReceivedEventArgs(int received) 21 | { 22 | Received = received; 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Proxy/Server/HttpProxyServer.cs: -------------------------------------------------------------------------------- 1 | using BlueDwarf.Net.Proxy.Client; 2 | using Fiddler; 3 | 4 | namespace BlueDwarf.Net.Proxy.Server 5 | { 6 | public class HttpProxyServer : IProxyServer 7 | { 8 | public ProxyRoute ProxyRoute { get; set; } 9 | 10 | public void Start() 11 | { 12 | FiddlerApplication.Startup(3128,FiddlerCoreStartupFlags.Default); 13 | var proxy = FiddlerApplication.oProxy; 14 | FiddlerApplication.BeforeRequest += OnBeforeRequest; 15 | } 16 | 17 | private void OnBeforeRequest(Session session) 18 | { 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Proxy/Server/IProxyServer.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Proxy.Server 4 | { 5 | using System; 6 | using Client; 7 | 8 | /// 9 | /// Proxy server interface 10 | /// 11 | public interface IProxyServer: IDisposable 12 | { 13 | /// 14 | /// Occurs when a client connects. 15 | /// 16 | event EventHandler Connect; 17 | 18 | /// 19 | /// Occurs when data is transferred, from or to client. 20 | /// 21 | event EventHandler Transfer; 22 | 23 | /// 24 | /// Gets or sets the listening port. 25 | /// 0 to auto-select 26 | /// null to stop 27 | /// 28 | /// 29 | /// The port. 30 | /// 31 | int? Port { get; set; } 32 | 33 | /// 34 | /// Gets or sets the proxy outgoing routes. 35 | /// If first route fails, then second is tried, etc. 36 | /// 37 | /// 38 | /// The proxy routes. 39 | /// 40 | Route[] Routes { get; set; } 41 | } 42 | } -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Proxy/Server/IProxyServerFactory.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Proxy.Server 4 | { 5 | /// 6 | /// Proxy server factory interface 7 | /// (since we may create several proxy servers at the same time) 8 | /// 9 | public interface IProxyServerFactory 10 | { 11 | /// 12 | /// Creates a socks proxy server. 13 | /// 14 | /// 15 | IProxyServer CreateSocksProxyServer(); 16 | } 17 | } -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Proxy/Server/MSocksServer/Socks4ThreadInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | namespace MSocksServer.Socks4Server 3 | { 4 | public class Socks4ThreadInfo 5 | { 6 | private string _ip; 7 | private int _port; 8 | public string Ip 9 | { 10 | get 11 | { 12 | return this._ip; 13 | } 14 | } 15 | public int Port 16 | { 17 | get 18 | { 19 | return this._port; 20 | } 21 | } 22 | public Socks4ThreadInfo(string ip, int port) 23 | { 24 | this._ip = ip; 25 | this._port = port; 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Proxy/Server/ProxyServerFactory.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Proxy.Server 4 | { 5 | using Annotations; 6 | using Microsoft.Practices.Unity; 7 | using Name; 8 | 9 | [UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)] 10 | public class ProxyServerFactory : IProxyServerFactory 11 | { 12 | [Dependency] 13 | public INameResolver NameResolver { get; set; } 14 | 15 | /// 16 | /// Creates a socks proxy server. 17 | /// 18 | /// 19 | public IProxyServer CreateSocksProxyServer() 20 | { 21 | return new MSocksProxyServer(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Net/Proxy/Server/ProxyServerTransferEventArgs.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Proxy.Server 4 | { 5 | using System; 6 | 7 | /// 8 | /// Sent when data is exchanged from client to proxy server 9 | /// 10 | public class ProxyServerTransferEventArgs : EventArgs 11 | { 12 | /// 13 | /// Gets the bytes written. 14 | /// 15 | /// 16 | /// The bytes written. 17 | /// 18 | public int BytesWritten { get; private set; } 19 | /// 20 | /// Gets the bytes read. 21 | /// 22 | /// 23 | /// The bytes read. 24 | /// 25 | public int BytesRead { get; private set; } 26 | 27 | /// 28 | /// Initializes a new instance of the class. 29 | /// 30 | /// The bytes read. 31 | /// The bytes written. 32 | public ProxyServerTransferEventArgs(int bytesRead, int bytesWritten) 33 | { 34 | BytesRead = bytesRead; 35 | BytesWritten = bytesWritten; 36 | } 37 | } 38 | } -------------------------------------------------------------------------------- /BlueDwarf.Core/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://code.google.com/p/blue-dwarf/ 3 | 4 | using System.Reflection; 5 | using System.Runtime.CompilerServices; 6 | using System.Runtime.InteropServices; 7 | 8 | [assembly: AssemblyTitle("BlueDwarf Core")] 9 | [assembly: AssemblyDescription("Core engine for Blue Dwarf")] 10 | 11 | [assembly: ComVisible(false)] 12 | 13 | [assembly: InternalsVisibleTo("BlueDwarf.Test, PublicKey=" 14 | + "00240000048000009400000006020000002400005253413100040000010001004f7a980f6539c6" 15 | + "c9fbb86d4812601c72ee96def6ad0b1925d815bc21cccd97041c3f1e474c075f666ab1e98ee2a4" 16 | + "1b8dafa79a5943c21f80eb88e73b8e7c78774535cd13dc417f0d38c478e8dabf28cc72bf5cc3ff" 17 | + "bd9669f8bf45a91793a81838bfd55a356cd5e31ef154703aad8d8de7c76c30fe9ea55e31dfaf71" 18 | + "2bb1609d")] 19 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Properties/BlueDwarf.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/picrap/BlueDwarf/444f8306c79815e9b24a19d0cc850e5ed714501f/BlueDwarf.Core/Properties/BlueDwarf.snk -------------------------------------------------------------------------------- /BlueDwarf.Core/Properties/ProductInfo.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | using System.Reflection; 5 | 6 | [assembly: AssemblyCompany("Proud dwarves corp.")] 7 | [assembly: AssemblyProduct("Blue Dwarf")] 8 | 9 | [assembly: AssemblyCopyright("Distributed under MIT license http://opensource.org/licenses/MIT")] 10 | [assembly: AssemblyTrademark("")] 11 | [assembly: AssemblyCulture("")] 12 | 13 | [assembly: AssemblyVersion("0.7.3")] 14 | 15 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Reflection/CustomAttributeProviderExtensions.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Reflection 4 | { 5 | using System; 6 | using System.Linq; 7 | using System.Reflection; 8 | 9 | public static class CustomAttributeProviderExtensions 10 | { 11 | /// 12 | /// Gets a single custom attribute, usable without this ugly cast. 13 | /// 14 | /// The type of the attribute. 15 | /// The custom attribute provider. 16 | /// if set to true [inherit]. 17 | /// 18 | public static TAttribute GetCustomAttribute(this ICustomAttributeProvider customAttributeProvider, bool inherit = true) 19 | where TAttribute : Attribute 20 | { 21 | return customAttributeProvider.GetCustomAttributes(typeof(TAttribute), inherit).Cast().SingleOrDefault(); 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Reflection/PropertyAccessor.cs: -------------------------------------------------------------------------------- 1 | #region SignReferences 2 | // This is the blue dwarf 3 | // more information at https://github.com/picrap/BlueDwarf 4 | #endregion 5 | 6 | namespace BlueDwarf.Reflection 7 | { 8 | using System; 9 | 10 | /// 11 | /// Property accessor, a simple version 12 | /// 13 | /// The type of the property. 14 | public class PropertyAccessor 15 | { 16 | private readonly Func _get; 17 | private readonly Action _set; 18 | 19 | /// 20 | /// Gets or sets the value. 21 | /// 22 | /// 23 | /// The value. 24 | /// 25 | public TProperty Value 26 | { 27 | get { return _get(); } 28 | set { _set(value); } 29 | } 30 | 31 | /// 32 | /// Initializes a new instance of the class. 33 | /// 34 | /// The get. 35 | /// The set. 36 | public PropertyAccessor(Func get, Action set) 37 | { 38 | _get = get; 39 | _set = set; 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Utility/EnumerableExtensions.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Utility 4 | { 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Linq; 8 | 9 | public static class EnumerableExtensions 10 | { 11 | public static IEnumerable WhereNonNull(this IEnumerable items) 12 | where TItem : class 13 | { 14 | return items.Where(i => i != null); 15 | } 16 | 17 | public static IEnumerable SelectNonNull(this IEnumerable source, Func selector) 18 | where TResult : class 19 | { 20 | return source.Select(selector).WhereNonNull(); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Utility/EventHandlerExtensions.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Utility 4 | { 5 | using System; 6 | 7 | public static class EventHandlerExtensions 8 | { 9 | public static void Raise(this EventHandler handler, object sender) 10 | { 11 | if (handler != null) 12 | handler(sender, EventArgs.Empty); 13 | } 14 | 15 | public static void Raise(this EventHandler handler, object sender, TEventArgs eventArgs) 16 | where TEventArgs : EventArgs 17 | { 18 | if (handler != null) 19 | handler(sender, eventArgs); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Utility/ObjectExtensions.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace BlueDwarf.Utility 3 | { 4 | using System; 5 | using System.Reflection; 6 | 7 | /// 8 | /// Extensions to object 9 | /// 10 | public static class ObjectExtensions 11 | { 12 | /// 13 | /// Equals, with null support. 14 | /// 15 | /// a. 16 | /// The b. 17 | /// 18 | public static bool SafeEquals(this object a, object b) 19 | { 20 | if (a == null || b == null) 21 | return (a == null) == (b == null); 22 | return a.Equals(b); 23 | } 24 | } 25 | } -------------------------------------------------------------------------------- /BlueDwarf.Core/Utility/ObjectTypeConverter.cs: -------------------------------------------------------------------------------- 1 | #region Mr. Advice MVVM 2 | // // Mr. Advice MVVM 3 | // // A simple MVVM package using Mr. Advice aspect weaver 4 | // // https://github.com/ArxOne/MrAdvice.MVVM 5 | // // Released under MIT license http://opensource.org/licenses/mit-license.php 6 | #endregion 7 | 8 | namespace BlueDwarf.Utility 9 | { 10 | using System; 11 | 12 | /// 13 | /// Type converter, with more conversion than System.Convert 14 | /// 15 | public static class ObjectTypeConverter 16 | { 17 | /// 18 | /// Converts the specified object to target type. 19 | /// 20 | /// The o. 21 | /// Type of the target. 22 | /// 23 | /// Can not create URI 24 | public static object Convert(object o, Type targetType) 25 | { 26 | if (o == null) 27 | return targetType.Default(); 28 | 29 | if (targetType == typeof(Uri)) 30 | return ConvertToUri(o); 31 | 32 | var sourceType = o.GetType(); 33 | if (sourceType == typeof(Uri)) 34 | return Convert(o.ToString(), targetType); 35 | 36 | var c = System.Convert.ChangeType(o, targetType); 37 | return c; 38 | } 39 | 40 | private static Uri ConvertToUri(object o) 41 | { 42 | try 43 | { 44 | return new Uri(Convert(o)); 45 | } 46 | catch (UriFormatException) 47 | { } 48 | try 49 | { 50 | return new Uri(Convert(o), UriKind.Relative); 51 | } 52 | catch (UriFormatException) 53 | { } 54 | throw new InvalidCastException("Can not create URI"); 55 | } 56 | 57 | /// 58 | /// Converts the specified object to target type. 59 | /// 60 | /// 61 | /// The o. 62 | /// 63 | public static T Convert(object o) 64 | { 65 | return (T)Convert(o, typeof(T)); 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Utility/StreamExtensions.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.Utility 5 | { 6 | using System.IO; 7 | using System.Net.Security; 8 | 9 | /// 10 | /// Extensions to Stream 11 | /// 12 | public static class StreamExtensions 13 | { 14 | /// 15 | /// Opens SSL channel. 16 | /// 17 | /// The stream. 18 | /// The target host. 19 | /// 20 | public static Stream AsSsl(this Stream stream, string targetHost) 21 | { 22 | if (stream is SslStream) 23 | return stream; 24 | 25 | var sslStream = new SslStream(stream); 26 | sslStream.AuthenticateAsClient(targetHost); 27 | return sslStream; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Utility/StringExtensions.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Utility 4 | { 5 | using System; 6 | 7 | /// 8 | /// Extensions to 9 | /// 10 | public static class StringExtensions 11 | { 12 | public static bool IsNullOrEmpty(this string s) 13 | { 14 | return string.IsNullOrEmpty(s); 15 | } 16 | 17 | /// 18 | /// Converts to URI, or null if it is no valid URI. 19 | /// 20 | /// The s. 21 | /// 22 | public static Uri ToSafeUri(this string s) 23 | { 24 | try 25 | { 26 | if (s != null) 27 | return new Uri(s); 28 | } 29 | catch (UriFormatException) 30 | { } 31 | return null; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /BlueDwarf.Core/Utility/TypeExtensions.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Utility 4 | { 5 | using System; 6 | using System.Collections.Generic; 7 | 8 | /// 9 | /// Extensions for Type 10 | /// 11 | public static class TypeExtensions 12 | { 13 | public static bool IsNullable(this Type type) 14 | { 15 | return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>); 16 | } 17 | 18 | /// 19 | /// Gets the original type that was made Nullable. 20 | /// (this is probably the worst method name I ever wrote) 21 | /// 22 | /// The type. 23 | /// 24 | public static Type GetNullabled(this Type type) 25 | { 26 | if (!IsNullable(type)) 27 | return null; 28 | return type.GetGenericArguments()[0]; 29 | } 30 | 31 | /// 32 | /// Enumerates all types from given type to System.Object. 33 | /// 34 | /// The type. 35 | /// 36 | public static IEnumerable GetSelfAndBaseTypes(this Type type) 37 | { 38 | while (type != null) 39 | { 40 | yield return type; 41 | type = type.BaseType; 42 | } 43 | } 44 | 45 | /// 46 | /// Creates a default instance. 47 | /// 48 | /// The type. 49 | /// 50 | public static object Default(this Type type) 51 | { 52 | if (type.IsClass) 53 | return null; 54 | return Activator.CreateInstance(type); 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /BlueDwarf.Core/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /BlueDwarf.Core/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /BlueDwarf.Test/HostScannerTest.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.Test 5 | { 6 | using System.Linq; 7 | using System.Net; 8 | using System.Text.RegularExpressions; 9 | using Microsoft.VisualStudio.TestTools.UnitTesting; 10 | using Net.Proxy; 11 | using Net.Proxy.Scanner; 12 | 13 | [TestClass] 14 | public class HostScannerTest 15 | { 16 | [TestMethod] 17 | [TestCategory("Host Parsing")] 18 | public void ParsePortsTest() 19 | { 20 | var portRegex = new Regex(@"^" + HostPort.PortEx + HostScanner.AfterDigitEx); 21 | //var portRegex = new Regex(@"(?(\d{1,4}))"); 22 | for (int i = 0; i <= 65535; i++) 23 | { 24 | var match = portRegex.Match(i.ToString()); 25 | Assert.IsTrue(match.Success); 26 | var p = int.Parse(match.Groups["port"].Value); 27 | Assert.AreEqual(i, p); 28 | } 29 | 30 | Assert.IsFalse(portRegex.Match("65536").Success); 31 | Assert.IsFalse(portRegex.Match("65540").Success); 32 | Assert.IsFalse(portRegex.Match("65600").Success); 33 | Assert.IsFalse(portRegex.Match("66000").Success); 34 | Assert.IsFalse(portRegex.Match("70000").Success); 35 | } 36 | 37 | [TestMethod] 38 | [TestCategory("Host Parsing")] 39 | public void ParseIP_0_0_0_0_Test() 40 | { 41 | var ipV4Regex = new Regex(@"^" + HostPort.IPv4Ex + HostScanner.AfterDigitEx); 42 | var match = ipV4Regex.Match("0.0.0.0"); 43 | Assert.IsTrue(match.Success); 44 | } 45 | 46 | [TestMethod] 47 | [TestCategory("Host Parsing")] 48 | public void ParseIP_255_255_255_255_Test() 49 | { 50 | var ipV4Regex = new Regex(@"^" + HostPort.IPv4Ex + HostScanner.AfterDigitEx); 51 | var match = ipV4Regex.Match("255.255.255.255"); 52 | Assert.IsTrue(match.Success); 53 | } 54 | 55 | [TestMethod] 56 | [TestCategory("Host Parsing")] 57 | public void ParseHostPort_123_45_67_89_7654_Test() 58 | { 59 | var ipV4Regex = new Regex(HostScanner.IPColonPortEx); 60 | var match = ipV4Regex.Match("123.45.67.89:7654"); 61 | Assert.IsTrue(match.Success); 62 | Assert.AreEqual("123.45.67.89", match.Groups["address"].Value); 63 | Assert.AreEqual("7654", match.Groups["port"].Value); 64 | } 65 | 66 | [TestMethod] 67 | [TestCategory("Host Parsing")] 68 | public void ParsePageTest() 69 | { 70 | var hostScanner = new HostScanner(); 71 | var hosts = hostScanner.Scan("here 123.45.67.89:3128 there 13.24.35.46 : 57 and everywhere 98.76.54.32 1").ToArray(); 72 | Assert.IsTrue(hosts.Contains(new ProxyServer(ProxyProtocol.HttpConnect, IPAddress.Parse("123.45.67.89"), 3128))); 73 | Assert.IsTrue(hosts.Contains(new ProxyServer(ProxyProtocol.HttpConnect, IPAddress.Parse("13.24.35.46"), 57))); 74 | Assert.IsTrue(hosts.Contains(new ProxyServer(ProxyProtocol.HttpConnect, IPAddress.Parse("98.76.54.32"), 1))); 75 | } 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /BlueDwarf.Test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | using System.Reflection; 5 | using System.Runtime.InteropServices; 6 | 7 | // General Information about an assembly is controlled through the following 8 | // set of attributes. Change these attribute values to modify the information 9 | // associated with an assembly. 10 | [assembly: AssemblyTitle("BlueDwarf.Test")] 11 | [assembly: AssemblyDescription("")] 12 | [assembly: AssemblyConfiguration("")] 13 | [assembly: AssemblyCompany("")] 14 | [assembly: AssemblyProduct("BlueDwarf.Test")] 15 | [assembly: AssemblyCopyright("Copyright © 2015")] 16 | [assembly: AssemblyTrademark("")] 17 | [assembly: AssemblyCulture("")] 18 | 19 | // Setting ComVisible to false makes the types in this assembly not visible 20 | // to COM components. If you need to access a type in this assembly from 21 | // COM, set the ComVisible attribute to true on that type. 22 | [assembly: ComVisible(false)] 23 | 24 | // The following GUID is for the ID of the typelib if this project is exposed to COM 25 | [assembly: Guid("08091d2e-e7a2-4693-80d0-08fce329f61a")] 26 | 27 | // Version information for an assembly consists of the following four values: 28 | // 29 | // Major Version 30 | // Minor Version 31 | // Build Number 32 | // Revision 33 | // 34 | // You can specify all the values or you can default the Build and Revision Numbers 35 | // by using the '*' as shown below: 36 | // [assembly: AssemblyVersion("1.0.*")] 37 | [assembly: AssemblyVersion("1.0.0.0")] 38 | [assembly: AssemblyFileVersion("1.0.0.0")] 39 | -------------------------------------------------------------------------------- /BlueDwarf.Test/ProxyServerTest.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.Test 5 | { 6 | using Microsoft.VisualStudio.TestTools.UnitTesting; 7 | using Net.Proxy; 8 | 9 | [TestClass] 10 | public class ProxyServerTest 11 | { 12 | [TestMethod] 13 | [TestCategory("ProxyServer")] 14 | public void LiteralWindowsProxyServerTest() 15 | { 16 | var p = new ProxyServer("http=1.2.3.4:8080"); 17 | Assert.AreEqual(ProxyProtocol.HttpConnect, p.Protocol); 18 | Assert.AreEqual("1.2.3.4", p.Host); 19 | Assert.AreEqual(8080, p.Port); 20 | } 21 | 22 | [TestMethod] 23 | [TestCategory("ProxyServer")] 24 | public void LiteralUriProxyServerTest() 25 | { 26 | var p = new ProxyServer("socks://[::1]:1080"); 27 | Assert.AreEqual(ProxyProtocol.Socks4A, p.Protocol); 28 | // WTF? there is a full expansion of IPv6 addresses in URI parsing. 29 | Assert.AreEqual("[0000:0000:0000:0000:0000:0000:0000:0001]", p.Host); 30 | Assert.AreEqual(1080, p.Port); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /BlueDwarf.Test/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /BlueDwarf.Tunnel/BlueDwarf Tunnel.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | BlueDwarf.Tunnel 5 | $version$ 6 | $title$ 7 | $author$ 8 | $author$ 9 | http://opensource.org/licenses/mit-license.php 10 | https://github.com/picrap/BlueDwarf/wiki/BlueDwarf-Tunnel 11 | https://raw.githubusercontent.com/picrap/BlueDwarf/master/Icon/BlueDwarf.png 12 | false 13 | Multiple proxy tunnel 14 | $description$ 15 | 16 | Copyright 2015 17 | multiple proxy tunnel socks socks4 socks4a http connect 18 | 19 | 20 | 21 | false 22 | 23 | 24 | 25 | 26 | 27 | -------------------------------------------------------------------------------- /BlueDwarf.Tunnel/IO/StreamExtensions.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.IO 4 | { 5 | using System.IO; 6 | using System.Text; 7 | 8 | /// 9 | /// Exntensions to Stream 10 | /// 11 | public static class StreamExtensions 12 | { 13 | /// 14 | /// Reads all available data. 15 | /// 16 | /// The stream. 17 | /// The buffer. 18 | /// The offset. 19 | /// The count. 20 | /// 21 | public static int ReadAll(this Stream stream, byte[] buffer, int offset, int count) 22 | { 23 | var totalRead = 0; 24 | while (count > 0) 25 | { 26 | var bytesRead = stream.Read(buffer, offset, count); 27 | if (bytesRead == 0) 28 | break; 29 | 30 | totalRead += bytesRead; 31 | offset += bytesRead; 32 | count -= bytesRead; 33 | } 34 | return totalRead; 35 | } 36 | 37 | /// 38 | /// Reads the line as ASCII. 39 | /// 40 | /// The stream. 41 | /// 42 | public static string ReadLineAscii(this Stream stream) 43 | { 44 | var lineBuilder = new StringBuilder(); 45 | for (; ; ) 46 | { 47 | var b = stream.ReadByte(); 48 | if (b == -1) 49 | break; 50 | var c = (char)b; 51 | if (c == '\r') 52 | continue; 53 | if (c == '\n') 54 | break; 55 | lineBuilder.Append(c); 56 | } 57 | return lineBuilder.ToString(); 58 | } 59 | } 60 | } -------------------------------------------------------------------------------- /BlueDwarf.Tunnel/Net/Connect.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net 4 | { 5 | using System; 6 | using System.IO; 7 | using System.Net; 8 | using System.Net.Sockets; 9 | using Utility; 10 | 11 | /// 12 | /// Socket connection helper 13 | /// 14 | public static class Connect 15 | { 16 | /// 17 | /// Simple socket connection to specified host+port. 18 | /// 19 | /// The target host. 20 | /// The target port. 21 | /// The retry. 22 | /// The timeout. 23 | /// 24 | public static Socket To(string targetHost, int targetPort, int retry = 2, int timeout = 1000) 25 | { 26 | var timeoutTimeSpan = TimeSpan.FromMilliseconds(timeout); 27 | for (int i = 0; i < retry; i++) 28 | { 29 | try 30 | { 31 | var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); 32 | socket.Connect(targetHost, targetPort, timeoutTimeSpan); 33 | if (socket.Connected) 34 | return socket; 35 | } 36 | catch (SocketException) 37 | { 38 | } 39 | catch (IOException) 40 | { 41 | } 42 | } 43 | return null; 44 | } 45 | /// 46 | /// Simple socket connection to specified address+port. 47 | /// 48 | /// The target. 49 | /// The target port. 50 | /// The retry. 51 | /// The timeout. 52 | /// 53 | public static Socket To(IPAddress target, int targetPort, int retry = 2, int timeout = 1000) 54 | { 55 | var timeoutTimeSpan = TimeSpan.FromMilliseconds(timeout); 56 | for (int i = 0; i < retry; i++) 57 | { 58 | try 59 | { 60 | var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); 61 | socket.Connect(target, targetPort, timeoutTimeSpan); 62 | if (socket.Connected) 63 | return socket; 64 | } 65 | catch (SocketException) 66 | { 67 | } 68 | catch (IOException) 69 | { 70 | } 71 | } 72 | return null; 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /BlueDwarf.Tunnel/Net/HostEndPoint.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.Net 5 | { 6 | using System; 7 | using System.Diagnostics; 8 | using System.Linq; 9 | using System.Net; 10 | using System.Net.Sockets; 11 | 12 | /// 13 | /// Represents a server (host and port) 14 | /// 15 | [DebuggerDisplay("Server: {IPEndPoint}")] 16 | public class HostEndPoint : DnsEndPoint 17 | { 18 | private IPAddress _ipAddress; 19 | 20 | /// 21 | /// Gets the IPEndPoint (resolves Host if necessary). 22 | /// 23 | /// 24 | /// The ip end point. 25 | /// 26 | public IPEndPoint IPEndPoint 27 | { 28 | get 29 | { 30 | if (_ipAddress == null) 31 | _ipAddress = ParseHost() ?? ResolveHost(); 32 | return new IPEndPoint(_ipAddress, Port); 33 | } 34 | } 35 | 36 | /// 37 | /// Initializes a new instance of the class. 38 | /// 39 | /// The ip address. 40 | /// The port. 41 | public HostEndPoint(IPAddress ipAddress, int port) 42 | : base(ipAddress.ToString(), port) 43 | { 44 | _ipAddress = ipAddress; 45 | } 46 | 47 | /// 48 | /// Initializes a new instance of the class. 49 | /// 50 | /// Nom d'hôte ou représentation sous forme de chaîne de l'adresse IP. 51 | /// Numéro de port associé à l'adresse ou 0 pour spécifier tout port disponible. est dans l'ordre des hôtes. 52 | public HostEndPoint(string host, int port) 53 | : base(host, port) 54 | { 55 | } 56 | 57 | /// 58 | /// Gets the ip address from the host. 59 | /// 60 | /// 61 | private IPAddress ResolveHost() 62 | { 63 | try 64 | { 65 | var addresses = Dns.GetHostAddresses(Host); 66 | return addresses.FirstOrDefault(a => a.AddressFamily == AddressFamily.InterNetwork) 67 | ?? addresses.FirstOrDefault(a => a.AddressFamily == AddressFamily.InterNetworkV6); 68 | } 69 | catch (SocketException) { } 70 | catch (ArgumentException) { } 71 | return null; 72 | } 73 | 74 | /// 75 | /// Parses the host. 76 | /// 77 | /// 78 | private IPAddress ParseHost() 79 | { 80 | IPAddress ipAddress; 81 | IPAddress.TryParse(Host, out ipAddress); 82 | return ipAddress; 83 | } 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /BlueDwarf.Tunnel/Net/Proxy/Client/IProxyClient.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Proxy.Client 4 | { 5 | /// 6 | /// Proxy client interface 7 | /// 8 | public interface IProxyClient 9 | { 10 | /// 11 | /// Creates a route. 12 | /// 13 | /// The proxy servers. 14 | /// 15 | Route CreateRoute(params ProxyServer[] proxyServers); 16 | } 17 | } -------------------------------------------------------------------------------- /BlueDwarf.Tunnel/Net/Proxy/Client/ProxyRouteException.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Proxy.Client 4 | { 5 | using System; 6 | 7 | /// 8 | /// Exception for proxy route. 9 | /// Can be thrown when a connection to intermediate proxy server or target fails. 10 | /// 11 | public class ProxyRouteException : Exception 12 | { 13 | /// 14 | /// Gets or sets the proxy where the connexion error happened. 15 | /// 16 | /// 17 | /// The proxy. 18 | /// 19 | public ProxyServer Proxy { get; set; } 20 | 21 | /// 22 | /// If all proxy succeed but connection to target fails, the TargetHost is filled. 23 | /// 24 | /// 25 | /// The target host. 26 | /// 27 | public string TargetHost { get; set; } 28 | 29 | /// 30 | /// Initializes a new instance of the class. 31 | /// 32 | /// The proxy. 33 | public ProxyRouteException(ProxyServer proxy) 34 | { 35 | Proxy = proxy; 36 | } 37 | 38 | /// 39 | /// Initializes a new instance of the class. 40 | /// 41 | /// The target host. 42 | public ProxyRouteException(string targetHost) 43 | { 44 | TargetHost = targetHost; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /BlueDwarf.Tunnel/Net/Proxy/Client/Route.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Proxy.Client 4 | { 5 | using System.Linq; 6 | using System.Net; 7 | using System.Net.Sockets; 8 | using Utility; 9 | 10 | /// 11 | /// Represents a route to target 12 | /// This class holds the router instance 13 | /// 14 | public class Route 15 | { 16 | /// 17 | /// Method prototype to connect to given target (IP+port) and using given route 18 | /// 19 | /// The address. 20 | /// The target port. 21 | /// The route. 22 | /// 23 | public delegate Socket ConnectAddressDelegate(IPAddress address, int targetPort, Route route); 24 | 25 | /// 26 | /// Gets the relays (the proxy servers tunnel). 27 | /// 28 | /// 29 | /// The relays. 30 | /// 31 | public ProxyServer[] Relays { get; private set; } 32 | 33 | private readonly ConnectAddressDelegate _connectAddress; 34 | 35 | /// 36 | /// Initializes a new instance of the class. 37 | /// 38 | /// The connect address. 39 | /// The route. 40 | public Route(ConnectAddressDelegate connectAddress, params ProxyServer[] route) 41 | { 42 | _connectAddress = connectAddress; 43 | Relays = route.Where(r => r != null).ToArray(); 44 | } 45 | 46 | /// 47 | /// Adds an element to current route and returns a new route. 48 | /// 49 | /// The route. 50 | /// The proxy server. 51 | /// 52 | /// The result of the operator. 53 | /// 54 | public static Route operator +(Route route, ProxyServer proxyServer) 55 | { 56 | return new Route(route._connectAddress, route.Relays.Concat(new[] { proxyServer }).ToArray()); 57 | } 58 | 59 | /// 60 | /// Connects to the specified target. 61 | /// 62 | /// The target. 63 | /// The target port. 64 | /// 65 | public Socket Connect(IPAddress targetAddress, int targetPort) 66 | { 67 | return _connectAddress(targetAddress, targetPort, this); 68 | } 69 | 70 | /// 71 | /// Connects to the specified target. 72 | /// 73 | /// The target. 74 | /// 75 | public Socket Connect(EndPoint target) 76 | { 77 | var ipTarget = target.ToIPEndPoint(); 78 | return Connect(ipTarget.Address, ipTarget.Port); 79 | } 80 | } 81 | } -------------------------------------------------------------------------------- /BlueDwarf.Tunnel/Net/Proxy/Client/RouteExtensions.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.Net.Proxy.Client 5 | { 6 | using System.IO; 7 | using System.Linq; 8 | using System.Net; 9 | using System.Net.Sockets; 10 | 11 | /// 12 | /// Extensions to 13 | /// 14 | public static class RouteExtensions 15 | { 16 | /// 17 | /// Connects to target host/address and port. 18 | /// 19 | /// The route. 20 | /// The host or address. 21 | /// The port. 22 | /// 23 | /// 24 | public static Socket Connect(this Route route, string hostOrAddress, int port) 25 | { 26 | IPAddress ipAddress; 27 | if (!IPAddress.TryParse(hostOrAddress, out ipAddress)) 28 | { 29 | var entry = Dns.GetHostEntry(hostOrAddress); 30 | ipAddress = entry.AddressList.FirstOrDefault(a => a.AddressFamily == AddressFamily.InterNetwork) 31 | ?? entry.AddressList.FirstOrDefault(a => a.AddressFamily == AddressFamily.InterNetworkV6); 32 | } 33 | if (ipAddress == null) 34 | throw new IOException(string.Format("Impossible to resolve '{0}'", hostOrAddress)); 35 | return route.Connect(ipAddress, port); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /BlueDwarf.Tunnel/Net/Proxy/Client/TunnelProxyClient.Http.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Proxy.Client 4 | { 5 | using System.IO; 6 | using System.Net; 7 | using System.Net.Sockets; 8 | using Http; 9 | using Starksoft.Aspen.Proxy; 10 | 11 | partial class TunnelProxyClient 12 | { 13 | /// 14 | /// Proxy connection using HTTP. 15 | /// 16 | /// The socket. 17 | /// The target. 18 | /// 19 | private Socket HttpProxyConnect(Socket socket, IPEndPoint target) 20 | { 21 | //try 22 | //{ 23 | // var proxyClient = new HttpProxyClient(new TcpClient { Client = socket }); 24 | // var tcpClient = proxyClient.CreateConnection(target.Address.ToString(), target.Port); 25 | // return tcpClient.Client; 26 | //} 27 | //catch (ProxyException) 28 | //{ 29 | // throw new ProxyRouteException(new ProxyServer(ProxyProtocol.HttpConnect, target.Address, target.Port)); 30 | //} 31 | 32 | try 33 | { 34 | using (var stream = new NetworkStream(socket, false)) 35 | { 36 | HttpRequest.CreateConnect(target.Address.ToString(), target.Port).Write(stream); 37 | var httpResponse = HttpResponse.FromStream(stream); 38 | if (httpResponse.StatusCode != 200) 39 | { 40 | #if DEBUG 41 | var content = httpResponse.ReadContentString(stream); 42 | #endif 43 | //var bc = new BlueCoatHttpAuthentication(); 44 | //bc.Handle(stream, httpResponse, content, networkCredential, routeUntilHere); 45 | return null; 46 | } 47 | return socket; 48 | } 49 | } 50 | catch (IOException) 51 | { } 52 | return null; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /BlueDwarf.Tunnel/Net/Proxy/Client/TunnelProxyClient.Socks.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Proxy.Client 4 | { 5 | using System.Net; 6 | using System.Net.Sockets; 7 | using Starksoft.Aspen.Proxy; 8 | 9 | partial class TunnelProxyClient 10 | { 11 | private Socket SocksProxyConnect(Socket socket, IPEndPoint target) 12 | { 13 | try 14 | { 15 | var proxyClient = new Socks4aProxyClient(new TcpClient { Client = socket }); 16 | var tcpClient = proxyClient.CreateConnection(target.Address.ToString(), target.Port); 17 | return tcpClient.Client; 18 | } 19 | catch (ProxyException) 20 | { 21 | throw new ProxyRouteException(new ProxyServer(ProxyProtocol.HttpConnect, target.Address, target.Port)); 22 | } 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /BlueDwarf.Tunnel/Net/Proxy/ProxyProtocol.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Net.Proxy 4 | { 5 | /// 6 | /// Supported proxy protocols 7 | /// 8 | public enum ProxyProtocol 9 | { 10 | /// 11 | /// HTTP tunneling 12 | /// 13 | HttpConnect, 14 | /// 15 | /// SOCKS4 (anonymous) 16 | /// 17 | Socks4A, 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /BlueDwarf.Tunnel/Net/Proxy/ProxyProtocolUtility.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.Net.Proxy 5 | { 6 | using System; 7 | 8 | /// 9 | /// Utility class (utility and extensions) for 10 | /// 11 | public static class ProxyProtocolUtility 12 | { 13 | /// 14 | /// Converts a literal string to a protocol. 15 | /// 16 | /// The literal protocol. 17 | /// 18 | /// literalProtocol 19 | public static ProxyProtocol FromLiteral(string literalProtocol) 20 | { 21 | switch (literalProtocol.ToLower()) 22 | { 23 | case "http": 24 | return ProxyProtocol.HttpConnect; 25 | case "socks": 26 | case "socks4": 27 | case "socks4a": 28 | return ProxyProtocol.Socks4A; 29 | default: 30 | throw new ArgumentOutOfRangeException("literalProtocol"); 31 | } 32 | } 33 | 34 | /// 35 | /// Converts a protocol to a literal. 36 | /// 37 | /// The proxy protocol. 38 | /// 39 | /// proxyProtocol 40 | public static string ToLiteral(this ProxyProtocol proxyProtocol) 41 | { 42 | switch (proxyProtocol) 43 | { 44 | case ProxyProtocol.HttpConnect: 45 | return "http"; 46 | case ProxyProtocol.Socks4A: 47 | return "socks"; 48 | default: 49 | throw new ArgumentOutOfRangeException("proxyProtocol"); 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /BlueDwarf.Tunnel/Net/Proxy/ProxyServer.Literal.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.Net.Proxy 5 | { 6 | using System; 7 | 8 | partial class ProxyServer 9 | { 10 | /// 11 | /// Parses the literal value. 12 | /// Accepted formats are protocol=host:port or protocol://host:port 13 | /// 14 | /// The literal value. 15 | /// 16 | private static Uri ParseLiteral(string literalValue) 17 | { 18 | return ParseLiteralProxy(literalValue) ?? ParseLiteralUri(literalValue); 19 | } 20 | 21 | /// 22 | /// Parses the literal in Windows proxy form (protocol=host:port). 23 | /// 24 | /// The literal value. 25 | /// 26 | private static Uri ParseLiteralProxy(string literalValue) 27 | { 28 | var index = literalValue.IndexOf('='); 29 | if (index < 0) 30 | return null; 31 | var scheme = literalValue.Substring(0, index); 32 | var hostAndPort = literalValue.Substring(index + 1); 33 | // and now for the lazy part 34 | return ParseLiteralUri(string.Format("{0}://{1}", scheme, hostAndPort)); 35 | } 36 | 37 | /// 38 | /// Parses the literal URI (protocol://host:port). 39 | /// 40 | /// The literal value. 41 | /// 42 | private static Uri ParseLiteralUri(string literalValue) 43 | { 44 | try 45 | { 46 | return new Uri(literalValue); 47 | } 48 | catch (UriFormatException) 49 | { } 50 | return null; 51 | } 52 | 53 | /// 54 | /// Gets the host from literal. 55 | /// 56 | /// The literal value. 57 | /// 58 | private static string GetHostFromLiteral(string literalValue) 59 | { 60 | var uri = ParseLiteral(literalValue); 61 | if (uri == null) 62 | return null; 63 | return uri.Host; 64 | } 65 | 66 | /// 67 | /// Gets the port from literal. 68 | /// 69 | /// The literal value. 70 | /// 71 | private static int GetPortFromLiteral(string literalValue) 72 | { 73 | var uri = ParseLiteral(literalValue); 74 | if (uri == null) 75 | return -1; 76 | return uri.Port; 77 | } 78 | 79 | /// 80 | /// Gets the protocol from literal. 81 | /// 82 | /// The literal value. 83 | /// 84 | private static ProxyProtocol GetProtocolFromLiteral(string literalValue) 85 | { 86 | var uri = ParseLiteral(literalValue); 87 | if (uri == null) 88 | return ProxyProtocol.HttpConnect; 89 | return GetProtocol(uri.Scheme); 90 | } 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /BlueDwarf.Tunnel/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | using System.Reflection; 5 | 6 | [assembly: AssemblyTitle("BlueDwarf Tunnel")] 7 | [assembly: AssemblyDescription("Allows to chain proxy servers in order to reach a given network target. Supports HTTP CONNECT and SOCKS proxy servers.")] 8 | -------------------------------------------------------------------------------- /BlueDwarf.Tunnel/Utility/EndPointExtensions.cs: -------------------------------------------------------------------------------- 1 | #region Arx One 2 | // This is the blue dwarf 3 | // more information at https://github.com/picrap/BlueDwarf 4 | #endregion 5 | 6 | namespace BlueDwarf.Utility 7 | { 8 | using System.IO; 9 | using System.Linq; 10 | using System.Net; 11 | using System.Net.Sockets; 12 | using Net; 13 | 14 | /// 15 | /// Extensions to 16 | /// 17 | public static class EndPointExtensions 18 | { 19 | /// 20 | /// Convert an to . 21 | /// 22 | /// The end point. 23 | /// 24 | /// When not possible 25 | public static IPEndPoint ToIPEndPoint(this EndPoint endPoint) 26 | { 27 | var ipEndPoint = endPoint as IPEndPoint; 28 | if (ipEndPoint != null) 29 | return ipEndPoint; 30 | var dnsEndPoint = endPoint as DnsEndPoint; 31 | if (dnsEndPoint != null) 32 | { 33 | var ipAddress = dnsEndPoint.TryResolveName(); 34 | if (ipAddress != null) 35 | return new IPEndPoint(ipAddress, dnsEndPoint.Port); 36 | } 37 | var hostEndPoint = endPoint as HostEndPoint; 38 | if (hostEndPoint != null) 39 | return hostEndPoint.IPEndPoint; 40 | throw new IOException(string.Format("Can't handle type '{0}'", endPoint.GetType().FullName)); 41 | } 42 | 43 | /// 44 | /// Tries to resolve the Name property from the given . 45 | /// 46 | /// The DNS end point. 47 | /// 48 | /// 49 | public static IPAddress TryResolveName(this DnsEndPoint dnsEndPoint) 50 | { 51 | try 52 | { 53 | var addresses = Dns.GetHostAddresses(dnsEndPoint.Host); 54 | return addresses.FirstOrDefault(a => a.AddressFamily == AddressFamily.InterNetwork) 55 | ?? addresses.FirstOrDefault(a => a.AddressFamily == AddressFamily.InterNetworkV6); 56 | } 57 | catch (SocketException e) 58 | { 59 | throw new IOException(string.Format("Can't resolve '{0}'", dnsEndPoint.Host), e); 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /BlueDwarf.Tunnel/Utility/SocketExtensions.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.Utility 5 | { 6 | using System; 7 | using System.Net; 8 | using System.Net.Sockets; 9 | 10 | /// 11 | /// Extensions to Socket class 12 | /// 13 | public static class SocketExtensions 14 | { 15 | /// 16 | /// Connects the specified socket. 17 | /// 18 | /// The socket. 19 | /// The host. 20 | /// The port. 21 | /// The timeout. 22 | public static void Connect(this Socket socket, string host, int port, TimeSpan timeout) 23 | { 24 | AsyncConnect(socket, (s, a, o) => s.BeginConnect(host, port, a, o), timeout); 25 | } 26 | 27 | /// 28 | /// Connects the specified socket. 29 | /// 30 | /// The socket. 31 | /// The address. 32 | /// The port. 33 | /// The timeout. 34 | public static void Connect(this Socket socket, IPAddress address, int port, TimeSpan timeout) 35 | { 36 | AsyncConnect(socket, (s, a, o) => s.BeginConnect(address, port, a, o), timeout); 37 | } 38 | 39 | /// 40 | /// Asyncs the connect. 41 | /// 42 | /// The socket. 43 | /// The connect. 44 | /// The timeout. 45 | private static void AsyncConnect(Socket socket, Func connect, TimeSpan timeout) 46 | { 47 | var asyncResult = connect(socket, null, null); 48 | if (asyncResult.AsyncWaitHandle.WaitOne(timeout)) 49 | { 50 | socket.EndConnect(asyncResult); 51 | return; 52 | } 53 | 54 | try 55 | { 56 | socket.Close(); 57 | } 58 | catch (SocketException) 59 | { 60 | } 61 | catch (ObjectDisposedException) 62 | { 63 | } 64 | } 65 | 66 | /// 67 | /// Safe converts Socket to Stream. 68 | /// 69 | /// The socket. 70 | /// A stream or null if socket is null 71 | public static NetworkStream ToNetworkStream(this Socket socket) 72 | { 73 | if (socket == null) 74 | return null; 75 | return new NetworkStream(socket, true); 76 | } 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /BlueDwarf.Tunnel/Utility/UriExtensions.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Utility 4 | { 5 | using System; 6 | using System.Net; 7 | 8 | /// 9 | /// Extensions to 10 | /// 11 | public static class UriExtensions 12 | { 13 | /// 14 | /// Gets the network credential from the given URI. 15 | /// 16 | /// The URI. 17 | /// Credential or null if none specified 18 | public static NetworkCredential GetNetworkCredential(this Uri uri) 19 | { 20 | var userPassword = uri.UserInfo; 21 | if (string.IsNullOrEmpty(userPassword)) 22 | return null; 23 | var parts = userPassword.Split(new[] { ':' }, 2); 24 | if (parts.Length != 2) 25 | return null; 26 | return new NetworkCredential(parts[0], parts[1]); 27 | } 28 | 29 | /// 30 | /// Gets a literal representation of host and port from the given URI. 31 | /// 32 | /// The URI. 33 | /// 34 | public static string GetHostAndPort(this Uri uri) 35 | { 36 | return string.Format("{0}:{1}", uri.Host, uri.Port); 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /BlueDwarf.Tunnel/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /BlueDwarf.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.31101.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlueDwarf", "BlueDwarf\BlueDwarf.csproj", "{AEA3BA3F-2974-466C-BE49-17AD34CF9F5F}" 7 | EndProject 8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".nuget", ".nuget", "{5A7DB477-41AA-40D9-80C3-FC9BF20D9286}" 9 | ProjectSection(SolutionItems) = preProject 10 | .nuget\NuGet.Config = .nuget\NuGet.Config 11 | .nuget\NuGet.exe = .nuget\NuGet.exe 12 | .nuget\NuGet.targets = .nuget\NuGet.targets 13 | EndProjectSection 14 | EndProject 15 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlueDwarf.Core", "BlueDwarf.Core\BlueDwarf.Core.csproj", "{BBD1E465-0350-44DA-9D4C-485DA9670703}" 16 | EndProject 17 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlueDwarf.Test", "BlueDwarf.Test\BlueDwarf.Test.csproj", "{4E026AAC-764E-4A65-80FD-C41371EB8D8F}" 18 | EndProject 19 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tools", "Tools", "{B931890B-6776-4A3B-B5EC-CD6D7B4088A7}" 20 | ProjectSection(SolutionItems) = preProject 21 | Tools\490fc8e027f9320a04d00960ce799809.pfx = Tools\490fc8e027f9320a04d00960ce799809.pfx 22 | appveyor.yml = appveyor.yml 23 | EndProjectSection 24 | EndProject 25 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlueDwarf.Tunnel", "BlueDwarf.Tunnel\BlueDwarf.Tunnel.csproj", "{ABFD2F65-C917-4509-A1F5-B7353D117680}" 26 | EndProject 27 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{11A01D03-1CD1-495E-B9A0-C425C13959D3}" 28 | EndProject 29 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Icon", "Icon", "{A2F51918-39AC-4769-A6DB-A05873695B6E}" 30 | ProjectSection(SolutionItems) = preProject 31 | Icon\BlueDwarf.png = Icon\BlueDwarf.png 32 | EndProjectSection 33 | EndProject 34 | Global 35 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 36 | Debug|Any CPU = Debug|Any CPU 37 | Release|Any CPU = Release|Any CPU 38 | EndGlobalSection 39 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 40 | {AEA3BA3F-2974-466C-BE49-17AD34CF9F5F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 41 | {AEA3BA3F-2974-466C-BE49-17AD34CF9F5F}.Debug|Any CPU.Build.0 = Debug|Any CPU 42 | {AEA3BA3F-2974-466C-BE49-17AD34CF9F5F}.Release|Any CPU.ActiveCfg = Release|Any CPU 43 | {AEA3BA3F-2974-466C-BE49-17AD34CF9F5F}.Release|Any CPU.Build.0 = Release|Any CPU 44 | {BBD1E465-0350-44DA-9D4C-485DA9670703}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 45 | {BBD1E465-0350-44DA-9D4C-485DA9670703}.Debug|Any CPU.Build.0 = Debug|Any CPU 46 | {BBD1E465-0350-44DA-9D4C-485DA9670703}.Release|Any CPU.ActiveCfg = Release|Any CPU 47 | {BBD1E465-0350-44DA-9D4C-485DA9670703}.Release|Any CPU.Build.0 = Release|Any CPU 48 | {4E026AAC-764E-4A65-80FD-C41371EB8D8F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 49 | {4E026AAC-764E-4A65-80FD-C41371EB8D8F}.Debug|Any CPU.Build.0 = Debug|Any CPU 50 | {4E026AAC-764E-4A65-80FD-C41371EB8D8F}.Release|Any CPU.ActiveCfg = Release|Any CPU 51 | {4E026AAC-764E-4A65-80FD-C41371EB8D8F}.Release|Any CPU.Build.0 = Release|Any CPU 52 | {ABFD2F65-C917-4509-A1F5-B7353D117680}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 53 | {ABFD2F65-C917-4509-A1F5-B7353D117680}.Debug|Any CPU.Build.0 = Debug|Any CPU 54 | {ABFD2F65-C917-4509-A1F5-B7353D117680}.Release|Any CPU.ActiveCfg = Release|Any CPU 55 | {ABFD2F65-C917-4509-A1F5-B7353D117680}.Release|Any CPU.Build.0 = Release|Any CPU 56 | EndGlobalSection 57 | GlobalSection(SolutionProperties) = preSolution 58 | HideSolutionNode = FALSE 59 | EndGlobalSection 60 | GlobalSection(NestedProjects) = preSolution 61 | {4E026AAC-764E-4A65-80FD-C41371EB8D8F} = {11A01D03-1CD1-495E-B9A0-C425C13959D3} 62 | EndGlobalSection 63 | GlobalSection(ExtensibilityGlobals) = postSolution 64 | EnterpriseLibraryConfigurationToolBinariesPath = packages\Unity.2.1.505.2\lib\NET35;packages\Unity.Interception.2.1.505.2\lib\NET35 65 | EndGlobalSection 66 | EndGlobal 67 | -------------------------------------------------------------------------------- /BlueDwarf.sln.DotSettings: -------------------------------------------------------------------------------- 1 |  2 | True 3 | This is the blue dwarf 4 | more information at https://github.com/picrap/BlueDwarf -------------------------------------------------------------------------------- /BlueDwarf/ApplicationOptions.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf 4 | { 5 | using CommandLine; 6 | 7 | public class ApplicationOptions 8 | { 9 | [Option('p', "proxy-port", Required = false, HelpText = "Sockets proxy server port.")] 10 | public int ProxyPort { get; set; } 11 | 12 | [Option('m', "minimized", Required = false, HelpText = "Starts minimized.")] 13 | public bool Minimized { get; set; } 14 | 15 | [Option('d', "download", Required = false, HelpText = "Downloads the URI.")] 16 | public string DownloadUri { get; set; } 17 | 18 | [Option('t', "save-text", Required = false, HelpText = "Saves the file as text.")] 19 | public string SaveTextPath { get; set; } 20 | 21 | [Option("proxy", Required = false, HelpText = "Sets proxy (for downloading URIs).")] 22 | public string Proxy { get; set; } 23 | 24 | [Option('s', "first-start", Required = false, HelpText = "Simulates first start (debug feature).")] 25 | public bool FirstStart { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /BlueDwarf/BlueDwarfApplication.xaml: -------------------------------------------------------------------------------- 1 |  5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 10 | 11 | 15 | 16 | 20 | 21 | 24 | 25 | 32 | 33 | 37 | 38 | 42 | 43 | 46 | 47 | 50 | 51 | 10 52 | 10,0,0,0 53 | 54 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /BlueDwarf/Resources/key.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/picrap/BlueDwarf/444f8306c79815e9b24a19d0cc850e5ed714501f/BlueDwarf/Resources/key.ico -------------------------------------------------------------------------------- /BlueDwarf/Resources/passe100.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/picrap/BlueDwarf/444f8306c79815e9b24a19d0cc850e5ed714501f/BlueDwarf/Resources/passe100.png -------------------------------------------------------------------------------- /BlueDwarf/Resources/passe300.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/picrap/BlueDwarf/444f8306c79815e9b24a19d0cc850e5ed714501f/BlueDwarf/Resources/passe300.png -------------------------------------------------------------------------------- /BlueDwarf/UIConfiguration.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf 4 | { 5 | using System.Windows; 6 | using ArxOne.MrAdvice.MVVM.Navigation; 7 | using ArxOne.MrAdvice.Utility; 8 | using Microsoft.Practices.Unity; 9 | 10 | public static class UIConfiguration 11 | { 12 | /// 13 | /// Just a nicer way to use singletons 14 | /// 15 | /// 16 | private static LifetimeManager AsSingleton() 17 | { 18 | return new ContainerControlledLifetimeManager(); 19 | } 20 | 21 | /// 22 | /// Configures the specified container with application instances. 23 | /// 24 | /// The container. 25 | public static void Configure(IUnityContainer container) 26 | { 27 | container.RegisterInstance(typeof(INavigator), Application.Current.GetNavigator()); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /BlueDwarf/Utility/BindingExtensions.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.Utility 5 | { 6 | using System.Windows.Data; 7 | 8 | /// 9 | /// Extensions to binding 10 | /// 11 | internal static class BindingExtensions 12 | { 13 | /// 14 | /// Gets the value of binding related to data context. 15 | /// 16 | /// The binding. 17 | /// The data item. 18 | /// 19 | public static object GetValue(this Binding binding, object dataContext) 20 | { 21 | if (binding == null || dataContext == null) 22 | return null; 23 | 24 | var bindingPath = binding.Path.Path; 25 | var properties = bindingPath.Split('.'); 26 | 27 | var currentObject = dataContext; 28 | 29 | foreach (var property in properties) 30 | { 31 | var currentType = currentObject.GetType(); 32 | var propertyInfo = currentType.GetProperty(property); 33 | if (propertyInfo == null) 34 | return null; 35 | currentObject = propertyInfo.GetValue(currentObject, null); 36 | if (currentObject == null) 37 | return null; 38 | } 39 | 40 | return currentObject; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /BlueDwarf/Utility/CollectionExtensions.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Utility 4 | { 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | using System.Windows.Controls; 8 | 9 | public static class CollectionExtensions 10 | { 11 | public static void AddRange(this ICollection collection, IEnumerable items) 12 | { 13 | foreach (var item in items) 14 | collection.Add(item); 15 | } 16 | 17 | public static void AddRange(this ItemCollection collection, IEnumerable items) 18 | { 19 | foreach (var item in items) 20 | collection.Add(item); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /BlueDwarf/Utility/ExclusiveUpdate.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.Utility 5 | { 6 | using System; 7 | using System.Reflection; 8 | using ArxOne.MrAdvice.Advice; 9 | using ArxOne.MrAdvice.Introduction; 10 | 11 | [AttributeUsage(AttributeTargets.Method)] 12 | public class ExclusiveUpdate : Attribute, IMethodAdvice, IMethodInfoAdvice 13 | { 14 | public IntroducedField Locked { get; set; } 15 | 16 | public void Advise(MethodInfoAdviceContext context) 17 | { 18 | var methodInfo = context.TargetMethod as MethodInfo; 19 | if (methodInfo != null && methodInfo.ReturnType != (typeof(void))) 20 | throw new InvalidOperationException("ExclusiveUpdate can only be applied to void methods"); 21 | } 22 | 23 | public void Advise(MethodAdviceContext context) 24 | { 25 | var locked = Locked[context]; 26 | if (locked) 27 | return; 28 | try 29 | { 30 | Locked[context] = true; 31 | context.Proceed(); 32 | } 33 | finally 34 | { 35 | Locked[context] = false; 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /BlueDwarf/Utility/ServiceProviderExtensions.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.Utility 4 | { 5 | using System; 6 | 7 | public static class ServiceProviderExtensions 8 | { 9 | public static TService GetService(this IServiceProvider serviceProvider) 10 | { 11 | return (TService)serviceProvider.GetService(typeof(TService)); 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /BlueDwarf/View/HomeLocalProxyKeepaliveView.xaml: -------------------------------------------------------------------------------- 1 |  14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /BlueDwarf/View/HomeLocalProxyKeepaliveView.xaml.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.View 5 | { 6 | /// 7 | /// Interaction logic for HomeLocalProxyKeepaliveView.xaml 8 | /// 9 | public partial class HomeLocalProxyKeepaliveView 10 | { 11 | public HomeLocalProxyKeepaliveView() 12 | { 13 | InitializeComponent(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /BlueDwarf/View/HomeProxyConfigurationView.xaml: -------------------------------------------------------------------------------- 1 |  12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 31 | 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /BlueDwarf/View/HomeProxyConfigurationView.xaml.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.View 5 | { 6 | /// 7 | /// Interaction logic for HomeProxyConfigurationView.xaml 8 | /// 9 | public partial class HomeProxyConfigurationView 10 | { 11 | public HomeProxyConfigurationView() 12 | { 13 | InitializeComponent(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /BlueDwarf/View/HomeStatusView.xaml: -------------------------------------------------------------------------------- 1 |  12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /BlueDwarf/View/HomeStatusView.xaml.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.View 5 | { 6 | /// 7 | /// Interaction logic for HomeStatusView.xaml 8 | /// 9 | public partial class HomeStatusView 10 | { 11 | public HomeStatusView() 12 | { 13 | InitializeComponent(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /BlueDwarf/View/HomeTunnelConfigurationView.xaml.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.View 5 | { 6 | /// 7 | /// Interaction logic for HomeTunnelConfigurationView.xaml 8 | /// 9 | public partial class HomeTunnelConfigurationView 10 | { 11 | public HomeTunnelConfigurationView() 12 | { 13 | InitializeComponent(); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /BlueDwarf/View/HomeView.xaml: -------------------------------------------------------------------------------- 1 |  18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /BlueDwarf/View/HomeView.xaml.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.View 5 | { 6 | using System.Linq; 7 | using System.Windows; 8 | 9 | /// 10 | /// Interaction logic for HomeView.xaml 11 | /// 12 | public partial class HomeView 13 | { 14 | /// 15 | /// Initializes a new instance of the class. 16 | /// 17 | public HomeView() 18 | { 19 | InitializeComponent(); 20 | Loaded += OnLoaded; 21 | } 22 | 23 | /// 24 | /// Called when page is loaded. 25 | /// 26 | /// The sender. 27 | /// The instance containing the event data. 28 | private void OnLoaded(object sender, RoutedEventArgs e) 29 | { 30 | if (ContentSource == null) 31 | ContentSource = MenuLinkGroups.First().Links.First().Source; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /BlueDwarf/View/HomeWelcomeView.xaml: -------------------------------------------------------------------------------- 1 |  14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /BlueDwarf/View/HomeWelcomeView.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Windows; 6 | using System.Windows.Controls; 7 | using System.Windows.Data; 8 | using System.Windows.Documents; 9 | using System.Windows.Input; 10 | using System.Windows.Media; 11 | using System.Windows.Media.Imaging; 12 | using System.Windows.Navigation; 13 | using System.Windows.Shapes; 14 | 15 | namespace BlueDwarf.View 16 | { 17 | /// 18 | /// Logique d'interaction pour HomeWelcomeView.xaml 19 | /// 20 | public partial class HomeWelcomeView : UserControl 21 | { 22 | public HomeWelcomeView() 23 | { 24 | InitializeComponent(); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /BlueDwarf/View/ImageSource.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.View 5 | { 6 | using System; 7 | using System.Windows; 8 | using System.Windows.Controls; 9 | using DependencyProperty = System.Windows.DependencyProperty; 10 | 11 | public class ImageSource 12 | { 13 | /// 14 | /// Gets or sets the source. 15 | /// 16 | /// 17 | /// The source. 18 | /// 19 | // TODO: this does not work... 20 | //[Attached(Notification = DependencyPropertyNotification.OnPropertyNameChanged)] 21 | //public static string Uri { get; set; } 22 | 23 | public static readonly DependencyProperty UriProperty = DependencyProperty.RegisterAttached( 24 | "Uri", typeof (string), typeof (ImageSource), new PropertyMetadata(default(string),OnUriChanged)); 25 | 26 | public static void SetUri(DependencyObject element, string value) 27 | { 28 | element.SetValue(UriProperty, value); 29 | } 30 | 31 | public static string GetUri(DependencyObject element) 32 | { 33 | return (string) element.GetValue(UriProperty); 34 | } 35 | 36 | /// 37 | /// Called when [source changed]. 38 | /// 39 | /// The d. 40 | /// The instance containing the event data. 41 | public static void OnUriChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) 42 | { 43 | var image = d as Image; 44 | if (image != null) 45 | { 46 | if (e.NewValue == null) 47 | image.Source = null; 48 | else 49 | image.Source = new System.Windows.Media.Imaging.BitmapImage(new Uri((string)e.NewValue)); 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /BlueDwarf/View/ProxyAnalysisView.xaml.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.View 4 | { 5 | /// 6 | /// ProxyAnalysisView.xaml 7 | /// 8 | public partial class ProxyAnalysisView 9 | { 10 | public ProxyAnalysisView() 11 | { 12 | InitializeComponent(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /BlueDwarf/View/ProxyPickerView.xaml.cs: -------------------------------------------------------------------------------- 1 |  2 | namespace BlueDwarf.View 3 | { 4 | using System.Diagnostics; 5 | using System.Windows.Navigation; 6 | 7 | /// 8 | /// Logique d'interaction pour ProxyPickerView.xaml 9 | /// 10 | public partial class ProxyPickerView 11 | { 12 | public ProxyPickerView() 13 | { 14 | InitializeComponent(); 15 | } 16 | 17 | private void OnHyperlinkRequestNavigate(object sender, RequestNavigateEventArgs e) 18 | { 19 | Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri)); 20 | e.Handled = true; 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /BlueDwarf/View/WebDownloaderView.xaml: -------------------------------------------------------------------------------- 1 |  12 | 13 | 14 | -------------------------------------------------------------------------------- /BlueDwarf/View/WebDownloaderView.xaml.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.View 4 | { 5 | /// 6 | /// Interaction logic for WebBrowserView.xaml 7 | /// 8 | public partial class WebDownloaderView 9 | { 10 | public WebDownloaderView() 11 | { 12 | InitializeComponent(); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /BlueDwarf/ViewModel/Properties/CategoryNotifyPropertyChanged.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.ViewModel.Properties 5 | { 6 | using ArxOne.MrAdvice.Advice; 7 | using ArxOne.MrAdvice.Annotation; 8 | using ArxOne.MrAdvice.MVVM.Properties; 9 | 10 | [Priority(AspectPriority.Notification)] 11 | public class CategoryNotifyPropertyChanged: NotifyPropertyChanged 12 | { 13 | /// 14 | /// Gets or sets the category. 15 | /// 16 | /// 17 | /// The category. 18 | /// 19 | public object Category { get; set; } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /BlueDwarf/ViewModel/Properties/CategoryPropertyChangedEventArgs.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.ViewModel.Properties 4 | { 5 | using System.ComponentModel; 6 | 7 | public class CategoryPropertyChangedEventArgs : PropertyChangedEventArgs 8 | { 9 | public object Category { get; private set; } 10 | 11 | public CategoryPropertyChangedEventArgs(string propertyName, object category) 12 | : base(propertyName) 13 | { 14 | Category = category; 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /BlueDwarf/ViewModel/Properties/PropertyChangedEventArgsExtensions.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.ViewModel.Properties 4 | { 5 | using System; 6 | using System.ComponentModel; 7 | 8 | /// 9 | /// Extensions to make it more handy (because we're pragmatic people) 10 | /// 11 | public static class PropertyChangedEventArgsExtensions 12 | { 13 | /// 14 | /// Gets the property category, as an object. 15 | /// 16 | /// The instance containing the event data. 17 | /// 18 | public static object GetCategory(this PropertyChangedEventArgs e) 19 | { 20 | var categoryPropertyChangedEventArgs = e as CategoryPropertyChangedEventArgs; 21 | if (categoryPropertyChangedEventArgs == null) 22 | return null; 23 | return categoryPropertyChangedEventArgs.Category; 24 | } 25 | 26 | /// 27 | /// Gets the property category, as the requested type (whose only pupose is to avoid casts in client calls). 28 | /// 29 | /// The type of the category. 30 | /// The instance containing the event data. 31 | /// 32 | public static TCategory GetCategory(this PropertyChangedEventArgs e) 33 | { 34 | try 35 | { 36 | var category = GetCategory(e); 37 | if (category != null) 38 | return (TCategory)category; 39 | } 40 | catch (InvalidCastException) 41 | { 42 | } 43 | return default(TCategory); 44 | } 45 | } 46 | } -------------------------------------------------------------------------------- /BlueDwarf/ViewModel/Proxy.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | 4 | namespace BlueDwarf.ViewModel 5 | { 6 | using System; 7 | using Net.Geolocation; 8 | using Net.Proxy; 9 | 10 | public class Proxy 11 | { 12 | /// 13 | /// Gets the proxy server. 14 | /// 15 | /// 16 | /// The proxy server. 17 | /// 18 | public ProxyServer ProxyServer { get; private set; } 19 | 20 | /// 21 | /// Gets the geolocation. 22 | /// 23 | /// 24 | /// The geolocation. 25 | /// 26 | public AddressGeolocation Geolocation { get; private set; } 27 | 28 | public string DisplayType 29 | { 30 | get 31 | { 32 | switch(ProxyServer.Protocol) 33 | { 34 | case ProxyProtocol.HttpConnect: 35 | return "HTTP"; 36 | case ProxyProtocol.Socks4A: 37 | return "SOCKS"; 38 | default: 39 | throw new ArgumentOutOfRangeException(); 40 | } 41 | } 42 | } 43 | 44 | /// 45 | /// Gets the display name. 46 | /// 47 | /// 48 | /// The display name. 49 | /// 50 | public string DisplayName { get { return ProxyServer.Host + ":" + ProxyServer.Port; } } 51 | 52 | /// 53 | /// Gets the name of the country. 54 | /// 55 | /// 56 | /// The name of the country. 57 | /// 58 | public string CountryName { get { return Geolocation.CountryName; } } 59 | 60 | /// 61 | /// Gets the country code. 62 | /// 63 | /// 64 | /// The country code. 65 | /// 66 | public string CountryCode { get { return Geolocation.CountryCode; } } 67 | 68 | /// 69 | /// Gets the ping (in ms). 70 | /// 71 | /// 72 | /// The ping ms. 73 | /// 74 | public int PingMs { get; private set; } 75 | 76 | /// 77 | /// Gets the speed (in kB/s). 78 | /// 79 | /// 80 | /// The speed KBPS. 81 | /// 82 | public int SpeedKbps { get; private set; } 83 | 84 | /// 85 | /// Initializes a new instance of the class. 86 | /// 87 | /// The proxy server. 88 | /// The geolocation. 89 | /// The ping (in ms). 90 | /// The speed (in kB/s). 91 | public Proxy(ProxyServer proxyServer, AddressGeolocation geolocation, int pingMs, int speedKbps) 92 | { 93 | ProxyServer = proxyServer; 94 | Geolocation = geolocation; 95 | PingMs = pingMs; 96 | SpeedKbps = speedKbps; 97 | } 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /BlueDwarf/ViewModel/ProxyAnalysisViewModel.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.ViewModel 4 | { 5 | using System; 6 | using Annotations; 7 | using ArxOne.MrAdvice.MVVM.Navigation; 8 | using ArxOne.MrAdvice.MVVM.Properties; 9 | using Microsoft.Practices.Unity; 10 | using Net.Proxy.Client.Diagnostic; 11 | 12 | [UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)] 13 | public class ProxyAnalysisViewModel : ViewModel 14 | { 15 | [Dependency] 16 | public INavigator Navigator { get; set; } 17 | 18 | [Dependency] 19 | public ISystemProxyAnalyzer SystemProxyAnalyzer { get; set; } 20 | 21 | [NotifyPropertyChanged] 22 | public bool RequiresProxy { get; set; } 23 | 24 | [NotifyPropertyChanged] 25 | public bool DoesNotRequireProxy { get; set; } 26 | 27 | [NotifyPropertyChanged] 28 | public Uri DefaultProxy { get; set; } 29 | 30 | [NotifyPropertyChanged] 31 | public bool ProxyAllowsSensitiveSites { get; set; } 32 | 33 | [NotifyPropertyChanged] 34 | public bool DnsResolvesLocal { get; set; } 35 | 36 | [NotifyPropertyChanged] 37 | public bool DnsResolvesSensitiveSites { get; set; } 38 | 39 | [NotifyPropertyChanged] 40 | public bool ProxyConnectsToSensitiveIP { get; set; } 41 | 42 | [NotifyPropertyChanged] 43 | public bool WorkWithLocalProxy { get; set; } 44 | 45 | [NotifyPropertyChanged] 46 | public bool WorkWithTwoProxy { get; set; } 47 | 48 | [NotifyPropertyChanged] 49 | public bool WorkWithSomethingElse { get; set; } 50 | 51 | public override void Load() 52 | { 53 | ShowAsyncLoad(LoadDiagnostic); 54 | } 55 | 56 | /// 57 | /// Analyses proxy status, asynchronously. 58 | /// 59 | private void LoadDiagnostic() 60 | { 61 | var diagnostic = SystemProxyAnalyzer.Diagnose(); 62 | RequiresProxy = diagnostic.DefaultProxy != null; 63 | DoesNotRequireProxy = !RequiresProxy; 64 | DefaultProxy = diagnostic.DefaultProxy; 65 | ProxyAllowsSensitiveSites = diagnostic.SensitiveHttpGetRoute.HasFlag(RouteStatus.ProxyAcceptsName) 66 | && diagnostic.SensitiveHttpsConnectRoute.HasFlag(RouteStatus.ProxyAcceptsName) 67 | && diagnostic.SensitiveHttpConnectRoute.HasFlag(RouteStatus.ProxyAcceptsName); 68 | DnsResolvesLocal = diagnostic.SafeLocalDns; 69 | DnsResolvesSensitiveSites = diagnostic.SensitiveLocalDns; 70 | ProxyConnectsToSensitiveIP = diagnostic.SensitiveHttpsConnectRoute.HasFlag(RouteStatus.ProxyAcceptsAddress) 71 | && diagnostic.SensitiveHttpConnectRoute.HasFlag(RouteStatus.ProxyAcceptsAddress); 72 | 73 | if (DnsResolvesSensitiveSites && ProxyConnectsToSensitiveIP) 74 | WorkWithLocalProxy = true; 75 | else if (!ProxyConnectsToSensitiveIP) 76 | WorkWithTwoProxy = true; 77 | else 78 | WorkWithSomethingElse = true; 79 | } 80 | 81 | /// 82 | /// Asks to apply recommandations 83 | /// 84 | public void Apply() 85 | { 86 | Navigator.Exit(true); 87 | } 88 | 89 | /// 90 | /// Asks not to apply th recommandations. 91 | /// 92 | public void Cancel() 93 | { 94 | Navigator.Exit(false); 95 | } 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /BlueDwarf/ViewModel/ViewModel.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.ViewModel 4 | { 5 | using System; 6 | using System.Reflection; 7 | using ArxOne.MrAdvice.MVVM.Properties; 8 | using ArxOne.MrAdvice.MVVM.Threading; 9 | using Properties; 10 | 11 | /// 12 | /// View-model base (in case we write more than one). 13 | /// 14 | public class ViewModel : ArxOne.MrAdvice.MVVM.ViewModel.ViewModel 15 | { 16 | [NotifyPropertyChanged] 17 | public bool Loading { get; set; } 18 | 19 | [UISync] 20 | public override void OnPropertyChanged(PropertyInfo propertyInfo, NotifyPropertyChanged sender) 21 | { 22 | var categoryNotifyPropertyChanged = sender as CategoryNotifyPropertyChanged; 23 | var category = categoryNotifyPropertyChanged != null ? categoryNotifyPropertyChanged.Category : null; 24 | OnPropertyChanged(new CategoryPropertyChangedEventArgs(propertyInfo.Name, category)); 25 | } 26 | 27 | /// 28 | /// Asynchronously invokes the action and shows the wait overlay (assuming view handles it). 29 | /// 30 | /// The action. 31 | [Async] 32 | protected void ShowAsyncLoad(Action action) 33 | { 34 | bool loading = Loading; 35 | try 36 | { 37 | Loading = true; 38 | action(); 39 | } 40 | finally 41 | { 42 | Loading = loading; 43 | } 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /BlueDwarf/ViewModel/WebDownloaderViewModel.cs: -------------------------------------------------------------------------------- 1 | // This is the blue dwarf 2 | // more information at https://github.com/picrap/BlueDwarf 3 | namespace BlueDwarf.ViewModel 4 | { 5 | using System.IO; 6 | using Annotations; 7 | using ArxOne.MrAdvice.MVVM.Navigation; 8 | using ArxOne.MrAdvice.MVVM.Properties; 9 | using Microsoft.Practices.Unity; 10 | using Properties; 11 | 12 | /// 13 | /// Simple file download using IE ActiveX control 14 | /// We're not supposed to know this here, so that's going to be our little secret... 15 | /// 16 | [UsedImplicitly(ImplicitUseKindFlags.InstantiatedNoFixedConstructorSignature)] 17 | public class WebDownloaderViewModel : ViewModel 18 | { 19 | [Dependency] 20 | public INavigator Navigator { get; set; } 21 | 22 | [NotifyPropertyChanged] 23 | public string DownloadUri { get; set; } 24 | 25 | [NotifyPropertyChanged] 26 | public string SaveTextPath { get; set; } 27 | 28 | private string _documentText; 29 | [NotifyPropertyChanged] 30 | public string DocumentText 31 | { 32 | get { return _documentText; } 33 | set 34 | { 35 | _documentText = value; 36 | OnDocumentTextChanged(); 37 | } 38 | } 39 | 40 | /// 41 | /// Called when document text changed. 42 | /// 43 | private void OnDocumentTextChanged() 44 | { 45 | if (SaveTextPath != null) 46 | { 47 | var parentDirectory = Path.GetDirectoryName(SaveTextPath); 48 | if (!Directory.Exists(parentDirectory)) 49 | Directory.CreateDirectory(parentDirectory); 50 | using (var streamWriter = File.CreateText(SaveTextPath)) 51 | streamWriter.Write(DocumentText); 52 | } 53 | Navigator.Exit(false); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /BlueDwarf/app.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /BlueDwarf/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /Icon/BlueDwarf.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/picrap/BlueDwarf/444f8306c79815e9b24a19d0cc850e5ed714501f/Icon/BlueDwarf.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Welcome to the blue dwarf 2 | A small application allowing to discretely go outdoor, when your corporate proxy won't give you such liberty. 3 | 4 | ## Features 5 | * Allows use of two nested proxy servers 6 | * Handles HTTP or SOCKS proxy server (SOCKS to be done) 7 | * Exposes a local SOCKS proxy server 8 | * Uses IE to send keepalive signal to corporate proxy 9 | 10 | ## Download 11 | 12 | ### If your proxy and firewall are cool enough 13 | You can use the **[ClickOnce installer](http://openstore.craponne.fr/BlueDwarf.application)**. 14 | 15 | ### If it is not cool enough to allow ClickOnce 16 | You can still **[download the application directly](http://openstore.craponne.fr/BlueDwarf.exe)**. 17 | Then, simply launch the application, it will register to start automatically next time. 18 | -------------------------------------------------------------------------------- /Tools/490fc8e027f9320a04d00960ce799809.pfx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/picrap/BlueDwarf/444f8306c79815e9b24a19d0cc850e5ed714501f/Tools/490fc8e027f9320a04d00960ce799809.pfx -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | # BlueDwarf tunnel appveyor.yml script 2 | 3 | version: '{branch}-{build}' 4 | 5 | branches: 6 | only: 7 | - master 8 | 9 | before_build: 10 | nuget restore 11 | 12 | nuget: 13 | account_feed: true 14 | project_feed: true 15 | disable_publish_on_pr: true 16 | 17 | configuration: Release 18 | platform: Any CPU 19 | 20 | build: 21 | parallel: true 22 | publish_nuget: true 23 | publish_nuget_symbols: true 24 | verbosity: minimal 25 | 26 | environment: 27 | pfxKey: 28 | secure: 7kj0HlKk9INPLkabdbsdKp6R2i8BvgBzj03hzqUbLuU= 29 | 30 | after_test: 31 | - ps: $pfxKeyS = ConvertTo-SecureString $env:pfxKey -AsPlainText -Force 32 | - ps: Import-PfxCertificate -FilePath Tools\490fc8e027f9320a04d00960ce799809.pfx cert:\CurrentUser\My -Password $pfxKeyS 33 | - msbuild /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" /t:Publish /property:ApplicationRevision=%APPVEYOR_BUILD_NUMBER% 34 | - ps: $root = Resolve-Path .\BlueDwarf\bin\Release\app.publish; [IO.Directory]::GetFiles($root.Path, '*.*', 'AllDirectories') | % { Push-AppveyorArtifact $_ -FileName $_.Substring($root.Path.Length + 1) -DeploymentName ClickOnce } 35 | 36 | deploy: 37 | - provider: NuGet 38 | api_key: 39 | secure: rEYnR9JThbc6x8DdCo1K8+fgsGKzjNKzTZsldXFLYMm/tFPC7JWWvuKpVTrDBd+g 40 | skip_symbols: false 41 | 42 | - provider: FTP 43 | protocol: sftp 44 | host: openstore.craponne.fr:7623 45 | username: openstore 46 | password: 47 | secure: /Yr9Wtf5W7SfwBuz/LYLPN+aaxzjPjtIpfzLloth97U= 48 | folder: openstore.arxone.com 49 | artifact: ClickOnce 50 | --------------------------------------------------------------------------------