Frode - 2008-07-08

I have one SFTP-server set up with key-auth. (not mine, but I have delivered a public-part of a key-pair)

The key-pair was created using Solaris keygen.

I have copied the private-part to my windows-laptop, and does development here. This works fine, and I can succesfully connect to the SFTP-server and list content.
But when I try to run the same class on the Solaris (using he same private-key) the server doesn't seem to recognise the key,and starts to ask for password instead.
If I try to use Solaris SFTP with the same key, it works fine.

Sample-code :

   public void testPlainConnection() throws JSchException, SftpException {
        JSch jSch = new JSch();
        final byte[] prvkey = ("-----BEGIN RSA PRIVATE KEY-----\r\n"
                + "[cutting out this]"
                + "-----END RSA PRIVATE KEY-----").getBytes(); // Private key
                                                                // must be byte
                                                                // array
        final byte[] emptyPassPhrase = new byte[0]; // Empty passphrase for now,
                                                    // get real passphrase from
                                                    // MyUserInfo

        jSch.addIdentity("id", // String userName
                prvkey, // byte[] privateKey
                null, // byte[] publicKey
                emptyPassPhrase // byte[] passPhrase
                );
        jSch.setKnownHosts("kh");
        Session session = jSch.getSession("username", host, port);
        UserInfo ui = new MyUserInfo(); // MyUserInfo implements UserInfo
        session.setUserInfo(ui);
        session.connect();
        Channel channel = session.openChannel("sftp");
        ChannelSftp sftp = (ChannelSftp) channel;
        sftp.connect();
        System.out.println(sftp.ls("."));
        sftp.disconnect();
        session.disconnect();
    }

    public static class MyUserInfo implements UserInfo {
        public String getPassword() {
            return "";
        }

        public boolean promptYesNo(String str) {
            System.out.println(str);
            return true;
        }

        public String getPassphrase() {
            return "";
        }

        public boolean promptPassphrase(String message) {
            System.out.println("PP:" + message);
            return true;
        }

        public boolean promptPassword(String message) {
            System.out.println("PW:" + message);
            return true;
        }

        public void showMessage(String message) {
            System.out.println(message);
        }
    }

-----

I have also tried the SSHTools with the same result ; working on Windows, but not on Solaris.
When I tried the commercail version of SSHTools from Maverick, I could succesfully connect both from Windows and Solaris.
I would really like to get JSCH to work...

/frode