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. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * 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) { public static final int getKeySize(AlgorithmParameters parameters) {
String algorithm = parameters.getAlgorithm(); switch (parameters.getAlgorithm()) {
switch (algorithm) {
case "EC": case "EC":
try { // ECKeySizeParameterSpec is SunEC internal only
ECKeySizeParameterSpec ps = parameters.getParameterSpec( if (parameters.getProvider().getName().equals("SunEC")) {
try {
ECKeySizeParameterSpec ps = parameters.getParameterSpec(
ECKeySizeParameterSpec.class); ECKeySizeParameterSpec.class);
if (ps != null) { if (ps != null) {
return ps.getKeySize(); return ps.getKeySize();
}
} catch (InvalidParameterSpecException ipse) {
// ignore
} }
} catch (InvalidParameterSpecException ipse) {
// ignore
} }
try { try {