hierynomus / hierynomus/sshj

add a configuration option to prevent BouncyCastle from registering at runtime so that sshj is compatible with GraalVM's native mode

Open
#782 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
2.7k
Forks
620
Avg merge
3d 23h
Merged PRs (30d)
11

Description

add a configuration option to prevent BouncyCastle from registering at runtime so that sshj is compatible with GraalVM's native mode

```console
C:\MyJavaProjects\java_native> C:\MyJavaProjects\java_native\app\build\native\nativeBuild\Example.exe
Exception in thread "main" com.oracle.svm.core.jdk.UnsupportedFeatureError: Trying to verify a provider that was not registered at build time: BC version 1.69. All providers must be registered and verified in the Native Image builder.
at com.oracle.svm.core.util.VMError.unsupportedFeature(VMError.java:89)
at javax.crypto.JceSecurity.getVerificationResult(JceSecurity.java:403)
at javax.crypto.JceSecurity.getInstance(JceSecurity.java:140)
at javax.crypto.KeyAgreement.getInstance(KeyAgreement.java:280)
at net.schmizz.sshj.common.SecurityUtils.registerSecurityProvider(SecurityUtils.java:94)
at net.schmizz.sshj.common.SecurityUtils.register(SecurityUtils.java:280)
at net.schmizz.sshj.common.SecurityUtils.isBouncyCastleRegistered(SecurityUtils.java:251)
at net.schmizz.sshj.DefaultConfig.(DefaultConfig.java:78)
at net.schmizz.sshj.SSHClient.(SSHClient.java:131)
at demo.SshjExample.init(SshjExample.java:22)
at demo.Example.main(Example.java:25)

C:\MyJavaProjects\java_native>
```

> In the class [net.schmizz.sshj.common.SecurityUtils](https://github.com/hierynomus/sshj/blob/master/src/main/java/net/schmizz/sshj/common/SecurityUtils.java), if you follow the above stacktrace and reach that registerSecurityProvider() method, you'll see that the method always tries to register the BouncyCastleProvider at runtime [here](https://github.com/hierynomus/sshj/blob/d7e402c557a2ec9b6c481c96fa0f7d9e96a81f67/src/main/java/net/schmizz/sshj/common/SecurityUtils.java#L89), which is a no-no in native mode, hence the above UnsupportedFeatureError exception. The BouncyCastleProvider is already registered at build time (by the BouncyCastleFeature class) so there's no need to register it again at runtime; and this behaviour makes the [sshj](https://github.com/hierynomus/sshj) library incompatible with GraalVM's native mode.
To work around the issue, maybe you should substitute the SecurityUtils.register() method to do nothing, to prevent it from calling that troublesome registerSecurityProvider() method. Another option is to use a different ssh library, like Apache MINA, which may be more compatible with GraalVM's native mode.

https://github.com/oracle/graal/issues/3197#issuecomment-1111608066

https://github.com/insinfo/java_native

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.