Java Code Examples for java.security.KeyStoreException#toString()

The following examples show how to use java.security.KeyStoreException#toString() . 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: Main.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Import a single entry named alias from srckeystore
 * @returns 1 if the import action succeed
 *          0 if user choose to ignore an alias-dumplicated entry
 *          2 if setEntry throws Exception
 */
private int doImportKeyStoreSingle(KeyStore srckeystore, String alias)
        throws Exception {

    String newAlias = (dest==null) ? alias : dest;

    if (keyStore.containsAlias(newAlias)) {
        Object[] source = {alias};
        if (noprompt) {
            System.err.println(new MessageFormat(rb.getString(
                    "Warning.Overwriting.existing.alias.alias.in.destination.keystore")).format(source));
        } else {
            String reply = getYesNoReply(new MessageFormat(rb.getString(
                    "Existing.entry.alias.alias.exists.overwrite.no.")).format(source));
            if ("NO".equals(reply)) {
                newAlias = inputStringFromStdin(rb.getString
                        ("Enter.new.alias.name.RETURN.to.cancel.import.for.this.entry."));
                if ("".equals(newAlias)) {
                    System.err.println(new MessageFormat(rb.getString(
                            "Entry.for.alias.alias.not.imported.")).format(
                            source));
                    return 0;
                }
            }
        }
    }

    Pair<Entry,char[]> objs = recoverEntry(srckeystore, alias, srcstorePass, srckeyPass);
    Entry entry = objs.fst;

    PasswordProtection pp = null;

    // According to keytool.html, "The destination entry will be protected
    // using destkeypass. If destkeypass is not provided, the destination
    // entry will be protected with the source entry password."
    // so always try to protect with destKeyPass.
    char[] newPass = null;
    if (destKeyPass != null) {
        newPass = destKeyPass;
        pp = new PasswordProtection(destKeyPass);
    } else if (objs.snd != null) {
        newPass = objs.snd;
        pp = new PasswordProtection(objs.snd);
    }

    try {
        Certificate c = srckeystore.getCertificate(alias);
        if (c != null) {
            checkWeak("<" + newAlias + ">", c);
        }
        keyStore.setEntry(newAlias, entry, pp);
        // Place the check so that only successful imports are blocked.
        // For example, we don't block a failed SecretEntry import.
        if (P12KEYSTORE.equalsIgnoreCase(storetype)) {
            if (newPass != null && !Arrays.equals(newPass, storePass)) {
                throw new Exception(rb.getString(
                        "The.destination.pkcs12.keystore.has.different.storepass.and.keypass.Please.retry.with.destkeypass.specified."));
            }
        }
        return 1;
    } catch (KeyStoreException kse) {
        Object[] source2 = {alias, kse.toString()};
        MessageFormat form = new MessageFormat(rb.getString(
                "Problem.importing.entry.for.alias.alias.exception.Entry.for.alias.alias.not.imported."));
        System.err.println(form.format(source2));
        return 2;
    }
}
 
Example 2
Source File: Main.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Import a single entry named alias from srckeystore
 * @returns 1 if the import action succeed
 *          0 if user choose to ignore an alias-dumplicated entry
 *          2 if setEntry throws Exception
 */
private int doImportKeyStoreSingle(KeyStore srckeystore, String alias)
        throws Exception {

    String newAlias = (dest==null) ? alias : dest;

    if (keyStore.containsAlias(newAlias)) {
        Object[] source = {alias};
        if (noprompt) {
            System.err.println(new MessageFormat(rb.getString(
                    "Warning.Overwriting.existing.alias.alias.in.destination.keystore")).format(source));
        } else {
            String reply = getYesNoReply(new MessageFormat(rb.getString(
                    "Existing.entry.alias.alias.exists.overwrite.no.")).format(source));
            if ("NO".equals(reply)) {
                newAlias = inputStringFromStdin(rb.getString
                        ("Enter.new.alias.name.RETURN.to.cancel.import.for.this.entry."));
                if ("".equals(newAlias)) {
                    System.err.println(new MessageFormat(rb.getString(
                            "Entry.for.alias.alias.not.imported.")).format(
                            source));
                    return 0;
                }
            }
        }
    }

    Pair<Entry,char[]> objs = recoverEntry(srckeystore, alias, srcstorePass, srckeyPass);
    Entry entry = objs.fst;

    PasswordProtection pp = null;

    // According to keytool.html, "The destination entry will be protected
    // using destkeypass. If destkeypass is not provided, the destination
    // entry will be protected with the source entry password."
    // so always try to protect with destKeyPass.
    char[] newPass = null;
    if (destKeyPass != null) {
        newPass = destKeyPass;
        pp = new PasswordProtection(destKeyPass);
    } else if (objs.snd != null) {
        newPass = objs.snd;
        pp = new PasswordProtection(objs.snd);
    }

    try {
        Certificate c = srckeystore.getCertificate(alias);
        if (c != null) {
            checkWeak("<" + newAlias + ">", c);
        }
        keyStore.setEntry(newAlias, entry, pp);
        // Place the check so that only successful imports are blocked.
        // For example, we don't block a failed SecretEntry import.
        if (P12KEYSTORE.equalsIgnoreCase(storetype)) {
            if (newPass != null && !Arrays.equals(newPass, storePass)) {
                throw new Exception(rb.getString(
                        "The.destination.pkcs12.keystore.has.different.storepass.and.keypass.Please.retry.with.destkeypass.specified."));
            }
        }
        return 1;
    } catch (KeyStoreException kse) {
        Object[] source2 = {alias, kse.toString()};
        MessageFormat form = new MessageFormat(rb.getString(
                "Problem.importing.entry.for.alias.alias.exception.Entry.for.alias.alias.not.imported."));
        System.err.println(form.format(source2));
        return 2;
    }
}
 
Example 3
Source File: Main.java    From jdk8u60 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Import a single entry named alias from srckeystore
 * @returns 1 if the import action succeed
 *          0 if user choose to ignore an alias-dumplicated entry
 *          2 if setEntry throws Exception
 */
private int doImportKeyStoreSingle(KeyStore srckeystore, String alias)
        throws Exception {

    String newAlias = (dest==null) ? alias : dest;

    if (keyStore.containsAlias(newAlias)) {
        Object[] source = {alias};
        if (noprompt) {
            System.err.println(new MessageFormat(rb.getString(
                    "Warning.Overwriting.existing.alias.alias.in.destination.keystore")).format(source));
        } else {
            String reply = getYesNoReply(new MessageFormat(rb.getString(
                    "Existing.entry.alias.alias.exists.overwrite.no.")).format(source));
            if ("NO".equals(reply)) {
                newAlias = inputStringFromStdin(rb.getString
                        ("Enter.new.alias.name.RETURN.to.cancel.import.for.this.entry."));
                if ("".equals(newAlias)) {
                    System.err.println(new MessageFormat(rb.getString(
                            "Entry.for.alias.alias.not.imported.")).format(
                            source));
                    return 0;
                }
            }
        }
    }

    Pair<Entry,char[]> objs = recoverEntry(srckeystore, alias, srcstorePass, srckeyPass);
    Entry entry = objs.fst;

    PasswordProtection pp = null;

    // According to keytool.html, "The destination entry will be protected
    // using destkeypass. If destkeypass is not provided, the destination
    // entry will be protected with the source entry password."
    // so always try to protect with destKeyPass.
    char[] newPass = null;
    if (destKeyPass != null) {
        newPass = destKeyPass;
        pp = new PasswordProtection(destKeyPass);
    } else if (objs.snd != null) {
        newPass = objs.snd;
        pp = new PasswordProtection(objs.snd);
    }

    try {
        keyStore.setEntry(newAlias, entry, pp);
        // Place the check so that only successful imports are blocked.
        // For example, we don't block a failed SecretEntry import.
        if (P12KEYSTORE.equalsIgnoreCase(storetype)) {
            if (newPass != null && !Arrays.equals(newPass, storePass)) {
                throw new Exception(rb.getString(
                        "The.destination.pkcs12.keystore.has.different.storepass.and.keypass.Please.retry.with.destkeypass.specified."));
            }
        }
        return 1;
    } catch (KeyStoreException kse) {
        Object[] source2 = {alias, kse.toString()};
        MessageFormat form = new MessageFormat(rb.getString(
                "Problem.importing.entry.for.alias.alias.exception.Entry.for.alias.alias.not.imported."));
        System.err.println(form.format(source2));
        return 2;
    }
}
 
Example 4
Source File: Main.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Import a single entry named alias from srckeystore
 * @returns 1 if the import action succeed
 *          0 if user choose to ignore an alias-dumplicated entry
 *          2 if setEntry throws Exception
 */
private int doImportKeyStoreSingle(KeyStore srckeystore, String alias)
        throws Exception {

    String newAlias = (dest==null) ? alias : dest;

    if (keyStore.containsAlias(newAlias)) {
        Object[] source = {alias};
        if (noprompt) {
            System.err.println(new MessageFormat(rb.getString(
                    "Warning.Overwriting.existing.alias.alias.in.destination.keystore")).format(source));
        } else {
            String reply = getYesNoReply(new MessageFormat(rb.getString(
                    "Existing.entry.alias.alias.exists.overwrite.no.")).format(source));
            if ("NO".equals(reply)) {
                newAlias = inputStringFromStdin(rb.getString
                        ("Enter.new.alias.name.RETURN.to.cancel.import.for.this.entry."));
                if ("".equals(newAlias)) {
                    System.err.println(new MessageFormat(rb.getString(
                            "Entry.for.alias.alias.not.imported.")).format(
                            source));
                    return 0;
                }
            }
        }
    }

    Pair<Entry,char[]> objs = recoverEntry(srckeystore, alias, srcstorePass, srckeyPass);
    Entry entry = objs.fst;

    PasswordProtection pp = null;

    // According to keytool.html, "The destination entry will be protected
    // using destkeypass. If destkeypass is not provided, the destination
    // entry will be protected with the source entry password."
    // so always try to protect with destKeyPass.
    char[] newPass = null;
    if (destKeyPass != null) {
        newPass = destKeyPass;
        pp = new PasswordProtection(destKeyPass);
    } else if (objs.snd != null) {
        newPass = objs.snd;
        pp = new PasswordProtection(objs.snd);
    }

    try {
        Certificate c = srckeystore.getCertificate(alias);
        if (c != null) {
            checkWeak("<" + newAlias + ">", c);
        }
        keyStore.setEntry(newAlias, entry, pp);
        // Place the check so that only successful imports are blocked.
        // For example, we don't block a failed SecretEntry import.
        if (P12KEYSTORE.equalsIgnoreCase(storetype)) {
            if (newPass != null && !Arrays.equals(newPass, storePass)) {
                throw new Exception(rb.getString(
                        "The.destination.pkcs12.keystore.has.different.storepass.and.keypass.Please.retry.with.destkeypass.specified."));
            }
        }
        return 1;
    } catch (KeyStoreException kse) {
        Object[] source2 = {alias, kse.toString()};
        MessageFormat form = new MessageFormat(rb.getString(
                "Problem.importing.entry.for.alias.alias.exception.Entry.for.alias.alias.not.imported."));
        System.err.println(form.format(source2));
        return 2;
    }
}
 
Example 5
Source File: Main.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Import a single entry named alias from srckeystore
 * @returns 1 if the import action succeed
 *          0 if user choose to ignore an alias-dumplicated entry
 *          2 if setEntry throws Exception
 */
private int doImportKeyStoreSingle(KeyStore srckeystore, String alias)
        throws Exception {

    String newAlias = (dest==null) ? alias : dest;

    if (keyStore.containsAlias(newAlias)) {
        Object[] source = {alias};
        if (noprompt) {
            System.err.println(new MessageFormat(rb.getString(
                    "Warning.Overwriting.existing.alias.alias.in.destination.keystore")).format(source));
        } else {
            String reply = getYesNoReply(new MessageFormat(rb.getString(
                    "Existing.entry.alias.alias.exists.overwrite.no.")).format(source));
            if ("NO".equals(reply)) {
                newAlias = inputStringFromStdin(rb.getString
                        ("Enter.new.alias.name.RETURN.to.cancel.import.for.this.entry."));
                if ("".equals(newAlias)) {
                    System.err.println(new MessageFormat(rb.getString(
                            "Entry.for.alias.alias.not.imported.")).format(
                            source));
                    return 0;
                }
            }
        }
    }

    Pair<Entry,char[]> objs = recoverEntry(srckeystore, alias, srcstorePass, srckeyPass);
    Entry entry = objs.fst;

    PasswordProtection pp = null;

    // According to keytool.html, "The destination entry will be protected
    // using destkeypass. If destkeypass is not provided, the destination
    // entry will be protected with the source entry password."
    // so always try to protect with destKeyPass.
    char[] newPass = null;
    if (destKeyPass != null) {
        newPass = destKeyPass;
        pp = new PasswordProtection(destKeyPass);
    } else if (objs.snd != null) {
        newPass = objs.snd;
        pp = new PasswordProtection(objs.snd);
    }

    try {
        Certificate c = srckeystore.getCertificate(alias);
        if (c != null) {
            checkWeak("<" + newAlias + ">", c);
        }
        keyStore.setEntry(newAlias, entry, pp);
        // Place the check so that only successful imports are blocked.
        // For example, we don't block a failed SecretEntry import.
        if (P12KEYSTORE.equalsIgnoreCase(storetype)) {
            if (newPass != null && !Arrays.equals(newPass, storePass)) {
                throw new Exception(rb.getString(
                        "The.destination.pkcs12.keystore.has.different.storepass.and.keypass.Please.retry.with.destkeypass.specified."));
            }
        }
        return 1;
    } catch (KeyStoreException kse) {
        Object[] source2 = {alias, kse.toString()};
        MessageFormat form = new MessageFormat(rb.getString(
                "Problem.importing.entry.for.alias.alias.exception.Entry.for.alias.alias.not.imported."));
        System.err.println(form.format(source2));
        return 2;
    }
}
 
Example 6
Source File: Main.java    From Bytecoder with Apache License 2.0 4 votes vote down vote up
/**
 * Import a single entry named alias from srckeystore
 * @return  1 if the import action succeed
 *          0 if user choose to ignore an alias-dumplicated entry
 *          2 if setEntry throws Exception
 */
private int doImportKeyStoreSingle(KeyStore srckeystore, String alias)
        throws Exception {

    String newAlias = (dest==null) ? alias : dest;

    if (keyStore.containsAlias(newAlias)) {
        Object[] source = {alias};
        if (noprompt) {
            System.err.println(new MessageFormat(rb.getString(
                    "Warning.Overwriting.existing.alias.alias.in.destination.keystore")).format(source));
        } else {
            String reply = getYesNoReply(new MessageFormat(rb.getString(
                    "Existing.entry.alias.alias.exists.overwrite.no.")).format(source));
            if ("NO".equals(reply)) {
                newAlias = inputStringFromStdin(rb.getString
                        ("Enter.new.alias.name.RETURN.to.cancel.import.for.this.entry."));
                if ("".equals(newAlias)) {
                    System.err.println(new MessageFormat(rb.getString(
                            "Entry.for.alias.alias.not.imported.")).format(
                            source));
                    return 0;
                }
            }
        }
    }

    Pair<Entry,char[]> objs = recoverEntry(srckeystore, alias, srcstorePass, srckeyPass);
    Entry entry = objs.fst;

    PasswordProtection pp = null;

    // According to keytool.html, "The destination entry will be protected
    // using destkeypass. If destkeypass is not provided, the destination
    // entry will be protected with the source entry password."
    // so always try to protect with destKeyPass.
    char[] newPass = null;
    if (destKeyPass != null) {
        newPass = destKeyPass;
        pp = new PasswordProtection(destKeyPass);
    } else if (objs.snd != null) {
        newPass = P12KEYSTORE.equalsIgnoreCase(storetype) ?
                storePass : objs.snd;
        pp = new PasswordProtection(newPass);
    }

    try {
        Certificate c = srckeystore.getCertificate(alias);
        if (c != null) {
            checkWeak("<" + newAlias + ">", c);
        }
        keyStore.setEntry(newAlias, entry, pp);
        // Place the check so that only successful imports are blocked.
        // For example, we don't block a failed SecretEntry import.
        if (P12KEYSTORE.equalsIgnoreCase(storetype)) {
            if (newPass != null && !Arrays.equals(newPass, storePass)) {
                throw new Exception(rb.getString(
                        "The.destination.pkcs12.keystore.has.different.storepass.and.keypass.Please.retry.with.destkeypass.specified."));
            }
        }
        return 1;
    } catch (KeyStoreException kse) {
        Object[] source2 = {alias, kse.toString()};
        MessageFormat form = new MessageFormat(rb.getString(
                "Problem.importing.entry.for.alias.alias.exception.Entry.for.alias.alias.not.imported."));
        System.err.println(form.format(source2));
        return 2;
    }
}
 
Example 7
Source File: Main.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Import a single entry named alias from srckeystore
 * @return  1 if the import action succeed
 *          0 if user choose to ignore an alias-dumplicated entry
 *          2 if setEntry throws Exception
 */
private int doImportKeyStoreSingle(KeyStore srckeystore, String alias)
        throws Exception {

    String newAlias = (dest==null) ? alias : dest;

    if (keyStore.containsAlias(newAlias)) {
        Object[] source = {alias};
        if (noprompt) {
            System.err.println(new MessageFormat(rb.getString(
                    "Warning.Overwriting.existing.alias.alias.in.destination.keystore")).format(source));
        } else {
            String reply = getYesNoReply(new MessageFormat(rb.getString(
                    "Existing.entry.alias.alias.exists.overwrite.no.")).format(source));
            if ("NO".equals(reply)) {
                newAlias = inputStringFromStdin(rb.getString
                        ("Enter.new.alias.name.RETURN.to.cancel.import.for.this.entry."));
                if ("".equals(newAlias)) {
                    System.err.println(new MessageFormat(rb.getString(
                            "Entry.for.alias.alias.not.imported.")).format(
                            source));
                    return 0;
                }
            }
        }
    }

    Pair<Entry,char[]> objs = recoverEntry(srckeystore, alias, srcstorePass, srckeyPass);
    Entry entry = objs.fst;

    PasswordProtection pp = null;

    // According to keytool.html, "The destination entry will be protected
    // using destkeypass. If destkeypass is not provided, the destination
    // entry will be protected with the source entry password."
    // so always try to protect with destKeyPass.
    char[] newPass = null;
    if (destKeyPass != null) {
        newPass = destKeyPass;
        pp = new PasswordProtection(destKeyPass);
    } else if (objs.snd != null) {
        newPass = objs.snd;
        pp = new PasswordProtection(objs.snd);
    }

    try {
        Certificate c = srckeystore.getCertificate(alias);
        if (c != null) {
            checkWeak("<" + newAlias + ">", c);
        }
        keyStore.setEntry(newAlias, entry, pp);
        // Place the check so that only successful imports are blocked.
        // For example, we don't block a failed SecretEntry import.
        if (P12KEYSTORE.equalsIgnoreCase(storetype)) {
            if (newPass != null && !Arrays.equals(newPass, storePass)) {
                throw new Exception(rb.getString(
                        "The.destination.pkcs12.keystore.has.different.storepass.and.keypass.Please.retry.with.destkeypass.specified."));
            }
        }
        return 1;
    } catch (KeyStoreException kse) {
        Object[] source2 = {alias, kse.toString()};
        MessageFormat form = new MessageFormat(rb.getString(
                "Problem.importing.entry.for.alias.alias.exception.Entry.for.alias.alias.not.imported."));
        System.err.println(form.format(source2));
        return 2;
    }
}
 
Example 8
Source File: Main.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Import a single entry named alias from srckeystore
 * @returns 1 if the import action succeed
 *          0 if user choose to ignore an alias-dumplicated entry
 *          2 if setEntry throws Exception
 */
private int doImportKeyStoreSingle(KeyStore srckeystore, String alias)
        throws Exception {

    String newAlias = (dest==null) ? alias : dest;

    if (keyStore.containsAlias(newAlias)) {
        Object[] source = {alias};
        if (noprompt) {
            System.err.println(new MessageFormat(rb.getString(
                    "Warning.Overwriting.existing.alias.alias.in.destination.keystore")).format(source));
        } else {
            String reply = getYesNoReply(new MessageFormat(rb.getString(
                    "Existing.entry.alias.alias.exists.overwrite.no.")).format(source));
            if ("NO".equals(reply)) {
                newAlias = inputStringFromStdin(rb.getString
                        ("Enter.new.alias.name.RETURN.to.cancel.import.for.this.entry."));
                if ("".equals(newAlias)) {
                    System.err.println(new MessageFormat(rb.getString(
                            "Entry.for.alias.alias.not.imported.")).format(
                            source));
                    return 0;
                }
            }
        }
    }

    Pair<Entry,char[]> objs = recoverEntry(srckeystore, alias, srcstorePass, srckeyPass);
    Entry entry = objs.fst;

    PasswordProtection pp = null;

    // According to keytool.html, "The destination entry will be protected
    // using destkeypass. If destkeypass is not provided, the destination
    // entry will be protected with the source entry password."
    // so always try to protect with destKeyPass.
    char[] newPass = null;
    if (destKeyPass != null) {
        newPass = destKeyPass;
        pp = new PasswordProtection(destKeyPass);
    } else if (objs.snd != null) {
        newPass = objs.snd;
        pp = new PasswordProtection(objs.snd);
    }

    try {
        keyStore.setEntry(newAlias, entry, pp);
        // Place the check so that only successful imports are blocked.
        // For example, we don't block a failed SecretEntry import.
        if (P12KEYSTORE.equalsIgnoreCase(storetype)) {
            if (newPass != null && !Arrays.equals(newPass, storePass)) {
                throw new Exception(rb.getString(
                        "The.destination.pkcs12.keystore.has.different.storepass.and.keypass.Please.retry.with.destkeypass.specified."));
            }
        }
        return 1;
    } catch (KeyStoreException kse) {
        Object[] source2 = {alias, kse.toString()};
        MessageFormat form = new MessageFormat(rb.getString(
                "Problem.importing.entry.for.alias.alias.exception.Entry.for.alias.alias.not.imported."));
        System.err.println(form.format(source2));
        return 2;
    }
}
 
Example 9
Source File: Main.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Import a single entry named alias from srckeystore
 * @returns 1 if the import action succeed
 *          0 if user choose to ignore an alias-dumplicated entry
 *          2 if setEntry throws Exception
 */
private int doImportKeyStoreSingle(KeyStore srckeystore, String alias)
        throws Exception {

    String newAlias = (dest==null) ? alias : dest;

    if (keyStore.containsAlias(newAlias)) {
        Object[] source = {alias};
        if (noprompt) {
            System.err.println(new MessageFormat(rb.getString(
                    "Warning.Overwriting.existing.alias.alias.in.destination.keystore")).format(source));
        } else {
            String reply = getYesNoReply(new MessageFormat(rb.getString(
                    "Existing.entry.alias.alias.exists.overwrite.no.")).format(source));
            if ("NO".equals(reply)) {
                newAlias = inputStringFromStdin(rb.getString
                        ("Enter.new.alias.name.RETURN.to.cancel.import.for.this.entry."));
                if ("".equals(newAlias)) {
                    System.err.println(new MessageFormat(rb.getString(
                            "Entry.for.alias.alias.not.imported.")).format(
                            source));
                    return 0;
                }
            }
        }
    }

    Pair<Entry,char[]> objs = recoverEntry(srckeystore, alias, srcstorePass, srckeyPass);
    Entry entry = objs.fst;

    PasswordProtection pp = null;

    // According to keytool.html, "The destination entry will be protected
    // using destkeypass. If destkeypass is not provided, the destination
    // entry will be protected with the source entry password."
    // so always try to protect with destKeyPass.
    char[] newPass = null;
    if (destKeyPass != null) {
        newPass = destKeyPass;
        pp = new PasswordProtection(destKeyPass);
    } else if (objs.snd != null) {
        newPass = objs.snd;
        pp = new PasswordProtection(objs.snd);
    }

    try {
        keyStore.setEntry(newAlias, entry, pp);
        // Place the check so that only successful imports are blocked.
        // For example, we don't block a failed SecretEntry import.
        if (P12KEYSTORE.equalsIgnoreCase(storetype)) {
            if (newPass != null && !Arrays.equals(newPass, storePass)) {
                throw new Exception(rb.getString(
                        "The.destination.pkcs12.keystore.has.different.storepass.and.keypass.Please.retry.with.destkeypass.specified."));
            }
        }
        return 1;
    } catch (KeyStoreException kse) {
        Object[] source2 = {alias, kse.toString()};
        MessageFormat form = new MessageFormat(rb.getString(
                "Problem.importing.entry.for.alias.alias.exception.Entry.for.alias.alias.not.imported."));
        System.err.println(form.format(source2));
        return 2;
    }
}
 
Example 10
Source File: Main.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Import a single entry named alias from srckeystore
 * @returns 1 if the import action succeed
 *          0 if user choose to ignore an alias-dumplicated entry
 *          2 if setEntry throws Exception
 */
private int doImportKeyStoreSingle(KeyStore srckeystore, String alias)
        throws Exception {

    String newAlias = (dest==null) ? alias : dest;

    if (keyStore.containsAlias(newAlias)) {
        Object[] source = {alias};
        if (noprompt) {
            System.err.println(new MessageFormat(rb.getString(
                    "Warning.Overwriting.existing.alias.alias.in.destination.keystore")).format(source));
        } else {
            String reply = getYesNoReply(new MessageFormat(rb.getString(
                    "Existing.entry.alias.alias.exists.overwrite.no.")).format(source));
            if ("NO".equals(reply)) {
                newAlias = inputStringFromStdin(rb.getString
                        ("Enter.new.alias.name.RETURN.to.cancel.import.for.this.entry."));
                if ("".equals(newAlias)) {
                    System.err.println(new MessageFormat(rb.getString(
                            "Entry.for.alias.alias.not.imported.")).format(
                            source));
                    return 0;
                }
            }
        }
    }

    Pair<Entry,char[]> objs = recoverEntry(srckeystore, alias, srcstorePass, srckeyPass);
    Entry entry = objs.fst;

    PasswordProtection pp = null;

    // According to keytool.html, "The destination entry will be protected
    // using destkeypass. If destkeypass is not provided, the destination
    // entry will be protected with the source entry password."
    // so always try to protect with destKeyPass.
    char[] newPass = null;
    if (destKeyPass != null) {
        newPass = destKeyPass;
        pp = new PasswordProtection(destKeyPass);
    } else if (objs.snd != null) {
        newPass = objs.snd;
        pp = new PasswordProtection(objs.snd);
    }

    try {
        keyStore.setEntry(newAlias, entry, pp);
        // Place the check so that only successful imports are blocked.
        // For example, we don't block a failed SecretEntry import.
        if (P12KEYSTORE.equalsIgnoreCase(storetype)) {
            if (newPass != null && !Arrays.equals(newPass, storePass)) {
                throw new Exception(rb.getString(
                        "The.destination.pkcs12.keystore.has.different.storepass.and.keypass.Please.retry.with.destkeypass.specified."));
            }
        }
        return 1;
    } catch (KeyStoreException kse) {
        Object[] source2 = {alias, kse.toString()};
        MessageFormat form = new MessageFormat(rb.getString(
                "Problem.importing.entry.for.alias.alias.exception.Entry.for.alias.alias.not.imported."));
        System.err.println(form.format(source2));
        return 2;
    }
}
 
Example 11
Source File: Main.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Import a single entry named alias from srckeystore
 * @returns 1 if the import action succeed
 *          0 if user choose to ignore an alias-dumplicated entry
 *          2 if setEntry throws Exception
 */
private int doImportKeyStoreSingle(KeyStore srckeystore, String alias)
        throws Exception {

    String newAlias = (dest==null) ? alias : dest;

    if (keyStore.containsAlias(newAlias)) {
        Object[] source = {alias};
        if (noprompt) {
            System.err.println(new MessageFormat(rb.getString(
                    "Warning.Overwriting.existing.alias.alias.in.destination.keystore")).format(source));
        } else {
            String reply = getYesNoReply(new MessageFormat(rb.getString(
                    "Existing.entry.alias.alias.exists.overwrite.no.")).format(source));
            if ("NO".equals(reply)) {
                newAlias = inputStringFromStdin(rb.getString
                        ("Enter.new.alias.name.RETURN.to.cancel.import.for.this.entry."));
                if ("".equals(newAlias)) {
                    System.err.println(new MessageFormat(rb.getString(
                            "Entry.for.alias.alias.not.imported.")).format(
                            source));
                    return 0;
                }
            }
        }
    }

    Pair<Entry,char[]> objs = recoverEntry(srckeystore, alias, srcstorePass, srckeyPass);
    Entry entry = objs.fst;

    PasswordProtection pp = null;

    // According to keytool.html, "The destination entry will be protected
    // using destkeypass. If destkeypass is not provided, the destination
    // entry will be protected with the source entry password."
    // so always try to protect with destKeyPass.
    char[] newPass = null;
    if (destKeyPass != null) {
        newPass = destKeyPass;
        pp = new PasswordProtection(destKeyPass);
    } else if (objs.snd != null) {
        newPass = objs.snd;
        pp = new PasswordProtection(objs.snd);
    }

    try {
        keyStore.setEntry(newAlias, entry, pp);
        // Place the check so that only successful imports are blocked.
        // For example, we don't block a failed SecretEntry import.
        if (P12KEYSTORE.equalsIgnoreCase(storetype)) {
            if (newPass != null && !Arrays.equals(newPass, storePass)) {
                throw new Exception(rb.getString(
                        "The.destination.pkcs12.keystore.has.different.storepass.and.keypass.Please.retry.with.destkeypass.specified."));
            }
        }
        return 1;
    } catch (KeyStoreException kse) {
        Object[] source2 = {alias, kse.toString()};
        MessageFormat form = new MessageFormat(rb.getString(
                "Problem.importing.entry.for.alias.alias.exception.Entry.for.alias.alias.not.imported."));
        System.err.println(form.format(source2));
        return 2;
    }
}
 
Example 12
Source File: Main.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Import a single entry named alias from srckeystore
 * @returns 1 if the import action succeed
 *          0 if user choose to ignore an alias-dumplicated entry
 *          2 if setEntry throws Exception
 */
private int doImportKeyStoreSingle(KeyStore srckeystore, String alias)
        throws Exception {

    String newAlias = (dest==null) ? alias : dest;

    if (keyStore.containsAlias(newAlias)) {
        Object[] source = {alias};
        if (noprompt) {
            System.err.println(new MessageFormat(rb.getString(
                    "Warning.Overwriting.existing.alias.alias.in.destination.keystore")).format(source));
        } else {
            String reply = getYesNoReply(new MessageFormat(rb.getString(
                    "Existing.entry.alias.alias.exists.overwrite.no.")).format(source));
            if ("NO".equals(reply)) {
                newAlias = inputStringFromStdin(rb.getString
                        ("Enter.new.alias.name.RETURN.to.cancel.import.for.this.entry."));
                if ("".equals(newAlias)) {
                    System.err.println(new MessageFormat(rb.getString(
                            "Entry.for.alias.alias.not.imported.")).format(
                            source));
                    return 0;
                }
            }
        }
    }

    Pair<Entry,char[]> objs = recoverEntry(srckeystore, alias, srcstorePass, srckeyPass);
    Entry entry = objs.fst;

    PasswordProtection pp = null;

    // According to keytool.html, "The destination entry will be protected
    // using destkeypass. If destkeypass is not provided, the destination
    // entry will be protected with the source entry password."
    // so always try to protect with destKeyPass.
    char[] newPass = null;
    if (destKeyPass != null) {
        newPass = destKeyPass;
        pp = new PasswordProtection(destKeyPass);
    } else if (objs.snd != null) {
        newPass = objs.snd;
        pp = new PasswordProtection(objs.snd);
    }

    try {
        Certificate c = srckeystore.getCertificate(alias);
        if (c != null) {
            checkWeak("<" + newAlias + ">", c);
        }
        keyStore.setEntry(newAlias, entry, pp);
        // Place the check so that only successful imports are blocked.
        // For example, we don't block a failed SecretEntry import.
        if (P12KEYSTORE.equalsIgnoreCase(storetype)) {
            if (newPass != null && !Arrays.equals(newPass, storePass)) {
                throw new Exception(rb.getString(
                        "The.destination.pkcs12.keystore.has.different.storepass.and.keypass.Please.retry.with.destkeypass.specified."));
            }
        }
        return 1;
    } catch (KeyStoreException kse) {
        Object[] source2 = {alias, kse.toString()};
        MessageFormat form = new MessageFormat(rb.getString(
                "Problem.importing.entry.for.alias.alias.exception.Entry.for.alias.alias.not.imported."));
        System.err.println(form.format(source2));
        return 2;
    }
}
 
Example 13
Source File: Main.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Import a single entry named alias from srckeystore
 * @returns 1 if the import action succeed
 *          0 if user choose to ignore an alias-dumplicated entry
 *          2 if setEntry throws Exception
 */
private int doImportKeyStoreSingle(KeyStore srckeystore, String alias)
        throws Exception {

    String newAlias = (dest==null) ? alias : dest;

    if (keyStore.containsAlias(newAlias)) {
        Object[] source = {alias};
        if (noprompt) {
            System.err.println(new MessageFormat(rb.getString(
                    "Warning.Overwriting.existing.alias.alias.in.destination.keystore")).format(source));
        } else {
            String reply = getYesNoReply(new MessageFormat(rb.getString(
                    "Existing.entry.alias.alias.exists.overwrite.no.")).format(source));
            if ("NO".equals(reply)) {
                newAlias = inputStringFromStdin(rb.getString
                        ("Enter.new.alias.name.RETURN.to.cancel.import.for.this.entry."));
                if ("".equals(newAlias)) {
                    System.err.println(new MessageFormat(rb.getString(
                            "Entry.for.alias.alias.not.imported.")).format(
                            source));
                    return 0;
                }
            }
        }
    }

    Pair<Entry,char[]> objs = recoverEntry(srckeystore, alias, srcstorePass, srckeyPass);
    Entry entry = objs.fst;

    PasswordProtection pp = null;

    // According to keytool.html, "The destination entry will be protected
    // using destkeypass. If destkeypass is not provided, the destination
    // entry will be protected with the source entry password."
    // so always try to protect with destKeyPass.
    char[] newPass = null;
    if (destKeyPass != null) {
        newPass = destKeyPass;
        pp = new PasswordProtection(destKeyPass);
    } else if (objs.snd != null) {
        newPass = objs.snd;
        pp = new PasswordProtection(objs.snd);
    }

    try {
        keyStore.setEntry(newAlias, entry, pp);
        // Place the check so that only successful imports are blocked.
        // For example, we don't block a failed SecretEntry import.
        if (P12KEYSTORE.equalsIgnoreCase(storetype)) {
            if (newPass != null && !Arrays.equals(newPass, storePass)) {
                throw new Exception(rb.getString(
                        "The.destination.pkcs12.keystore.has.different.storepass.and.keypass.Please.retry.with.destkeypass.specified."));
            }
        }
        return 1;
    } catch (KeyStoreException kse) {
        Object[] source2 = {alias, kse.toString()};
        MessageFormat form = new MessageFormat(rb.getString(
                "Problem.importing.entry.for.alias.alias.exception.Entry.for.alias.alias.not.imported."));
        System.err.println(form.format(source2));
        return 2;
    }
}
 
Example 14
Source File: Main.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Import a single entry named alias from srckeystore
 * @returns 1 if the import action succeed
 *          0 if user choose to ignore an alias-dumplicated entry
 *          2 if setEntry throws Exception
 */
private int doImportKeyStoreSingle(KeyStore srckeystore, String alias)
        throws Exception {

    String newAlias = (dest==null) ? alias : dest;

    if (keyStore.containsAlias(newAlias)) {
        Object[] source = {alias};
        if (noprompt) {
            System.err.println(new MessageFormat(rb.getString(
                    "Warning.Overwriting.existing.alias.alias.in.destination.keystore")).format(source));
        } else {
            String reply = getYesNoReply(new MessageFormat(rb.getString(
                    "Existing.entry.alias.alias.exists.overwrite.no.")).format(source));
            if ("NO".equals(reply)) {
                newAlias = inputStringFromStdin(rb.getString
                        ("Enter.new.alias.name.RETURN.to.cancel.import.for.this.entry."));
                if ("".equals(newAlias)) {
                    System.err.println(new MessageFormat(rb.getString(
                            "Entry.for.alias.alias.not.imported.")).format(
                            source));
                    return 0;
                }
            }
        }
    }

    Pair<Entry,char[]> objs = recoverEntry(srckeystore, alias, srcstorePass, srckeyPass);
    Entry entry = objs.fst;

    PasswordProtection pp = null;

    // According to keytool.html, "The destination entry will be protected
    // using destkeypass. If destkeypass is not provided, the destination
    // entry will be protected with the source entry password."
    // so always try to protect with destKeyPass.
    char[] newPass = null;
    if (destKeyPass != null) {
        newPass = destKeyPass;
        pp = new PasswordProtection(destKeyPass);
    } else if (objs.snd != null) {
        newPass = objs.snd;
        pp = new PasswordProtection(objs.snd);
    }

    try {
        keyStore.setEntry(newAlias, entry, pp);
        // Place the check so that only successful imports are blocked.
        // For example, we don't block a failed SecretEntry import.
        if (P12KEYSTORE.equalsIgnoreCase(storetype)) {
            if (newPass != null && !Arrays.equals(newPass, storePass)) {
                throw new Exception(rb.getString(
                        "The.destination.pkcs12.keystore.has.different.storepass.and.keypass.Please.retry.with.destkeypass.specified."));
            }
        }
        return 1;
    } catch (KeyStoreException kse) {
        Object[] source2 = {alias, kse.toString()};
        MessageFormat form = new MessageFormat(rb.getString(
                "Problem.importing.entry.for.alias.alias.exception.Entry.for.alias.alias.not.imported."));
        System.err.println(form.format(source2));
        return 2;
    }
}