8311592: ECKeySizeParameterSpec causes too many exceptions on third party providers

Reviewed-by: hchao, valeriep
This commit is contained in:
Anthony Scarpino 2023-07-25 15:48:31 +00:00
parent 9606cbcd23
commit e554fdee25

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2012, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -128,17 +128,19 @@ public final class KeyUtil {
*/
public static final int getKeySize(AlgorithmParameters parameters) {
String algorithm = parameters.getAlgorithm();
switch (algorithm) {
switch (parameters.getAlgorithm()) {
case "EC":
try {
ECKeySizeParameterSpec ps = parameters.getParameterSpec(
// ECKeySizeParameterSpec is SunEC internal only
if (parameters.getProvider().getName().equals("SunEC")) {
try {
ECKeySizeParameterSpec ps = parameters.getParameterSpec(
ECKeySizeParameterSpec.class);
if (ps != null) {
return ps.getKeySize();
if (ps != null) {
return ps.getKeySize();
}
} catch (InvalidParameterSpecException ipse) {
// ignore
}
} catch (InvalidParameterSpecException ipse) {
// ignore
}
try {