Skip to content

Commit e554fde

Browse files
author
Anthony Scarpino
committed
8311592: ECKeySizeParameterSpec causes too many exceptions on third party providers
Reviewed-by: hchao, valeriep
1 parent 9606cbc commit e554fde

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, 2022, 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
@@ -128,17 +128,19 @@ public static int getKeySize(Key key) {
128128
*/
129129
public static final int getKeySize(AlgorithmParameters parameters) {
130130

131-
String algorithm = parameters.getAlgorithm();
132-
switch (algorithm) {
131+
switch (parameters.getAlgorithm()) {
133132
case "EC":
134-
try {
135-
ECKeySizeParameterSpec ps = parameters.getParameterSpec(
133+
// ECKeySizeParameterSpec is SunEC internal only
134+
if (parameters.getProvider().getName().equals("SunEC")) {
135+
try {
136+
ECKeySizeParameterSpec ps = parameters.getParameterSpec(
136137
ECKeySizeParameterSpec.class);
137-
if (ps != null) {
138-
return ps.getKeySize();
138+
if (ps != null) {
139+
return ps.getKeySize();
140+
}
141+
} catch (InvalidParameterSpecException ipse) {
142+
// ignore
139143
}
140-
} catch (InvalidParameterSpecException ipse) {
141-
// ignore
142144
}
143145

144146
try {

0 commit comments

Comments
 (0)