Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

could not connect to my Huawei switch. #89

Closed
zhanglinqiang opened this issue Oct 29, 2021 · 4 comments
Closed

could not connect to my Huawei switch. #89

zhanglinqiang opened this issue Oct 29, 2021 · 4 comments

Comments

@zhanglinqiang
Copy link

zhanglinqiang commented Oct 29, 2021

Hello, I can't connect to my switch after migrating ganymed-ssh2 to jsch(Session.connect: java.security.SignatureException: Could not verify signature). Other ssh service like Ubuntu, Centos working well. Can anyone help?
using ganymed-ssh2 and linux ssh command worked.
jsch version:

       <dependency>

            <groupId>com.github.mwiede</groupId>

            <artifactId>jsch</artifactId>

            <version>0.1.69</version>

        </dependency>

Here is my session config code:

Properties p = new Properties();
        String rawkex = session.getConfig("kex");
        String extendKex = "diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1";
        String finalKex = Stream.concat(Arrays.stream(rawkex.split(",")), Arrays.stream(extendKex.split(",")))
                .distinct()
                .collect(Collectors.joining(","));
        p.setProperty("kex", finalKex);

        String serverHostKey = session.getConfig("server_host_key");
        //enable ssh-dss
        p.setProperty("server_host_key", serverHostKey + ",ssh-dss");
        p.setProperty("StrictHostKeyChecking", "no");
        p.setProperty("PreferredAuthentications", "password,keyboard-interactive");
        //Solaris
        p.setProperty("dhgex_preferred", "1024");
        p.setProperty("dhgex_min", "1024");

Java version:

openjdk version "1.8.0_302"
OpenJDK Runtime Environment (build 1.8.0_302-b08)
OpenJDK 64-Bit Server VM (build 25.302-b08, mixed mode)

Stacktrace:

com.jcraft.jsch.JSchException: Session.connect: java.security.SignatureException: Could not verify signature
	at com.jcraft.jsch.Session.connect(Session.java:570)
	at com.topsec.tap.collector.agent.connection.JschConnection.initializeOpen(JschConnection.java:186)
	at com.topsec.tap.collector.agent.connection.JschConnection.open(JschConnection.java:116)
	at com.topsec.tap.collector.agent.connection.JschConnection.main(JschConnection.java:730)
Caused by: java.security.SignatureException: Could not verify signature
	at sun.security.ec.ECDSASignature.engineVerify(ECDSASignature.java:413)
	at java.security.Signature$Delegate.engineVerify(Signature.java:1394)
	at java.security.Signature.verify(Signature.java:771)
	at com.jcraft.jsch.jce.SignatureECDSAN.verify(SignatureECDSAN.java:175)
	at com.jcraft.jsch.KeyExchange.verify(KeyExchange.java:346)
	at com.jcraft.jsch.DHGEX.next(DHGEX.java:224)
	at com.jcraft.jsch.Session.connect(Session.java:331)
	... 3 more
Caused by: java.security.SignatureException: Invalid encoding for signature
	at sun.security.util.ECUtil.decodeSignature(ECUtil.java:258)
	at sun.security.ec.ECDSASignature.engineVerify(ECDSASignature.java:409)
	... 9 more
Caused by: java.io.IOException: Invalid encoding: redundant leading 0s
	at sun.security.util.DerInputBuffer.getBigInteger(DerInputBuffer.java:161)
	at sun.security.util.DerValue.getPositiveBigInteger(DerValue.java:559)
	at sun.security.util.ECUtil.decodeSignature(ECUtil.java:242)
	... 10 more

ssh server information using ssh -vvv :

OpenSSH_8.2p1 Ubuntu-4ubuntu0.3, OpenSSL 1.1.1f  31 Mar 2020
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug3: kex names ok: [diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1]
debug2: resolve_canonicalize: hostname 10.8.20.100 is address
debug2: ssh_connect_direct
debug1: Connecting to 10.8.20.100 [10.8.20.100] port 22.
debug1: Connection established.
debug1: identity file /home/leen/.ssh/id_rsa type 0
debug1: identity file /home/leen/.ssh/id_rsa-cert type -1
debug1: identity file /home/leen/.ssh/id_dsa type -1
debug1: identity file /home/leen/.ssh/id_dsa-cert type -1
debug1: identity file /home/leen/.ssh/id_ecdsa type -1
debug1: identity file /home/leen/.ssh/id_ecdsa-cert type -1
debug1: identity file /home/leen/.ssh/id_ecdsa_sk type -1
debug1: identity file /home/leen/.ssh/id_ecdsa_sk-cert type -1
debug1: identity file /home/leen/.ssh/id_ed25519 type -1
debug1: identity file /home/leen/.ssh/id_ed25519-cert type -1
debug1: identity file /home/leen/.ssh/id_ed25519_sk type -1
debug1: identity file /home/leen/.ssh/id_ed25519_sk-cert type -1
debug1: identity file /home/leen/.ssh/id_xmss type -1
debug1: identity file /home/leen/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.3
debug1: Remote protocol version 2.0, remote software version -
debug1: no match: -
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to 10.8.20.100:22 as 'admin2'
debug3: hostkeys_foreach: reading file "/home/leen/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /home/leen/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from 10.8.20.100
debug3: order_hostkeyalgs: prefer hostkeyalgs: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
debug3: receive packet: type 20
debug1: SSH2_MSG_KEXINIT received
debug2: local client KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1,ext-info-c
debug2: host key algorithms: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,rsa-sha2-512-cert-v01@openssh.com,rsa-sha2-256-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com,ssh-ed25519,sk-ssh-ed25519@openssh.com,rsa-sha2-512,rsa-sha2-256,ssh-rsa,ssh-dss
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,zlib@openssh.com,zlib
debug2: compression stoc: none,zlib@openssh.com,zlib
debug2: languages ctos: 
debug2: languages stoc: 
debug2: first_kex_follows 0 
debug2: reserved 0 
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1
debug2: host key algorithms: ecdsa-sha2-nistp521,ssh-dss,ssh-rsa
debug2: ciphers ctos: aes256-ctr,aes128-ctr,aes256-cbc,aes128-cbc,3des-cbc
debug2: ciphers stoc: aes256-ctr,aes128-ctr,aes256-cbc,aes128-cbc,3des-cbc
debug2: MACs ctos: hmac-sha2-256,hmac-sha2-256-96,hmac-sha1,hmac-sha1-96,hmac-md5,hmac-md5-96
debug2: MACs stoc: hmac-sha2-256,hmac-sha2-256-96,hmac-sha1,hmac-sha1-96,hmac-md5,hmac-md5-96
debug2: compression ctos: none,zlib
debug2: compression stoc: none,zlib
debug2: languages ctos: 
debug2: languages stoc: 
debug2: first_kex_follows 0 
debug2: reserved 0 
debug1: kex: algorithm: diffie-hellman-group-exchange-sha1
debug1: kex: host key algorithm: ecdsa-sha2-nistp521
debug1: kex: server->client cipher: aes128-ctr MAC: hmac-sha2-256 compression: none
debug1: kex: client->server cipher: aes128-ctr MAC: hmac-sha2-256 compression: none
debug3: send packet: type 34
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(2048<8192<8192) sent
debug3: receive packet: type 31
debug1: got SSH2_MSG_KEX_DH_GEX_GROUP
debug2: bits set: 2049/4096
debug3: send packet: type 32
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug3: receive packet: type 33
debug1: got SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: ecdsa-sha2-nistp521 SHA256:RJpTh5BR8X+DWEK6+otU4KD3STSHpBy4zs5YEPNEI1Y
debug3: hostkeys_foreach: reading file "/home/leen/.ssh/known_hosts"
debug3: record_hostkey: found key type ECDSA in file /home/leen/.ssh/known_hosts:1
debug3: load_hostkeys: loaded 1 keys from 10.8.20.100
debug1: Host '10.8.20.100' is known and matches the ECDSA host key.
debug1: Found key in /home/leen/.ssh/known_hosts:1
debug2: bits set: 2045/4096
debug3: send packet: type 21
debug2: set_newkeys: mode 1
debug1: rekey out after 4294967296 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: receive packet: type 21
debug1: SSH2_MSG_NEWKEYS received
debug2: set_newkeys: mode 0
debug1: rekey in after 4294967296 blocks
debug1: Will attempt key: /home/leen/.ssh/id_rsa RSA SHA256:Prg2XpliU/m8Hnk6gwyLgL0fr+/r6F1LN0AByCyVHOo agent
debug1: Will attempt key: /home/leen/.ssh/id_dsa 
debug1: Will attempt key: /home/leen/.ssh/id_ecdsa 
debug1: Will attempt key: /home/leen/.ssh/id_ecdsa_sk 
debug1: Will attempt key: /home/leen/.ssh/id_ed25519 
debug1: Will attempt key: /home/leen/.ssh/id_ed25519_sk 
debug1: Will attempt key: /home/leen/.ssh/id_xmss 
debug2: pubkey_prepare: done
debug3: send packet: type 5
debug3: receive packet: type 6
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,password
debug3: start over, passed a different list publickey,password
debug3: preferred publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /home/leen/.ssh/id_rsa RSA SHA256:Prg2XpliU/m8Hnk6gwyLgL0fr+/r6F1LN0AByCyVHOo agent
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: password
debug3: start over, passed a different list password
debug3: preferred publickey,keyboard-interactive,password
debug3: authmethod_lookup password
debug3: remaining preferred: ,keyboard-interactive,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
@zhanglinqiang
Copy link
Author

I found that the error is in ECUtil.decodeSignature(byte[]), the DerValue array returned by DerInputStream reports an error when calling getPositiveBigInteger(), the data available in DerValue is 0

@norrisjeremy
Copy link
Contributor

Hi @zhanglinqiang,

Would you be able to test whether the changes in #90 fix the issue you are seeing?

Thanks,
Jeremy

@zhanglinqiang
Copy link
Author

Hi @zhanglinqiang,

Would you be able to test whether the changes in #90 fix the issue you are seeing?

Thanks, Jeremy
Amazing! Your changes in #90 solved my problem. Thank you very much for your support.

@norrisjeremy
Copy link
Contributor

Hi @zhanglinqiang,

I believe this issue should be resolved in the 0.1.70 release.

Thanks,
Jeremy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants