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()); } }
/** 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 { defaultKeyPairSize = 1024; // DSA } 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, ""); }