1649 * implementation for the specified keystore file.
1650 * @throws IOException if there is an I/O or format problem with the
1651 * keystore data, if a password is required but not given,
1652 * or if the given password was incorrect. If the error is
1653 * due to a wrong password, the {@link Throwable#getCause cause}
1654 * of the {@code IOException} should be an
1655 * {@code UnrecoverableKeyException}.
1656 * @throws NoSuchAlgorithmException if the algorithm used to check the
1657 * integrity of the keystore cannot be found.
1658 * @throws CertificateException if any of the certificates in the
1659 * keystore could not be loaded.
1660 * @throws IllegalArgumentException if file does not exist or does not
1661 * refer to a normal file.
1662 * @throws NullPointerException if file is {@code null}.
1663 * @throws SecurityException if a security manager exists and its
1664 * {@link java.lang.SecurityManager#checkRead} method denies
1665 * read access to the specified file.
1666 *
1667 * @see Provider
1668 *
1669 * @since 1.9
1670 */
1671 public static final KeyStore getInstance(File file, char[] password)
1672 throws KeyStoreException, IOException, NoSuchAlgorithmException,
1673 CertificateException {
1674 return getInstance(file, password, null, true);
1675 }
1676
1677 /**
1678 * Returns a loaded keystore object of the appropriate keystore type.
1679 * First the keystore type is determined by probing the specified file.
1680 * Then a keystore object is instantiated and loaded using the data from
1681 * that file.
1682 * A {@code LoadStoreParameter} may be supplied which specifies how to
1683 * unlock the keystore data or perform an integrity check.
1684 *
1685 * <p>
1686 * This method traverses the list of registered security {@linkplain
1687 * Provider providers}, starting with the most preferred Provider.
1688 * For each {@link KeyStoreSpi} implementation supported by a
1689 * Provider, it invokes the {@link
1705 * implementation for the specified keystore file.
1706 * @throws IOException if there is an I/O or format problem with the
1707 * keystore data. If the error is due to an incorrect
1708 * {@code ProtectionParameter} (e.g. wrong password)
1709 * the {@link Throwable#getCause cause} of the
1710 * {@code IOException} should be an
1711 * {@code UnrecoverableKeyException}.
1712 * @throws NoSuchAlgorithmException if the algorithm used to check the
1713 * integrity of the keystore cannot be found.
1714 * @throws CertificateException if any of the certificates in the
1715 * keystore could not be loaded.
1716 * @throws IllegalArgumentException if file does not exist or does not
1717 * refer to a normal file, or if param is not recognized.
1718 * @throws NullPointerException if file is {@code null}.
1719 * @throws SecurityException if a security manager exists and its
1720 * {@link java.lang.SecurityManager#checkRead} method denies
1721 * read access to the specified file.
1722 *
1723 * @see Provider
1724 *
1725 * @since 1.9
1726 */
1727 public static final KeyStore getInstance(File file,
1728 LoadStoreParameter param) throws KeyStoreException, IOException,
1729 NoSuchAlgorithmException, CertificateException {
1730 return getInstance(file, null, param, false);
1731 }
1732
1733 // Used by getInstance(File, char[]) & getInstance(File, LoadStoreParameter)
1734 private static final KeyStore getInstance(File file, char[] password,
1735 LoadStoreParameter param, boolean hasPassword)
1736 throws KeyStoreException, IOException, NoSuchAlgorithmException,
1737 CertificateException {
1738
1739 if (file == null) {
1740 throw new NullPointerException();
1741 }
1742
1743 if (file.isFile() == false) {
1744 throw new IllegalArgumentException(
1745 "File does not exist or it does not refer to a normal file: " +
1989 * as the initial call. If the initial call failed with a
1990 * KeyStoreException, subsequent calls also throw a KeyStoreException.
1991 *
1992 * <p>Calls to {@link #getProtectionParameter getProtectionParameter()}
1993 * will return a {@link KeyStore.PasswordProtection PasswordProtection}
1994 * object encapsulating the password that was used to invoke the
1995 * {@code load} method.
1996 *
1997 * <p><em>Note</em> that the {@link #getKeyStore} method is executed
1998 * within the {@link AccessControlContext} of the code invoking this
1999 * method.
2000 *
2001 * @return a new Builder object
2002 * @param file the File that contains the KeyStore data
2003 * @param protection the ProtectionParameter securing the KeyStore data
2004 * @throws NullPointerException if file or protection is null
2005 * @throws IllegalArgumentException if protection is not an instance
2006 * of either PasswordProtection or CallbackHandlerProtection; or
2007 * if file does not exist or does not refer to a normal file
2008 *
2009 * @since 1.9
2010 */
2011 public static Builder newInstance(File file,
2012 ProtectionParameter protection) {
2013
2014 return newInstance("", null, file, protection);
2015 }
2016
2017 private static final class FileBuilder extends Builder {
2018
2019 private final String type;
2020 private final Provider provider;
2021 private final File file;
2022 private ProtectionParameter protection;
2023 private ProtectionParameter keyProtection;
2024 private final AccessControlContext context;
2025
2026 private KeyStore keyStore;
2027
2028 private Throwable oldException;
2029
|
1649 * implementation for the specified keystore file.
1650 * @throws IOException if there is an I/O or format problem with the
1651 * keystore data, if a password is required but not given,
1652 * or if the given password was incorrect. If the error is
1653 * due to a wrong password, the {@link Throwable#getCause cause}
1654 * of the {@code IOException} should be an
1655 * {@code UnrecoverableKeyException}.
1656 * @throws NoSuchAlgorithmException if the algorithm used to check the
1657 * integrity of the keystore cannot be found.
1658 * @throws CertificateException if any of the certificates in the
1659 * keystore could not be loaded.
1660 * @throws IllegalArgumentException if file does not exist or does not
1661 * refer to a normal file.
1662 * @throws NullPointerException if file is {@code null}.
1663 * @throws SecurityException if a security manager exists and its
1664 * {@link java.lang.SecurityManager#checkRead} method denies
1665 * read access to the specified file.
1666 *
1667 * @see Provider
1668 *
1669 * @since 9
1670 */
1671 public static final KeyStore getInstance(File file, char[] password)
1672 throws KeyStoreException, IOException, NoSuchAlgorithmException,
1673 CertificateException {
1674 return getInstance(file, password, null, true);
1675 }
1676
1677 /**
1678 * Returns a loaded keystore object of the appropriate keystore type.
1679 * First the keystore type is determined by probing the specified file.
1680 * Then a keystore object is instantiated and loaded using the data from
1681 * that file.
1682 * A {@code LoadStoreParameter} may be supplied which specifies how to
1683 * unlock the keystore data or perform an integrity check.
1684 *
1685 * <p>
1686 * This method traverses the list of registered security {@linkplain
1687 * Provider providers}, starting with the most preferred Provider.
1688 * For each {@link KeyStoreSpi} implementation supported by a
1689 * Provider, it invokes the {@link
1705 * implementation for the specified keystore file.
1706 * @throws IOException if there is an I/O or format problem with the
1707 * keystore data. If the error is due to an incorrect
1708 * {@code ProtectionParameter} (e.g. wrong password)
1709 * the {@link Throwable#getCause cause} of the
1710 * {@code IOException} should be an
1711 * {@code UnrecoverableKeyException}.
1712 * @throws NoSuchAlgorithmException if the algorithm used to check the
1713 * integrity of the keystore cannot be found.
1714 * @throws CertificateException if any of the certificates in the
1715 * keystore could not be loaded.
1716 * @throws IllegalArgumentException if file does not exist or does not
1717 * refer to a normal file, or if param is not recognized.
1718 * @throws NullPointerException if file is {@code null}.
1719 * @throws SecurityException if a security manager exists and its
1720 * {@link java.lang.SecurityManager#checkRead} method denies
1721 * read access to the specified file.
1722 *
1723 * @see Provider
1724 *
1725 * @since 9
1726 */
1727 public static final KeyStore getInstance(File file,
1728 LoadStoreParameter param) throws KeyStoreException, IOException,
1729 NoSuchAlgorithmException, CertificateException {
1730 return getInstance(file, null, param, false);
1731 }
1732
1733 // Used by getInstance(File, char[]) & getInstance(File, LoadStoreParameter)
1734 private static final KeyStore getInstance(File file, char[] password,
1735 LoadStoreParameter param, boolean hasPassword)
1736 throws KeyStoreException, IOException, NoSuchAlgorithmException,
1737 CertificateException {
1738
1739 if (file == null) {
1740 throw new NullPointerException();
1741 }
1742
1743 if (file.isFile() == false) {
1744 throw new IllegalArgumentException(
1745 "File does not exist or it does not refer to a normal file: " +
1989 * as the initial call. If the initial call failed with a
1990 * KeyStoreException, subsequent calls also throw a KeyStoreException.
1991 *
1992 * <p>Calls to {@link #getProtectionParameter getProtectionParameter()}
1993 * will return a {@link KeyStore.PasswordProtection PasswordProtection}
1994 * object encapsulating the password that was used to invoke the
1995 * {@code load} method.
1996 *
1997 * <p><em>Note</em> that the {@link #getKeyStore} method is executed
1998 * within the {@link AccessControlContext} of the code invoking this
1999 * method.
2000 *
2001 * @return a new Builder object
2002 * @param file the File that contains the KeyStore data
2003 * @param protection the ProtectionParameter securing the KeyStore data
2004 * @throws NullPointerException if file or protection is null
2005 * @throws IllegalArgumentException if protection is not an instance
2006 * of either PasswordProtection or CallbackHandlerProtection; or
2007 * if file does not exist or does not refer to a normal file
2008 *
2009 * @since 9
2010 */
2011 public static Builder newInstance(File file,
2012 ProtectionParameter protection) {
2013
2014 return newInstance("", null, file, protection);
2015 }
2016
2017 private static final class FileBuilder extends Builder {
2018
2019 private final String type;
2020 private final Provider provider;
2021 private final File file;
2022 private ProtectionParameter protection;
2023 private ProtectionParameter keyProtection;
2024 private final AccessControlContext context;
2025
2026 private KeyStore keyStore;
2027
2028 private Throwable oldException;
2029
|