Enable proxy authentication for SOCKS4 and HTTP

This commit is contained in:
0xboobface 2018-08-30 13:18:19 +02:00
parent cd827a0cb8
commit 79a1ccc011
2 changed files with 20 additions and 16 deletions

View File

@ -48,11 +48,19 @@ public class HttpClient {
System.setProperty("http.proxyPort", Config.getInstance().getSettings().proxyPort);
System.setProperty("https.proxyHost", Config.getInstance().getSettings().proxyHost);
System.setProperty("https.proxyPort", Config.getInstance().getSettings().proxyPort);
if(Config.getInstance().getSettings().proxyUser != null && !Config.getInstance().getSettings().proxyUser.isEmpty()) {
System.setProperty("http.proxyUser", Config.getInstance().getSettings().proxyUser);
System.setProperty("http.proxyPassword", Config.getInstance().getSettings().proxyPassword);
}
break;
case SOCKS4:
System.setProperty("socksProxyVersion", "4");
System.setProperty("socksProxyHost", Config.getInstance().getSettings().proxyHost);
System.setProperty("socksProxyPort", Config.getInstance().getSettings().proxyPort);
if(Config.getInstance().getSettings().proxyUser != null && !Config.getInstance().getSettings().proxyUser.isEmpty()) {
System.setProperty("java.net.socks.username", Config.getInstance().getSettings().proxyUser);
System.setProperty("java.net.socks.password", Config.getInstance().getSettings().proxyPassword);
}
break;
case SOCKS5:
System.setProperty("socksProxyVersion", "5");
@ -74,6 +82,8 @@ public class HttpClient {
System.clearProperty("socksProxyPort");
System.clearProperty("java.net.socks.username");
System.clearProperty("java.net.socks.password");
System.clearProperty("http.proxyUser");
System.clearProperty("http.proxyPassword");
break;
}
}

View File

@ -1,4 +1,8 @@
package ctbrec.ui;
import static ctbrec.Settings.ProxyType.DIRECT;
import static ctbrec.Settings.ProxyType.HTTP;
import static ctbrec.Settings.ProxyType.SOCKS4;
import static ctbrec.Settings.ProxyType.SOCKS5;
import java.util.ArrayList;
import java.util.List;
@ -38,10 +42,10 @@ public class ProxySettingsPane extends TitledPane implements EventHandler<Action
Label l = new Label("Type");
layout.add(l, 0, 0);
List<ProxyType> proxyTypes = new ArrayList<>();
proxyTypes.add(ProxyType.DIRECT);
proxyTypes.add(ProxyType.HTTP);
proxyTypes.add(ProxyType.SOCKS4);
proxyTypes.add(ProxyType.SOCKS5);
proxyTypes.add(DIRECT);
proxyTypes.add(HTTP);
proxyTypes.add(SOCKS4);
proxyTypes.add(SOCKS5);
proxyType = new ComboBox<>(new ObservableListWrapper<>(proxyTypes));
proxyType.setOnAction(this);
layout.add(proxyType, 1, 0);
@ -87,26 +91,16 @@ public class ProxySettingsPane extends TitledPane implements EventHandler<Action
}
private void setComponentDisableState() {
switch (proxyType.getValue()) {
case DIRECT:
if(proxyType.getValue() == DIRECT) {
proxyHost.setDisable(true);
proxyPort.setDisable(true);
proxyUser.setDisable(true);
proxyPassword.setDisable(true);
break;
case HTTP:
case SOCKS4:
proxyHost.setDisable(false);
proxyPort.setDisable(false);
proxyUser.setDisable(true);
proxyPassword.setDisable(true);
break;
case SOCKS5:
} else {
proxyHost.setDisable(false);
proxyPort.setDisable(false);
proxyUser.setDisable(false);
proxyPassword.setDisable(false);
break;
}
}
}