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

Invalid encoding for signature: redundant leading 0s #354

Closed
charego opened this issue Aug 31, 2017 · 4 comments · Fixed by #361
Closed

Invalid encoding for signature: redundant leading 0s #354

charego opened this issue Aug 31, 2017 · 4 comments · Fixed by #361

Comments

@charego
Copy link
Contributor

charego commented Aug 31, 2017

Related bugs:

  1. https://sourceforge.net/p/jsch/bugs/111/
  2. https://bugs.openjdk.java.net/browse/JDK-8174719

Synopsis:

Security fix in Java 8u121 exposed an encoding issue in some SSH libraries. In other words, these libraries were relying on buggy code in the JDK. Now that it's fixed in the JDK, these libraries mess up. Specifically: redundant 0s should be stripped from the signature.

Environment:

  • Java 8u144
  • sshj 0.21.1
  • connecting to Cisco devices (IOS XRs)
ERROR [net.schmizz.concurrent.Promise] <<kex done>> woke to: net.schmizz.sshj.transport.TransportException: Invalid encoding for signature
...
Caused by: net.schmizz.sshj.transport.TransportException: Invalid encoding for signature
    at net.schmizz.sshj.transport.TransportException$1.chain(TransportException.java:33)
    at net.schmizz.sshj.transport.TransportException$1.chain(TransportException.java:27)
    at net.schmizz.concurrent.Promise.deliverError(Promise.java:96)
    at net.schmizz.concurrent.Event.deliverError(Event.java:74)
    at net.schmizz.concurrent.ErrorDeliveryUtil.alertEvents(ErrorDeliveryUtil.java:34)
    at net.schmizz.sshj.transport.KeyExchanger.notifyError(KeyExchanger.java:386)
    at net.schmizz.sshj.transport.TransportImpl.die(TransportImpl.java:600)
    at net.schmizz.sshj.transport.Reader.run(Reader.java:67)
Caused by: net.schmizz.sshj.common.SSHException: Invalid encoding for signature
    at net.schmizz.sshj.common.SSHException$1.chain(SSHException.java:36)
    at net.schmizz.sshj.common.SSHException$1.chain(SSHException.java:29)
    at net.schmizz.sshj.transport.TransportImpl.die(TransportImpl.java:595)
    ... 1 common frames omitted
Caused by: net.schmizz.sshj.common.SSHRuntimeException: Invalid encoding for signature
    at net.schmizz.sshj.signature.SignatureDSA.verify(SignatureDSA.java:102)
    at net.schmizz.sshj.transport.kex.AbstractDHG.next(AbstractDHG.java:85)
    at net.schmizz.sshj.transport.KeyExchanger.handle(KeyExchanger.java:358)
    at net.schmizz.sshj.transport.TransportImpl.handle(TransportImpl.java:503)
    at net.schmizz.sshj.transport.Decoder.decode(Decoder.java:102)
    at net.schmizz.sshj.transport.Decoder.received(Decoder.java:170)
    at net.schmizz.sshj.transport.Reader.run(Reader.java:59)
Caused by: java.security.SignatureException: Invalid encoding for signature
    at sun.security.provider.DSA.engineVerify(DSA.java:283)
    at sun.security.provider.DSA.engineVerify(DSA.java:244)
    at java.security.Signature$Delegate.engineVerify(Signature.java:1219)
    at java.security.Signature.verify(Signature.java:652)
    at net.schmizz.sshj.signature.SignatureDSA.verify(SignatureDSA.java:100)
    ... 6 common frames omitted
Caused by: java.io.IOException: Invalid encoding: redundant leading 0s
    at sun.security.util.DerInputBuffer.getBigInteger(DerInputBuffer.java:152)
    at sun.security.util.DerValue.getBigInteger(DerValue.java:512)
    at sun.security.provider.DSA.engineVerify(DSA.java:281)
    ... 10 common frames omitted
@hierynomus
Copy link
Owner

If you have a unit test case to reproduce this that would be great.

@hierynomus
Copy link
Owner

@charlesrgould Can you craft some unit test case that fails so that we can make work of solving this? thanks!

@charego
Copy link
Contributor Author

charego commented Sep 7, 2017

I've been trying to do just that. On our devices it's intermittent. The code logs in to the device several times in short succession, using username-password auth. Occasionally we see this exception about the key exchange messing up. Do you have any insight (or guess) as to what could be the problem?

Feel free to close the two tickets I created if I fail to generate a test case within the next few weeks.

@hierynomus
Copy link
Owner

hierynomus commented Sep 7, 2017 via email

hierynomus added a commit that referenced this issue Sep 29, 2017
* Fix for signature verify in DSA

* Cleaned up signature verification

* Fixed import

* Ignored erroneous pmd warnings

* Updated JavaDoc
CCLiu added a commit to CCLiu/sshj that referenced this issue Jan 11, 2018
* Check whether filename is a child of the current file (Fixes hierynomus#341)

* Fixed codacy

* Updated README release notes

* Removed oraclejdk7 as that is no longer supported on trusty, added openjdk

* Added gradle caching to travis config

* Removed use of DataTypeConverter as that is no longer in default JDK9

* Removed build of broken openJDK7 in favour of using animal-sniffer to detect java 1.6 compatibility

* Improved test stability

* Correctly determine KeyType for ECDSA public key (Fixes hierynomus#356)

* fixed build

* Fixed Java9 build?

* Disambiguated signature initialization

* Removed deprecated method

* Organised imports

* Added 'out/' to gitignore

* Added support for new-style fingerprints (hierynomus#365)

* Added support for new-style fingerprints

* Fixed codacy warnings

* Fix decoding signature bytes (Fixes hierynomus#355, hierynomus#354) (hierynomus#361)

* Fix for signature verify in DSA

* Cleaned up signature verification

* Fixed import

* Ignored erroneous pmd warnings

* Updated JavaDoc

* Extracted ASN.1/DER encoding to method (hierynomus#368)

* Update net.i2p.crypto:eddsa to 0.2.0 (hierynomus#372)

* Update net.i2p.crypto:eddsa to 0.2.0

* Update net.i2p.crypto.eddsa to 0.2.0

* Update net.i2p.crypto.eddsa to 0.2.0

* Update net.i2p.crypto.eddsa to 0.2.0

* Log security provider registration failures (hierynomus#374)

* Migrate remaining block ciphers

* Updated README for v0.23.0 release

* Using new release plugin

* Updated build plugins

* Fix escaping in WildcardHostMatcher (hierynomus#382)

* Escape '[' and ']' in WildcardHostMatcher

* Anchoring regex to match entire string (Fixes hierynomus#381)

* Updated builds to include CodeCov

* - Experimenting with travis

* - fix ip for online testing

* - account for different working dir

* - yaml-yaml

* - double before_install

* - still -d

* - try common format

* - Fixed server keys
- Use sshj branding

* - grr, ip

* - minor improvements

* - eh?

* - switch username back

* - orly?

* - desperation

* - One more time

* Upgraded gradle to cope with java9

* Separated out integration tests

* Fixed length bug in putString (Fixes hierynomus#187)

* Removed docker from travis yml as it is included in gradle build now

* Added integration test to travis

* Update AndroidConfig (hierynomus#389)

* Add EdDSA signature for AndroidConfig.

* Initialize KeyExchange- and FileKeyProviderFactories with registered "bouncyCastle" (in fact, SpongyCastle is registered).

See hierynomus#308 for discussion.

* Added integration test for append scenario (Fixes hierynomus#390)

* Fixed headers
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

Successfully merging a pull request may close this issue.

2 participants