Search in sources :

Example 1 with PasswordQualityConfig

use of org.kse.gui.password.PasswordQualityConfig 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, "");
}
Also used : PacProxySelector(org.kse.utilities.net.PacProxySelector) ProxyAddress(org.kse.utilities.net.ProxyAddress) Rectangle(java.awt.Rectangle) ArrayList(java.util.ArrayList) SystemProxySelector(org.kse.utilities.net.SystemProxySelector) NoProxySelector(org.kse.utilities.net.NoProxySelector) Date(java.util.Date) ProxyConfigurationType(org.kse.utilities.net.ProxyConfigurationType) ManualProxySelector(org.kse.utilities.net.ManualProxySelector) Preferences(java.util.prefs.Preferences) File(java.io.File) PasswordQualityConfig(org.kse.gui.password.PasswordQualityConfig)

Aggregations

Rectangle (java.awt.Rectangle)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 Preferences (java.util.prefs.Preferences)1 PasswordQualityConfig (org.kse.gui.password.PasswordQualityConfig)1 ManualProxySelector (org.kse.utilities.net.ManualProxySelector)1 NoProxySelector (org.kse.utilities.net.NoProxySelector)1 PacProxySelector (org.kse.utilities.net.PacProxySelector)1 ProxyAddress (org.kse.utilities.net.ProxyAddress)1 ProxyConfigurationType (org.kse.utilities.net.ProxyConfigurationType)1 SystemProxySelector (org.kse.utilities.net.SystemProxySelector)1