[JSch-users] Public key authentication without file (bug fix)
Status: Alpha
Brought to you by:
ymnk
From: n s. <nsc...@ya...> - 2007-07-20 18:13:08
|
----- Forwarded Message ---- From: n schembr <nsc...@ya...> To: n schembr <nsc...@ya...> Sent: Friday, July 20, 2007 2:10:44 PM Subject: Re: [JSch-users] Public key authentication without file (bug fix) Okay, I think I found it. userinfo is not being used. userinfo is null. This returns false. class UserAuthKeyboardInteractive extends UserAuth{ public boolean start(Session session, UserInfo userinfo) throws Exception{ this.userinfo=userinfo; // if(!(userinfo instanceof UIKeyboardInteractive)){ // return false; // } I'm not sure about the rest of the code, but a userinfo != null test is used before userinfo is used. if (userinfo !=null){ if(!(userinfo instanceof UIKeyboardInteractive)){ return false; } } The following code work great after above change: try { JSch jsch=new JSch(); String knownHosts = "oak,10.200.55.100 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAozQicuuBybpy2pS/kDXiTl3Lb+QSqtNc5dFXHnPVflTcevX9yjB1UupnCgEF+BB/DH2TyVzW38a7LMq7wc1pCiMKjn1SxRB1PwGebUpU0cUKsKbZ3caDIAuEmx0Vl/cUx1MVc+lBtQzkZly5KKeQHXKMo6evhyPf+xpLankxzCU="; InputStream i = new ByteArrayInputStream(knownHosts.getBytes()); jsch.setKnownHosts(i); String user="bob"; String host="oak"; Session session=jsch.getSession(user, host, 22); Hashtable config = new Hashtable(); session.setPassword("mypassword"); session.connect(); Channel channel=session.openChannel("sftp"); channel.connect(); ChannelSftp c=(ChannelSftp)channel; int mode=ChannelSftp.OVERWRITE; try { // mode=ChannelSftp.RESUME; } //mode=ChannelSftp.APPEND; } // c.put(p1, p2, monitor, mode); c.put("/etc/passwd",".",mode); } catch (SftpException ex) { ex.printStackTrace(); } } catch (JSchException ex) { ex.printStackTrace(); } } I can see how userInfo would be of value in building a large application, but I'm just coping log files. I'm thinking that the simple connection code could be changed to session.setUserId("Bob"); session.setPassword("Bobspassword"); session.setExpectedHostKeyHash("1d:da:80:c3:db:42:04:96:e6:e2:4a:1f:fb:f8:69:c2"); // or jsch.setKnownHosts(oak,10.200.55.123 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAozQicuuBybpy2pS/kDXiTl3Lb+QSqtNc5dFXHnPVflTcevX9yjB1UupnCgEF+BB/DH2TyVzW38a7LMq7wc1pCiMKjn1SxRB1PwGebUpU0cUKsKbZ3caDIAuEmx0Vl/cUx1MVc+lBtQzkZly5KKeQHXKMo6evhyPf+xpLankxzCU="); session.connect(); or String user="bob"; String host="oak"; String passwd ="mypasswd"; String expectedHostKeyHash ="1d:da:80:c3:db:42:04:96:e6:e2:4a:1f:fb:f8:69:c2"; Session session=jsch.getSession(user,passwd, host, 22, expectedHostKeyHash ); session.connect(); Thank you for your time, Nicholas A. Schembri State College PA, USA ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2005. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ JSch-users mailing list JSc...@li... https://lists.sourceforge.net/lists/listinfo/jsch-users |