java.security.KeyStoreException#toString ( )源码实例Demo

下面列出了java.security.KeyStoreException#toString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dragonwell8_jdk   文件: Main.java
/**
 * 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;
    }
}
 
源代码2 项目: TencentKona-8   文件: Main.java
/**
 * 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;
    }
}
 
源代码3 项目: jdk8u60   文件: Main.java
/**
 * 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;
    }
}
 
源代码4 项目: openjdk-jdk8u   文件: Main.java
/**
 * 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;
    }
}
 
源代码5 项目: openjdk-jdk8u-backup   文件: Main.java
/**
 * 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;
    }
}
 
源代码6 项目: Bytecoder   文件: Main.java
/**
 * 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;
    }
}
 
源代码7 项目: openjdk-jdk9   文件: Main.java
/**
 * 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;
    }
}
 
源代码8 项目: jdk8u-jdk   文件: Main.java
/**
 * 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;
    }
}
 
源代码9 项目: hottub   文件: Main.java
/**
 * 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;
    }
}
 
源代码10 项目: openjdk-8-source   文件: Main.java
/**
 * 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;
    }
}
 
源代码11 项目: openjdk-8   文件: Main.java
/**
 * 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;
    }
}
 
源代码12 项目: jdk8u_jdk   文件: Main.java
/**
 * 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;
    }
}
 
源代码13 项目: jdk8u-jdk   文件: Main.java
/**
 * 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;
    }
}
 
源代码14 项目: jdk8u-dev-jdk   文件: Main.java
/**
 * 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;
    }
}