Java Code Examples for java.security.KeyStore#getType()

The following examples show how to use java.security.KeyStore#getType() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApkSigningConfigPanel.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
@Override
public String getStoreType() {
    try {
        File f = new File(path.getText());
        if (f.exists()) {
            KeyStore ks = KeyStore.getInstance("jks");
            ks.load(new FileInputStream(f), keystorePassword.getPassword());
            return ks.getType();
        }
    } catch (Exception keyStoreException) {
    }
    return "jks";
}
 
Example 2
Source File: KeystoreSelector.java    From NBANDROID-V2 with Apache License 2.0 5 votes vote down vote up
@Override
public String getStoreType() {
    try {
        File f = new File(path.getText());
        if (f.exists()) {
            KeyStore ks = KeyStore.getInstance("jks");
            ks.load(new FileInputStream(f), keystorePassword.getPassword());
            return ks.getType();
        }
    } catch (Exception keyStoreException) {
    }
    return "jks";
}
 
Example 3
Source File: DProperties.java    From keystore-explorer with GNU General Public License v3.0 5 votes vote down vote up
private DefaultMutableTreeNode createPropertiesNodes() throws CryptoException {
	KeyStore keyStore = currentState.getKeyStore();

	String root = MessageFormat.format(res.getString("DProperties.properties.Root"), history.getName());
	DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(root);

	String file = history.getPath();
	DefaultMutableTreeNode fileNode = new DefaultMutableTreeNode(MessageFormat.format(
			res.getString("DProperties.properties.File"), file));
	rootNode.add(fileNode);

	String type = keyStore.getType();
	DefaultMutableTreeNode typeNode = new DefaultMutableTreeNode(MessageFormat.format(
			res.getString("DProperties.properties.Type"), type));
	rootNode.add(typeNode);

	String provider = keyStore.getProvider().getName();
	DefaultMutableTreeNode providerNode = new DefaultMutableTreeNode(MessageFormat.format(
			res.getString("DProperties.properties.Provider"), provider));
	rootNode.add(providerNode);

	createKeysNodes(rootNode);

	createKeyPairsNodes(rootNode);

	createTrustedCertificatesNodes(rootNode);

	return rootNode;
}
 
Example 4
Source File: Main.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Load the srckeystore from a stream, used in -importkeystore
 * @return the src KeyStore
 */
KeyStore loadSourceKeyStore() throws Exception {

    InputStream is = null;
    File srcksfile = null;
    boolean srcIsPasswordless = false;

    if (P11KEYSTORE.equalsIgnoreCase(srcstoretype) ||
            KeyStoreUtil.isWindowsKeyStore(srcstoretype)) {
        if (!NONE.equals(srcksfname)) {
            System.err.println(MessageFormat.format(rb.getString
                (".keystore.must.be.NONE.if.storetype.is.{0}"), srcstoretype));
            System.err.println();
            tinyHelp();
        }
    } else {
        srcksfile = new File(srcksfname);
        is = new FileInputStream(srcksfile);
    }

    KeyStore store;
    try {
        // Probe for keystore type when filename is available
        if (srcksfile != null && is != null && srcProviderName == null &&
                srcstoretype == null) {
            store = KeyStore.getInstance(srcksfile, srcstorePass);
            srcstoretype = store.getType();
            if (srcstoretype.equalsIgnoreCase("pkcs12")) {
                srcIsPasswordless = PKCS12KeyStore.isPasswordless(srcksfile);
            }
        } else {
            if (srcstoretype == null) {
                srcstoretype = KeyStore.getDefaultType();
            }
            if (srcProviderName == null) {
                store = KeyStore.getInstance(srcstoretype);
            } else {
                store = KeyStore.getInstance(srcstoretype, srcProviderName);
            }
        }

        if (srcstorePass == null
                && !srcprotectedPath
                && !KeyStoreUtil.isWindowsKeyStore(srcstoretype)
                && !srcIsPasswordless) {
            System.err.print(rb.getString("Enter.source.keystore.password."));
            System.err.flush();
            srcstorePass = Password.readPassword(System.in);
            passwords.add(srcstorePass);
        }

        // always let keypass be storepass when using pkcs12
        if (P12KEYSTORE.equalsIgnoreCase(srcstoretype)) {
            if (srckeyPass != null && srcstorePass != null &&
                    !Arrays.equals(srcstorePass, srckeyPass)) {
                MessageFormat form = new MessageFormat(rb.getString(
                    "Warning.Different.store.and.key.passwords.not.supported.for.PKCS12.KeyStores.Ignoring.user.specified.command.value."));
                Object[] source = {"-srckeypass"};
                System.err.println(form.format(source));
                srckeyPass = srcstorePass;
            }
        }

        store.load(is, srcstorePass);   // "is" already null in PKCS11
    } finally {
        if (is != null) {
            is.close();
        }
    }

    if (srcstorePass == null
            && !srcIsPasswordless
            && !KeyStoreUtil.isWindowsKeyStore(srcstoretype)) {
        // anti refactoring, copied from printNoIntegrityWarning(),
        // but change 2 lines
        System.err.println();
        System.err.println(rb.getString
            (".WARNING.WARNING.WARNING."));
        System.err.println(rb.getString
            (".The.integrity.of.the.information.stored.in.the.srckeystore."));
        System.err.println(rb.getString
            (".WARNING.WARNING.WARNING."));
        System.err.println();
    }

    return store;
}