Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-6514

SFTP: NPE if no private key file is supplied

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.10.4, 2.11.0
    • Fix Version/s: 2.10.7, 2.11.1, 2.12.0
    • Component/s: camel-ftp
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      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)

      { 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

        Attachments

          Activity

            People

            • Assignee:
              davsclaus Claus Ibsen
              Reporter:
              joerg Joerg Heinicke
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: