jsch icon indicating copy to clipboard operation
jsch copied to clipboard

Some bizarre exception when using SSH key to log on

Open nskmda opened this issue 1 year ago • 3 comments

Team,

I'm getting the following stack trace when using an SSH key to connect to the target server (actually, an outdated one, for which I had to enable ssh-rsa "stuff".

Here's the trace:

failed to parse public key
java.lang.ArrayIndexOutOfBoundsException: 0
	at com.jcraft.jsch.KeyPair.load(KeyPair.java:1015)
	at com.jcraft.jsch.IdentityFile.newInstance(IdentityFile.java:44)
	at com.jcraft.jsch.JSch.addIdentity(JSch.java:524)
	at com.pin.ftp.connection.SftpSession.openSession(SftpSession.java:75)
	at com.pin.ftp.connection.SftpManager.connect(SftpManager.java:119)
	at com.pin.ftp.connectiontester.ConnectionProbe.testConnection(ConnectionProbe.java:26)
	at com.pin.ftp.connectiontester.ConnectionCheckerForMember.handleRequest(ConnectionCheckerForMember.java:36)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at lambdainternal.EventHandlerLoader$PojoMethodRequestHandler.handleRequest(EventHandlerLoader.java:290)
	at lambdainternal.EventHandlerLoader$PojoHandlerAsStreamHandler.handleRequest(EventHandlerLoader.java:207)
	at lambdainternal.EventHandlerLoader$2.call(EventHandlerLoader.java:925)
	at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:273)
	at lambdainternal.AWSLambda.startRuntime(AWSLambda.java:208)
	at lambdainternal.AWSLambda.main(AWSLambda.java:198)

do you need any other log messages or this might be telling you something about the key I'm using? maybe the key is wrong or something?

The key is ssh-rsa (in the public portion) and in the private portion it says -----BEGIN RSA PRIVATE KEY-----

nskmda avatar Jan 22 '24 23:01 nskmda

Hi @nskmda,

The byte[] pubkey argument you are passing to the JSch.addIdentity() would appear to be an empty array instead of a an actual ssh public key string.

Thanks, Jeremy

norrisjeremy avatar Jan 23 '24 20:01 norrisjeremy

@norrisjeremy

The byte[] pubkey argument you are passing to the JSch.addIdentity() would appear to be an empty array instead of a an actual ssh public key string.

So, is it safe to pass null if I don't happen to immediately have the public key info (so that I don't need to try to pull it out of the private key material)?

If yes, you can close the request.

nskmda avatar Jan 23 '24 22:01 nskmda

Hi @nskmda,

Yes it should be fine to pass null if you don't have the public key.

Thanks, Jeremy

norrisjeremy avatar Jan 23 '24 22:01 norrisjeremy