mirror of
https://git.huckle.dev/Huckles-Minecraft-Archive/jpexs-decompiler.git
synced 2026-09-24 21:40:46 +00:00
Proxy fixes
This commit is contained in:
@@ -22,6 +22,27 @@ class Connection
|
||||
Socket socket = null;
|
||||
InputStream in = null;
|
||||
OutputStream out = null;
|
||||
static SSLSocketFactory sf;
|
||||
|
||||
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){
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void promoteToClientSSL(){
|
||||
SSLSocketFactory f = (SSLSocketFactory) SSLSocketFactory.getDefault();
|
||||
@@ -36,22 +57,11 @@ class Connection
|
||||
}
|
||||
|
||||
public void promoteToServerSSL(){
|
||||
String ksName = "server.jks";
|
||||
char ksPass[] = "ServerJKS".toCharArray();
|
||||
char ctPass[] = "ServerKey".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);
|
||||
SSLSocketFactory sf=sc.getSocketFactory();
|
||||
try{
|
||||
socket=sf.createSocket(socket,null,socket.getPort(),false);
|
||||
((SSLSocket)socket).setUseClientMode(false);
|
||||
}catch(Exception ex){
|
||||
|
||||
ex.printStackTrace();
|
||||
}
|
||||
try {
|
||||
in = socket.getInputStream();
|
||||
|
||||
@@ -126,7 +126,7 @@ class Handler implements Runnable
|
||||
}
|
||||
catch(SSLHandshakeException she)
|
||||
{
|
||||
client.close();
|
||||
she.printStackTrace();
|
||||
break;
|
||||
}
|
||||
catch (IOException e)
|
||||
@@ -136,7 +136,7 @@ class Handler implements Runnable
|
||||
}
|
||||
|
||||
|
||||
if(request.getCommand().equals("CONNECT")){
|
||||
if(request.getCommand().equals("CONNECT")){
|
||||
secureServer=request.getHost();
|
||||
securePort=request.getPort();
|
||||
if((ProxyConfig.httpsMode==ProxyConfig.HTTPS_FILTER)||((ProxyConfig.httpsMode==ProxyConfig.HTTPS_FILTERLIST)&&(ProxyConfig.enabledHttpsServers.contains(secureServer)))){
|
||||
@@ -392,7 +392,24 @@ class Handler implements Runnable
|
||||
|
||||
if((ProxyConfig.httpsMode==ProxyConfig.HTTPS_FILTER)||((ProxyConfig.httpsMode==ProxyConfig.HTTPS_FILTERLIST)&&(ProxyConfig.enabledHttpsServers.contains(secureHost))))
|
||||
{
|
||||
http=Https.open(secureHost,securePort,ProxyConfig.useHTTPSProxy);
|
||||
if(ProxyConfig.useHTTPSProxy){
|
||||
http=Https.open(ProxyConfig.httpsProxyHost,ProxyConfig.httpsProxyPort,true);
|
||||
Request connectReq=new Request(null);
|
||||
connectReq.setStatusLine("CONNECT "+secureHost+":"+securePort+" HTTP/1.1");
|
||||
connectReq.setCommand("CONNECT");
|
||||
connectReq.setURL(secureHost+":"+securePort);
|
||||
connectReq.setProtocol("HTTP/1.1");
|
||||
try {
|
||||
http.sendRequest(connectReq);
|
||||
Reply rep=http.recvReply(connectReq);
|
||||
} catch (RetryRequestException ex) {
|
||||
|
||||
}
|
||||
((Https)http).promoteToClientSSL();
|
||||
}else{
|
||||
http=Https.open(secureHost,securePort,false);
|
||||
((Https)http).promoteToClientSSL();
|
||||
}
|
||||
/*http = new Http(request.getHost(),request.getPort(),ProxyConfig.useHTTPSProxy);
|
||||
if(ProxyConfig.useHTTPSProxy){
|
||||
Request connectReq=new Request(client);
|
||||
|
||||
@@ -86,7 +86,7 @@ class Http extends HttpConnection
|
||||
|
||||
try
|
||||
{
|
||||
return recv();
|
||||
return recv();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
@@ -130,20 +130,25 @@ class Http extends HttpConnection
|
||||
{
|
||||
|
||||
/* Prepare HTTP/1.1 request */
|
||||
request.removeHeaderField("Proxy-Connection");
|
||||
if(request.containsHeaderField("Connection")&&(request.getHeaderField("Connection").toLowerCase().equals("keep-alive"))){
|
||||
//request.removeHeaderField("Connection");
|
||||
}else{
|
||||
request.setHeaderField("Connection", "open");
|
||||
|
||||
request.removeHeaderField("Proxy-Connection");
|
||||
|
||||
|
||||
if(!proxy){
|
||||
if(request.containsHeaderField("Connection")&&(request.getHeaderField("Connection").toLowerCase().equals("keep-alive"))){
|
||||
|
||||
}else{
|
||||
request.setHeaderField("Connection", "open");
|
||||
}
|
||||
if (!request.containsHeaderField("Host"))
|
||||
{
|
||||
request.setHeaderField("Host", request.getHost());
|
||||
}
|
||||
}
|
||||
if (!request.containsHeaderField("Host"))
|
||||
{
|
||||
request.setHeaderField("Host", request.getHost());
|
||||
}
|
||||
|
||||
if (proxy)
|
||||
{
|
||||
request.write(getOutputStream());
|
||||
request.write(getOutputStream());
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -151,7 +156,7 @@ class Http extends HttpConnection
|
||||
StringBuffer head = new StringBuffer();
|
||||
head.append(request.getCommand());
|
||||
head.append(" ");
|
||||
head.append(request.getPath());
|
||||
head.append(request.getPath());
|
||||
head.append(" ");
|
||||
head.append("HTTP/1.0");
|
||||
request.statusLine = head.toString();
|
||||
|
||||
@@ -23,20 +23,7 @@ public class Https extends Http {
|
||||
|
||||
public Https(String host, int port, boolean isProxy) throws IOException
|
||||
{
|
||||
super(host, port,isProxy);
|
||||
if(isProxy){
|
||||
Request connectReq=new Request(null);
|
||||
connectReq.setCommand("CONNECT");
|
||||
connectReq.setURL(host+":"+port);
|
||||
connectReq.setProtocol("HTTP/1.1");
|
||||
try {
|
||||
sendRequest(connectReq);
|
||||
recvReply(connectReq);
|
||||
} catch (RetryRequestException ex) {
|
||||
|
||||
}
|
||||
}
|
||||
promoteToClientSSL();
|
||||
super(host, port,isProxy);
|
||||
}
|
||||
|
||||
private static String cacheKey(String host, int port)
|
||||
|
||||
@@ -15,7 +15,7 @@ public class Main
|
||||
public static boolean DEBUG_MODE = false;
|
||||
|
||||
public static void main(String argv[])
|
||||
{
|
||||
{
|
||||
List<Replacement> replacements = new ArrayList<Replacement>();
|
||||
if ((new File(REPLACEMENTSFILE)).exists()) {
|
||||
try {
|
||||
|
||||
@@ -36,4 +36,8 @@ public class ProxyConfig {
|
||||
public static String httpProxyHost="";
|
||||
public static int httpProxyPort=0;
|
||||
|
||||
public static String httpsKeyStoreFile=null;
|
||||
public static String httpsKeyStorePass=null;
|
||||
public static String httpsKeyPass=null;
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user