use of org.kse.utilities.net.ProxyAddress in project keystore-explorer by kaikramer.
the class ApplicationSettings method getCurrentProxySettings.
private void getCurrentProxySettings(Preferences preferences) {
// Get current proxy settings
ProxySelector proxySelector = ProxySelector.getDefault();
if (proxySelector instanceof NoProxySelector) {
preferences.put(KSE3_PROXY, ProxyConfigurationType.NONE.name());
} else if (proxySelector instanceof SystemProxySelector) {
preferences.put(KSE3_PROXY, ProxyConfigurationType.SYSTEM.name());
} else if (proxySelector instanceof PacProxySelector) {
PacProxySelector pacProxySelector = (PacProxySelector) proxySelector;
preferences.put(KSE3_PACURL, pacProxySelector.getPacUrl());
preferences.put(KSE3_PROXY, ProxyConfigurationType.PAC.name());
} else if (proxySelector instanceof ManualProxySelector) {
ManualProxySelector manualProxySelector = (ManualProxySelector) proxySelector;
ProxyAddress httpProxyAddress = manualProxySelector.getHttpProxyAddress();
if (httpProxyAddress != null) {
preferences.put(KSE3_HTTPHOST, httpProxyAddress.getHost());
preferences.putInt(KSE3_HTTPPORT, httpProxyAddress.getPort());
}
ProxyAddress httpsProxyAddress = manualProxySelector.getHttpsProxyAddress();
if (httpsProxyAddress != null) {
preferences.put(KSE3_HTTPSHOST, httpsProxyAddress.getHost());
preferences.putInt(KSE3_HTTPSPORT, httpsProxyAddress.getPort());
}
ProxyAddress socksProxyAddress = manualProxySelector.getSocksProxyAddress();
if (socksProxyAddress != null) {
preferences.put(KSE3_SOCKSHOST, socksProxyAddress.getHost());
preferences.putInt(KSE3_SOCKSPORT, socksProxyAddress.getPort());
}
preferences.put(KSE3_PROXY, ProxyConfigurationType.MANUAL.name());
}
}
use of org.kse.utilities.net.ProxyAddress in project keystore-explorer by kaikramer.
the class DPreferences method initInternetProxyTab.
private void initInternetProxyTab() {
jrbNoProxy = new JRadioButton(res.getString("DPreferences.jrbNoProxy.text"));
jrbNoProxy.setToolTipText(res.getString("DPreferences.jrbNoProxy.tooltip"));
PlatformUtil.setMnemonic(jrbNoProxy, res.getString("DPreferences.jrbNoProxy.mnemonic").charAt(0));
jrbSystemProxySettings = new JRadioButton(res.getString("DPreferences.jrbSystemProxySettings.text"), true);
jrbSystemProxySettings.setToolTipText(res.getString("DPreferences.jrbSystemProxySettings.tooltip"));
PlatformUtil.setMnemonic(jrbSystemProxySettings, res.getString("DPreferences.jrbSystemProxySettings.mnemonic").charAt(0));
jrbManualProxyConfig = new JRadioButton(res.getString("DPreferences.jrbManualProxyConfig.text"));
jrbManualProxyConfig.setToolTipText(res.getString("DPreferences.jrbManualProxyConfig.tooltip"));
PlatformUtil.setMnemonic(jrbManualProxyConfig, res.getString("DPreferences.jrbManualProxyConfig.mnemonic").charAt(0));
jlHttpHost = new JLabel(res.getString("DPreferences.jlHttpHost.text"));
jtfHttpHost = new JTextField(20);
jtfHttpHost.setToolTipText(res.getString("DPreferences.jtfHttpHost.tooltip"));
jtfHttpHost.setEnabled(false);
jlHttpPort = new JLabel(res.getString("DPreferences.jlHttpPort.text"));
jtfHttpPort = new JTextField(5);
jtfHttpPort.setToolTipText(res.getString("DPreferences.jtfHttpPort.tooltip"));
jtfHttpPort.setEnabled(false);
jlHttpsHost = new JLabel(res.getString("DPreferences.jlHttpsHost.text"));
jtfHttpsHost = new JTextField(20);
jtfHttpsHost.setToolTipText(res.getString("DPreferences.jtfHttpsHost.tooltip"));
jtfHttpsHost.setEnabled(false);
jlHttpsPort = new JLabel(res.getString("DPreferences.jlHttpsPort.text"));
jtfHttpsPort = new JTextField(5);
jtfHttpsPort.setToolTipText(res.getString("DPreferences.jtfHttpsPort.tooltip"));
jtfHttpsPort.setEnabled(false);
jlSocksHost = new JLabel(res.getString("DPreferences.jlSocksHost.text"));
jtfSocksHost = new JTextField(20);
jtfSocksHost.setToolTipText(res.getString("DPreferences.jtfSocksHost.tooltip"));
jtfSocksHost.setEnabled(false);
jlSocksPort = new JLabel(res.getString("DPreferences.jlSocksPort.text"));
jtfSocksPort = new JTextField(5);
jtfSocksPort.setToolTipText(res.getString("DPreferences.jtfSocksPort.tooltip"));
jtfSocksPort.setEnabled(false);
jrbAutomaticProxyConfig = new JRadioButton(res.getString("DPreferences.jrbAutomaticProxyConfig.text"));
jrbAutomaticProxyConfig.setToolTipText(res.getString("DPreferences.jrbAutomaticProxyConfig.tooltip"));
PlatformUtil.setMnemonic(jrbAutomaticProxyConfig, res.getString("DPreferences.jrbAutomaticProxyConfig.mnemonic").charAt(0));
jlPacUrl = new JLabel(res.getString("DPreferences.jlPacUrl.text"));
jtfPacUrl = new JTextField(30);
jtfPacUrl.setToolTipText(res.getString("DPreferences.jtfPacUrl.tooltip"));
jtfPacUrl.setEnabled(false);
ButtonGroup bgProxies = new ButtonGroup();
bgProxies.add(jrbNoProxy);
bgProxies.add(jrbSystemProxySettings);
bgProxies.add(jrbManualProxyConfig);
bgProxies.add(jrbAutomaticProxyConfig);
// layout
jpInternetProxy = new JPanel();
jpInternetProxy.setLayout(new MigLayout("insets dialog", "[20][]", ""));
jpInternetProxy.add(jrbNoProxy, "left, span, wrap");
jpInternetProxy.add(jrbSystemProxySettings, "left, span, wrap");
jpInternetProxy.add(jrbManualProxyConfig, "left, span, wrap");
jpInternetProxy.add(jlHttpHost, "skip, right");
jpInternetProxy.add(jtfHttpHost, "");
jpInternetProxy.add(jlHttpPort, "gap unrel, right");
jpInternetProxy.add(jtfHttpPort, "wrap");
jpInternetProxy.add(jlHttpsHost, "skip, right");
jpInternetProxy.add(jtfHttpsHost, "");
jpInternetProxy.add(jlHttpsPort, "gap unrel, right");
jpInternetProxy.add(jtfHttpsPort, "wrap");
jpInternetProxy.add(jlSocksHost, "skip, right");
jpInternetProxy.add(jtfSocksHost, "");
jpInternetProxy.add(jlSocksPort, "gap unrel, right");
jpInternetProxy.add(jtfSocksPort, "wrap");
jpInternetProxy.add(jrbAutomaticProxyConfig, "left, span, wrap");
jpInternetProxy.add(jlPacUrl, "skip, right");
jpInternetProxy.add(jtfPacUrl, "span, wrap push");
jrbAutomaticProxyConfig.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent evt) {
updateProxyControls();
}
});
jrbManualProxyConfig.addItemListener(new ItemListener() {
@Override
public void itemStateChanged(ItemEvent evt) {
updateProxyControls();
}
});
ProxySelector proxySelector = ProxySelector.getDefault();
if (proxySelector instanceof SystemProxySelector) {
jrbSystemProxySettings.setSelected(true);
} else if (proxySelector instanceof PacProxySelector) {
jrbAutomaticProxyConfig.setSelected(true);
PacProxySelector pacProxySelector = (PacProxySelector) proxySelector;
jtfPacUrl.setText(pacProxySelector.getPacUrl());
} else if (proxySelector instanceof ManualProxySelector) {
jrbManualProxyConfig.setSelected(true);
ManualProxySelector manualProxySelector = (ManualProxySelector) proxySelector;
ProxyAddress httpProxy = manualProxySelector.getHttpProxyAddress();
ProxyAddress httpsProxy = manualProxySelector.getHttpsProxyAddress();
ProxyAddress socksProxy = manualProxySelector.getSocksProxyAddress();
if (httpProxy != null) {
jtfHttpHost.setText(httpProxy.getHost());
jtfHttpHost.setCaretPosition(0);
jtfHttpPort.setText("" + httpProxy.getPort());
jtfHttpPort.setCaretPosition(0);
}
if (httpsProxy != null) {
jtfHttpsHost.setText(httpsProxy.getHost());
jtfHttpsHost.setCaretPosition(0);
jtfHttpsPort.setText("" + httpsProxy.getPort());
jtfHttpsPort.setCaretPosition(0);
}
if (socksProxy != null) {
jtfSocksHost.setText(socksProxy.getHost());
jtfSocksHost.setCaretPosition(0);
jtfSocksPort.setText("" + socksProxy.getPort());
jtfSocksPort.setCaretPosition(0);
}
} else {
jrbNoProxy.setSelected(true);
}
}
use of org.kse.utilities.net.ProxyAddress in project keystore-explorer by kaikramer.
the class DPreferences method storeProxyPreferences.
private boolean storeProxyPreferences() {
// Store current proxy selector - compare with new one to see if default needs updated
ProxySelector defaultProxySelector = ProxySelector.getDefault();
if (jrbNoProxy.isSelected()) {
NoProxySelector noProxySelector = new NoProxySelector();
if (!noProxySelector.equals(defaultProxySelector)) {
ProxySelector.setDefault(noProxySelector);
}
} else if (jrbSystemProxySettings.isSelected()) {
SystemProxySelector systemProxySelector = new SystemProxySelector();
if (!systemProxySelector.equals(defaultProxySelector)) {
ProxySelector.setDefault(systemProxySelector);
}
} else if (jrbManualProxyConfig.isSelected()) {
String httpHost = jtfHttpHost.getText().trim();
String httpPortStr = jtfHttpPort.getText().trim();
String httpsHost = jtfHttpsHost.getText().trim();
String httpsPortStr = jtfHttpsPort.getText().trim();
String socksHost = jtfSocksHost.getText().trim();
String socksPortStr = jtfSocksPort.getText().trim();
ProxyAddress httpProxyAddress = null;
ProxyAddress httpsProxyAddress = null;
ProxyAddress socksProxyAddress = null;
// Require at least one of the HTTP host or HTTPS host or SOCKS host manual settings
if ((httpHost.length() == 0) && (httpsHost.length() == 0) && (socksHost.length() == 0)) {
jtpPreferences.setSelectedIndex(3);
JOptionPane.showMessageDialog(this, res.getString("DPreferences.ManualConfigReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return false;
} else {
if (httpHost.length() > 0) {
if (httpPortStr.length() == 0) {
jtpPreferences.setSelectedIndex(3);
JOptionPane.showMessageDialog(this, res.getString("DPreferences.PortReqHttp.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return false;
} else {
try {
int httpPort = Integer.parseInt(httpPortStr);
if (httpPort < 1) {
throw new NumberFormatException();
}
httpProxyAddress = new ProxyAddress(httpHost, httpPort);
} catch (NumberFormatException ex) {
jtpPreferences.setSelectedIndex(3);
JOptionPane.showMessageDialog(this, res.getString("DPreferences.IntegerPortReqHttp.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return false;
}
}
}
if (httpsHost.length() > 0) {
if (httpsPortStr.length() == 0) {
jtpPreferences.setSelectedIndex(3);
JOptionPane.showMessageDialog(this, res.getString("DPreferences.PortReqHttps.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return false;
} else {
try {
int httpsPort = Integer.parseInt(httpsPortStr);
if (httpsPort < 1) {
throw new NumberFormatException();
}
httpsProxyAddress = new ProxyAddress(httpsHost, httpsPort);
} catch (NumberFormatException ex) {
jtpPreferences.setSelectedIndex(3);
JOptionPane.showMessageDialog(this, res.getString("DPreferences.IntegerPortReqHttps.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return false;
}
}
}
if (socksHost.length() > 0) {
if (socksPortStr.length() == 0) {
jtpPreferences.setSelectedIndex(3);
JOptionPane.showMessageDialog(this, res.getString("DPreferences.PortReqSocks.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return false;
} else {
try {
int socksPort = Integer.parseInt(socksPortStr);
if (socksPort < 1) {
throw new NumberFormatException();
}
socksProxyAddress = new ProxyAddress(socksHost, socksPort);
} catch (NumberFormatException ex) {
jtpPreferences.setSelectedIndex(3);
JOptionPane.showMessageDialog(this, res.getString("DPreferences.IntegerPortReqSocks.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return false;
}
}
}
ManualProxySelector manualProxySelector = new ManualProxySelector(httpProxyAddress, httpsProxyAddress, null, socksProxyAddress);
if (!manualProxySelector.equals(defaultProxySelector)) {
ProxySelector.setDefault(manualProxySelector);
}
}
} else if (jrbAutomaticProxyConfig.isSelected()) {
String pacUrl = jtfPacUrl.getText().trim();
if (pacUrl.length() == 0) {
jtpPreferences.setSelectedIndex(3);
JOptionPane.showMessageDialog(this, res.getString("DPreferences.PacUrlReq.message"), getTitle(), JOptionPane.WARNING_MESSAGE);
return false;
}
PacProxySelector pacProxySelector = new PacProxySelector(pacUrl);
if (!pacProxySelector.equals(defaultProxySelector)) {
ProxySelector.setDefault(pacProxySelector);
}
}
return true;
}
use of org.kse.utilities.net.ProxyAddress in project keystore-explorer by kaikramer.
the class ApplicationSettings method load.
/**
* Load application settings from persistent store.
*/
public void load() {
Preferences preferences = getUnderlyingPreferences();
// Authority certificates
useCaCertificates = preferences.getBoolean(KSE3_USECACERTS, false);
String cacertsPath = preferences.get(KSE3_CACERTSFILE, AuthorityCertificates.getDefaultCaCertificatesLocation().toString());
caCertificatesFile = cleanFilePath(new File(cacertsPath));
useWindowsTrustedRootCertificates = preferences.getBoolean(KSE3_USEWINTRUSTROOTCERTS, false);
// Trust checks
enableImportTrustedCertTrustCheck = preferences.getBoolean(KSE3_ENABLEIMPORTTRUSTEDCERTTRUSTCHECK, false);
enableImportCaReplyTrustCheck = preferences.getBoolean(KSE3_ENABLEIMPORTCAREPLYTRUSTCHECK, false);
// Key pair generation
generateKeyPairType = KeyPairType.resolveJce(preferences.get(KSE3_KEYPAIRTYPE, RSA.jce()));
if (generateKeyPairType == null) {
generateKeyPairType = RSA;
}
int defaultKeyPairSize;
if (generateKeyPairType == RSA) {
defaultKeyPairSize = 2048;
} else {
// DSA
defaultKeyPairSize = 1024;
}
generateKeyPairSize = preferences.getInt(KSE3_KEYPAIRSIZE, defaultKeyPairSize);
// Secret key generation
generateSecretKeyType = SecretKeyType.resolveJce(preferences.get(KSE3_SECKEYTYPE, AES.jce()));
if (generateSecretKeyType == null) {
generateSecretKeyType = AES;
}
generateSecretKeySize = preferences.getInt(KSE3_SECKEYSIZE, 192);
// Certificate fingerprint
certificateFingerprintType = DigestType.resolveJce(preferences.get(KSE3_CERTFINGERTYPE, SHA1.jce()));
if (certificateFingerprintType == null) {
certificateFingerprintType = SHA1;
}
// Password quality
passwordQualityConfig = new PasswordQualityConfig(preferences.getBoolean(KSE3_PWDQUALENABLE, false), preferences.getBoolean(KSE3_MINPWDQUALENFORCE, false), preferences.getInt(KSE3_MINPWDQUAL, 60));
// Internet proxy settings
ProxyConfigurationType proxyConfigurationType = ProxyConfigurationType.resolve(preferences.get(KSE3_PROXY, ProxyConfigurationType.SYSTEM.name()));
// default should be system settings because of "java.net.useSystemProxies=true", save it for later usage
SystemProxySelector.setSystemProxySelector(ProxySelector.getDefault());
switch(proxyConfigurationType) {
case NONE:
ProxySelector.setDefault(new NoProxySelector());
break;
case PAC:
// Use PAC URL for proxy configuration
String pacUrl = preferences.get(KSE3_PACURL, null);
if (pacUrl != null) {
ProxySelector.setDefault(new PacProxySelector(pacUrl));
} else {
ProxySelector.setDefault(new NoProxySelector());
}
break;
case MANUAL:
// Use manual settings for HTTP, HTTPS and SOCKS
ProxyAddress httpProxyAddress = null;
ProxyAddress httpsProxyAddress = null;
ProxyAddress socksProxyAddress = null;
String httpHost = preferences.get(KSE3_HTTPHOST, null);
int httpPort = preferences.getInt(KSE3_HTTPPORT, 0);
if (httpHost != null && httpPort > 0) {
httpProxyAddress = new ProxyAddress(httpHost, httpPort);
}
String httpsHost = preferences.get(KSE3_HTTPSHOST, null);
int httpsPort = preferences.getInt(KSE3_HTTPSPORT, 0);
if (httpsHost != null && httpsPort > 0) {
httpsProxyAddress = new ProxyAddress(httpsHost, httpsPort);
}
String socksHost = preferences.get(KSE3_SOCKSHOST, null);
int socksPort = preferences.getInt(KSE3_SOCKSPORT, 0);
if (socksHost != null && socksPort > 0) {
socksProxyAddress = new ProxyAddress(socksHost, socksPort);
}
if (httpProxyAddress != null || httpsProxyAddress != null) {
ProxySelector.setDefault(new ManualProxySelector(httpProxyAddress, httpsProxyAddress, null, socksProxyAddress));
} else {
// no manual settings - use no proxy to connect to the Internet
ProxySelector.setDefault(new NoProxySelector());
}
break;
case SYSTEM:
default:
ProxySelector.setDefault(new SystemProxySelector());
break;
}
// Application size and position
sizeAndPosition = new Rectangle(preferences.getInt(KSE3_XPOS, 0), preferences.getInt(KSE3_YPOS, 0), preferences.getInt(KSE3_WIDTH, KseFrame.DEFAULT_WIDTH), preferences.getInt(KSE3_HEIGHT, KseFrame.DEFAULT_HEIGHT));
// User interface
showToolBar = preferences.getBoolean(KSE3_SHOWTOOLBAR, true);
showStatusBar = preferences.getBoolean(KSE3_SHOWSTATUSBAR, true);
tabLayout = preferences.getInt(KSE3_TABLAYOUT, JTabbedPane.WRAP_TAB_LAYOUT);
// Recent files
ArrayList<File> recentFilesList = new ArrayList<File>();
for (int i = 1; i <= KseFrame.RECENT_FILES_SIZE; i++) {
String recentFile = preferences.get(KSE3_RECENTFILE + i, null);
if (recentFile == null) {
break;
} else {
recentFilesList.add(cleanFilePath(new File(recentFile)));
}
}
recentFiles = recentFilesList.toArray(new File[recentFilesList.size()]);
// Current directory
String currentDirectoryStr = preferences.get(KSE3_CURRENTDIR, null);
if (currentDirectoryStr != null) {
currentDirectory = cleanFilePath(new File(currentDirectoryStr));
}
// Look and feel
lookAndFeelClass = preferences.get(KSE3_LOOKFEEL, null);
lookAndFeelDecorated = preferences.getBoolean(KSE3_LOOKFEELDECOR, false);
// Licensing
licenseAgreed = preferences.getBoolean(KSE3_LICENSEAGREED, false);
// Tip of the day
showTipsOnStartUp = preferences.getBoolean(KSE3_TIPSONSTARTUP, true);
nextTipIndex = preferences.getInt(KSE3_TIPINDEX, 0);
// Default distinguished name
defaultDN = preferences.get(KSE3_DEFAULTDN, "");
// SSL host names and ports for "Examine SSL"
sslHosts = preferences.get(KSE3_SSLHOSTS, "www.google.com;www.amazon.com");
sslPorts = preferences.get(KSE3_SSLPORTS, "443");
// auto update check
autoUpdateCheckEnabled = preferences.getBoolean(KSE3_AUTO_UPDATE_CHECK_ENABLED, true);
autoUpdateCheckInterval = preferences.getInt(KSE3_AUTO_UPDATE_CHECK_INTERVAL, 14);
autoUpdateCheckLastCheck = getDate(preferences, KSE3_AUTO_UPDATE_CHECK_LAST_CHECK, new Date());
// PKCS#11 libraries
p11Libs = preferences.get(KSE3_PKCS11_LIBS, "");
}
Aggregations