diff --git a/ZitiBackgroundTask/IpHeader.cs b/ZitiBackgroundTask/IpHeader.cs deleted file mode 100644 index ee1c09e6..00000000 --- a/ZitiBackgroundTask/IpHeader.cs +++ /dev/null @@ -1,477 +0,0 @@ -using System.Net; -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; - - -namespace ZitiBackgroundTask -{ - public enum Protocol - { - TCP = 6, - UDP = 17, - Unknown = -1 - }; - - /// - /// This class encapsulates all the IP header fields and provides a mechanism - /// to set and get the details of them through a parameterized contructor - /// and public properties respectively. - /// - class IpHeader - { - // Eight bits for version and header length. - public byte _versionAndHeaderLength; - // Eight bits for differentiated services (TOS). - public byte _differentiatedServices; - // Sixteen bits for total length of the datagram (header + message). - public ushort _totalLength; - // Sixteen bits for identification. - public ushort _identification; - // Eight bits for flags and fragmentation offset. - public ushort _flagsAndOffset; - // Eight bits for TTL (Time To Live). - public byte _ttl; - // Eight bits for the underlying protocol. - public byte _protocol; - // Sixteen bits containing the checksum of the header - // (checksum can be negative so taken as short). - public short _checksum; - // Thirty two bit source IP Address. - internal uint _sourceIPAddress; - // Thirty two bit destination IP Address. - internal uint _destinationIPAddress; - // Header length. - public byte _headerLength; - // Data carried by the datagram. - public byte[] _ipData = default;//new byte[2 << 15]; - - public void WriteTo(TextWriter writer) - { - writer.WriteLine("_vionAndHeaderLength: " + _versionAndHeaderLength); - writer.WriteLine("ByDifferentiatedServices: " + _differentiatedServices); - writer.WriteLine("UsTotalLength: " + _totalLength); - writer.WriteLine("UsIdentification: " + _identification); - writer.WriteLine("usFlagsAndOffset: " + _flagsAndOffset); - writer.WriteLine("_ttl: " + _ttl); - writer.WriteLine("_protocol: " + _protocol); - writer.WriteLine("SChecksum: " + _checksum); - writer.WriteLine("UiSourceIPAddress: " + _sourceIPAddress); - writer.WriteLine("UiDestinationIPAddress: " + _destinationIPAddress); - writer.WriteLine("_headerLength: " + _headerLength); - writer.WriteLine("As Hex: "); - writer.WriteLine(BinaryVisualiser.FormatAsHex(Data, _totalLength)); - writer.Flush(); - } - - public void WriteTo(System.IO.Stream stream) - {/* - write(stream, _versionAndHeaderLength); - write(stream, _differentiatedServices); - write(stream, _totalLength); - write(stream, _identification); - write(stream, _fagsAndOffset); - write(stream, _ttl); - write(stream, _protocol); - write(stream, SChecksum); - write(stream, _sourceIPAddress); - write(stream, _destinationIPAddress); - write(stream, _headerLength); - writeIpData(stream);*/ - - System.IO.BinaryWriter writer = new BinaryWriter(stream); - writer.Write(_versionAndHeaderLength); - writer.Write(_differentiatedServices); - writer.Write(_totalLength); - writer.Write(_identification); - writer.Write(_flagsAndOffset); - writer.Write(_ttl); - writer.Write(_protocol); - writer.Write(_checksum); - writer.Write(_sourceIPAddress); - writer.Write(_destinationIPAddress); - writer.Write(_headerLength); - writer.Write(_ipData, 0, MessageLength); - writer.Flush(); - } - /* - private void write(BinaryWriter target, byte toWrite) - { - target.WriteByte(toWrite); - } - private void write(BinaryWriter target, ushort toWrite) - { - byte[] bytes = BitConverter.GetBytes(toWrite); - target.Write(bytes, 0, bytes.Length); - } - private void write(BinaryWriter target, short toWrite) - { - byte[] bytes = BitConverter.GetBytes(toWrite); - target.Write(bytes, 0, bytes.Length); - } - private void write(BinaryWriter target, uint toWrite) - { - byte[] bytes = BitConverter.GetBytes(toWrite); - target.Write(bytes, 0, bytes.Length); - } - private void writeIpData(BinaryWriter target) - { - target.Write(ByIPData, 0, MessageLength); - }*/ - - private byte[] _ipPacket = new byte[2 << 15]; //65535 is the biggest packet possible - - private IpHeader() - { - //private use only - } - - public IpHeader([System.Runtime.InteropServices.WindowsRuntime.ReadOnlyArray()] - byte[] byBuffer, int nReceived) : this(byBuffer, 0, nReceived) - { - } - - public IpHeader(System.IO.Stream stream) - { - BinaryReader binaryReader = new BinaryReader(stream); - } - - public IpHeader([System.Runtime.InteropServices.WindowsRuntime.ReadOnlyArray()] - byte[] byBuffer, int position, int nReceived) : - this(new BinaryReader(new MemoryStream(byBuffer, position, nReceived - position))) - {/* - // Create MemoryStream out of the received bytes. - MemoryStream memoryStream = new MemoryStream(byBuffer, position, nReceived - position); - // Next we create a BinaryReader out of the MemoryStream. - BinaryReader binaryReader = new BinaryReader(memoryStream); - - return new IpHeader(binaryReader);*/ - } - - public IpHeader(BinaryReader binaryReader) - { - this.initialize(binaryReader); - } - - private void initialize(BinaryReader binaryReader) - { - try - { - // The first eight bits of the IP header contain the version and - // header length so we read them. - _versionAndHeaderLength = binaryReader.ReadByte(); - // The next eight bits contain the Differentiated services. - _differentiatedServices = binaryReader.ReadByte(); - // Next eight bits hold the total length of the datagram. - _totalLength = (ushort)IPAddress.NetworkToHostOrder( - binaryReader.ReadInt16()); - // Next sixteen have the identification bytes. - _identification = (ushort)IPAddress.NetworkToHostOrder( - binaryReader.ReadInt16()); - // Next sixteen bits contain the flags and fragmentation offset. - _flagsAndOffset = (ushort)IPAddress.NetworkToHostOrder( - binaryReader.ReadInt16()); - // Next eight bits have the TTL value. - _ttl = binaryReader.ReadByte(); - // Next eight represnts the protocol encapsulated in the datagram. - _protocol = binaryReader.ReadByte(); - // Next sixteen bits contain the checksum of the header. - _checksum = IPAddress.NetworkToHostOrder(binaryReader.ReadInt16()); - // Next thirty two bits have the source IP address. - _sourceIPAddress = (uint)(binaryReader.ReadInt32()); - // Next thirty two hold the destination IP address. - _destinationIPAddress = (uint)(binaryReader.ReadInt32()); - // Now we calculate the header length. - _headerLength = _versionAndHeaderLength; - // The last four bits of the version and header length field contain the - // header length, we perform some simple binary airthmatic operations to - // extract them. - _headerLength <<= 4; - _headerLength >>= 4; - // Multiply by four to get the exact header length. - _headerLength *= 4; - // Copy the data carried by the data gram into another array so that - // according to the protocol being carried in the IP datagram - _ipData = binaryReader.ReadBytes(_totalLength - _headerLength); -/* Array.Copy(byBuffer, _headerLength, _ipData, 0, - _totalLength - _headerLength);*/ - } - catch (Exception ex) - { - - VPNHelper.LogLine(ex.Message); - } - } - - public byte[] IpPacket - { - get { return _ipPacket; } - } - - public string Version - { - get - { - // Calculate the IP version. The four bits of the IP header - // contain the IP version. - if ((_versionAndHeaderLength >> 4) == 4) - { - return "IP v4"; - } - else if ((_versionAndHeaderLength >> 4) == 6) - { - return "IP v6"; - } - else - { - return "Unknown"; - } - } - } - - public string HeaderLength - { - get - { - return _headerLength.ToString(); - } - } - - public ushort MessageLength - { - get - { - // MessageLength = Total length of the datagram - Header length. - return (ushort)(_totalLength - _headerLength); - } - } - - public string DifferentiatedServices - { - get - { - // Returns the differentiated services in hexadecimal format. - return string.Format("0x{0:x2} ({1})", _differentiatedServices, - _differentiatedServices); - } - } - - public string Flags - { - get - { - // The first three bits of the flags and fragmentation field - // represent the flags (which indicate whether the data is - // fragmented or not). - int nFlags = _flagsAndOffset >> 13; - if (nFlags == 2) - { - return "Don't fragment"; - } - else if (nFlags == 1) - { - return "More fragments to come"; - } - else - { - return nFlags.ToString(); - } - } - } - - public string FragmentationOffset - { - get - { - // The last thirteen bits of the flags and fragmentation field - // contain the fragmentation offset. - int nOffset = _flagsAndOffset << 3; - nOffset >>= 3; - return nOffset.ToString(); - } - } - - public string TTL - { - get - { - return _ttl.ToString(); - } - } - - public Protocol ProtocolType - { - get - { - // The protocol field represents the protocol in the data portion - // of the datagram. - if (_protocol == 6) // A value of six represents the TCP protocol. - { - return Protocol.TCP; - } - else if (_protocol == 17) // Seventeen for UDP. - { - return Protocol.UDP; - } - else - { - return Protocol.Unknown; - } - } - } - - public string Checksum - { - get - { - // Returns the checksum in hexadecimal format. - return string.Format("0x{0:x2}", _checksum); - } - } - - public IPAddress SourceAddress - { - get - { - return new IPAddress(_sourceIPAddress); - } - } - - public IPAddress DestinationAddress - { - get - { - return new IPAddress(_destinationIPAddress); - } - } - - public ushort TotalLength - { - get - { - return _totalLength; - } - } - - public string Identification - { - get - { - return _identification.ToString(); - } - } - - public byte[] Data - { - get - { - return _ipData; - } - } - - - public string ToLoooongString() - { - StringBuilder b = new StringBuilder(); - b.Append("Checksum: "); - b.Append(this.Checksum); - //b.Append("Data: "); - //b.Append(this.Data); - b.Append(" DestinationAddress: "); - b.Append(this.DestinationAddress); - b.Append(" DifferentiatedServices: "); - b.Append(this.DifferentiatedServices); - b.Append(" Flags: "); - b.Append(this.Flags); - b.Append(" FragmentationOffset: "); - b.Append(this.FragmentationOffset); - b.Append(" HeaderLength: "); - b.Append(this.HeaderLength); - b.Append(" Identification: "); - b.Append(this.Identification); - b.Append(" MessageLength: "); - b.Append(this.MessageLength); - b.Append(" ProtocolType: "); - b.Append(this.ProtocolType); - b.Append(" ChecksumIP: "); - b.Append(this.Checksum); - b.Append(" SourceAddress: "); - b.Append(this.SourceAddress); - b.Append(" TTL: "); - b.Append(this.TTL); - b.Append(" TotalLength: "); - b.Append(this.TotalLength); - b.Append(" Version: "); - b.Append(this.Version); - - return b.ToString(); - } - - - public static IEnumerable FromStream(Stream stream) - { - IpHeader header = new IpHeader(); - - byte[] _ipPacket = header._ipPacket; - int readResult = stream.Read(_ipPacket, 0, 4); - while (readResult > 0) - { - byte[] pktBytes = new byte[2] { _ipPacket[2], _ipPacket[3] }; - if (BitConverter.IsLittleEndian) - { - Array.Reverse(pktBytes); - } - - ushort utotalIpPacketLen = BitConverter.ToUInt16(pktBytes, 0); - - int totalIpPacketLen = utotalIpPacketLen - 4; - readResult = stream.Read(_ipPacket, 4, totalIpPacketLen); - if (readResult > 0) - { - using (MemoryStream ms = new MemoryStream(_ipPacket)) - using (BinaryReader br = new BinaryReader(ms)) - { - header.initialize(br); - } - } - - yield return header; - - header = new IpHeader(); - _ipPacket = header._ipPacket; - readResult = stream.Read(_ipPacket, 0, 4); - } - } - - } - - internal class Hex - { - public static byte[] StringToByteArrayFastest(string hex) - { - if (hex.Length % 2 == 1) - throw new Exception("The binary key cannot have an odd number of digits"); - - byte[] arr = new byte[hex.Length >> 1]; - - for (int i = 0; i < hex.Length >> 1; ++i) - { - arr[i] = (byte)((GetHexVal(hex[i << 1]) << 4) + (GetHexVal(hex[(i << 1) + 1]))); - } - - return arr; - } - - public static int GetHexVal(char hex) - { - int val = (int)hex; - //For uppercase A-F letters: - return val - (val < 58 ? 48 : 55); - //For lowercase a-f letters: - //return val - (val < 58 ? 48 : 87); - //Or the two combined, but a bit slower: - //return val - (val < 58 ? 48 : (val < 97 ? 55 : 87)); - } - } -} diff --git a/ZitiBackgroundTask/Properties/AssemblyInfo.cs b/ZitiBackgroundTask/Properties/AssemblyInfo.cs deleted file mode 100644 index c16cccae..00000000 --- a/ZitiBackgroundTask/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("ZitiBackgroundTask")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("")] -[assembly: AssemblyProduct("ZitiBackgroundTask")] -[assembly: AssemblyCopyright("Copyright © 2019")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] -[assembly: ComVisible(false)] \ No newline at end of file diff --git a/ZitiBackgroundTask/VPNHelper.cs b/ZitiBackgroundTask/VPNHelper.cs deleted file mode 100644 index cb92c2f3..00000000 --- a/ZitiBackgroundTask/VPNHelper.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using Windows.Networking.Vpn; - -namespace NetFoundry.VPN -{ - public sealed class VPNHelper - { - - public static void ConnectReal() - { - - } - public void ConnectDebug() - { - - } - public static void LogLine(string text, VpnChannel channel) - { - System.Diagnostics.Debug.WriteLine("__X___: " + Environment.CurrentManagedThreadId + ":" + - channel?.GetHashCode() + ":" + text); - } - - public static void LogLine(string text) - { - LogLine(text, null); - } - } -} \ No newline at end of file diff --git a/ZitiBackgroundTask/ZitiBackgroundTask.csproj b/ZitiBackgroundTask/ZitiBackgroundTask.csproj deleted file mode 100644 index c5dee93f..00000000 --- a/ZitiBackgroundTask/ZitiBackgroundTask.csproj +++ /dev/null @@ -1,172 +0,0 @@ - - - - - Debug - AnyCPU - {7393400B-5F2D-493C-BC39-AB3198A9749F} - winmdobj - Properties - NetFoundry.VPN - ZitiBackgroundTask - en-US - UAP - 10.0.17763.0 - 10.0.17763.0 - 14 - 512 - {A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} - false - - - AnyCPU - true - full - false - bin\Debug\ - DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP - prompt - 4 - - - AnyCPU - pdbonly - true - bin\Release\ - TRACE;NETFX_CORE;WINDOWS_UWP - prompt - 4 - - - x86 - true - bin\x86\Debug\ - DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP - ;2008 - full - false - prompt - - - x86 - bin\x86\Release\ - TRACE;NETFX_CORE;WINDOWS_UWP - true - ;2008 - pdbonly - false - prompt - - - ARM - true - bin\ARM\Debug\ - DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP - ;2008 - full - false - prompt - - - ARM - bin\ARM\Release\ - TRACE;NETFX_CORE;WINDOWS_UWP - true - ;2008 - pdbonly - false - prompt - - - ARM64 - true - bin\ARM64\Debug\ - DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP - ;2008 - full - false - prompt - - - ARM64 - bin\ARM64\Release\ - TRACE;NETFX_CORE;WINDOWS_UWP - true - ;2008 - pdbonly - false - prompt - - - x64 - true - bin\x64\Debug\ - DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP - ;2008 - full - false - prompt - - - x64 - bin\x64\Release\ - TRACE;NETFX_CORE;WINDOWS_UWP - true - ;2008 - pdbonly - false - prompt - - - PackageReference - - - - - - - - - - - - - - - - - - - - - - - - - 6.2.8 - - - 12.0.3 - - - 1.8.6 - - - 4.5.3 - - - - 14.0 - - - - - - - \ No newline at end of file diff --git a/ZitiBackgroundTask/src/VPNTask.cs b/ZitiBackgroundTask/src/VPNTask.cs deleted file mode 100644 index dfe44884..00000000 --- a/ZitiBackgroundTask/src/VPNTask.cs +++ /dev/null @@ -1,67 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Windows.ApplicationModel.Background; -using Windows.Networking; -using Windows.Networking.Sockets; -using Windows.Networking.Vpn; -using Windows.Storage.Streams; -using System.Diagnostics; -using System.Threading; -using System.Runtime.InteropServices.WindowsRuntime; -using NetFoundry.VPN.Util; - - -namespace NetFoundry.VPN -{ - public sealed class VPNTask : IBackgroundTask - { - - internal static IVpnPlugIn ziti = null; - private static object lockobj = new object(); - - public void Run(IBackgroundTaskInstance taskInstance) - { - var backgroundTaskDeferral = taskInstance.GetDeferral(); - try - { - taskInstance.Canceled += TaskInstance_Canceled; - VpnChannel.ProcessEventAsync(GetPlugin(), taskInstance.TriggerDetails); - } - catch (Exception e) - { - LogHelper.LogLine("An exception occurred. " + e.Message); - LogHelper.LogLine(e.StackTrace); - } - finally - { - backgroundTaskDeferral.Complete(); - } - } - - private void TaskInstance_Canceled(IBackgroundTaskInstance sender, BackgroundTaskCancellationReason reason) - { - LogHelper.LogLine("TaskInstance_Canceled_a_" + sender.ToString()); - LogHelper.LogLine("TaskInstance_Canceled_b_" + reason.ToString()); - - VpnChannel.ProcessEventAsync(GetPlugin(), sender.TriggerDetails); - - LogHelper.LogLine("TaskInstance_Canceled - done. it has been triggered"); - } - - public static IVpnPlugIn GetPlugin() - { - lock (lockobj) { - if (ziti == null) - { - LogHelper.LogLine("singleton ziti plugin created"); - ziti = new ZitiVPNPlugin(); - } - } - - return ziti; - } - } -} diff --git a/ZitiBackgroundTask/src/VpnPluginContext.cs b/ZitiBackgroundTask/src/VpnPluginContext.cs deleted file mode 100644 index 4df738eb..00000000 --- a/ZitiBackgroundTask/src/VpnPluginContext.cs +++ /dev/null @@ -1,81 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -using Windows.Networking; -using Windows.Networking.Sockets; -using Windows.Networking.Vpn; - -namespace NetFoundry.VPN -{ - public sealed class VpnPluginContext - { - internal static VpnPluginContext CURRENT_CONTEXT = new VpnPluginContext(); - - public static VpnPluginContext GetActiveContext() - { - return CURRENT_CONTEXT; - } - public static void ResetActiveContext() - { - CURRENT_CONTEXT = new VpnPluginContext(); - } - - internal IReadOnlyList assignedClientIPv4list = null; - internal IReadOnlyList assignedClientIPv6list = null; - internal VpnDomainNameAssignment vpnDomainNameAssignmenta = new VpnDomainNameAssignment(); - internal VpnRouteAssignment vpnRouteAssignmenta = new VpnRouteAssignment { ExcludeLocalSubnets = false }; - - internal const uint VPN_MTU = 0x4000;//0xFF00; //16 * 1024; //(2 << 15) - 1; - - //internal const uint VPN_MAX_FRAME = 0xFF00; // 16* 1024; // * 32; //(2 << 15) - 1; - internal const uint VPN_MAX_FRAME = 0x00F0; // 16* 1024; // * 32; //(2 << 15) - 1; - - internal List suffixes = new List(); - internal List fqdns = new List(); - internal List routes = new List(); - internal List ipsToCapture = new List(); - - private HostName dns { get; set; } - public HostName DnsServer - { - get - { - return dns; - } - set - { - dns = value; - //dnsServers.Clear(); - //dnsServers.Add(dns); - } - } - - public void addSuffix(string suffix) - { - suffixes.Add(suffix); - } - public void addFQDN(string suffix) - { - fqdns.Add(suffix); - } - /* Maybe implement this some day - public void AddCIDR(string ip) - { - string[] parts = ip.Split('/'); - if (parts.Length != 2) - { - throw new Exception("Invalid CIDR format supplied."); - } - routes.Add(new VpnRoute(new HostName(parts[0]), Byte.Parse(parts[1]))); - }*/ - - public void AddIP(string ip) - { - ipsToCapture.Add(ip); - routes.Add(new VpnRoute(new HostName(ip), 32)); - } - } -} diff --git a/ZitiBackgroundTask/src/VpnPluginState.cs b/ZitiBackgroundTask/src/VpnPluginState.cs deleted file mode 100644 index 760e8059..00000000 --- a/ZitiBackgroundTask/src/VpnPluginState.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace NetFoundry.VPN -{ - enum VpnPluginState - { - Disconnected, - Connecting, - Connected, - Disconnecting - } -} diff --git a/ZitiBackgroundTask/src/ZitiVPNPlugin.cs b/ZitiBackgroundTask/src/ZitiVPNPlugin.cs deleted file mode 100644 index 9bc3d5e3..00000000 --- a/ZitiBackgroundTask/src/ZitiVPNPlugin.cs +++ /dev/null @@ -1,296 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Net; -using System.Text; -using System.Threading.Tasks; -using Windows.Networking.Vpn; -using Windows.Networking.Sockets; -using Windows.Storage.Streams; -using Windows.Networking; -using System.Runtime.InteropServices.WindowsRuntime; -using Windows.ApplicationModel.Background; -using System.Net.Sockets; -using System.Security.Cryptography; -using Buffer = System.Buffer; -using NetFoundry.VPN.IP; -using NetFoundry.VPN.Util; - -namespace NetFoundry.VPN -{ - public sealed class ZitiVPNPlugin : IVpnPlugIn - { - internal static int DESIRED_PORT = 8900; - internal static string DESIRED_HOST = "192.168.1.114"; - StreamSocket tcpTransport = null; - - VpnPluginContext vpnContext = VpnPluginContext.GetActiveContext(); - - public ZitiVPNPlugin() - { - Task.Run(() => - { - //start up a server that listens locally and just emits what it receives - NetFoundry.VPN.Debugging.DebugTcpServer.Start(); - }); - } - - public void Connect(VpnChannel channel) - { - try - { - HostName tcpHostname = new HostName(DESIRED_HOST); - string tcpPort = DESIRED_PORT.ToString(); - tcpTransport = new StreamSocket(); - tcpTransport.ConnectAsync(tcpHostname, tcpPort).AsTask().Wait(); //this will succeed... proving you CAN connect... - tcpTransport.CancelIOAsync().AsTask().Wait(); - tcpTransport.Dispose(); //close/dispose of the connection - - tcpTransport = new StreamSocket(); - channel.AssociateTransport(tcpTransport, null); - tcpTransport.ConnectAsync(tcpHostname, tcpPort).AsTask().Wait(); //fails with "no host is known". AssociateTransport is 'doing something' - - string desiredIP = "169.254.100.101"; - - VpnDomainNameAssignment vpnDomainNameAssignment = new VpnDomainNameAssignment(); - - List dnsServers = new List(); - dnsServers.Add(vpnContext.DnsServer); - - List proxyServers = new List(); - //proxyServers not used yet - - foreach (string suf in vpnContext.suffixes) - { - addSuffix(vpnDomainNameAssignment, suf, dnsServers, proxyServers); - } - - foreach (string fqdn in vpnContext.fqdns) - { - addFQDN(vpnDomainNameAssignment, fqdn, dnsServers, proxyServers); - } - - var vpnRouteAssignment = new VpnRouteAssignment { ExcludeLocalSubnets = false }; - var inclusionRoutes = vpnRouteAssignment.Ipv4InclusionRoutes; - foreach (VpnRoute route in vpnContext.routes) - { - LogHelper.LogLine("Adding an included route: " + route, channel); - inclusionRoutes.Add(route); - } - - VpnInterfaceId vpnInterfaceId = null; - - channel.StartWithMainTransport( - new[] { new HostName(desiredIP) }, //this will only succeed if the ip is not 'localhost', 'hostname', '127.0.0.1' etc. must be 'off machine' - vpnContext.assignedClientIPv6list, - vpnInterfaceId, - vpnRouteAssignment, - vpnDomainNameAssignment, - VpnPluginContext.VPN_MTU, - VpnPluginContext.VPN_MAX_FRAME, - false, - tcpTransport); - } - catch (Exception e) - { - LogHelper.LogLine(e.Message); - } - } - - public void addSuffix(VpnDomainNameAssignment domainNameAssignment, string suffix, IEnumerable dnsServers, IEnumerable proxyServers) - { - var vdni1 = new VpnDomainNameInfo(suffix, VpnDomainNameType.Suffix, dnsServers, proxyServers); - domainNameAssignment.DomainNameList.Add(vdni1); - } - public void addFQDN(VpnDomainNameAssignment domainNameAssignment, string suffix, IEnumerable dnsServers, IEnumerable proxyServers) - { - var vdni1 = new VpnDomainNameInfo(suffix, VpnDomainNameType.FullyQualified, dnsServers, proxyServers); - domainNameAssignment.DomainNameList.Add(vdni1); - } - - public async void Disconnect(VpnChannel channel) - { - VpnPluginContext.ResetActiveContext(); - try - { - await tcpTransport?.CancelIOAsync(); - tcpTransport?.Dispose(); - }catch(Exception e) - { - LogHelper.LogLine("bad stuff: " + e.Message); - } - } - - public void GetKeepAlivePayload(VpnChannel channel, out VpnPacketBuffer keepAlivePacket) - { - throw new NotImplementedException(); - } - - public void Encapsulate(VpnChannel channel, VpnPacketBufferList packets, VpnPacketBufferList encapulatedPackets) - { - while (packets?.Size > 0) - { - var packet = packets.RemoveAtBegin(); - VpnAppId packetAppId = packet.AppId; - Windows.Storage.Streams.Buffer packetBuffer = packet.Buffer; - DataReader fromBuffer = DataReader.FromBuffer(packetBuffer); - uint fromBufferUnconsumedBufferLength = fromBuffer.UnconsumedBufferLength; - byte[] bytes = new byte[fromBufferUnconsumedBufferLength]; - fromBuffer.ReadBytes(bytes); - - int bytesRead = bytes.Count(); - - - IpHeader ipHeader = new IpHeader(bytes, bytesRead); - string sourcePort = "0"; - string destPort = "0"; - - // Now according to the protocol being carried by the IP datagram we parse - // the data field of the datagram. - switch (ipHeader.Protocol) - { - case Protocol.TCP: - TcpHeader tcpHeader = new TcpHeader(ipHeader.Data, ipHeader.MessageLength, ipHeader); - - // If the port is equal to 53 then the underlying protocol is DNS. - // Note: DNS can use either TCP or UDP hence checking is done twice. - if (tcpHeader.DestinationPort == "53" || tcpHeader.SourcePort == "53") - { - //DnsHeader dnsHeader = new DnsHeader(ipHeader.Data, (int)ipHeader.MessageLength); - //dnsHeader.PrintDebug(); - //LogLine(dnsHeader.ToString()); - } - - sourcePort = tcpHeader.SourcePort; - destPort = tcpHeader.DestinationPort; - - - LogHelper.LogLine("ENCAP: " + tcpHeader.ToShortString()); - LogHelper.LogLine("ENCAP: " + tcpHeader.ToLoooongString()); - //LogLine("ENCAP: " + BinaryVisualiser.FormatAsHex(ipHeader.Data, ipHeader.MessageLength)); - LogHelper.LogLine("ENCAP: TOTAL BYTES:" + bytesRead + "\n" + - BinaryVisualiser.FormatAsHex(bytes, bytesRead)); - - break; - case Protocol.UDP: - UdpHeader udpHeader = new UdpHeader(ipHeader.Data, (int)ipHeader.MessageLength); - //TreeNode udpNode = MakeUDPTreeNode(udpHeader); - //rootNode.Nodes.Add(udpNode); - // If the port is equal to 53 then the underlying protocol is DNS. - // Note: DNS can use either TCP or UDP, thats the reason - // why the checking has been done twice. - if (udpHeader.DestinationPort == "53" || udpHeader.SourcePort == "53") - { - //DnsHeader dnsHeader = new DnsHeader(ipHeader.Data, (int)ipHeader.MessageLength); - //dnsHeader.PrintDebug(); - //LogLine(dnsHeader.ToString()); - } - - sourcePort = udpHeader.SourcePort; - destPort = udpHeader.DestinationPort; - break; - default: - LogHelper.LogLine("THE PACKET WAS NOT TCP NOR UDP: Protocol = " + ipHeader.Protocol.GetName()); - break; - } - - string msg = null; - - - if (vpnContext.ipsToCapture.Contains(ipHeader.DestinationAddress.ToString())) - { - msg = string.Format("SUCCESS!!!! type:{0}. from {1}:{3} to {2}:{4}", ipHeader.Protocol, - ipHeader.SourceAddress, ipHeader.DestinationAddress, sourcePort, destPort); - encapulatedPackets.Append(packet); - } - else - { - msg = string.Format("refusing to send {4} from {0}:{2} to {1}:{3}", ipHeader.SourceAddress, - ipHeader.DestinationAddress, sourcePort, destPort, ipHeader.Protocol); - - } - - LogHelper.LogLine(msg, channel); - } - } - - public void Decapsulate(VpnChannel channel, VpnPacketBuffer encapBuffer, VpnPacketBufferList decapsulatedPackets, VpnPacketBufferList controlPacketsToSend) - { - try - { - var buf = channel.GetVpnReceivePacketBuffer(); - - - if (encapBuffer.Buffer.Length > buf.Buffer.Capacity) - { - LogHelper.LogLine( - "DROPPING PACKET!!! " + encapBuffer.Buffer.Length + - " bytes. This is bigger than the buffer capacity of: " + encapBuffer.Buffer.Length, channel); - } - else - { - byte[] bytes = encapBuffer.Buffer.ToArray(); - - LogHelper.LogLine("DECAP: OVERALL PAYLOAD:" + bytes.Length + "\n" + - BinaryVisualiser.FormatAsHex(bytes, bytes.Length)); - - - int srcOffset = 0; - foreach (IpHeader h in IpHeader.FromStream(new MemoryStream(bytes))) - { - if (buf == null) - { - buf = channel.GetVpnReceivePacketBuffer(); - } - - TcpHeader tcpHeader = new TcpHeader(h.Data, h.MessageLength, h); - - LogHelper.LogLine("DECAP: " + tcpHeader.ToShortString()); - LogHelper.LogLine("DECAP: " + tcpHeader.ToLoooongString()); - LogHelper.LogLine("DECAP: TOTAL BYTES:" + h.TotalLength + "\n" + - BinaryVisualiser.FormatAsHex(h.IpPacket, h.TotalLength)); - - encapBuffer.Buffer.CopyTo((uint)srcOffset, buf.Buffer, 0, h.TotalLength); - - buf.Buffer.Length = h.TotalLength; - - decapsulatedPackets.Append(buf); - buf = null; - srcOffset += h.TotalLength; - } - - if (encapBuffer != null) return; - - int remainingBytes = (int)encapBuffer.Buffer.Length; - Span bytesAsSpan = new Span(bytes); - System.IO.Stream stream = encapBuffer.Buffer.AsStream(); - - while (remainingBytes > 0) - { - IpHeader ipHeader = new IpHeader(stream); - - LogHelper.LogLine(ipHeader.ToLoooongString()); - LogHelper.LogLine(BinaryVisualiser.FormatAsHex(bytes, ipHeader.TotalLength)); - - encapBuffer.Buffer.CopyTo((uint)srcOffset, buf.Buffer, 0, ipHeader.TotalLength); - buf.Buffer.Length = ipHeader.TotalLength; - decapsulatedPackets.Append(buf); - - srcOffset += ipHeader.TotalLength; - remainingBytes -= ipHeader.TotalLength; - - buf = channel.GetVpnReceivePacketBuffer(); //get a new buffer... - } - - return; - } - } - catch (Exception e) - { - LogHelper.LogLine("exception???? " + e.Message); - } - } - } -} \ No newline at end of file diff --git a/ZitiBackgroundTask/src/_backup_eligable_to_delete/IpHeader.cs b/ZitiBackgroundTask/src/_backup_eligable_to_delete/IpHeader.cs deleted file mode 100644 index df7b7187..00000000 --- a/ZitiBackgroundTask/src/_backup_eligable_to_delete/IpHeader.cs +++ /dev/null @@ -1,273 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net; -using System.Security.AccessControl; -using System.Security.Cryptography; -using System.Text; -using System.Threading.Tasks; - -namespace NetFoundry.IP -{ - internal sealed class IpHeader - { - const ushort fragmentOffsetMask = 0b0001_1111_1111_1111; // 13 bits for fragment offset - - // The entire IP packet - private byte[] networkBytes; - - public IpHeader(byte[] networkBytes) - { - this.networkBytes = networkBytes; - - using (MemoryStream ms = new MemoryStream(networkBytes)) - using (BinaryReader br = new BinaryReader(ms)) - { - initialize(br); - } - } - - private void initialize(BinaryReader networkBytes) - { - try - { - // see https://tools.ietf.org/html/rfc791#page-11 - // 0 1 2 3 - // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // |Version| IHL |Type of Service| Total Length | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | Identification |Flags| Fragment Offset | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | Time to Live | Protocol | Header Checksum | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | Source Address | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | Destination Address | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | Options | Padding | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // - // Example Internet Datagram Header - - // byte 1 - The first eight bits of the IP header contain the version and - // header length. read the byte and then shift it to get the version - // and header len - byte versionAndHeaderLength = networkBytes.ReadByte(); - - VersionAsInt = versionAndHeaderLength >> 4; // shift the byte to get the bits we want - - // Calculate the IP version. The four bits of the IP header - // contain the IP version. - if (VersionAsInt == 4) - { - Version = "IP v4"; - } - else if (VersionAsInt == 6) - { - Version = "IP v6"; - } - else - { - Version = "Unknown"; - } - - // ip header length is contained in the last 4 bytes... - //mask off the first 4 bytes and then per the spec the result - //is a 4 bit field tells us the length of the IP header in 32 bit increments (4 bytes) - HeaderLength = (versionAndHeaderLength & 0xF) * 4; - - // byte 2 - TypeOfService = networkBytes.ReadByte(); - - // bytes 3, 4 - TotalLength = (ushort)IPAddress.NetworkToHostOrder(networkBytes.ReadInt16()); - - // bytes 5, 6 - identification bytes. - Identification = (ushort)IPAddress.NetworkToHostOrder(networkBytes.ReadInt16()); - - // bytes 7, 8 - flags and fragment offset - ushort flagsAndFragmentOffset = (ushort)IPAddress.NetworkToHostOrder(networkBytes.ReadInt16()); - Flags = (byte)(flagsAndFragmentOffset >> 13); // shift 13 bits to get the first 3 - FragmentOffset = (ushort)(flagsAndFragmentOffset & fragmentOffsetMask); //mask the lower 13 bits - - // byte 9 - TimeToLive = networkBytes.ReadByte(); - - // byte 10 - Protocol = (Protocol)networkBytes.ReadByte(); - - // byte 11, 12 - HeaderChecksum = (ushort)IPAddress.NetworkToHostOrder(networkBytes.ReadInt16()); - - // bytes 13 - 16 - SourceAddress = new IPAddress(networkBytes.ReadBytes(4)); - - // bytes 17 - 20 - DestinationAddress = new IPAddress(networkBytes.ReadBytes(4)); - } - catch (Exception ex) - { - ZitiBackgroundTask.ZitiVPNPlugin.LogLine(ex.Message); - } - } - - // first 4 bits of the first byte. using int for convinience with other apis - public int VersionAsInt { get; set; } - public string Version { get; set; } - - // last 4 bits of the first byte is the total HeaderLength length. using int for convinience with other apis - public int HeaderLength { get; set; } - - // 1 byte - public byte TypeOfService { get; set; } - - // 2 bytes - public ushort TotalLength { get; set; } - - // 2 bytes - public ushort Identification { get; set; } - - // 3 bits - byte closest thing - public byte Flags { get; set; } - - // 13 bits - ushort closest thing... - public ushort FragmentOffset { get; set; } - - // 1 byte - public int TimeToLive { get; set; } - - // 1 byte - public Protocol Protocol { get; set; } - - // 2 bytes - public ushort HeaderChecksum { get; set; } - - // 4 bytes - public IPAddress SourceAddress { get; set; } - - // 4 bytes - public IPAddress DestinationAddress { get; set; } - - // 4 bytes - public byte[] Options { get; set; } - - /* - public ushort MessageLength - { - get - { - // MessageLength = Total length of the datagram - Header length. - return (ushort)(_totalLength - _headerLength); - } - } - - public string DifferentiatedServices - { - get - { - // Returns the differentiated services in hexadecimal format. - return string.Format("0x{0:x2} ({1})", _differentiatedServices, _differentiatedServices); - } - } - - public string Flags - { - get - { - // The first three bits of the flags and fragmentation field - // represent the flags (which indicate whether the data is - // fragmented or not). - int nFlags = _flagsAndOffset >> 13; - if (nFlags == 2) - { - return "Don't fragment"; - } - else if (nFlags == 1) - { - return "More fragments to come"; - } - else - { - return nFlags.ToString(); - } - } - } - - public string FragmentationOffset - { - get - { - // The last thirteen bits of the flags and fragmentation field - // contain the fragmentation offset. - int nOffset = _flagsAndOffset << 3; - nOffset >>= 3; - return nOffset.ToString(); - } - } - - public string TTL - { - get - { - return _ttl.ToString(); - } - } - - public Protocol ProtocolType - { - get - { - // The protocol field represents the protocol in the data portion - // of the datagram. - if (_protocol == 6) // A value of six represents the TCP protocol. - { - return Protocol.TCP; - } - else if (_protocol == 17) // Seventeen for UDP. - { - return Protocol.UDP; - } - else - { - return Protocol.Unknown; - } - } - } - - public string Checksum - { - get - { - // Returns the checksum in hexadecimal format. - return string.Format("0x{0:x2}", _checksum); - } - } - - public IPAddress SourceAddress - { - get - { - return new IPAddress(_sourceIPAddress); - } - } - - public IPAddress DestinationAddress - { - get - { - return new IPAddress(_destinationIPAddress); - } - } - - public string Identification - { - get - { - return _identification.ToString(); - } - }*/ - } -} - \ No newline at end of file diff --git a/ZitiBackgroundTask/src/_backup_eligable_to_delete/Packet.cs b/ZitiBackgroundTask/src/_backup_eligable_to_delete/Packet.cs deleted file mode 100644 index 08bff627..00000000 --- a/ZitiBackgroundTask/src/_backup_eligable_to_delete/Packet.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices.WindowsRuntime; -using System.Text; -using System.Threading.Tasks; - -namespace NetFoundry.IP -{ - internal class Packet - { - internal IpHeader ipHeader; - internal byte[] bytes; - - internal Packet() - { - //for the subclasses... - } - - public Packet([ReadOnlyArray]byte[] networkBytes) - { - ipHeader = new IpHeader(networkBytes); - } - } -} - -namespace ZitiBackgroundTask.Ziti -{ - public sealed class IpPacket - { - private NetFoundry.IP.Packet ipPacket; - - public IpPacket([ReadOnlyArray]byte[] networkBytes) - { - ipPacket = new NetFoundry.IP.Packet(networkBytes); - } - } -} \ No newline at end of file diff --git a/ZitiBackgroundTask/src/_backup_eligable_to_delete/Protocol.cs b/ZitiBackgroundTask/src/_backup_eligable_to_delete/Protocol.cs deleted file mode 100644 index 67db19c2..00000000 --- a/ZitiBackgroundTask/src/_backup_eligable_to_delete/Protocol.cs +++ /dev/null @@ -1,162 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace NetFoundry.IP -{ - internal enum Protocol - { - //see https://en.wikipedia.org/wiki/List_of_IP_protocol_numbers - Unknown = -1, - HOPOPT = 0, //IPv6 Hop-by-Hop Option - ICMP = 1, //Internet Control Message Protocol - IGMP = 2, //Internet Group Management Protocol - GGP = 3, //Gateway-to-Gateway Protocol - IP_in_IP = 4, //IP in IP (encapsulation) - ST = 5, //Internet Stream Protocol - TCP = 6, //Transmission Control Protocol - CBT = 7, //Core-based trees - EGP = 8, //Exterior Gateway Protocol - IGP = 9, //Interior Gateway Protocol (any private interior gateway (used by Cisco for their IGRP)) - BBN_RCC_MON = 10, //BBN RCC Monitoring - NVP_II = 11, //Network Voice Protocol - PUP = 12, //Xerox PUP - ARGUS = 13, //ARGUS - EMCON = 14, //EMCON - XNET = 15, //Cross Net Debugger - CHAOS = 16, //Chaos - UDP = 17, //User Datagram Protocol - MUX = 18, //Multiplexing - DCN_MEAS = 19, //DCN Measurement Subsystems - HMP = 20, //Host Monitoring Protocol - PRM = 21, //Packet Radio Measurement - XNS_IDP = 22, //XEROX NS IDP - TRUNK_1 = 23, //Trunk-1 - TRUNK_2 = 24, //Trunk-2 - LEAF_1 = 25, //Leaf-1 - LEAF_2 = 26, //Leaf-2 - RDP = 27, //Reliable Data Protocol - IRTP = 28, //Internet Reliable Transaction Protocol - ISO_TP4 = 29, //ISO Transport Protocol Class 4 - NETBLT = 30, //Bulk Data Transfer Protocol - MFE_NSP = 31, //MFE Network Services Protocol - MERIT_INP = 32, //MERIT Internodal Protocol - DCCP = 33, //Datagram Congestion Control Protocol - THIRD_PARTY_CONNECT = 34, //Third Party Connect Protocol - IDPR = 35, //Inter-Domain Policy Routing Protocol - XTP = 36, //Xpress Transport Protocol - DDP = 37, //Datagram Delivery Protocol - IDPR_CMTP = 38, //IDPR Control Message Transport Protocol - TPplusplus = 39, //TP++ Transport Protocol - IL = 40, //IL Transport Protocol - IPv6 = 41, //IPv6 Encapsulation - SDRP = 42, //Source Demand Routing Protocol - IPv6_Route = 43, //Routing Header for IPv6 - IPv6_Frag = 44, //Fragment Header for IPv6 - IDRP = 45, //Inter-Domain Routing Protocol - RSVP = 46, //Resource Reservation Protocol - GREs = 47, //Generic Routing Encapsulation - DSR = 48, //Dynamic Source Routing Protocol - BNA = 49, //Burroughs Network Architecture - ESP = 50, //Encapsulating Security Payload - AH = 51, //Authentication Header - I_NLSP = 52, //Integrated Net Layer Security Protocol - SwIPe = 53, //SwIPe - NARP = 54, //NBMA Address Resolution Protocol - MOBILE = 55, //IP Mobility (Min Encap) - TLSP = 56, //Transport Layer Security Protocol (using Kryptonet key management) - SKIP = 57, //Simple Key-Management for Internet Protocol - IPv6_ICMP = 58, //ICMP for IPv6 - IPv6_NoNxt = 59, //No Next Header for IPv6 - IPv6_Opts = 60, //Destination Options for IPv6 - HOST_INTERNAL_PROTOCOL = 61, //Any host internal protocol - CFTP = 62, //CFTP - LOCAL_NETWORK = 63, //Any local network - SAT_EXPAK = 64, //SATNET and Backroom EXPAK - KRYPTOLAN = 65, //Kryptolan - RVD = 66, //MIT Remote Virtual Disk Protocol - IPPC = 67, //Internet Pluribus Packet Core - DISTRIBUTED_FS = 68, //Any distributed file system - SAT_MON = 69, //SATNET Monitoring - VISA = 70, //VISA Protocol - IPCU = 71, //Internet Packet Core Utility - CPNX = 72, //Computer Protocol Network Executive - CPHB = 73, //Computer Protocol Heart Beat - WSN = 74, //Wang Span Network - PVP = 75, //Packet Video Protocol - BR_SAT_MON = 76, //Backroom SATNET Monitoring - SUN_ND = 77, //SUN ND PROTOCOL-Temporary - WB_MON = 78, //WIDEBAND Monitoring - WB_EXPAK = 79, //WIDEBAND EXPAK - ISO_IP = 80, //International Organization for Standardization Internet Protocol - VMTP = 81, //Versatile Message Transaction Protocol - SECURE_VMTP = 82, //Secure Versatile Message Transaction Protocol - VINES = 83, //VINES - TTP = 84, //TTP - IPTM = 84, //Internet Protocol Traffic Manager - NSFNET_IGP = 85, //NSFNET-IGP - DGP = 86, //Dissimilar Gateway Protocol - TCF = 87, //TCF - EIGRP = 88, //EIGRP - OSPF = 89, //Open Shortest Path First - Sprite_RPC = 90, //Sprite RPC Protocol - LARP = 91, //Locus Address Resolution Protocol - MTP = 92, //Multicast Transport Protocol - AX_25 = 93, //AX.25 - OS = 94, //KA9Q NOS compatible IP over IP tunneling - MICP = 95, //Mobile Internetworking Control Protocol - SCC_SP = 96, //Semaphore Communications Sec. Pro - ETHERIP = 97, //Ethernet-within-IP Encapsulation - ENCAP = 98, //Encapsulation Header - PRIVATE_ENCRYPTION = 99, //Any private encryption scheme - GMTP = 100, //GMTP - IFMP = 101, //Ipsilon Flow Management Protocol - PNNI = 102, //PNNI over IP - PIM = 103, //Protocol Independent Multicast - ARIS = 104, //IBM's ARIS (Aggregate Route IP Switching) Protocol - SCPS = 105, //SCPS (Space Communications Protocol Standards) - QNX = 106, //QNX - ACTIVE_NETWORKS = 107, //Active Networks - IPComp = 108, //IP Payload Compression Protocol - SNP = 109, //Sitara Networks Protocol - Compaq_Peer = 110, //Compaq Peer Protocol - IPX_in_IP = 111, //IPX in IP - VRRP = 112, //Virtual Router Redundancy Protocol, Common Address Redundancy Protocol (not IANA assigned) - PGM = 113, //PGM Reliable Transport Protocol - ANY_HOP = 114, //Any 0-hop protocol - L2TP = 115, //Layer Two Tunneling Protocol Version 3 - DDX = 116, //D-II Data Exchange (DDX) - IATP = 117, //Interactive Agent Transfer Protocol - STP = 118, //Schedule Transfer Protocol - SRP = 119, //SpectraLink Radio Protocol - UTI = 120, //Universal Transport Interface Protocol - SMP = 121, //Simple Message Protocol - SM = 122, //Simple Multicast Protocol - PTP = 123, //Performance Transparency Protocol - IS_IS_over_IPv4 = 124, //Intermediate System to Intermediate System (IS-IS) Protocol over IPv4 - FIRE = 125, //Flexible Intra-AS Routing Environment - CRTP = 126, //Combat Radio Transport Protocol - CRUDP = 127, //Combat Radio User Datagram - SSCOPMCE = 128, //Service-Specific Connection-Oriented Protocol in a Multilink and Connectionless Environment - IPLT = 129, // - SPS = 130, //Secure Packet Shield - PIPE = 131, //Private IP Encapsulation within IP - SCTP = 132, //Stream Control Transmission Protocol - FC = 133, //Fibre Channel - RSVP_E2E_IGNORE = 134, //Reservation Protocol (RSVP) End-to-End Ignore - Mobility_Header = 135, //Mobility Extension Header for IPv6 - UDPLite = 136, //Lightweight User Datagram Protocol - MPLS_in_IP = 137, //Multiprotocol Label Switching Encapsulated in IP - manet = 138, //MANET Protocols - HIP = 139, //Host Identity Protocol - Shim6 = 140, //Site Multihoming by IPv6 Intermediation - WESP = 141, //Wrapped Encapsulating Security Payload - ROHC = 142, //Robust Header Compression - - //Unassigned = 143 - 252, // - //Use for experimentation and testing = 253 - 254, // - Reserved = 255, // - }; -} \ No newline at end of file diff --git a/ZitiBackgroundTask/src/_backup_eligable_to_delete/TCP.cs b/ZitiBackgroundTask/src/_backup_eligable_to_delete/TCP.cs deleted file mode 100644 index 77b41798..00000000 --- a/ZitiBackgroundTask/src/_backup_eligable_to_delete/TCP.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace NetFoundry.IP -{ - internal sealed class Tcp : Packet - { - private Tcp() - { - } - } -} \ No newline at end of file diff --git a/ZitiBackgroundTask/src/_backup_eligable_to_delete/UDP.cs b/ZitiBackgroundTask/src/_backup_eligable_to_delete/UDP.cs deleted file mode 100644 index 6bd2aa52..00000000 --- a/ZitiBackgroundTask/src/_backup_eligable_to_delete/UDP.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace NetFoundry.IP -{ - internal sealed class Udp : Packet - { - - private Udp() - { - } - } -} \ No newline at end of file diff --git a/ZitiBackgroundTask/src/debugging/DebugTcpServer.cs b/ZitiBackgroundTask/src/debugging/DebugTcpServer.cs deleted file mode 100644 index ea9fba94..00000000 --- a/ZitiBackgroundTask/src/debugging/DebugTcpServer.cs +++ /dev/null @@ -1,58 +0,0 @@ -// This code is adapted from a sample found at the URL -// "http://blogs.msdn.com/b/jmanning/archive/2004/12/19/325699.aspx" - -using System; -using System.Net; -using System.Net.Sockets; -using System.IO; -using System.Text; - -namespace NetFoundry.VPN.Debugging -{ - public sealed class DebugTcpServer - { - static void Main(string[] args) - { - DebugTcpServer.Start(); - Console.WriteLine("listening. press any key to quit"); - Console.ReadKey(); - } - - private static bool started = false; - public static void Start() - { - started = false; - if (started) return; - started = true; - - Console.WriteLine("Starting echo server..."); - - TcpListener listener = new TcpListener(IPAddress.Loopback, ZitiVPNPlugin.DESIRED_PORT); - listener.Start(); - - while (true) - { - TcpClient client = listener.AcceptTcpClient(); - System.Threading.Tasks.Task.Run(() => - { - NetworkStream stream = client.GetStream(); - StreamWriter writer = new StreamWriter(stream, Encoding.ASCII) { AutoFlush = true }; - StreamReader reader = new StreamReader(stream, Encoding.ASCII); - - try - { - string inputLine = ""; - while (inputLine != null) - { - inputLine = reader.ReadLine(); - writer.WriteLine("Echoing string: " + inputLine); - Console.WriteLine("Echoing string: " + inputLine); - } - } - catch { /* don't really care at this point */} - Console.WriteLine("Server saw disconnect from client."); - }); - } - } - } -} \ No newline at end of file diff --git a/ZitiBackgroundTask/src/ip/DnsHeader.cs b/ZitiBackgroundTask/src/ip/DnsHeader.cs deleted file mode 100644 index 6fe8de73..00000000 --- a/ZitiBackgroundTask/src/ip/DnsHeader.cs +++ /dev/null @@ -1,115 +0,0 @@ -using System.Net; -using System; -using System.IO; - -namespace NetFoundry.VPN.IP -{ - /// - /// This class encapsulates all the DNS header fields and provides a mechanism - /// to set and get the details of them through a parameterized contructor - /// and public properties respectively. - /// - internal sealed class DnsHeader - { - public void PrintDebug() - { - System.Diagnostics.Debug.WriteLine("DNS"); - System.Diagnostics.Debug.WriteLine(" Identification: " + Identification); - System.Diagnostics.Debug.WriteLine(" Flags: " + Flags); - System.Diagnostics.Debug.WriteLine(" Questions: " + TotalQuestions); - System.Diagnostics.Debug.WriteLine(" Answer RRs: " + TotalAnswerRRs); - System.Diagnostics.Debug.WriteLine(" Authority RRs: " + TotalAuthorityRRs); - System.Diagnostics.Debug.WriteLine(" Additional RRs: " + TotalAdditionalRRs); - } - - // Sixteen bits for identification. - private ushort UsIdentification; - // Sixteen bits for DNS flags. - private ushort UsFlags; - // Sixteen bits indicating the number of entries in the questions list. - private ushort UsTotalQuestions; - // Sixteen bits indicating the number of entries in the answer - // resource record list. - private ushort UsTotalAnswerRRs; - // Sixteen bits indicating the number of entries in the authority - // resource record list. - private ushort UsTotalAuthorityRRs; - // Sixteen bits indicating the number of entries in the additional - // resource record list. - private ushort UsTotalAdditionalRRs; - - public DnsHeader([System.Runtime.InteropServices.WindowsRuntime.ReadOnlyArray()] byte[]byBuffer, int nReceived) - { - - // Create MemoryStream out of the received bytes. - MemoryStream memoryStream = new MemoryStream(byBuffer, 0, nReceived); - // Next we create a BinaryReader out of the MemoryStream. - BinaryReader binaryReader = new BinaryReader(memoryStream); - // First sixteen bits are for identification. - UsIdentification = (ushort)IPAddress.NetworkToHostOrder( - binaryReader.ReadInt16()); - // Next sixteen contain the flags. - UsFlags = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16()); - // Read the total numbers of questions in the quesion list. - UsTotalQuestions = (ushort)IPAddress.NetworkToHostOrder( - binaryReader.ReadInt16()); - // Read the total number of answers in the answer list. - UsTotalAnswerRRs = (ushort)IPAddress.NetworkToHostOrder( - binaryReader.ReadInt16()); - // Read the total number of entries in the authority list. - UsTotalAuthorityRRs = (ushort)IPAddress.NetworkToHostOrder( - binaryReader.ReadInt16()); - // Total number of entries in the additional resource record list. - UsTotalAdditionalRRs = (ushort)IPAddress.NetworkToHostOrder( - binaryReader.ReadInt16()); - } - - public string Identification - { - get - { - return string.Format("0x{0:x2}", UsIdentification); - } - } - - public string Flags - { - get - { - return string.Format("0x{0:x2}", UsFlags); - } - } - - public string TotalQuestions - { - get - { - return UsTotalQuestions.ToString(); - } - } - - public string TotalAnswerRRs - { - get - { - return UsTotalAnswerRRs.ToString(); - } - } - - public string TotalAuthorityRRs - { - get - { - return UsTotalAuthorityRRs.ToString(); - } - } - - public string TotalAdditionalRRs - { - get - { - return UsTotalAdditionalRRs.ToString(); - } - } - } -} diff --git a/ZitiBackgroundTask/src/ip/ICMP.cs b/ZitiBackgroundTask/src/ip/ICMP.cs deleted file mode 100644 index 51eec10e..00000000 --- a/ZitiBackgroundTask/src/ip/ICMP.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace NetFoundry.VPN.IP -{ - internal sealed class Icmp : Packet - { - - private Icmp() { } - } -} \ No newline at end of file diff --git a/ZitiBackgroundTask/src/ip/IpHeader.cs b/ZitiBackgroundTask/src/ip/IpHeader.cs deleted file mode 100644 index e085b1b3..00000000 --- a/ZitiBackgroundTask/src/ip/IpHeader.cs +++ /dev/null @@ -1,360 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net; -using System.Security.AccessControl; -using System.Security.Cryptography; -using System.Text; -using System.Threading.Tasks; -using System.Runtime.InteropServices.WindowsRuntime; - -using NetFoundry.VPN.Util; - -namespace NetFoundry.VPN.IP -{ - internal sealed class IpHeader - { - const ushort fragmentOffsetMask = 0b0001_1111_1111_1111; // 13 bits for fragment offset - - // The entire IP packet - private byte[] networkBytes; - - public IpHeader(byte[] networkBytes) : this(networkBytes, 0, networkBytes.Length) - { - } - - private IpHeader() - { - //private use only - } - - public IpHeader([ReadOnlyArray()] byte[] networkBytes, int nReceived) : this(networkBytes, 0, nReceived) - { - } - - public IpHeader(System.IO.Stream stream) - { - BinaryReader binaryReader = new BinaryReader(stream); - } - - public IpHeader([ReadOnlyArray()] byte[] networkBytes, int position, int nReceived) /*: this(new BinaryReader(new MemoryStream(networkBytes, position, nReceived - position))) - */ - { - this.networkBytes = networkBytes; - - using (MemoryStream ms = new MemoryStream(networkBytes)) - using (BinaryReader br = new BinaryReader(ms)) - { - initialize(br); - } - } - - private IpHeader(BinaryReader binaryReader) - { - this.initialize(binaryReader); - } - - private void initialize(BinaryReader bytesAsReader) - { - try - { - // see https://tools.ietf.org/html/rfc791#page-11 - // 0 1 2 3 - // 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // |Version| IHL |Type of Service| Total Length | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | Identification |Flags| Fragment Offset | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | Time to Live | Protocol | Header Checksum | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | Source Address | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | Destination Address | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // | Options | Padding | - // +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - // - // Example Internet Datagram Header - - // byte 1 - The first eight bits of the IP header contain the version and - // header length. read the byte and then shift it to get the version - // and header len - byte versionAndHeaderLength = bytesAsReader.ReadByte(); - - VersionAsInt = versionAndHeaderLength >> 4; // shift the byte to get the bits we want - - // Calculate the IP version. The four bits of the IP header - // contain the IP version. - if (VersionAsInt == 4) - { - Version = "IP v4"; - } - else if (VersionAsInt == 6) - { - Version = "IP v6"; - } - else - { - Version = "Unknown"; - } - - // ip header length is contained in the last 4 bytes... - //mask off the first 4 bytes and then per the spec the result - //is a 4 bit field tells us the length of the IP header in 32 bit increments (4 bytes) - HeaderLength = (versionAndHeaderLength & 0xF) * 4; - - // byte 2 - TypeOfService = bytesAsReader.ReadByte(); - - // bytes 3, 4 - TotalLength = (ushort)IPAddress.NetworkToHostOrder(bytesAsReader.ReadInt16()); - - // bytes 5, 6 - identification bytes. - Identification = (ushort)IPAddress.NetworkToHostOrder(bytesAsReader.ReadInt16()); - - // bytes 7, 8 - flags and fragment offset - ushort flagsAndFragmentOffset = (ushort)IPAddress.NetworkToHostOrder(bytesAsReader.ReadInt16()); - Flags = (byte)(flagsAndFragmentOffset >> 13); // shift 13 bits to get the first 3 - FragmentOffset = (ushort)(flagsAndFragmentOffset & fragmentOffsetMask); //mask the lower 13 bits - - // byte 9 - TimeToLive = bytesAsReader.ReadByte(); - - // byte 10 - Protocol = (Protocol)bytesAsReader.ReadByte(); - - // byte 11, 12 - HeaderChecksum = (ushort)IPAddress.NetworkToHostOrder(bytesAsReader.ReadInt16()); - - // bytes 13 - 16 - SourceAddress = new IPAddress(bytesAsReader.ReadBytes(4)); - - // bytes 17 - 20 - DestinationAddress = new IPAddress(bytesAsReader.ReadBytes(4)); - } - catch (Exception ex) - { - LogHelper.LogLine(ex.Message); - } - } - - // first 4 bits of the first byte. using int for convinience with other apis - public int VersionAsInt { get; set; } - /*int _version; - public int Version - { - get { return _version; } - set { _version = value; } - }*/ - public string Version { get; set; } - - /* - public byte _headerLength; - // last 4 bits of the first byte is the total HeaderLength length. using int for convinience with other apis - public byte HeaderLength - { - get { return _headerLength; } - set { _headerLength = value; } - }*/ - public int HeaderLength { get; set; } - - // 1 byte - public byte TypeOfService { get; set; } - - // 2 bytes - public ushort TotalLength { get; set; } - - // 2 bytes - public ushort Identification { get; set; } - - // 3 bits - byte closest thing - public byte Flags { get; set; } - - // 13 bits - ushort closest thing... - public ushort FragmentOffset { get; set; } - - // 1 byte - public int TimeToLive { get; set; } - - // 1 byte - public Protocol Protocol { get; set; } - - // 2 bytes - public ushort HeaderChecksum { get; set; } - - // 4 bytes - public IPAddress SourceAddress { get; set; } - - // 4 bytes - public IPAddress DestinationAddress { get; set; } - - // 4 bytes - public byte[] Options { get; set; } - - public ushort MessageLength - { - get - { - // MessageLength = Total length of the datagram - Header length. - return (ushort)(TotalLength - HeaderLength); - } - } - - public string DifferentiatedServices - { - get - { - // Returns the differentiated services in hexadecimal format. - return string.Format("0x{0:x2} ({1})", DifferentiatedServices, DifferentiatedServices); - } - } - - /*public string Flags - { - get - { - // The first three bits of the flags and fragmentation field - // represent the flags (which indicate whether the data is - // fragmented or not). - int nFlags = _flagsAndOffset >> 13; - if (nFlags == 2) - { - return "Don't fragment"; - } - else if (nFlags == 1) - { - return "More fragments to come"; - } - else - { - return nFlags.ToString(); - } - } - }*/ - - public string FragmentationOffset - { - get - { - // The last thirteen bits of the flags and fragmentation field - // contain the fragmentation offset. - int nOffset = Flags << 3; - nOffset >>= 3; - return nOffset.ToString(); - } - } - - public string TTL - { - get - { - return TTL.ToString(); - } - } - - public string Checksum - { - get - { - // Returns the checksum in hexadecimal format. - return string.Format("0x{0:x2}", Checksum); - } - } - - - - public byte[] Data - { - get - { - return networkBytes; - } - } - - - public string ToLoooongString() - { - StringBuilder b = new StringBuilder(); - b.Append("Checksum: "); - b.Append(this.Checksum); - //b.Append("Data: "); - //b.Append(this.Data); - b.Append(" DestinationAddress: "); - b.Append(this.DestinationAddress); - b.Append(" DifferentiatedServices: "); - b.Append(this.DifferentiatedServices); - b.Append(" Flags: "); - b.Append(this.Flags); - b.Append(" FragmentationOffset: "); - b.Append(this.FragmentationOffset); - b.Append(" HeaderLength: "); - b.Append(this.HeaderLength); - b.Append(" Identification: "); - b.Append(this.Identification); - b.Append(" MessageLength: "); - b.Append(this.MessageLength); - b.Append(" ProtocolType: "); - b.Append(this.Protocol.GetName()); - b.Append(" ChecksumIP: "); - b.Append(this.Checksum); - b.Append(" SourceAddress: "); - b.Append(this.SourceAddress); - b.Append(" TTL: "); - b.Append(this.TTL); - b.Append(" TotalLength: "); - b.Append(this.TotalLength); - b.Append(" Version: "); - b.Append(this.Version); - - return b.ToString(); - } - public byte[] IpPacket - { - get { return networkBytes; } - } - - - public static IEnumerable FromStream(Stream stream) - { - IpHeader header = new IpHeader(); - - byte[] _ipPacket = header.networkBytes; - int readResult = stream.Read(_ipPacket, 0, 4); - while (readResult > 0) - { - byte[] pktBytes = new byte[2] { _ipPacket[2], _ipPacket[3] }; - if (BitConverter.IsLittleEndian) - { - Array.Reverse(pktBytes); - } - - ushort utotalIpPacketLen = BitConverter.ToUInt16(pktBytes, 0); - - int totalIpPacketLen = utotalIpPacketLen - 4; - readResult = stream.Read(_ipPacket, 4, totalIpPacketLen); - if (readResult > 0) - { - using (MemoryStream ms = new MemoryStream(_ipPacket)) - using (BinaryReader br = new BinaryReader(ms)) - { - header.initialize(br); - } - } - - yield return header; - - header = new IpHeader(); - _ipPacket = header.networkBytes; - readResult = stream.Read(_ipPacket, 0, 4); - } - } - - public void WriteTo(System.IO.Stream stream) - { - stream.Write(networkBytes, 0, TotalLength); - } - } -} - \ No newline at end of file diff --git a/ZitiBackgroundTask/src/ip/Packet.cs b/ZitiBackgroundTask/src/ip/Packet.cs deleted file mode 100644 index c17e9ad0..00000000 --- a/ZitiBackgroundTask/src/ip/Packet.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.InteropServices.WindowsRuntime; -using System.Text; -using System.Threading.Tasks; - -namespace NetFoundry.VPN.IP -{ - internal class Packet - { - internal IpHeader ipHeader; - - internal Packet() - { - //for the subclasses... - } - - public Packet([ReadOnlyArray]byte[] networkBytes) - { - ipHeader = new IpHeader(networkBytes); - } - } -} \ No newline at end of file diff --git a/ZitiBackgroundTask/src/ip/Protocol.cs b/ZitiBackgroundTask/src/ip/Protocol.cs deleted file mode 100644 index 50db9bf4..00000000 --- a/ZitiBackgroundTask/src/ip/Protocol.cs +++ /dev/null @@ -1,170 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace NetFoundry.VPN.IP -{ - internal static class ProtocolExtensionMethod - { - internal static string GetName(this Protocol theEnum) - { - return Enum.GetName(typeof(Protocol), theEnum); - } - } - - internal enum Protocol - { - //see https://en.wikipedia.org/wiki/List_of_IP_protocol_numbers - Unknown = -1, - HOPOPT = 0, //IPv6 Hop-by-Hop Option - ICMP = 1, //Internet Control Message Protocol - IGMP = 2, //Internet Group Management Protocol - GGP = 3, //Gateway-to-Gateway Protocol - IP_in_IP = 4, //IP in IP (encapsulation) - ST = 5, //Internet Stream Protocol - TCP = 6, //Transmission Control Protocol - CBT = 7, //Core-based trees - EGP = 8, //Exterior Gateway Protocol - IGP = 9, //Interior Gateway Protocol (any private interior gateway (used by Cisco for their IGRP)) - BBN_RCC_MON = 10, //BBN RCC Monitoring - NVP_II = 11, //Network Voice Protocol - PUP = 12, //Xerox PUP - ARGUS = 13, //ARGUS - EMCON = 14, //EMCON - XNET = 15, //Cross Net Debugger - CHAOS = 16, //Chaos - UDP = 17, //User Datagram Protocol - MUX = 18, //Multiplexing - DCN_MEAS = 19, //DCN Measurement Subsystems - HMP = 20, //Host Monitoring Protocol - PRM = 21, //Packet Radio Measurement - XNS_IDP = 22, //XEROX NS IDP - TRUNK_1 = 23, //Trunk-1 - TRUNK_2 = 24, //Trunk-2 - LEAF_1 = 25, //Leaf-1 - LEAF_2 = 26, //Leaf-2 - RDP = 27, //Reliable Data Protocol - IRTP = 28, //Internet Reliable Transaction Protocol - ISO_TP4 = 29, //ISO Transport Protocol Class 4 - NETBLT = 30, //Bulk Data Transfer Protocol - MFE_NSP = 31, //MFE Network Services Protocol - MERIT_INP = 32, //MERIT Internodal Protocol - DCCP = 33, //Datagram Congestion Control Protocol - THIRD_PARTY_CONNECT = 34, //Third Party Connect Protocol - IDPR = 35, //Inter-Domain Policy Routing Protocol - XTP = 36, //Xpress Transport Protocol - DDP = 37, //Datagram Delivery Protocol - IDPR_CMTP = 38, //IDPR Control Message Transport Protocol - TPplusplus = 39, //TP++ Transport Protocol - IL = 40, //IL Transport Protocol - IPv6 = 41, //IPv6 Encapsulation - SDRP = 42, //Source Demand Routing Protocol - IPv6_Route = 43, //Routing Header for IPv6 - IPv6_Frag = 44, //Fragment Header for IPv6 - IDRP = 45, //Inter-Domain Routing Protocol - RSVP = 46, //Resource Reservation Protocol - GREs = 47, //Generic Routing Encapsulation - DSR = 48, //Dynamic Source Routing Protocol - BNA = 49, //Burroughs Network Architecture - ESP = 50, //Encapsulating Security Payload - AH = 51, //Authentication Header - I_NLSP = 52, //Integrated Net Layer Security Protocol - SwIPe = 53, //SwIPe - NARP = 54, //NBMA Address Resolution Protocol - MOBILE = 55, //IP Mobility (Min Encap) - TLSP = 56, //Transport Layer Security Protocol (using Kryptonet key management) - SKIP = 57, //Simple Key-Management for Internet Protocol - IPv6_ICMP = 58, //ICMP for IPv6 - IPv6_NoNxt = 59, //No Next Header for IPv6 - IPv6_Opts = 60, //Destination Options for IPv6 - HOST_INTERNAL_PROTOCOL = 61, //Any host internal protocol - CFTP = 62, //CFTP - LOCAL_NETWORK = 63, //Any local network - SAT_EXPAK = 64, //SATNET and Backroom EXPAK - KRYPTOLAN = 65, //Kryptolan - RVD = 66, //MIT Remote Virtual Disk Protocol - IPPC = 67, //Internet Pluribus Packet Core - DISTRIBUTED_FS = 68, //Any distributed file system - SAT_MON = 69, //SATNET Monitoring - VISA = 70, //VISA Protocol - IPCU = 71, //Internet Packet Core Utility - CPNX = 72, //Computer Protocol Network Executive - CPHB = 73, //Computer Protocol Heart Beat - WSN = 74, //Wang Span Network - PVP = 75, //Packet Video Protocol - BR_SAT_MON = 76, //Backroom SATNET Monitoring - SUN_ND = 77, //SUN ND PROTOCOL-Temporary - WB_MON = 78, //WIDEBAND Monitoring - WB_EXPAK = 79, //WIDEBAND EXPAK - ISO_IP = 80, //International Organization for Standardization Internet Protocol - VMTP = 81, //Versatile Message Transaction Protocol - SECURE_VMTP = 82, //Secure Versatile Message Transaction Protocol - VINES = 83, //VINES - TTP = 84, //TTP - IPTM = 84, //Internet Protocol Traffic Manager - NSFNET_IGP = 85, //NSFNET-IGP - DGP = 86, //Dissimilar Gateway Protocol - TCF = 87, //TCF - EIGRP = 88, //EIGRP - OSPF = 89, //Open Shortest Path First - Sprite_RPC = 90, //Sprite RPC Protocol - LARP = 91, //Locus Address Resolution Protocol - MTP = 92, //Multicast Transport Protocol - AX_25 = 93, //AX.25 - OS = 94, //KA9Q NOS compatible IP over IP tunneling - MICP = 95, //Mobile Internetworking Control Protocol - SCC_SP = 96, //Semaphore Communications Sec. Pro - ETHERIP = 97, //Ethernet-within-IP Encapsulation - ENCAP = 98, //Encapsulation Header - PRIVATE_ENCRYPTION = 99, //Any private encryption scheme - GMTP = 100, //GMTP - IFMP = 101, //Ipsilon Flow Management Protocol - PNNI = 102, //PNNI over IP - PIM = 103, //Protocol Independent Multicast - ARIS = 104, //IBM's ARIS (Aggregate Route IP Switching) Protocol - SCPS = 105, //SCPS (Space Communications Protocol Standards) - QNX = 106, //QNX - ACTIVE_NETWORKS = 107, //Active Networks - IPComp = 108, //IP Payload Compression Protocol - SNP = 109, //Sitara Networks Protocol - Compaq_Peer = 110, //Compaq Peer Protocol - IPX_in_IP = 111, //IPX in IP - VRRP = 112, //Virtual Router Redundancy Protocol, Common Address Redundancy Protocol (not IANA assigned) - PGM = 113, //PGM Reliable Transport Protocol - ANY_HOP = 114, //Any 0-hop protocol - L2TP = 115, //Layer Two Tunneling Protocol Version 3 - DDX = 116, //D-II Data Exchange (DDX) - IATP = 117, //Interactive Agent Transfer Protocol - STP = 118, //Schedule Transfer Protocol - SRP = 119, //SpectraLink Radio Protocol - UTI = 120, //Universal Transport Interface Protocol - SMP = 121, //Simple Message Protocol - SM = 122, //Simple Multicast Protocol - PTP = 123, //Performance Transparency Protocol - IS_IS_over_IPv4 = 124, //Intermediate System to Intermediate System (IS-IS) Protocol over IPv4 - FIRE = 125, //Flexible Intra-AS Routing Environment - CRTP = 126, //Combat Radio Transport Protocol - CRUDP = 127, //Combat Radio User Datagram - SSCOPMCE = 128, //Service-Specific Connection-Oriented Protocol in a Multilink and Connectionless Environment - IPLT = 129, // - SPS = 130, //Secure Packet Shield - PIPE = 131, //Private IP Encapsulation within IP - SCTP = 132, //Stream Control Transmission Protocol - FC = 133, //Fibre Channel - RSVP_E2E_IGNORE = 134, //Reservation Protocol (RSVP) End-to-End Ignore - Mobility_Header = 135, //Mobility Extension Header for IPv6 - UDPLite = 136, //Lightweight User Datagram Protocol - MPLS_in_IP = 137, //Multiprotocol Label Switching Encapsulated in IP - manet = 138, //MANET Protocols - HIP = 139, //Host Identity Protocol - Shim6 = 140, //Site Multihoming by IPv6 Intermediation - WESP = 141, //Wrapped Encapsulating Security Payload - ROHC = 142, //Robust Header Compression - - //Unassigned = 143 - 252, // - //Use for experimentation and testing = 253 - 254, // - Reserved = 255, // - }; -} \ No newline at end of file diff --git a/ZitiBackgroundTask/src/ip/TCP.cs b/ZitiBackgroundTask/src/ip/TCP.cs deleted file mode 100644 index f42bf2b4..00000000 --- a/ZitiBackgroundTask/src/ip/TCP.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace NetFoundry.VPN.IP -{ - internal sealed class Tcp : Packet - { - private Tcp() - { - } - } -} \ No newline at end of file diff --git a/ZitiBackgroundTask/src/ip/TcpHeader.cs b/ZitiBackgroundTask/src/ip/TcpHeader.cs deleted file mode 100644 index 67438ce9..00000000 --- a/ZitiBackgroundTask/src/ip/TcpHeader.cs +++ /dev/null @@ -1,293 +0,0 @@ -using System.Net; -using System; -using System.IO; -using System.Text; -using NetFoundry.VPN.Util; - -namespace NetFoundry.VPN.IP -{ - /// - /// This class encapsulates all the TCP header fields and provides a mechanism - /// to set and get the details of them through a parameterized contructor - /// and public properties respectively. - /// - sealed class TcpHeader - { - private IpHeader ipHeader = null; - - // Sixteen bits for the source port number. - private ushort _sourcePort; - // Sixteen bits for the destination port number. - private ushort _destinationPort; - // Thirty two bits for the sequence number. - private uint _sequenceNumber = 555; - // Thirty two bits for the acknowledgement number. - private uint _acknowledgementNumber = 555; - // Sixteen bits for flags and data offset. - private ushort _dataOffsetAndFlags = 555; - // Sixteen bits for the window size. - private ushort _window = 555; - // Sixteen bits for the checksum, (checksum can be negative so taken as short). - private short _checksum = 555; - // Sixteen bits for the urgent pointer. - private ushort _urgentPointer; - // Header length. - private byte _headerLength; - // Length of the data being carried. - private ushort _messageLength; - // Data carried by the TCP packet. - private byte[] _tcpData = new byte[2 << 15]; - - - internal void WriteTo(System.IO.Stream stream) - { - - } - - public TcpHeader([System.Runtime.InteropServices.WindowsRuntime.ReadOnlyArray()] byte[] byBuffer, int nReceived, IpHeader ipHeader) - { - this.ipHeader = ipHeader; - try - { - // Create MemoryStream out of the received bytes. - MemoryStream memoryStream = new MemoryStream(byBuffer, 0, nReceived); - // Next we create a BinaryReader out of the MemoryStream. - BinaryReader binaryReader = new BinaryReader(memoryStream); - // The first sixteen bits contain the source port. - _sourcePort = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16()); - // The next sixteen contain the destiination port. - _destinationPort = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16()); - // Next thirty two have the sequence number. - _sequenceNumber = (uint)IPAddress.NetworkToHostOrder(binaryReader.ReadInt32()); - // Next thirty two have the acknowledgement number. - _acknowledgementNumber = (uint)IPAddress.NetworkToHostOrder(binaryReader.ReadInt32()); - // The next sixteen bits hold the flags and the data offset. - _dataOffsetAndFlags = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16()); - // The next sixteen contain the window size. - _window = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16()); - // In the next sixteen we have the checksum. - _checksum = (short)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16()); - // The following sixteen contain the urgent pointer. - _urgentPointer = (ushort)IPAddress.NetworkToHostOrder(binaryReader.ReadInt16()); - // The data offset indicates where the data begins, so using it we - // calculate the header length. - _headerLength = (byte)(_dataOffsetAndFlags >> 12); - _headerLength *= 4; - // Message length = Total length of the TCP packet - Header length. - _messageLength = (ushort)(nReceived - _headerLength); - // Copy the TCP data into the data buffer. - Array.Copy(byBuffer, _headerLength, _tcpData, 0, - nReceived - _headerLength); - } - catch (Exception ex) - { - LogHelper.LogLine(ex.Message); - } - } - - public string ToShortString() - { - string src = ipHeader.SourceAddress.MapToIPv4().ToString(); - string dst = ipHeader.DestinationAddress.MapToIPv4().ToString(); - - return string.Format("tcp from {0}:{1} to {2}:{3}. payload: {4}. ", src, SourcePort, dst, DestinationPort, MessageLength); - } - - public string ToLoooongString() - { - StringBuilder b = new StringBuilder(); - //b.Append(ipHeader.ToLoooongString()); - b.Append(" SequenceNumber: "); - b.Append(this.SequenceNumber); - b.Append(" AckNo: "); - b.Append(this.AcknowledgementNumber); - b.Append(" ChecksumTCP: "); - b.Append(this.Checksum); - //b.Append("Data: "); - //b.Append(this.Data); - b.Append(" DestinationPort: "); - b.Append(this.DestinationPort); - b.Append(" Flags: "); - b.Append(this.Flags); - b.Append(" HeaderLength: "); - b.Append(this.HeaderLength); - b.Append(" MessageLength: "); - b.Append(this.MessageLength); - b.Append(" SourcePort: "); - b.Append(this.SourcePort); - b.Append(" UrgentPointer: "); - b.Append(this.UrgentPointer); - b.Append(" WindowSize: "); - b.Append(this.WindowSize); - - return b.ToString(); - } - - public void WriteTo(TextWriter writer) - {/* - writer.WriteLine("ByVersionAndHeaderLength: " + ByVersionAndHeaderLength); - writer.WriteLine("ByDifferentiatedServices: " + ByDifferentiatedServices); - writer.WriteLine("UsTotalLength: " + UsTotalLength); - writer.WriteLine("UsIdentification: " + UsIdentification); - writer.WriteLine("usFlagsAndOffset: " + usFlagsAndOffset); - writer.WriteLine("ByTTL: " + ByTTL); - writer.WriteLine("ByProtocol: " + ByProtocol); - writer.WriteLine("SChecksum: " + SChecksum); - writer.WriteLine("UiSourceIPAddress: " + _sourceIPAddress); - writer.WriteLine("UiDestinationIPAddress: " + UiDestinationIPAddress); - writer.WriteLine("ByHeaderLength: " + ByHeaderLength); - writer.WriteLine("As Hex: "); - writer.WriteLine(BinaryVisualiser.FormatAsHex(Data, UsTotalLength));*/ - writer.WriteLine("NOT IMPLEMENTED YET"); - writer.Flush(); - } - - - - public string SourcePort - { - get - { - return _sourcePort.ToString(); - } - } - - public string DestinationPort - { - get - { - return _destinationPort.ToString(); - } - } - - public string SequenceNumber - { - get - { - return _sequenceNumber.ToString(); - } - } - - public string AcknowledgementNumber - { - get - { - // If the ACK flag is set then only we have a valid value in the - // acknowlegement field, so check for it beore returning anything. - if ((_dataOffsetAndFlags & 0x10) != 0) - { - return _acknowledgementNumber.ToString(); - } - else - { - return ""; - } - } - } - - public string HeaderLength - { - get - { - return _headerLength.ToString(); - } - } - - public string WindowSize - { - get - { - return _window.ToString(); - } - } - - public string UrgentPointer - { - get - { - // If the URG flag is set then only we have a valid value in the urgent - // pointer field, so check for it beore returning anything. - if ((_dataOffsetAndFlags & 0x20) != 0) - { - return _urgentPointer.ToString(); - } - else - { - return ""; - } - } - } - - public string Flags - { - get - { - // The last six bits of data offset and flags contain the control bits. - // First we extract the flags. - int nFlags = _dataOffsetAndFlags & 0x3F; - string strFlags = string.Format("0x{0:x2} (", nFlags); - // Now we start looking whether individual bits are set or not. - if ((nFlags & 0x01) != 0) - { - strFlags += "FIN, "; - } - if ((nFlags & 0x02) != 0) - { - strFlags += "SYN, "; - } - if ((nFlags & 0x04) != 0) - { - strFlags += "RST, "; - } - if ((nFlags & 0x08) != 0) - { - strFlags += "PSH, "; - } - if ((nFlags & 0x10) != 0) - { - strFlags += "ACK, "; - } - if ((nFlags & 0x20) != 0) - { - strFlags += "URG"; - } - strFlags += ")"; - - if (strFlags.Contains("()")) - { - strFlags = strFlags.Remove(strFlags.Length - 3); - } - else if (strFlags.Contains(", )")) - { - strFlags = strFlags.Remove(strFlags.Length - 3, 2); - } - return strFlags; - } - } - - public string Checksum - { - get - { - // Return the checksum in hexadecimal format. - return string.Format("0x{0:x2}", _checksum); - } - } - - public byte[] Data - { - get - { - return _tcpData; - } - } - - public ushort MessageLength - { - get - { - return _messageLength; - } - } - } -} \ No newline at end of file diff --git a/ZitiBackgroundTask/src/ip/UDP.cs b/ZitiBackgroundTask/src/ip/UDP.cs deleted file mode 100644 index e159bf7a..00000000 --- a/ZitiBackgroundTask/src/ip/UDP.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace NetFoundry.VPN.IP -{ - internal sealed class Udp : Packet - { - - private Udp() - { - } - } -} \ No newline at end of file diff --git a/ZitiBackgroundTask/src/ip/UdpHeader.cs b/ZitiBackgroundTask/src/ip/UdpHeader.cs deleted file mode 100644 index 8a74f18f..00000000 --- a/ZitiBackgroundTask/src/ip/UdpHeader.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System.Net; -using System; -using System.IO; - -namespace NetFoundry.VPN.IP -{ - /// - /// This class encapsulates all the UDP header fields and provides a mechanism - /// to set and get the details of them through a parameterized contructor - /// and public properties respectively. - /// - public sealed class UdpHeader - { - // Sixteen bits for the source port number. - private ushort UsSourcePort; - // Sixteen bits for the destination port number. - private ushort UsDestinationPort; - // Length of the UDP header. - private ushort UsLength; - // Sixteen bits for the checksum (checksum can be negative so taken as short). - private short SChecksum; - // Data carried by the UDP packet. - private byte[] ByUDPData = new byte[4096]; - - public UdpHeader([System.Runtime.InteropServices.WindowsRuntime.ReadOnlyArray()] byte[] byBuffer, int nReceived) - { - // Create MemoryStream out of the received bytes. - MemoryStream memoryStream = new MemoryStream(byBuffer, 0, nReceived); - // Next we create a BinaryReader out of the MemoryStream. - BinaryReader binaryReader = new BinaryReader(memoryStream); - // The first sixteen bits contain the source port. - UsSourcePort = (ushort)IPAddress.NetworkToHostOrder( - binaryReader.ReadInt16()); - // The next sixteen bits contain the destination port. - UsDestinationPort = (ushort)IPAddress.NetworkToHostOrder( - binaryReader.ReadInt16()); - // The next sixteen bits contain the length of the UDP packet. - UsLength = (ushort)IPAddress.NetworkToHostOrder( - binaryReader.ReadInt16()); - // The next sixteen bits contain the checksum. - SChecksum = IPAddress.NetworkToHostOrder(binaryReader.ReadInt16()); - // Copy the data carried by the UDP packet into the data buffer. - Array.Copy(byBuffer, 8, ByUDPData, 0, nReceived - 8); - } - - public string SourcePort - { - get - { - return UsSourcePort.ToString(); - } - } - - public string DestinationPort - { - get - { - return UsDestinationPort.ToString(); - } - } - - public string Length - { - get - { - return UsLength.ToString (); - } - } - - public string Checksum - { - get - { - // Return the checksum in hexadecimal format. - return string.Format("0x{0:x2}", SChecksum); - } - } - - public byte[] Data - { - get - { - return ByUDPData; - } - } - } -} \ No newline at end of file diff --git a/ZitiBackgroundTask/src/util/BinaryVisualiser.cs b/ZitiBackgroundTask/src/util/BinaryVisualiser.cs deleted file mode 100644 index 4f291552..00000000 --- a/ZitiBackgroundTask/src/util/BinaryVisualiser.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace NetFoundry.VPN.Util -{ - public static class BinaryVisualiser - { - public static string FormatAsHex([System.Runtime.InteropServices.WindowsRuntime.ReadOnlyArrayAttribute] - byte[] dataAsBytes, int len) - { - ReadOnlySpan data = new ReadOnlySpan(dataAsBytes); - - byte ReplaceControlCharacterWithDot(byte character) - => character < 31 || character >= 127 ? (byte)46 /* dot */ : character; - - byte[] ReplaceControlCharactersWithDots(byte[] characters) - => characters.Select(ReplaceControlCharacterWithDot).ToArray(); - - var result = new StringBuilder(); - const int lineWidth = 16; - for (var pos = 0; pos < len;) - { - var line = data.Slice(pos, Math.Min(lineWidth, data.Length - pos)).ToArray(); - var asHex = string.Join(" ", - line.Select(v => v.ToString("X2", System.Globalization.CultureInfo.InvariantCulture))); - asHex += new string(' ', lineWidth * 3 - 1 - asHex.Length); - var asCharacters = Encoding.ASCII.GetString(ReplaceControlCharactersWithDots(line)); - result.Append(FormattableString.Invariant($"{pos:X4} {asHex} {asCharacters}\n")); - if (line.Length > 0) - { - pos += line.Length; - } - else - { - break; - } - } - - return result.ToString(); - } - } -} diff --git a/ZitiBackgroundTask/src/util/HexHelper.cs b/ZitiBackgroundTask/src/util/HexHelper.cs deleted file mode 100644 index abc13e66..00000000 --- a/ZitiBackgroundTask/src/util/HexHelper.cs +++ /dev/null @@ -1,92 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Diagnostics; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices.WindowsRuntime; -using System.Text; -using System.Threading.Tasks; - -namespace NetFoundry.VPN.Util -{ - public sealed class HexHelper - { - - public static string FormatAsHex([ReadOnlyArrayAttribute] byte[] dataAsBytes, int len) - { - return FormatAsHex(dataAsBytes, len, 16); - } - - public static string FormatAsHex([ReadOnlyArrayAttribute] byte[] dataAsBytes, int len, byte lineWidth) - { - ReadOnlySpan data = new ReadOnlySpan(dataAsBytes); - - byte ReplaceControlCharacterWithDot(byte character) - => character < 31 || character >= 127 ? (byte)46 /* dot */ : character; - - byte[] ReplaceControlCharactersWithDots(byte[] characters) - => characters.Select(ReplaceControlCharacterWithDot).ToArray(); - - var result = new StringBuilder(); - //const int lineWidth = 16; - for (var pos = 0; pos < len;) - { - var howManyBytes = Math.Min(lineWidth, len - pos); - var line = data.Slice(pos, howManyBytes).ToArray(); - var asHex = string.Join(" ", - line.Select(v => v.ToString("X2", System.Globalization.CultureInfo.InvariantCulture))); - asHex += new string(' ', lineWidth * 3 - 1 - asHex.Length); - var asCharacters = Encoding.ASCII.GetString(ReplaceControlCharactersWithDots(line)); - result.Append(FormattableString.Invariant($"{pos:X4} {asHex} {asCharacters}\n")); - if (line.Length > 0) - { - pos += line.Length; - } - else - { - break; - } - } - - return result.ToString().Remove(result.Length - 1); - } - - public static byte[] FromDelimitedString(string hex, char delimiter) - { - string[] strBytes = hex.Split(delimiter); - byte[] bytes = new byte[strBytes.Length]; - int i = 0; - foreach(string b in strBytes) - { - bytes[i++] = Byte.Parse(b); - } - return bytes; - } - - public static byte[] FromString(string hex) - { - if (hex.Length % 2 == 1) - throw new Exception("The binary key cannot have an odd number of digits"); - int hexLen = hex.Length / 2; - byte[] bytes = new byte[hexLen]; - for(int i = 0; i < hexLen; i++) - { - string strByte = hex.Substring(i * 2, 2); - Debug.WriteLine("READ: " + strByte); - bytes[i] = Byte.Parse(strByte, System.Globalization.NumberStyles.AllowHexSpecifier); - } - return bytes; - } - - public static int GetHexVal(char hex) - { - int val = (int)hex; - //For uppercase A-F letters: - return val - (val < 58 ? 48 : 55); - //For lowercase a-f letters: - //return val - (val < 58 ? 48 : 87); - //Or the two combined, but a bit slower: - //return val - (val < 58 ? 48 : (val < 97 ? 55 : 87)); - } - } -} diff --git a/ZitiBackgroundTask/src/util/LogHelper.cs b/ZitiBackgroundTask/src/util/LogHelper.cs deleted file mode 100644 index 799bd328..00000000 --- a/ZitiBackgroundTask/src/util/LogHelper.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Diagnostics; -using Windows.Networking.Vpn; - -namespace NetFoundry.VPN.Util -{ - public sealed class LogHelper - { - private const string locator = "__X__"; - public static void LogLine(string msg) - { - Debug.WriteLine(string.Format("${0} ${1}: ${2}", locator, Environment.CurrentManagedThreadId, msg)); - } - public static void LogLine(string text, VpnChannel channel) - { - LogLine(channel?.GetHashCode() + ":" + text); - } - } -} diff --git a/ZitiBackgroundTask/src/ziti/Controller.cs b/ZitiBackgroundTask/src/ziti/Controller.cs deleted file mode 100644 index 2632bf07..00000000 --- a/ZitiBackgroundTask/src/ziti/Controller.cs +++ /dev/null @@ -1,139 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Net.Http; -using System.Security.Cryptography.X509Certificates; -using System.Text; -using System.Threading; -using System.Threading.Tasks; - - -using Newtonsoft.Json; - - -using bc = Org.BouncyCastle; -using Org.BouncyCastle.OpenSsl; -using Org.BouncyCastle.Crypto; -using Org.BouncyCastle.Security; -using Org.BouncyCastle.Pkcs; - -namespace NetFoundry.VPN.Ziti -{ - internal class Controller - { - private static HttpClient httpClient = null; - static string URL = "https://demo.ziti.netfoundry.io:1080/"; - - internal static void GetServices() - { - string json = @""; - bc.X509.X509Certificate x509Cert = null; - bc.X509.X509Certificate x509CaCert = null; - AsymmetricCipherKeyPair ackp = null; - - dynamic thing = JsonConvert.DeserializeObject(json); - string key = CleanPkiNode(thing.id.key?.ToString()); - string cert = CleanPkiNode(thing.id.cert?.ToString()); - string ca = CleanPkiNode(thing.id.ca?.ToString()); - - if (!string.IsNullOrEmpty(key)) - { - using (var keyReader = new StringReader(key)) - { - ackp = (AsymmetricCipherKeyPair)new PemReader(keyReader).ReadObject(); - } - } - - if (!string.IsNullOrEmpty(cert)) - { - using (var certReader = new StringReader(cert)) - { - x509Cert = (bc.X509.X509Certificate)new PemReader(certReader).ReadObject(); - } - } - - if (!string.IsNullOrEmpty(ca)) - { - using (var caReader = new StringReader(ca)) - { - x509CaCert = (bc.X509.X509Certificate)new PemReader(caReader).ReadObject(); - } - } - - var csharpCert = CreateDotNetCertificate(x509Cert, ackp); - - var cch = new HttpClientHandler(); - - cch.ClientCertificates.Add(csharpCert); - cch.ClientCertificateOptions = ClientCertificateOption.Manual; - httpClient = new HttpClient(new LoggingHandler(cch)) - { - BaseAddress = new Uri($"{URL}") - }; - } - internal static X509Certificate createCertificate() - { - return null; - } - - - static string CleanPkiNode(string source) - { - if (source == null) return null; - if (source.StartsWith("pem:")) - { - return source.Substring("pem:".Length); - } - else if (source.StartsWith("file://")) - { - throw new Exception("File pki not supported currently"); - } - else - { - throw new Exception("Unexpected pki?"); - } - } - private static X509Certificate CreateDotNetCertificate(Org.BouncyCastle.X509.X509Certificate certificate, - AsymmetricCipherKeyPair keyPair) - { - Pkcs12Store store = new Pkcs12Store(); - string friendlyName = new Guid().ToString(); - X509CertificateEntry certificateEntry = new X509CertificateEntry(certificate); - store.SetCertificateEntry(friendlyName, certificateEntry); - store.SetKeyEntry(friendlyName, new AsymmetricKeyEntry(keyPair.Private), new[] { certificateEntry }); - - MemoryStream stream = new MemoryStream(); - store.Save(stream, null, new SecureRandom()); - - return new X509Certificate2(stream.ToArray()); - } - } - - internal class LoggingHandler : DelegatingHandler - { - public LoggingHandler(HttpMessageHandler innerHandler) : base(innerHandler) - { - } - - protected override async Task SendAsync( - HttpRequestMessage request, - CancellationToken cancellationToken) - { - System.Diagnostics.Debug.WriteLine($"Request: {request}"); - try - { - // base.SendAsync calls the inner handler - var response = await base.SendAsync(request, cancellationToken); - System.Diagnostics.Debug.WriteLine($"Response: {response}"); - return response; - } - catch (Exception ex) - { - System.Diagnostics.Debug.WriteLine($"Failed to get response: {ex}"); - throw; - } - } - } - -} diff --git a/ZitiBackgroundTask/src/ziti/route/Intercept.cs b/ZitiBackgroundTask/src/ziti/route/Intercept.cs deleted file mode 100644 index 48254edd..00000000 --- a/ZitiBackgroundTask/src/ziti/route/Intercept.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Windows.Networking.Vpn; - -namespace ZitiBackgroundTask.Ziti.Route -{ - internal class Intercept - { - public string ServiceName { get; set; } - - public string DomainName { get; set; } - - public VpnDomainNameType DomainType { get; set; } - - public int Port { get; set; } - - } -} diff --git a/ZitiBackgroundTask/src/ziti/route/RouteInformation.cs b/ZitiBackgroundTask/src/ziti/route/RouteInformation.cs deleted file mode 100644 index 027c8105..00000000 --- a/ZitiBackgroundTask/src/ziti/route/RouteInformation.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using ZitiBackgroundTask.Ziti.Route; - -namespace ZitiBackgroundTask -{ - internal class RouteInformation - { - private static ObservableCollection _interceptsObservable = new ObservableCollection(); - - public static ObservableCollection Intercepts - { - get { return _interceptsObservable; } - } - } -} diff --git a/ZitiTunneler/App.config b/ZitiTunneler/App.config index 787dcbec..bae5d6d8 100644 --- a/ZitiTunneler/App.config +++ b/ZitiTunneler/App.config @@ -1,6 +1,6 @@ - + - + - \ No newline at end of file + diff --git a/ZitiTunneler/Properties/Resources.Designer.cs b/ZitiTunneler/Properties/Resources.Designer.cs index 07f1f130..ae6c82ec 100644 --- a/ZitiTunneler/Properties/Resources.Designer.cs +++ b/ZitiTunneler/Properties/Resources.Designer.cs @@ -9,54 +9,55 @@ //------------------------------------------------------------------------------ namespace ZitiTunneler.Properties { - - - /// - /// A strongly-typed resource class, for looking up localized strings, etc. - /// - // This class was auto-generated by the StronglyTypedResourceBuilder - // class via a tool like ResGen or Visual Studio. - // To add or remove a member, edit your .ResX file then rerun ResGen - // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] - [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Resources { - - private static global::System.Resources.ResourceManager resourceMan; - - private static global::System.Globalization.CultureInfo resourceCulture; - - [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Resources() { - } - - /// - /// Returns the cached ResourceManager instance used by this class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Resources.ResourceManager ResourceManager { - get { - if ((resourceMan == null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ZitiTunneler.Properties.Resources", typeof(Resources).Assembly); - resourceMan = temp; - } - return resourceMan; - } - } - - /// - /// Overrides the current thread's CurrentUICulture property for all - /// resource lookups using this strongly typed resource class. - /// - [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] - internal static global::System.Globalization.CultureInfo Culture { - get { - return resourceCulture; - } - set { - resourceCulture = value; - } - } - } + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("ZitiTunneler.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } } diff --git a/ZitiTunneler/Properties/Settings.Designer.cs b/ZitiTunneler/Properties/Settings.Designer.cs index 8b0c3a18..25514222 100644 --- a/ZitiTunneler/Properties/Settings.Designer.cs +++ b/ZitiTunneler/Properties/Settings.Designer.cs @@ -9,18 +9,18 @@ //------------------------------------------------------------------------------ namespace ZitiTunneler.Properties { - - - [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] - internal sealed partial class Settings:global::System.Configuration.ApplicationSettingsBase { - - private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); - - public static Settings Default { - get { - return defaultInstance; - } - } - } + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } } diff --git a/ZitiTunneler/ZitiTunneler.csproj b/ZitiTunneler/ZitiTunneler.csproj index 20fbdd37..6ed7cd5c 100644 --- a/ZitiTunneler/ZitiTunneler.csproj +++ b/ZitiTunneler/ZitiTunneler.csproj @@ -8,12 +8,13 @@ WinExe ZitiTunneler ZitiTunneler - v4.7.1 + v4.6.1 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 true true + AnyCPU diff --git a/ZitiUWPClient/AddIdentity.xaml b/ZitiUWPClient/AddIdentity.xaml deleted file mode 100644 index 0325c259..00000000 --- a/ZitiUWPClient/AddIdentity.xaml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - - - - - - - - - diff --git a/ZitiUWPClient/App.xaml b/ZitiUWPClient/App.xaml deleted file mode 100644 index d58a88ce..00000000 --- a/ZitiUWPClient/App.xaml +++ /dev/null @@ -1,7 +0,0 @@ - - - diff --git a/ZitiUWPClient/App.xaml.cs b/ZitiUWPClient/App.xaml.cs deleted file mode 100644 index 92aa022a..00000000 --- a/ZitiUWPClient/App.xaml.cs +++ /dev/null @@ -1,100 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Runtime.InteropServices.WindowsRuntime; -using Windows.ApplicationModel; -using Windows.ApplicationModel.Activation; -using Windows.Foundation; -using Windows.Foundation.Collections; -using Windows.UI.Xaml; -using Windows.UI.Xaml.Controls; -using Windows.UI.Xaml.Controls.Primitives; -using Windows.UI.Xaml.Data; -using Windows.UI.Xaml.Input; -using Windows.UI.Xaml.Media; -using Windows.UI.Xaml.Navigation; - -namespace TestUWPApp -{ - /// - /// Provides application-specific behavior to supplement the default Application class. - /// - sealed partial class App : Application - { - /// - /// Initializes the singleton application object. This is the first line of authored code - /// executed, and as such is the logical equivalent of main() or WinMain(). - /// - public App() - { - this.InitializeComponent(); - this.Suspending += OnSuspending; - } - - /// - /// Invoked when the application is launched normally by the end user. Other entry points - /// will be used such as when the application is launched to open a specific file. - /// - /// Details about the launch request and process. - protected override void OnLaunched(LaunchActivatedEventArgs e) - { - Frame rootFrame = Window.Current.Content as Frame; - - // Do not repeat app initialization when the Window already has content, - // just ensure that the window is active - if (rootFrame == null) - { - // Create a Frame to act as the navigation context and navigate to the first page - rootFrame = new Frame(); - - rootFrame.NavigationFailed += OnNavigationFailed; - - if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) - { - //TODO: Load state from previously suspended application - } - - // Place the frame in the current Window - Window.Current.Content = rootFrame; - } - - if (e.PrelaunchActivated == false) - { - if (rootFrame.Content == null) - { - // When the navigation stack isn't restored navigate to the first page, - // configuring the new page by passing required information as a navigation - // parameter - rootFrame.Navigate(typeof(MainPage), e.Arguments); - } - // Ensure the current window is active - Window.Current.Activate(); - } - } - - /// - /// Invoked when Navigation to a certain page fails - /// - /// The Frame which failed navigation - /// Details about the navigation failure - void OnNavigationFailed(object sender, NavigationFailedEventArgs e) - { - throw new Exception("Failed to load Page " + e.SourcePageType.FullName); - } - - /// - /// Invoked when application execution is being suspended. Application state is saved - /// without knowing whether the application will be terminated or resumed with the contents - /// of memory still intact. - /// - /// The source of the suspend request. - /// Details about the suspend request. - private void OnSuspending(object sender, SuspendingEventArgs e) - { - var deferral = e.SuspendingOperation.GetDeferral(); - //TODO: Save application state and stop any background activity - deferral.Complete(); - } - } -} diff --git a/ZitiUWPClient/Assets/LockScreenLogo.scale-200.png b/ZitiUWPClient/Assets/LockScreenLogo.scale-200.png deleted file mode 100644 index 735f57ad..00000000 Binary files a/ZitiUWPClient/Assets/LockScreenLogo.scale-200.png and /dev/null differ diff --git a/ZitiUWPClient/Assets/SplashScreen.scale-200.png b/ZitiUWPClient/Assets/SplashScreen.scale-200.png deleted file mode 100644 index 023e7f1f..00000000 Binary files a/ZitiUWPClient/Assets/SplashScreen.scale-200.png and /dev/null differ diff --git a/ZitiUWPClient/Assets/Square150x150Logo.scale-200.png b/ZitiUWPClient/Assets/Square150x150Logo.scale-200.png deleted file mode 100644 index af49fec1..00000000 Binary files a/ZitiUWPClient/Assets/Square150x150Logo.scale-200.png and /dev/null differ diff --git a/ZitiUWPClient/Assets/Square44x44Logo.scale-200.png b/ZitiUWPClient/Assets/Square44x44Logo.scale-200.png deleted file mode 100644 index ce342a2e..00000000 Binary files a/ZitiUWPClient/Assets/Square44x44Logo.scale-200.png and /dev/null differ diff --git a/ZitiUWPClient/Assets/Square44x44Logo.targetsize-24_altform-unplated.png b/ZitiUWPClient/Assets/Square44x44Logo.targetsize-24_altform-unplated.png deleted file mode 100644 index f6c02ce9..00000000 Binary files a/ZitiUWPClient/Assets/Square44x44Logo.targetsize-24_altform-unplated.png and /dev/null differ diff --git a/ZitiUWPClient/Assets/StoreLogo.png b/ZitiUWPClient/Assets/StoreLogo.png deleted file mode 100644 index 7385b56c..00000000 Binary files a/ZitiUWPClient/Assets/StoreLogo.png and /dev/null differ diff --git a/ZitiUWPClient/Assets/Wide310x150Logo.scale-200.png b/ZitiUWPClient/Assets/Wide310x150Logo.scale-200.png deleted file mode 100644 index 288995b3..00000000 Binary files a/ZitiUWPClient/Assets/Wide310x150Logo.scale-200.png and /dev/null differ diff --git a/ZitiUWPClient/MainPage.xaml b/ZitiUWPClient/MainPage.xaml deleted file mode 100644 index b9413385..00000000 --- a/ZitiUWPClient/MainPage.xaml +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - - - - - - - -