@@ -192,9 +192,9 @@ public final boolean permits(Set<CryptoPrimitive> primitives,
192
192
}
193
193
194
194
public final void permits (String algorithm , AlgorithmParameters ap ,
195
- ConstraintsParameters cp ) throws CertPathValidatorException {
196
-
197
- permits (algorithm , cp );
195
+ ConstraintsParameters cp , boolean checkKey )
196
+ throws CertPathValidatorException {
197
+ permits (algorithm , cp , checkKey );
198
198
if (ap != null ) {
199
199
permits (ap , cp );
200
200
}
@@ -219,36 +219,36 @@ private void permitsPSSParams(AlgorithmParameters ap,
219
219
PSSParameterSpec pssParams =
220
220
ap .getParameterSpec (PSSParameterSpec .class );
221
221
String digestAlg = pssParams .getDigestAlgorithm ();
222
- permits (digestAlg , cp );
222
+ permits (digestAlg , cp , false );
223
223
AlgorithmParameterSpec mgfParams = pssParams .getMGFParameters ();
224
224
if (mgfParams instanceof MGF1ParameterSpec ) {
225
225
String mgfDigestAlg =
226
226
((MGF1ParameterSpec )mgfParams ).getDigestAlgorithm ();
227
227
if (!mgfDigestAlg .equalsIgnoreCase (digestAlg )) {
228
- permits (mgfDigestAlg , cp );
228
+ permits (mgfDigestAlg , cp , false );
229
229
}
230
230
}
231
231
} catch (InvalidParameterSpecException ipse ) {
232
232
// ignore
233
233
}
234
234
}
235
235
236
- public final void permits (String algorithm , ConstraintsParameters cp )
237
- throws CertPathValidatorException {
238
-
239
- // Check if named curves in the key are disabled.
240
- for (Key key : cp .getKeys ()) {
241
- for (String curve : getNamedCurveFromKey (key )) {
242
- if (!checkAlgorithm (disabledAlgorithms , curve , decomposer )) {
243
- throw new CertPathValidatorException (
236
+ public final void permits (String algorithm , ConstraintsParameters cp ,
237
+ boolean checkKey ) throws CertPathValidatorException {
238
+ if ( checkKey ) {
239
+ // Check if named curves in the key are disabled.
240
+ for (Key key : cp .getKeys ()) {
241
+ for (String curve : getNamedCurveFromKey (key )) {
242
+ if (!checkAlgorithm (disabledAlgorithms , curve , decomposer )) {
243
+ throw new CertPathValidatorException (
244
244
"Algorithm constraints check failed on disabled " +
245
245
"algorithm: " + curve ,
246
246
null , null , -1 , BasicReason .ALGORITHM_CONSTRAINED );
247
+ }
247
248
}
248
249
}
249
250
}
250
-
251
- algorithmConstraints .permits (algorithm , cp );
251
+ algorithmConstraints .permits (algorithm , cp , checkKey );
252
252
}
253
253
254
254
private static List <String > getNamedCurveFromKey (Key key ) {
@@ -481,8 +481,8 @@ public boolean permits(String algorithm, AlgorithmParameters aps) {
481
481
return true ;
482
482
}
483
483
484
- public void permits (String algorithm , ConstraintsParameters cp )
485
- throws CertPathValidatorException {
484
+ public void permits (String algorithm , ConstraintsParameters cp ,
485
+ boolean checkKey ) throws CertPathValidatorException {
486
486
487
487
if (debug != null ) {
488
488
debug .println ("Constraints.permits(): " + algorithm + ", "
@@ -496,8 +496,10 @@ public void permits(String algorithm, ConstraintsParameters cp)
496
496
algorithms .add (algorithm );
497
497
}
498
498
499
- for (Key key : cp .getKeys ()) {
500
- algorithms .add (key .getAlgorithm ());
499
+ if (checkKey ) {
500
+ for (Key key : cp .getKeys ()) {
501
+ algorithms .add (key .getAlgorithm ());
502
+ }
501
503
}
502
504
503
505
// Check all applicable constraints
@@ -507,6 +509,9 @@ public void permits(String algorithm, ConstraintsParameters cp)
507
509
continue ;
508
510
}
509
511
for (Constraint constraint : list ) {
512
+ if (!checkKey && constraint instanceof KeySizeConstraint ) {
513
+ continue ;
514
+ }
510
515
constraint .permits (cp );
511
516
}
512
517
}
0 commit comments