Menu

#129 "JSchException: invalid privatekey" on OpenSSH 7.8 and above

v1.0 (example)
open
nobody
None
5
2020-06-01
2020-01-16
eed3si9n
No

steps

  1. use JSch for example via JGit with private key generated using OpenSSH 7.8 and above.

problem

See for example https://stackoverflow.com/a/53783283/3827

Caused by: com.jcraft.jsch.JSchException: invalid privatekey: [B@e4487af
    at com.jcraft.jsch.KeyPair.load(KeyPair.java:664)
    at com.jcraft.jsch.KeyPair.load(KeyPair.java:561)
    at com.jcraft.jsch.IdentityFile.newInstance(IdentityFile.java:40)
    at com.jcraft.jsch.JSch.addIdentity(JSch.java:407)
    at com.jcraft.jsch.JSch.addIdentity(JSch.java:367)
    at org.eclipse.jgit.transport.JschConfigSessionFactory.getJSch(JschConfigSessionFactory.java:276)
    at org.eclipse.jgit.transport.JschConfigSessionFactory.createSession(JschConfigSessionFactory.java:220)
    at org.eclipse.jgit.transport.JschConfigSessionFactory.createSession(JschConfigSessionFactory.java:176)
    at org.eclipse.jgit.transport.JschConfigSessionFactory.getSession(JschConfigSessionFactory.java:110)

expectation

This should work.

notes

https://www.openssh.com/txt/release-7.8

  • ssh-keygen(1): write OpenSSH format private keys by default
    instead of using OpenSSL's PEM format. The OpenSSH format,
    supported in OpenSSH releases since 2014 and described in the
    PROTOCOL.key file in the source distribution, offers substantially
    better protection against offline password guessing and supports
    key comments in private keys. If necessary, it is possible to write
    old PEM-style keys by adding "-m PEM" to ssh-keygen's arguments
    when generating or updating a key.

This is affecting JGit and their users https://bugs.eclipse.org/bugs/show_bug.cgi?id=558448

Discussion

  • Radu Coravu

    Radu Coravu - 2020-05-21

    +1 we are also interested in having this work for SFTP connections.

     
    • Tobias Hochgürtel

      Hello Radu Coravu, It looks like that there is now someone how forked this project https://sourceforge.net/p/jsch/bugs/119/#efc6

       
      • Radu Coravu

        Radu Coravu - 2020-06-01

        Thanks Tobias, I will keep this in mind.

         

Log in to post a comment.

MongoDB Logo MongoDB