This is an automated email from the ASF dual-hosted git repository. twolf pushed a commit to branch dev_3.0 in repository https://gitbox.apache.org/repos/asf/mina-sshd.git
commit 5bbb78ba52e75446a361dc473572fd8bdc1bf751 Author: Thomas Wolf <[email protected]> AuthorDate: Sat Sep 13 17:30:27 2025 +0200 Use default classloader to check for EdDSAKey class Don't use ThreadUtils to load the class; just let the JVM use whatever classloader is set, ensuring that we resolve the class as mandated by the external environment, which might use split classloaders (like Plexus classworlds, or OSGi bundle classloaders). --- .../bouncycastle/BouncyCastleEdDSAAccessor.java | 39 ++++++++++++++++++++++ .../BouncyCastleSecurityProviderRegistrar.java | 4 +-- .../common/util/security/eddsa/EdDSAAccessor.java | 39 ++++++++++++++++++++++ .../eddsa/EdDSASecurityProviderRegistrar.java | 5 +-- 4 files changed, 80 insertions(+), 7 deletions(-) diff --git a/sshd-common/src/main/java/org/apache/sshd/common/util/security/bouncycastle/BouncyCastleEdDSAAccessor.java b/sshd-common/src/main/java/org/apache/sshd/common/util/security/bouncycastle/BouncyCastleEdDSAAccessor.java new file mode 100644 index 000000000..9242376d7 --- /dev/null +++ b/sshd-common/src/main/java/org/apache/sshd/common/util/security/bouncycastle/BouncyCastleEdDSAAccessor.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sshd.common.util.security.bouncycastle; + +import org.bouncycastle.jcajce.interfaces.EdDSAKey; + +final class BouncyCastleEdDSAAccessor { + + static final BouncyCastleEdDSAAccessor INSTANCE = new BouncyCastleEdDSAAccessor(); + + private BouncyCastleEdDSAAccessor() { + super(); + } + + public boolean isSupported() { + try { + // Just something that forces class loading. + return EdDSAKey.class != null; + } catch (Throwable t) { + return false; + } + } +} diff --git a/sshd-common/src/main/java/org/apache/sshd/common/util/security/bouncycastle/BouncyCastleSecurityProviderRegistrar.java b/sshd-common/src/main/java/org/apache/sshd/common/util/security/bouncycastle/BouncyCastleSecurityProviderRegistrar.java index 25e5474b6..0872389e6 100644 --- a/sshd-common/src/main/java/org/apache/sshd/common/util/security/bouncycastle/BouncyCastleSecurityProviderRegistrar.java +++ b/sshd-common/src/main/java/org/apache/sshd/common/util/security/bouncycastle/BouncyCastleSecurityProviderRegistrar.java @@ -44,7 +44,6 @@ public class BouncyCastleSecurityProviderRegistrar extends AbstractSecurityProvi private static final String BCFIPS_PROVIDER_NAME = "BCFIPS"; private static final String BC_PROVIDER_NAME = "BC"; private static final String NAME_FIELD = "PROVIDER_NAME"; - private static final String EDDSA_KEY_CLASS_NAME = "org.bouncycastle.jcajce.interfaces.EdDSAKey"; // Do not define a static registrar instance to minimize class loading issues private final AtomicReference<Boolean> supportHolder = new AtomicReference<>(null); @@ -188,8 +187,7 @@ public class BouncyCastleSecurityProviderRegistrar extends AbstractSecurityProvi if (edDSASupported != null) { return edDSASupported.booleanValue(); } - Class<?> clazz = ThreadUtils.resolveDefaultClass(getClass(), EDDSA_KEY_CLASS_NAME); - edDSASupported = Boolean.valueOf(clazz != null); + edDSASupported = Boolean.valueOf(BouncyCastleEdDSAAccessor.INSTANCE.isSupported()); edDSASupportHolder.set(edDSASupported); return edDSASupported; } diff --git a/sshd-common/src/main/java/org/apache/sshd/common/util/security/eddsa/EdDSAAccessor.java b/sshd-common/src/main/java/org/apache/sshd/common/util/security/eddsa/EdDSAAccessor.java new file mode 100644 index 000000000..257c110d3 --- /dev/null +++ b/sshd-common/src/main/java/org/apache/sshd/common/util/security/eddsa/EdDSAAccessor.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.sshd.common.util.security.eddsa; + +import net.i2p.crypto.eddsa.EdDSAKey; + +final class EdDSAAccessor { + + static final EdDSAAccessor INSTANCE = new EdDSAAccessor(); + + private EdDSAAccessor() { + super(); + } + + public boolean isSupported() { + try { + // Just something that forces class loading. + return EdDSAKey.class != null; + } catch (Throwable t) { + return false; + } + } +} diff --git a/sshd-common/src/main/java/org/apache/sshd/common/util/security/eddsa/EdDSASecurityProviderRegistrar.java b/sshd-common/src/main/java/org/apache/sshd/common/util/security/eddsa/EdDSASecurityProviderRegistrar.java index 52fed9fc1..4134f204d 100644 --- a/sshd-common/src/main/java/org/apache/sshd/common/util/security/eddsa/EdDSASecurityProviderRegistrar.java +++ b/sshd-common/src/main/java/org/apache/sshd/common/util/security/eddsa/EdDSASecurityProviderRegistrar.java @@ -31,7 +31,6 @@ import org.apache.sshd.common.util.ExceptionUtils; import org.apache.sshd.common.util.security.AbstractSecurityProviderRegistrar; import org.apache.sshd.common.util.security.SecurityEntityFactory; import org.apache.sshd.common.util.security.SecurityUtils; -import org.apache.sshd.common.util.threads.ThreadUtils; /** * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> @@ -92,8 +91,7 @@ public class EdDSASecurityProviderRegistrar extends AbstractSecurityProviderRegi return supported.booleanValue(); } - Class<?> clazz = ThreadUtils.resolveDefaultClass(getClass(), "net.i2p.crypto.eddsa.EdDSAKey"); - supported = clazz != null; + supported = Boolean.valueOf(EdDSAAccessor.INSTANCE.isSupported()); supportHolder.set(supported); } @@ -164,5 +162,4 @@ public class EdDSASecurityProviderRegistrar extends AbstractSecurityProviderRegi return delegate.toString(); } } - }
