Joerg Kessler created CAMEL-6514:
------------------------------------

             Summary: SFTP: NPE if no private key file is supplied
                 Key: CAMEL-6514
                 URL: https://issues.apache.org/jira/browse/CAMEL-6514
             Project: Camel
          Issue Type: Bug
          Components: camel-ftp
    Affects Versions: 2.10.4
            Reporter: Joerg Kessler
            Priority: Minor


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) {
                    return new String[0];
                } else {
                    return new String[] { password };
                }
            }
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 


--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to