Details
Description
Hi,
a NPE is thrown if no private key file is supplied in the configuration for SFTP. The error is
Caused by: java.lang.NullPointerException: while trying to get the length of an array loaded from local variable 'foo'
at com.jcraft.jsch.Buffer.putString(Buffer.java:59)
I have analysed the code a bit and found that the problem is caused
by the class SftpOperations. The method createSession sets the userInfo for the seesion by an inline class. Here the method promptKeyboardInteractive does not work correctly if no private key file is supplied. In that case JSCH switches to user/pw authorization and this method is called. But since there is no password maintained the configation object returns NULL. The present implementation adds it to the string array causing the error in JSCH. JSCH either wants a NULL string array or an empty string array (I have tested both). So the code should look e.g. as follows:
public String[] promptKeyboardInteractive(String destination, String name, String instruction, String[] prompt, boolean[] echo) {
String password = configuration.getPassword();
if (password == null)
else {
return new String[]
;
}
}
With that change JSCH returns
Caused by: java.io.FileNotFoundException: ./data/ssh/id_rsa (No such file or directory)
at java.io.FileInputStream.open(Native Method)
and that is the real cause of the error
Best Regards,
Jörg