-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWinTunnel.cs
More file actions
105 lines (84 loc) · 3.26 KB
/
WinTunnel.cs
File metadata and controls
105 lines (84 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Net;
using System.Runtime.InteropServices;
using System.Security.Cryptography.X509Certificates;
namespace WinProxy
{
public class WinTunnel
{
public String m_strListeningPort, m_strForwardAddress, m_strLogFileLocation, m_strForwardPort;
private bool m_bLogToFile;
public IPEndPoint m_localEP;
public string m_serverName;
public int m_serverPort;
private bool m_bHttpsClient;
private bool m_bHttpsServer;
public static X509Certificate2 CertificateForClientConnection = null;
public delegate void WriteToConsole(string message);
private static WriteToConsole m_delWriteToConsole;
private static WriteToConsole m_delWriteToLog;
public static ConnectionManager connMgr;
ProxyClientListenerTask task;
public WinTunnel(String strListeningPort, string strForwardAddress, string strForwardPort, bool bHttpsClient, bool bHttpsServer,
string strLogFileLocation, WriteToConsole delWriteToConsole, WriteToConsole delWriteToLog, bool bLogToFile,
string strCertForClientConnection, string strClientConnectionCertPassword)
{
m_strListeningPort = strListeningPort;
m_strForwardAddress = strForwardAddress;
m_strForwardPort = strForwardPort;
m_bHttpsClient = bHttpsClient;
m_bHttpsServer = bHttpsServer;
m_strLogFileLocation = strLogFileLocation;
m_delWriteToConsole = delWriteToConsole;
m_delWriteToLog = delWriteToLog;
m_bLogToFile = bLogToFile;
if (bHttpsClient)
{
CertificateForClientConnection = new X509Certificate2(strCertForClientConnection, strClientConnectionCertPassword);
}
}
public static void WriteTextToConsole(string strConsoleText)
{
if (m_delWriteToConsole != null)
m_delWriteToConsole(strConsoleText + "\r\n");
}
public static void WriteTextToLog(string strLogText)
{
if (m_delWriteToLog != null)
{
m_delWriteToLog(strLogText);
}
}
/// <summary>
/// Stop this service.
/// </summary>
public void Stop()
{
//close the main listen socket
task.stop();
//Shutdown the connection manager
connMgr.shutdown();
connMgr = null;
WriteTextToConsole("WinTunnel stopped. ");
Logger.close();
}
public void Start()
{
WriteTextToConsole("*** Starting up WinTunnel ****");
WriteTextToConsole("Starting thread... ");
Logger.initialize(m_strLogFileLocation, m_bLogToFile);
m_localEP = new IPEndPoint(IPAddress.Any, Int32.Parse(m_strListeningPort));
m_serverName = m_strForwardAddress;
m_serverPort = Int32.Parse(m_strForwardPort);
connMgr = new ConnectionManager();
task = new ProxyClientListenerTask(m_localEP, m_serverName, m_serverPort, m_bHttpsClient, m_bHttpsServer);
Thread t = new Thread(task.run);
t.Start();
}
}
}