Skip to content

Commit e12d0b5

Browse files
committed
8311592: ECKeySizeParameterSpec causes too many exceptions on third party providers
Backport-of: e554fdee254ce51d605fe127b73644620e87e23b
1 parent 35cf71f commit e12d0b5

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/java.base/share/classes/sun/security/util/KeyUtil.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2012, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -144,17 +144,19 @@ public static final int getKeySize(Key key) {
144144
*/
145145
public static final int getKeySize(AlgorithmParameters parameters) {
146146

147-
String algorithm = parameters.getAlgorithm();
148-
switch (algorithm) {
147+
switch (parameters.getAlgorithm()) {
149148
case "EC":
150-
try {
151-
ECKeySizeParameterSpec ps = parameters.getParameterSpec(
149+
// ECKeySizeParameterSpec is SunEC internal only
150+
if (parameters.getProvider().getName().equals("SunEC")) {
151+
try {
152+
ECKeySizeParameterSpec ps = parameters.getParameterSpec(
152153
ECKeySizeParameterSpec.class);
153-
if (ps != null) {
154-
return ps.getKeySize();
154+
if (ps != null) {
155+
return ps.getKeySize();
156+
}
157+
} catch (InvalidParameterSpecException ipse) {
158+
// ignore
155159
}
156-
} catch (InvalidParameterSpecException ipse) {
157-
// ignore
158160
}
159161

160162
try {

0 commit comments

Comments
 (0)