Provide very weird fix that happens to work
@@ -6,8 +6,6 @@ import java.security.interfaces.ECKey;
import java.security.interfaces.ECPublicKey;
import java.security.spec.ECParameterSpec;
-import org.bouncycastle.jce.spec.ECNamedCurveSpec;
-
import won.cryptography.exception.KeyNotSupportedException;
/**
@@ -20,11 +18,18 @@ public class KeyInformationExtractorBouncyCastle implements KeyInformationExtrac
public String getCurveID(Key key) throws KeyNotSupportedException {
if (key instanceof ECKey) {
+ // doing this in a weird way. We changed this from an instanceof check for the
+ // ECParameterSpec class, which, due to some classloader magic gone wrong failed
+ // for the object which actually is of that class. I guess that the class is in
+ // multiple jars loaded from different classloaders... hard to know.
+ // This works.
ECParameterSpec spec = ((ECKey) key).getParams();
- if (spec instanceof ECNamedCurveSpec) {
- return ((ECNamedCurveSpec) spec).getName();
- } else
- return null;
+ Class<?> clazz = spec.getClass();
+ try {
+ return (String) clazz.getDeclaredMethod("getName").invoke(spec);
+ } catch (Exception e) {
+ throw new KeyNotSupportedException("Cannot get curve name from ECParameterSpec " + spec, e);
+ }
} else {
throw new KeyNotSupportedException("Key is not an elliptic curve key!");
}
