@@ -199,16 +199,16 @@ public final boolean permits(Set<CryptoPrimitive> primitives,
199
199
}
200
200
201
201
public final void permits (String algorithm , AlgorithmParameters ap ,
202
- ConstraintsParameters cp ) throws CertPathValidatorException {
203
-
204
- permits (algorithm , cp );
202
+ ConstraintsParameters cp , boolean checkKey )
203
+ throws CertPathValidatorException {
204
+ permits (algorithm , cp , checkKey );
205
205
if (ap != null ) {
206
206
permits (ap , cp );
207
207
}
208
208
}
209
209
210
210
private void permits (AlgorithmParameters ap , ConstraintsParameters cp )
211
- throws CertPathValidatorException {
211
+ throws CertPathValidatorException {
212
212
213
213
switch (ap .getAlgorithm ().toUpperCase (Locale .ENGLISH )) {
214
214
case "RSASSA-PSS" :
@@ -226,36 +226,38 @@ private void permitsPSSParams(AlgorithmParameters ap,
226
226
PSSParameterSpec pssParams =
227
227
ap .getParameterSpec (PSSParameterSpec .class );
228
228
String digestAlg = pssParams .getDigestAlgorithm ();
229
- permits (digestAlg , cp );
229
+ permits (digestAlg , cp , false );
230
230
AlgorithmParameterSpec mgfParams = pssParams .getMGFParameters ();
231
231
if (mgfParams instanceof MGF1ParameterSpec ) {
232
232
String mgfDigestAlg =
233
233
((MGF1ParameterSpec )mgfParams ).getDigestAlgorithm ();
234
234
if (!mgfDigestAlg .equalsIgnoreCase (digestAlg )) {
235
- permits (mgfDigestAlg , cp );
235
+ permits (mgfDigestAlg , cp , false );
236
236
}
237
237
}
238
238
} catch (InvalidParameterSpecException ipse ) {
239
239
// ignore
240
240
}
241
241
}
242
242
243
- public final void permits (String algorithm , ConstraintsParameters cp )
244
- throws CertPathValidatorException {
243
+ public final void permits (String algorithm , ConstraintsParameters cp ,
244
+ boolean checkKey ) throws CertPathValidatorException {
245
245
246
- // Check if named curves in the key are disabled.
247
- for (Key key : cp .getKeys ()) {
248
- for (String curve : getNamedCurveFromKey (key )) {
249
- if (!cachedCheckAlgorithm (curve )) {
250
- throw new CertPathValidatorException (
246
+ if (checkKey ) {
247
+ // Check if named curves in the key are disabled.
248
+ for (Key key : cp .getKeys ()) {
249
+ for (String curve : getNamedCurveFromKey (key )) {
250
+ if (!cachedCheckAlgorithm (curve )) {
251
+ throw new CertPathValidatorException (
251
252
"Algorithm constraints check failed on disabled " +
252
253
"algorithm: " + curve ,
253
254
null , null , -1 , BasicReason .ALGORITHM_CONSTRAINED );
255
+ }
254
256
}
255
257
}
256
258
}
257
259
258
- algorithmConstraints .permits (algorithm , cp );
260
+ algorithmConstraints .permits (algorithm , cp , checkKey );
259
261
}
260
262
261
263
private static List <String > getNamedCurveFromKey (Key key ) {
@@ -493,8 +495,8 @@ public boolean permits(String algorithm, AlgorithmParameters aps) {
493
495
return true ;
494
496
}
495
497
496
- public void permits (String algorithm , ConstraintsParameters cp )
497
- throws CertPathValidatorException {
498
+ public void permits (String algorithm , ConstraintsParameters cp ,
499
+ boolean checkKey ) throws CertPathValidatorException {
498
500
499
501
if (debug != null ) {
500
502
debug .println ("Constraints.permits(): " + algorithm + ", "
@@ -508,8 +510,10 @@ public void permits(String algorithm, ConstraintsParameters cp)
508
510
algorithms .add (algorithm );
509
511
}
510
512
511
- for (Key key : cp .getKeys ()) {
512
- algorithms .add (key .getAlgorithm ());
513
+ if (checkKey ) {
514
+ for (Key key : cp .getKeys ()) {
515
+ algorithms .add (key .getAlgorithm ());
516
+ }
513
517
}
514
518
515
519
// Check all applicable constraints
@@ -519,6 +523,9 @@ public void permits(String algorithm, ConstraintsParameters cp)
519
523
continue ;
520
524
}
521
525
for (Constraint constraint : list ) {
526
+ if (!checkKey && constraint instanceof KeySizeConstraint ) {
527
+ continue ;
528
+ }
522
529
constraint .permits (cp );
523
530
}
524
531
}
0 commit comments