You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Radhakrishnan Meiappan <rm...@rocketsoftware.com> on 2022/09/23 15:16:43 UTC

Apache Mina key based authentication

Hello,

I'm currently facing this problem and not able to proceed further. Any help or pointers would be greatly appreciated.

I'm setting up an SSH client with Apache Mina SSHD, to connect to a linux server via SSH and using key based authentication.
I've generated the key using puttygen

  *   Public Key
     *   copied the public key from puttygen UI to the authorized_keys of the server.
  *   Private Key - exported private key in 2 ways
     *   Export the private key from the puttygen menu - Conversions - Export ssh.com key and saved it to mykey.key
     *   Clicked on 'Save private key' button on puttygen and saved it to mykey.ppk

I'm using the following code to parse the keys in my client

Collection<KeyPair> keyPairs  = PuttyKeyUtils.DEFAULT_INSTANCE.loadKeyPairs(null, Paths.get(certFilePath), FilePasswordProvider.of(certFilePassword));

To the above code -

  *   If I pass the .ppk file I'm getting the below exception  - getting exception during parsing of the key file
Exception in thread "main" java.io.StreamCorruptedException: Negative block length requested: -1875473298
       at org.apache.sshd.common.config.keys.loader.putty.PuttyKeyReader.read(PuttyKeyReader.java:72)
       at org.apache.sshd.common.config.keys.loader.putty.PuttyKeyReader.readInt(PuttyKeyReader.java:61)
       at org.apache.sshd.common.config.keys.loader.putty.RSAPuttyKeyDecoder.loadKeyPairs(RSAPuttyKeyDecoder.java:64)
       at org.apache.sshd.common.config.keys.loader.putty.AbstractPuttyKeyDecoder.loadKeyPairs(AbstractPuttyKeyDecoder.java:270)
       at org.apache.sshd.common.config.keys.loader.putty.AbstractPuttyKeyDecoder.loadKeyPairs(AbstractPuttyKeyDecoder.java:259)
       at org.apache.sshd.common.config.keys.loader.putty.AbstractPuttyKeyDecoder.loadKeyPairs(AbstractPuttyKeyDecoder.java:216)
       at org.apache.sshd.common.config.keys.loader.putty.AbstractPuttyKeyDecoder.loadKeyPairs(AbstractPuttyKeyDecoder.java:161)
       at org.apache.sshd.common.config.keys.loader.putty.AbstractPuttyKeyDecoder.loadKeyPairs(AbstractPuttyKeyDecoder.java:129)
       at org.apache.sshd.common.config.keys.loader.KeyPairResourceParser$2.loadKeyPairs(KeyPairResourceParser.java:166)
       at org.apache.sshd.common.config.keys.loader.KeyPairResourceLoader.loadKeyPairs(KeyPairResourceLoader.java:157)
       at org.apache.sshd.common.config.keys.loader.KeyPairResourceLoader.loadKeyPairs(KeyPairResourceLoader.java:148)
       at org.apache.sshd.common.config.keys.loader.KeyPairResourceLoader.loadKeyPairs(KeyPairResourceLoader.java:139)
       at org.apache.sshd.common.config.keys.loader.KeyPairResourceLoader.loadKeyPairs(KeyPairResourceLoader.java:115)
       at org.apache.sshd.common.config.keys.loader.KeyPairResourceLoader.loadKeyPairs(KeyPairResourceLoader.java:90)
       at org.apache.sshd.common.config.keys.loader.KeyPairResourceLoader.loadKeyPairs(KeyPairResourceLoader.java:84)
       at TestMina5keystringWithPwd.listFolderStructure(TestMina5keystringWithPwd.java:96)

at TestMina5keystringWithPwd.main(TestMina5keystringWithPwd.java:46)



  *   If I pass the .key file, I'm getting this exception ( the load key pairs returns empty and sshd authentication just fails)
Exception in thread "main" org.apache.sshd.common.SshException: No more authentication methods available
       at org.apache.sshd.client.session.ClientUserAuthService.tryNext(ClientUserAuthService.java:330)
       at org.apache.sshd.client.session.ClientUserAuthService.processUserAuth(ClientUserAuthService.java:264)
       at org.apache.sshd.client.session.ClientUserAuthService.process(ClientUserAuthService.java:211)
       at org.apache.sshd.common.session.helpers.AbstractSession.doHandleMessage(AbstractSession.java:462)
       at org.apache.sshd.common.session.helpers.AbstractSession.handleMessage(AbstractSession.java:388)
       at org.apache.sshd.common.session.helpers.AbstractSession.decode(AbstractSession.java:1399)
       at org.apache.sshd.common.session.helpers.AbstractSession.messageReceived(AbstractSession.java:345)
       at org.apache.sshd.common.session.helpers.AbstractSessionIoHandler.messageReceived(AbstractSessionIoHandler.java:64)
       at org.apache.sshd.common.io.nio2.Nio2Session.handleReadCycleCompletion(Nio2Session.java:356)
       at org.apache.sshd.common.io.nio2.Nio2Session$1.onCompleted(Nio2Session.java:334)
       at org.apache.sshd.common.io.nio2.Nio2Session$1.onCompleted(Nio2Session.java:331)
       at org.apache.sshd.common.io.nio2.Nio2CompletionHandler.lambda$completed$0(Nio2CompletionHandler.java:38)
       at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
       at org.apache.sshd.common.io.nio2.Nio2CompletionHandler.completed(Nio2CompletionHandler.java:37)
       at java.base/sun.nio.ch.Invoker.invokeUnchecked(Invoker.java:129)
       at java.base/sun.nio.ch.Invoker$2.run(Invoker.java:221)
       at java.base/sun.nio.ch.AsynchronousChannelGroupImpl$1.run(AsynchronousChannelGroupImpl.java:113)
       at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
       at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)

-                 at java.base/java.lang.Thread.run(Thread.java:833)

Pls. let me know the right methods to parse a private key generated from putty in my sshd client.

Thanks
RK

================================
Rocket Software, Inc. and subsidiaries ? 77 Fourth Avenue, Waltham MA 02451 ? Main Office Toll Free Number: +1 855.577.4323
Contact Customer Support: https://my.rocketsoftware.com/RocketCommunity/RCEmailSupport
Unsubscribe from Marketing Messages/Manage Your Subscription Preferences - http://www.rocketsoftware.com/manage-your-email-preferences
Privacy Policy - http://www.rocketsoftware.com/company/legal/privacy-policy
================================

This communication and any attachments may contain confidential information of Rocket Software, Inc. All unauthorized use, disclosure or distribution is prohibited. If you are not the intended recipient, please notify Rocket Software immediately and destroy all copies of this communication. Thank you.

Re: Apache Mina key based authentication

Posted by Thomas Wolf <t....@gmail.com>.
On 23.09.22 17:16 , Radhakrishnan Meiappan wrote:
>    *   If I pass the .ppk file I'm getting the below exception  - getting exception during parsing of the key file

Check what the file format of that PPK file is. If it mentions anything
about "argon": you need at least Apache MINA sshd 2.9.0 to be able to
read that key file.

Otherwise it should be possible to export a key from PuTTY in the
OpenSSH format and use that.

Cheers,

   Thomas

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@mina.apache.org
For additional commands, e-mail: dev-help@mina.apache.org