Reputation: 21
Ive set up an SSH client with Apache Mina SSHD, to ssh into a linux server using private key generated from puttygen
The key is generated from puttygen and the public key is copied from the puttygen UI, to the authorized_keys files on the server.
The private key is exported in 2 ways
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.
Upvotes: 1
Views: 1291