[
https://issues.apache.org/jira/browse/SSHD-473?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14567257#comment-14567257
]
Jochen Seliger commented on SSHD-473:
-------------------------------------
Hi Lyor,
here first my Server.class:
package org.flowcontrol.uniselflow.web_services.ssh;
import java.io.IOException;
import org.apache.sshd.*;
import org.apache.sshd.common.keyprovider.FileKeyPairProvider;
import org.apache.sshd.server.PasswordAuthenticator;
public class SSH_SERVER {
public static void main(){
SshServer sshd = SshServer.setUpDefaultServer();
// System.out.println("sshd created");
sshd.setPasswordAuthenticator((PasswordAuthenticator) new
SSHDPasswordAuthenticator());// {
// public boolean authenticate(String username, String password,
ServerSession session) {
// return "tomek".equals(username) && "123".equals(password);
// }
// });
// sshd.setPublickeyAuthenticator(publickeyAuthenticator);
// sshd.setSessionFactory(sessionFactory);
// sshd.setKeyExchangeFactories(keyExchangeFactories);
// sshd.setKeyPairProvider(new FileKeyPairProvider(new
String[]{"C:/Benutzer/Jochen/Download/Putty/AdnectarKey"}));
sshd.setPort(8000);
try {
sshd.start();
System.out.println("sshd started on "+sshd.getPort());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
Next the PasswordAthentikator:
package org.flowcontrol.uniselflow.web_services.ssh;
import javax.swing.JOptionPane;
import org.apache.sshd.server.PasswordAuthenticator;
import org.apache.sshd.server.session.ServerSession;
public class SSHDPasswordAuthenticator implements PasswordAuthenticator{
@Override
public boolean authenticate(String arg0, String arg1, ServerSession arg2) {
// TODO Auto-generated method stub
JOptionPane.showMessageDialog(null,
"authenticate entered with user "+arg0 +", password " +arg1+",
session "+arg2,"success",
JOptionPane.CLOSED_OPTION);
return true;
}
}
and here the Client side createSSHClient-method:/
public static SshClient createSSHClient(boolean quiet){
System.out.println("createSSHClient "+quiet+ " entered");
SshClient client=SshClient.setUpDefaultClient();
client.start();
// client.getChannelFactories();
System.out.println("after SSHClient creation + start");
try {
ClientSession session =
client.connect("Jochen","192.168.100.13",8000).await().getSession();
session.addPasswordIdentity("salinger");
session.auth().verify();
ChannelShell Shellchannel=session.createShellChannel(); //"shell"
if ( Shellchannel != null ){
System.out.println("ShellChannel established");
JOptionPane.showMessageDialog(null,
"ShellChannel created " ,"success",
JOptionPane.CLOSED_OPTION);
USFClient.USFChannelShell = Shellchannel;
try {
Shellchannel.setIn(new NoCloseInputStream(System.in));
Shellchannel.setOut(new NoCloseOutputStream(System.out));
Shellchannel.setErr(new NoCloseOutputStream(System.err));
Shellchannel.open();
System.out.println("ShellChannell opened"); //Bis hier her
komme ich, ohne die Wihil-Schleife von 639-649
// W�hrend der Sever eine Auth-Fehler meldet
JOptionPane.showMessageDialog(null,
"ShellChannel opened " ,"success",
JOptionPane.CLOSED_OPTION);
Shellchannel.waitFor(ClientChannel.CLOSED, 0);
}
catch ( Exception err ){
err.printStackTrace();
JOptionPane.showMessageDialog(null,
"ShellChannel could not been opened "
,"failure",
JOptionPane.CLOSED_OPTION);
}
}
else {
System.out.println("ChannelShell could not been established");
}
// System.out.println("Session="+session);
// Ship authentification to the SSHDServer
// session.addPasswordIdentity("salinger");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
client.stop();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
client.stop();
}
return client;
}
This method is called at the startup of my application unde sertain conditions.
Jochen
> PasswordAuthentifikation
> ------------------------
>
> Key: SSHD-473
> URL: https://issues.apache.org/jira/browse/SSHD-473
> Project: MINA SSHD
> Issue Type: Bug
> Affects Versions: 0.14.0
> Environment: Windows 7, Java 8, Eclipse JUNO
> Reporter: Jochen Seliger
> Priority: Critical
>
> I run the sshd and the ssh client both on the windos mashine.
> The sshd I start on port 8000 and with password authentificator ans an own
> atthenicator class, which shall shoe a messagebox when envoced.
> The client I start aftercreating it as SshClient.setUpDefaultClient();
> without stting any factury with the statement ClientSession session =
> client.connect("Jochen","192.168.100.13",8000).await().getSession(); (Jochen
> is an existing user on the mashine).
> But till shellChannel I can proceed only when setting after session creation
> session.addPasswordIdentity("Jochen"); (it is tha same user as provided at
> session creation)
> There is no functionality to set the password.
> The method authPassword is depreciated.
> 1. My first question: How to proceed th use PasswordAuthentification?
> As stated I can proceesd til ssh-Shell, but the server is logging at a first
> run an autentification failure and at a second run authentification success:
> Mai 22, 2015 12:14:21 PM org.apache.sshd.client.session.ClientSessionImpl
> readIdentification
> INFORMATION: Server version string: SSH-2.0-SSHD-CORE-0.14.0
> Mai 22, 2015 12:14:22 PM
> org.apache.sshd.client.keyverifier.AcceptAllServerKeyVerifier verifyServerKey
> WARNUNG: Server at /192.168.100.13:8000 presented unverified DSA key:
> e4:76:f3:c2:15:64:7f:e4:5f:b7:86:35:a5:3e:85:35
> Mai 22, 2015 12:14:22 PM org.apache.sshd.common.session.AbstractSession
> doHandleMessage
> INFORMATION: Dequeing pending packets
> Mai 22, 2015 12:14:22 PM
> org.apache.sshd.client.session.ClientUserAuthServiceNew processUserAuth
> INFORMATION: Received SSH_MSG_USERAUTH_FAILURE
> Mai 22, 2015 12:14:22 PM
> org.apache.sshd.client.auth.UserAuthKeyboardInteractive process
> INFORMATION: Received Password authentication en-US
> Mai 22, 2015 12:14:22 PM
> org.apache.sshd.client.session.ClientUserAuthServiceNew processUserAuth
> INFORMATION: Received SSH_MSG_USERAUTH_SUCCESS
> ShellChannell opened
> Microsoft Windows [Version 6.0.6001]
> Copyright (c) 2006 Microsoft Corporation. Alle Rechte vorbehalten.
> C:\Users\Jochen\workspace\USF_SSH_WS>
> allthoug I did not provide an password.
> 2. Why thes two runs are processed?
> 3. Why the first run fails and the second one succedes?
> 4. How to proceede to get a functioning password and keypair authentication?
> Regards
> Jochen Seliger
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)