com.maverick.ssh2
Class KBIAuthentication

java.lang.Object
  extended bycom.maverick.ssh2.KBIAuthentication
All Implemented Interfaces:
AuthenticationClient, SshAuthentication

public class KBIAuthentication
extends java.lang.Object
implements AuthenticationClient

keyboard-interactive authentication implementation as specified in draft-ietf-secsh-auth-kbdinteract-04.txt. Keyboard interactive provides a challenge-response type authentication which allows clients to support authentication mechanisms where the actual specification is not known.

The process works by the client first requesting the keyboard-interactive method; the server then responds with any number of prompts to which the user must provide an answer. This is acheived through the use of the KBIRequestHandler interface.

 KBIAuthentication kbi = new KBIAuthentication();

 kbi.setKBIRequestHandler(new KBIRequestHandler() {
  	public void showPrompts(String name, String instruction, KBIPrompt[] prompts) {
 					try {
 						System.out.println(name);
 						System.out.println(instruction);
						for(int i=0;i<prompts.length;i++) {
							System.out.print(prompts[i].getPrompt());
							prompts[i].setResponse(reader.readLine());
						}
					} catch (IOException e) {
						e.printStackTrace();
					}
				}
			});

	ssh.authenticate(kbi);
 

Special care should be taken to check the echo flag of the KBIPrompt if set to false the user reponse entered by the user should not be echo'd back to the screen, for example in the process of entering a password.

Author:
Lee David Painter

Field Summary
 
Fields inherited from interface com.maverick.ssh.SshAuthentication
CANCELLED, COMPLETE, FAILED, FURTHER_AUTHENTICATION_REQUIRED, PUBLIC_KEY_ACCEPTABLE
 
Constructor Summary
KBIAuthentication()
           
 
Method Summary
 void authenticate(AuthenticationProtocol authentication, java.lang.String servicename)
          Perform the authentication according to the specification.
 java.lang.String getMethod()
          The SSH authentication method name
 java.lang.String getMethodName()
           
 java.lang.String getUsername()
          Get the username for this authentication attempt.
 void setKBIRequestHandler(KBIRequestHandler handler)
          Set the KBIRequestHandler for this authentication attempt.
 void setUsername(java.lang.String username)
          Set the username for this authentication attempt.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KBIAuthentication

public KBIAuthentication()
Method Detail

getUsername

public java.lang.String getUsername()
Description copied from interface: SshAuthentication
Get the username for this authentication attempt.

Specified by:
getUsername in interface SshAuthentication
Returns:
the username used.

setUsername

public void setUsername(java.lang.String username)
Description copied from interface: SshAuthentication
Set the username for this authentication attempt.

Specified by:
setUsername in interface SshAuthentication
Parameters:
username -

getMethod

public java.lang.String getMethod()
Description copied from interface: SshAuthentication
The SSH authentication method name

Specified by:
getMethod in interface SshAuthentication
Returns:
String

setKBIRequestHandler

public void setKBIRequestHandler(KBIRequestHandler handler)
Set the KBIRequestHandler for this authentication attempt.

Parameters:
handler -

authenticate

public void authenticate(AuthenticationProtocol authentication,
                         java.lang.String servicename)
                  throws SshException,
                         com.maverick.ssh2.AuthenticationResult
Description copied from interface: AuthenticationClient
Perform the authentication according to the specification. The expected result of this method is for the caller to catch an AuthenticationResult. If the method returns without throwing this then the caller will attempt to read the next message available expecting it to be either a SSH_MSG_USERAUTH_SUCCESS or SSH_MSG_USERAUTH_FAILURE.

Specified by:
authenticate in interface AuthenticationClient
Parameters:
authentication -
servicename -
Throws:
SshException
com.maverick.ssh2.AuthenticationResult

getMethodName

public java.lang.String getMethodName()
Returns:
"keyboard-interactive"


Copyright © 2003 3SP LTD. All Rights Reserved.