hierynomus / sshj

ssh, scp and sftp for java
Apache License 2.0
2.48k stars 600 forks source link

X25519 unsupported public key length [46] Error message #957

Open Atharva-2157 opened 3 weeks ago

Atharva-2157 commented 3 weeks ago

I am trying to connect to sftp server using SSHClient.

        SSHClient sshClient = new SSHClient();
        sshClient.addHostKeyVerifier(new PromiscuousVerifier());
        // Connect and authenticate
        sshClient.connect(sftpHost, sftpPort);
        sshClient.authPassword(sftpUser, sftpPass);

But at connect method I am getting this error - X25519 unsupported public key length [46] I tried to find the solution online but not found any can anyone help me to solve this.

exceptionfactory commented 3 weeks ago

@Atharva-2157 This error looks like it is coming from the Curve25519DH class as part of the key agreement initialization process.

Some Java Security Provider implementations have slight variations the encoded key handling, which could be an area for improvement in this class.

Can you provide the specific version of Java, and the version of the Bouncy Castle library that results in this particular error?

Atharva-2157 commented 3 weeks ago

Java 11.0.19

Bouncy Castle -

org.bouncycastle bcprov-jdk18on 1.75 org.bouncycastle bcpkix-jdk18on 1.75

sshj -

com.hierynomus sshj 0.38.0
exceptionfactory commented 3 weeks ago

Thanks for those details @Atharva-2157, that will be helpful in attempting to reproduce the problem.

exceptionfactory commented 3 weeks ago

@Atharva-2157 I was able to reproduce the problem on Java 11.

The problem is the result of different behavior in the Java 11 implementation of X25519 public keys, as opposed to Bouncy Castle and more recent Java versions.

I submitted pull request #959 to improve the behavior, making it more compatible across versions and providers.

With the existing version, it seems like the Bouncy Castle Provider is not being registered, and registering it may resolve the issue without code changes.