format proxy code, allow to change swf on the fly

This commit is contained in:
honfika@gmail.com
2014-09-01 16:56:55 +02:00
parent 8325d07b24
commit ed53ba9d0f
37 changed files with 1847 additions and 2267 deletions

View File

@@ -17,58 +17,58 @@ import javax.net.ssl.SSLServerSocketFactory;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
class Connection
{
class Connection {
Socket socket = null;
InputStream in = null;
OutputStream out = null;
static SSLSocketFactory sf;
static{
String ksName = ProxyConfig.httpsKeyStoreFile;
if(ksName!=null){
static {
String ksName = ProxyConfig.httpsKeyStoreFile;
if (ksName != null) {
char[] ksPass = ProxyConfig.httpsKeyStorePass.toCharArray();
char[] ctPass = ProxyConfig.httpsKeyPass.toCharArray();
try{
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(new FileInputStream(ksName), ksPass);
KeyManagerFactory kmf =
KeyManagerFactory.getInstance("SunX509");
kmf.init(ks, ctPass);
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(kmf.getKeyManagers(), null, null);
sf=sc.getSocketFactory();
}catch(Exception ex){
try {
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(new FileInputStream(ksName), ksPass);
KeyManagerFactory kmf
= KeyManagerFactory.getInstance("SunX509");
kmf.init(ks, ctPass);
SSLContext sc = SSLContext.getInstance("TLS");
sc.init(kmf.getKeyManagers(), null, null);
sf = sc.getSocketFactory();
} catch (Exception ex) {
}
}
}
}
}
public void promoteToClientSSL(){
SSLSocketFactory f = (SSLSocketFactory) SSLSocketFactory.getDefault();
try {
socket = (SSLSocket) f.createSocket(socket,null,socket.getPort(),false);
in = socket.getInputStream();
out = socket.getOutputStream();
} catch (IOException ex) {
public void promoteToClientSSL() {
SSLSocketFactory f = (SSLSocketFactory) SSLSocketFactory.getDefault();
try {
socket = (SSLSocket) f.createSocket(socket, null, socket.getPort(), false);
in = socket.getInputStream();
out = socket.getOutputStream();
} catch (IOException ex) {
}
}
}
public void promoteToServerSSL(){
try{
socket=sf.createSocket(socket,null,socket.getPort(),false);
((SSLSocket)socket).setUseClientMode(false);
}catch(Exception ex){
ex.printStackTrace();
}
try {
in = socket.getInputStream();
out = socket.getOutputStream();
} catch (IOException ex) {
public void promoteToServerSSL() {
try {
socket = sf.createSocket(socket, null, socket.getPort(), false);
((SSLSocket) socket).setUseClientMode(false);
} catch (Exception ex) {
ex.printStackTrace();
}
try {
in = socket.getInputStream();
out = socket.getOutputStream();
} catch (IOException ex) {
}
}
}
@@ -77,11 +77,10 @@ class Connection
*
* @param socket a socket
*/
Connection(Socket socket) throws IOException
{
this.socket = socket;
in = socket.getInputStream();
out = socket.getOutputStream();
Connection(Socket socket) throws IOException {
this.socket = socket;
in = socket.getInputStream();
out = socket.getOutputStream();
}
/**
@@ -90,82 +89,66 @@ class Connection
* @param host remote hostname
* @param port remote port
*/
Connection(String host, int port) throws IOException
{
this(new Socket(InetAddress.getByName(host), port));
Connection(String host, int port) throws IOException {
this(new Socket(InetAddress.getByName(host), port));
}
Connection()
{
Connection() {
}
/**
* Return the input stream.
*/
InputStream getInputStream()
{
return in;
InputStream getInputStream() {
return in;
}
/**
* Return the output stream.
*/
OutputStream getOutputStream()
{
return out;
OutputStream getOutputStream() {
return out;
}
void setInputStream(InputStream in)
{
this.in = in;
void setInputStream(InputStream in) {
this.in = in;
}
void setOutputStream(OutputStream out)
{
this.out = out;
void setOutputStream(OutputStream out) {
this.out = out;
}
/**
* Close the connection.
*/
void close()
{
if (socket != null)
{
try
{
socket.close();
}
catch (IOException e)
{
void close() {
if (socket != null) {
try {
socket.close();
} catch (IOException e) {
}
}
}
}
}
public Socket getSocket()
{
return socket;
public Socket getSocket() {
return socket;
}
public InetAddress getInetAddress()
{
return socket.getInetAddress();
}
public int getPort()
{
return socket.getPort();
public InetAddress getInetAddress() {
return socket.getInetAddress();
}
public String toString()
{
return getInetAddress().getHostAddress() + ":" + getPort();
public int getPort() {
return socket.getPort();
}
public String toString() {
return getInetAddress().getHostAddress() + ":" + getPort();
}
public void setTimeout(int timeout)
throws SocketException
{
socket.setSoTimeout(timeout);
throws SocketException {
socket.setSoTimeout(timeout);
}
}