Skip to content

Commit 37d3f23

Browse files
franferraxmartinuy
andcommitted
8315487: Security Providers Filter
Co-authored-by: Francisco Ferrari Bihurriet <[email protected]> Co-authored-by: Martin Balao <[email protected]>
1 parent 8c1b915 commit 37d3f23

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3619
-400
lines changed

src/java.base/share/classes/java/security/AlgorithmParameterGenerator.java

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,12 +148,20 @@ public final String getAlgorithm() {
148148
* the {@link Security#getProviders() Security.getProviders()} method.
149149
*
150150
* @implNote
151-
* The JDK Reference Implementation additionally uses the
152-
* {@code jdk.security.provider.preferred}
153-
* {@link Security#getProperty(String) Security} property to determine
154-
* the preferred provider order for the specified algorithm. This
155-
* may be different from the order of providers returned by
156-
* {@link Security#getProviders() Security.getProviders()}.
151+
* The JDK Reference Implementation additionally uses the following
152+
* properties to customize the behavior of this method:
153+
* <ul>
154+
* <li> The {@code jdk.security.provider.preferred}
155+
* {@link Security#getProperty(String) Security} property determines
156+
* the preferred provider order for the specified algorithm.
157+
* This may be different from the order of providers returned by
158+
* {@link Security#getProviders() Security.getProviders()}.</li>
159+
* <li> The {@code jdk.security.providers.filter}
160+
* {@link System#getProperty(String) System} and
161+
* {@link Security#getProperty(String) Security} properties determine
162+
* which services are enabled. A service that is not enabled by the
163+
* filter will not make its algorithm implementation available.</li>
164+
* </ul>
157165
*
158166
* @param algorithm the name of the algorithm this
159167
* parameter generator is associated with.
@@ -201,6 +209,14 @@ public static AlgorithmParameterGenerator getInstance(String algorithm)
201209
* <p> Note that the list of registered providers may be retrieved via
202210
* the {@link Security#getProviders() Security.getProviders()} method.
203211
*
212+
* @implNote
213+
* The JDK Reference Implementation additionally uses the
214+
* {@code jdk.security.providers.filter}
215+
* {@link System#getProperty(String) System} and
216+
* {@link Security#getProperty(String) Security} properties to determine
217+
* which services are enabled. A service that is not enabled by the filter
218+
* will not make its algorithm implementation available.
219+
*
204220
* @param algorithm the name of the algorithm this
205221
* parameter generator is associated with.
206222
* See the AlgorithmParameterGenerator section in the <a href=
@@ -252,6 +268,14 @@ public static AlgorithmParameterGenerator getInstance(String algorithm,
252268
* provider is returned. Note that the specified provider does not
253269
* have to be registered in the provider list.
254270
*
271+
* @implNote
272+
* The JDK Reference Implementation additionally uses the
273+
* {@code jdk.security.providers.filter}
274+
* {@link System#getProperty(String) System} and
275+
* {@link Security#getProperty(String) Security} properties to determine
276+
* which services are enabled. A service that is not enabled by the filter
277+
* will not make its algorithm implementation available.
278+
*
255279
* @param algorithm the string name of the algorithm this
256280
* parameter generator is associated with.
257281
* See the AlgorithmParameterGenerator section in the <a href=

src/java.base/share/classes/java/security/AlgorithmParameters.java

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,20 @@ public final String getAlgorithm() {
135135
* parameter encoding.
136136
*
137137
* @implNote
138-
* The JDK Reference Implementation additionally uses the
139-
* {@code jdk.security.provider.preferred}
140-
* {@link Security#getProperty(String) Security} property to determine
141-
* the preferred provider order for the specified algorithm. This
142-
* may be different from the order of providers returned by
143-
* {@link Security#getProviders() Security.getProviders()}.
138+
* The JDK Reference Implementation additionally uses the following
139+
* properties to customize the behavior of this method:
140+
* <ul>
141+
* <li> The {@code jdk.security.provider.preferred}
142+
* {@link Security#getProperty(String) Security} property determines
143+
* the preferred provider order for the specified algorithm.
144+
* This may be different from the order of providers returned by
145+
* {@link Security#getProviders() Security.getProviders()}.</li>
146+
* <li> The {@code jdk.security.providers.filter}
147+
* {@link System#getProperty(String) System} and
148+
* {@link Security#getProperty(String) Security} properties determine
149+
* which services are enabled. A service that is not enabled by the
150+
* filter will not make its algorithm implementation available.</li>
151+
* </ul>
144152
*
145153
* @param algorithm the name of the algorithm requested.
146154
* See the AlgorithmParameters section in the <a href=
@@ -188,6 +196,14 @@ public static AlgorithmParameters getInstance(String algorithm)
188196
* {@code init}, using an appropriate parameter specification or
189197
* parameter encoding.
190198
*
199+
* @implNote
200+
* The JDK Reference Implementation additionally uses the
201+
* {@code jdk.security.providers.filter}
202+
* {@link System#getProperty(String) System} and
203+
* {@link Security#getProperty(String) Security} properties to determine
204+
* which services are enabled. A service that is not enabled by the filter
205+
* will not make its algorithm implementation available.
206+
*
191207
* @param algorithm the name of the algorithm requested.
192208
* See the AlgorithmParameters section in the <a href=
193209
* "{@docRoot}/../specs/security/standard-names.html#algorithmparameters-algorithms">
@@ -239,6 +255,14 @@ public static AlgorithmParameters getInstance(String algorithm,
239255
* {@code init}, using an appropriate parameter specification or
240256
* parameter encoding.
241257
*
258+
* @implNote
259+
* The JDK Reference Implementation additionally uses the
260+
* {@code jdk.security.providers.filter}
261+
* {@link System#getProperty(String) System} and
262+
* {@link Security#getProperty(String) Security} properties to determine
263+
* which services are enabled. A service that is not enabled by the filter
264+
* will not make its algorithm implementation available.
265+
*
242266
* @param algorithm the name of the algorithm requested.
243267
* See the AlgorithmParameters section in the <a href=
244268
* "{@docRoot}/../specs/security/standard-names.html#algorithmparameters-algorithms">

src/java.base/share/classes/java/security/KeyFactory.java

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,20 @@ private KeyFactory(String algorithm) throws NoSuchAlgorithmException {
157157
* the {@link Security#getProviders() Security.getProviders()} method.
158158
*
159159
* @implNote
160-
* The JDK Reference Implementation additionally uses the
161-
* {@code jdk.security.provider.preferred}
162-
* {@link Security#getProperty(String) Security} property to determine
163-
* the preferred provider order for the specified algorithm. This
164-
* may be different from the order of providers returned by
165-
* {@link Security#getProviders() Security.getProviders()}.
160+
* The JDK Reference Implementation additionally uses the following
161+
* properties to customize the behavior of this method:
162+
* <ul>
163+
* <li> The {@code jdk.security.provider.preferred}
164+
* {@link Security#getProperty(String) Security} property determines
165+
* the preferred provider order for the specified algorithm.
166+
* This may be different from the order of providers returned by
167+
* {@link Security#getProviders() Security.getProviders()}.</li>
168+
* <li> The {@code jdk.security.providers.filter}
169+
* {@link System#getProperty(String) System} and
170+
* {@link Security#getProperty(String) Security} properties determine
171+
* which services are enabled. A service that is not enabled by the
172+
* filter will not make its algorithm implementation available.</li>
173+
* </ul>
166174
*
167175
* @param algorithm the name of the requested key algorithm.
168176
* See the KeyFactory section in the <a href=
@@ -199,6 +207,14 @@ public static KeyFactory getInstance(String algorithm)
199207
* <p> Note that the list of registered providers may be retrieved via
200208
* the {@link Security#getProviders() Security.getProviders()} method.
201209
*
210+
* @implNote
211+
* The JDK Reference Implementation additionally uses the
212+
* {@code jdk.security.providers.filter}
213+
* {@link System#getProperty(String) System} and
214+
* {@link Security#getProperty(String) Security} properties to determine
215+
* which services are enabled. A service that is not enabled by the filter
216+
* will not make its algorithm implementation available.
217+
*
202218
* @param algorithm the name of the requested key algorithm.
203219
* See the KeyFactory section in the <a href=
204220
* "{@docRoot}/../specs/security/standard-names.html#keyfactory-algorithms">
@@ -242,6 +258,14 @@ public static KeyFactory getInstance(String algorithm, String provider)
242258
* is returned. Note that the specified provider does not
243259
* have to be registered in the provider list.
244260
*
261+
* @implNote
262+
* The JDK Reference Implementation additionally uses the
263+
* {@code jdk.security.providers.filter}
264+
* {@link System#getProperty(String) System} and
265+
* {@link Security#getProperty(String) Security} properties to determine
266+
* which services are enabled. A service that is not enabled by the filter
267+
* will not make its algorithm implementation available.
268+
*
245269
* @param algorithm the name of the requested key algorithm.
246270
* See the KeyFactory section in the <a href=
247271
* "{@docRoot}/../specs/security/standard-names.html#keyfactory-algorithms">

src/java.base/share/classes/java/security/KeyPairGenerator.java

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,20 @@ private static KeyPairGenerator getInstance(Instance instance,
204204
* the {@link Security#getProviders() Security.getProviders()} method.
205205
*
206206
* @implNote
207-
* The JDK Reference Implementation additionally uses the
208-
* {@code jdk.security.provider.preferred}
209-
* {@link Security#getProperty(String) Security} property to determine
210-
* the preferred provider order for the specified algorithm. This
211-
* may be different from the order of providers returned by
212-
* {@link Security#getProviders() Security.getProviders()}.
207+
* The JDK Reference Implementation additionally uses the following
208+
* properties to customize the behavior of this method:
209+
* <ul>
210+
* <li> The {@code jdk.security.provider.preferred}
211+
* {@link Security#getProperty(String) Security} property determines
212+
* the preferred provider order for the specified algorithm.
213+
* This may be different from the order of providers returned by
214+
* {@link Security#getProviders() Security.getProviders()}.</li>
215+
* <li> The {@code jdk.security.providers.filter}
216+
* {@link System#getProperty(String) System} and
217+
* {@link Security#getProperty(String) Security} properties determine
218+
* which services are enabled. A service that is not enabled by the
219+
* filter will not make its algorithm implementation available.</li>
220+
* </ul>
213221
*
214222
* @param algorithm the standard string name of the algorithm.
215223
* See the KeyPairGenerator section in the <a href=
@@ -269,6 +277,14 @@ public static KeyPairGenerator getInstance(String algorithm)
269277
* <p> Note that the list of registered providers may be retrieved via
270278
* the {@link Security#getProviders() Security.getProviders()} method.
271279
*
280+
* @implNote
281+
* The JDK Reference Implementation additionally uses the
282+
* {@code jdk.security.providers.filter}
283+
* {@link System#getProperty(String) System} and
284+
* {@link Security#getProperty(String) Security} properties to determine
285+
* which services are enabled. A service that is not enabled by the filter
286+
* will not make its algorithm implementation available.
287+
*
272288
* @param algorithm the standard string name of the algorithm.
273289
* See the KeyPairGenerator section in the <a href=
274290
* "{@docRoot}/../specs/security/standard-names.html#keypairgenerator-algorithms">
@@ -312,6 +328,14 @@ public static KeyPairGenerator getInstance(String algorithm,
312328
* is returned. Note that the specified provider does not
313329
* have to be registered in the provider list.
314330
*
331+
* @implNote
332+
* The JDK Reference Implementation additionally uses the
333+
* {@code jdk.security.providers.filter}
334+
* {@link System#getProperty(String) System} and
335+
* {@link Security#getProperty(String) Security} properties to determine
336+
* which services are enabled. A service that is not enabled by the filter
337+
* will not make its algorithm implementation available.
338+
*
315339
* @param algorithm the standard string name of the algorithm.
316340
* See the KeyPairGenerator section in the <a href=
317341
* "{@docRoot}/../specs/security/standard-names.html#keypairgenerator-algorithms">

src/java.base/share/classes/java/security/KeyStore.java

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import javax.security.auth.DestroyFailedException;
3737
import javax.security.auth.callback.*;
3838

39+
import sun.security.jca.ProvidersFilter;
3940
import sun.security.util.Debug;
4041

4142
/**
@@ -841,12 +842,20 @@ private String getProviderName() {
841842
* the {@link Security#getProviders() Security.getProviders()} method.
842843
*
843844
* @implNote
844-
* The JDK Reference Implementation additionally uses the
845-
* {@code jdk.security.provider.preferred}
846-
* {@link Security#getProperty(String) Security} property to determine
847-
* the preferred provider order for the specified algorithm. This
848-
* may be different from the order of providers returned by
849-
* {@link Security#getProviders() Security.getProviders()}.
845+
* The JDK Reference Implementation additionally uses the following
846+
* properties to customize the behavior of this method:
847+
* <ul>
848+
* <li> The {@code jdk.security.provider.preferred}
849+
* {@link Security#getProperty(String) Security} property determines
850+
* the preferred provider order for the specified type.
851+
* This may be different from the order of providers returned by
852+
* {@link Security#getProviders() Security.getProviders()}.</li>
853+
* <li> The {@code jdk.security.providers.filter}
854+
* {@link System#getProperty(String) System} and
855+
* {@link Security#getProperty(String) Security} properties determine
856+
* which services are enabled. A service that is not enabled by the
857+
* filter will not make its type implementation available.</li>
858+
* </ul>.
850859
*
851860
* @param type the type of keystore.
852861
* See the KeyStore section in the <a href=
@@ -888,6 +897,14 @@ public static KeyStore getInstance(String type)
888897
* <p> Note that the list of registered providers may be retrieved via
889898
* the {@link Security#getProviders() Security.getProviders()} method.
890899
*
900+
* @implNote
901+
* The JDK Reference Implementation additionally uses the
902+
* {@code jdk.security.providers.filter}
903+
* {@link System#getProperty(String) System} and
904+
* {@link Security#getProperty(String) Security} properties to determine
905+
* which services are enabled. A service that is not enabled by the filter
906+
* will not make its type implementation available.
907+
*
891908
* @param type the type of keystore.
892909
* See the KeyStore section in the <a href=
893910
* "{@docRoot}/../specs/security/standard-names.html#keystore-types">
@@ -935,6 +952,14 @@ public static KeyStore getInstance(String type, String provider)
935952
* object is returned. Note that the specified provider object
936953
* does not have to be registered in the provider list.
937954
*
955+
* @implNote
956+
* The JDK Reference Implementation additionally uses the
957+
* {@code jdk.security.providers.filter}
958+
* {@link System#getProperty(String) System} and
959+
* {@link Security#getProperty(String) Security} properties to determine
960+
* which services are enabled. A service that is not enabled by the filter
961+
* will not make its type implementation available.
962+
*
938963
* @param type the type of keystore.
939964
* See the KeyStore section in the <a href=
940965
* "{@docRoot}/../specs/security/standard-names.html#keystore-types">
@@ -1677,6 +1702,14 @@ public final void setEntry(String alias, Entry entry,
16771702
* <p> Note that the list of registered providers may be retrieved via
16781703
* the {@link Security#getProviders() Security.getProviders()} method.
16791704
*
1705+
* @implNote
1706+
* The JDK Reference Implementation additionally uses the
1707+
* {@code jdk.security.providers.filter}
1708+
* {@link System#getProperty(String) System} and
1709+
* {@link Security#getProperty(String) Security} properties to determine
1710+
* which services are enabled. A service that is not enabled by the filter
1711+
* will not make its type implementation available.
1712+
*
16801713
* @param file the keystore file
16811714
* @param password the keystore password, which may be {@code null}
16821715
*
@@ -1730,6 +1763,14 @@ public static final KeyStore getInstance(File file, char[] password)
17301763
* <p> Note that the list of registered providers may be retrieved via
17311764
* the {@link Security#getProviders() Security.getProviders()} method.
17321765
*
1766+
* @implNote
1767+
* The JDK Reference Implementation additionally uses the
1768+
* {@code jdk.security.providers.filter}
1769+
* {@link System#getProperty(String) System} and
1770+
* {@link Security#getProperty(String) Security} properties to determine
1771+
* which services are enabled. A service that is not enabled by the filter
1772+
* will not make its type implementation available.
1773+
*
17331774
* @param file the keystore file
17341775
* @param param the {@code LoadStoreParameter} that specifies how to load
17351776
* the keystore, which may be {@code null}
@@ -1790,7 +1831,8 @@ private static final KeyStore getInstance(File file, char[] password,
17901831
// Detect the keystore type
17911832
for (Provider p : Security.getProviders()) {
17921833
for (Provider.Service s : p.getServices()) {
1793-
if (s.getType().equals("KeyStore")) {
1834+
if (ProvidersFilter.isAllowed(s) &&
1835+
s.getType().equals("KeyStore")) {
17941836
try {
17951837
KeyStoreSpi impl = (KeyStoreSpi) s.newInstance(null);
17961838
if (impl.engineProbe(dataStream)) {

0 commit comments

Comments
 (0)