3737import javax .security .auth .callback .*;
3838
3939import sun .security .util .Debug ;
40+ import sun .security .util .CryptoAlgorithmConstraints ;
4041
4142/**
4243 * This class represents a storage facility for cryptographic
@@ -839,12 +840,21 @@ private String getProviderName() {
839840 * the {@link Security#getProviders() Security.getProviders()} method.
840841 *
841842 * @implNote
842- * The JDK Reference Implementation additionally uses the
843- * {@code jdk.security.provider.preferred}
843+ * The JDK Reference Implementation additionally uses
844+ * <ul>
845+ * <li>the {@code jdk.security.provider.preferred}
844846 * {@link Security#getProperty(String) Security} property to determine
845- * the preferred provider order for the specified algorithm . This
847+ * the preferred provider order for the specified keystore type . This
846848 * may be different from the order of providers returned by
847849 * {@link Security#getProviders() Security.getProviders()}.
850+ * </li>
851+ * <li>the {@code jdk.crypto.disabledAlgorithms}
852+ * {@link Security#getProperty(String) Security} property to determine
853+ * if the specified keystore type is allowed. If the
854+ * {@systemProperty jdk.crypto.disabledAlgorithms} is set, it supersedes
855+ * the security property value.
856+ * </li>
857+ * </ul>
848858 *
849859 * @param type the type of keystore.
850860 * See the KeyStore section in the <a href=
@@ -866,6 +876,11 @@ public static KeyStore getInstance(String type)
866876 throws KeyStoreException
867877 {
868878 Objects .requireNonNull (type , "null type name" );
879+
880+ if (!CryptoAlgorithmConstraints .permits ("KEYSTORE" , type )) {
881+ throw new KeyStoreException (type + " is disabled" );
882+ }
883+
869884 try {
870885 Object [] objs = Security .getImpl (type , "KeyStore" , (String )null );
871886 return new KeyStore ((KeyStoreSpi )objs [0 ], (Provider )objs [1 ], type );
@@ -885,6 +900,14 @@ public static KeyStore getInstance(String type)
885900 * <p> Note that the list of registered providers may be retrieved via
886901 * the {@link Security#getProviders() Security.getProviders()} method.
887902 *
903+ * @implNote
904+ * The JDK Reference Implementation additionally uses
905+ * the {@code jdk.crypto.disabledAlgorithms}
906+ * {@link Security#getProperty(String) Security} property to determine
907+ * if the specified keystore type is allowed. If the
908+ * {@systemProperty jdk.crypto.disabledAlgorithms} is set, it supersedes
909+ * the security property value.
910+ *
888911 * @param type the type of keystore.
889912 * See the KeyStore section in the <a href=
890913 * "{@docRoot}/../specs/security/standard-names.html#keystore-types">
@@ -913,8 +936,15 @@ public static KeyStore getInstance(String type, String provider)
913936 throws KeyStoreException , NoSuchProviderException
914937 {
915938 Objects .requireNonNull (type , "null type name" );
916- if (provider == null || provider .isEmpty ())
939+
940+ if (provider == null || provider .isEmpty ()) {
917941 throw new IllegalArgumentException ("missing provider" );
942+ }
943+
944+ if (!CryptoAlgorithmConstraints .permits ("KEYSTORE" , type )) {
945+ throw new KeyStoreException (type + " is disabled" );
946+ }
947+
918948 try {
919949 Object [] objs = Security .getImpl (type , "KeyStore" , provider );
920950 return new KeyStore ((KeyStoreSpi )objs [0 ], (Provider )objs [1 ], type );
@@ -931,6 +961,14 @@ public static KeyStore getInstance(String type, String provider)
931961 * object is returned. Note that the specified provider object
932962 * does not have to be registered in the provider list.
933963 *
964+ * @implNote
965+ * The JDK Reference Implementation additionally uses
966+ * the {@code jdk.crypto.disabledAlgorithms}
967+ * {@link Security#getProperty(String) Security} property to determine
968+ * if the specified keystore type is allowed. If the
969+ * {@systemProperty jdk.crypto.disabledAlgorithms} is set, it supersedes
970+ * the security property value.
971+ *
934972 * @param type the type of keystore.
935973 * See the KeyStore section in the <a href=
936974 * "{@docRoot}/../specs/security/standard-names.html#keystore-types">
@@ -958,8 +996,15 @@ public static KeyStore getInstance(String type, Provider provider)
958996 throws KeyStoreException
959997 {
960998 Objects .requireNonNull (type , "null type name" );
961- if (provider == null )
999+
1000+ if (provider == null ) {
9621001 throw new IllegalArgumentException ("missing provider" );
1002+ }
1003+
1004+ if (!CryptoAlgorithmConstraints .permits ("KEYSTORE" , type )) {
1005+ throw new KeyStoreException (type + " is disabled" );
1006+ }
1007+
9631008 try {
9641009 Object [] objs = Security .getImpl (type , "KeyStore" , provider );
9651010 return new KeyStore ((KeyStoreSpi )objs [0 ], (Provider )objs [1 ], type );
@@ -1675,6 +1720,14 @@ public final void setEntry(String alias, Entry entry,
16751720 * <p> Note that the list of registered providers may be retrieved via
16761721 * the {@link Security#getProviders() Security.getProviders()} method.
16771722 *
1723+ * @implNote
1724+ * The JDK Reference Implementation additionally uses
1725+ * the {@code jdk.crypto.disabledAlgorithms}
1726+ * {@link Security#getProperty(String) Security} property to determine
1727+ * if the specified keystore type is allowed. If the
1728+ * {@systemProperty jdk.crypto.disabledAlgorithms} is set, it supersedes
1729+ * the security property value. Disallowed type will be skipped.
1730+ *
16781731 * @param file the keystore file
16791732 * @param password the keystore password, which may be {@code null}
16801733 *
@@ -1731,6 +1784,14 @@ public static final KeyStore getInstance(File file, char[] password)
17311784 * <p> Note that the list of registered providers may be retrieved via
17321785 * the {@link Security#getProviders() Security.getProviders()} method.
17331786 *
1787+ * @implNote
1788+ * The JDK Reference Implementation additionally uses
1789+ * the {@code jdk.crypto.disabledAlgorithms}
1790+ * {@link Security#getProperty(String) Security} property to determine
1791+ * if the specified keystore type is allowed. If the
1792+ * {@systemProperty jdk.crypto.disabledAlgorithms} is set, it supersedes
1793+ * the security property value. Disallowed type will be skipped.
1794+ *
17341795 * @param file the keystore file
17351796 * @param param the {@code LoadStoreParameter} that specifies how to load
17361797 * the keystore, which may be {@code null}
@@ -1802,8 +1863,12 @@ private static final KeyStore getInstance(File file, char[] password,
18021863 kdebug .println (s .getAlgorithm ()
18031864 + " keystore detected: " + file );
18041865 }
1805- keystore = new KeyStore (impl , p , s .getAlgorithm ());
1806- break ;
1866+ String ksAlgo = s .getAlgorithm ();
1867+ if (CryptoAlgorithmConstraints .permits (
1868+ "KEYSTORE" , ksAlgo )) {
1869+ keystore = new KeyStore (impl , p , ksAlgo );
1870+ break ;
1871+ }
18071872 }
18081873 } catch (NoSuchAlgorithmException e ) {
18091874 // ignore
0 commit comments