examples
Class SSH1Example

java.lang.Object
  extended bycom.mindbright.ssh.SSHInteractorAdapter
      extended byexamples.SSH1Example
All Implemented Interfaces:
SSHAuthenticator, SSHClientUser, SSHInteractor

public class SSH1Example
extends SSHInteractorAdapter
implements SSHAuthenticator, SSHClientUser

Examples on how to use the ssh1 classes.

NOTE that the ssh1 protocol is a deprecated protocol with known security vulnerabilities. Use version 2 if at all possible. Moreover the SSH1 api in MindTerm is less structured and harder to use. That said this class contains code demonstrating:

Usage: java -cp examples.jar examples.SSH1Example username port username password


Method Summary
 int getAliveInterval()
          Get alive interval (0 = do not send keepalive packets)
 int[] getAuthTypes(SSHClientUser origin)
          Get the authentication method the user wants to us
 java.lang.String getChallengeResponse(SSHClientUser origin, java.lang.String challenge)
          Present challenge to user an return answer
 int getCipher(SSHClientUser origin)
          Get desirect encryption algorithm
 int getCompressionLevel()
          Get desired level of compression
 java.lang.String getDisplay()
          Get the display for X11 forwardings
 SSHRSAKeyFile getIdentityFile(SSHClientUser origin)
          Return name of file containing private key for pubkey authentication
 java.lang.String getIdentityPassword(SSHClientUser origin)
          Return password protecting identify file
 SSHInteractor getInteractor()
          Get interactor which should handle the authentication phase
 int getMaxPacketSz()
          get maximum packet size (0 = no limit)
 java.lang.String getPassword(SSHClientUser origin)
          Get password to log in with
 java.net.Socket getProxyConnection()
          Return a connection to the server.
 java.lang.String getSrvHost()
          Get host to connect to
 int getSrvPort()
          Get port number to connect to
 java.lang.String getUsername(SSHClientUser origin)
          Get username to log in as
static void main(java.lang.String[] argv)
          Run the application
 void runSCP(java.lang.String remotefile)
          Transfer files with SCP
 void runWithCommand(java.lang.String command)
          Start a command over SSH1 connection and run a command and retrieve the output
 void runWithCommandInShell(java.lang.String command)
          Start a shell over SSH1 connection and run a command and retrieve the output
 void runWithPortFwd()
          Start an SSH1 connection with port forward.
 boolean verifyKnownHosts(RSAPublicKey hostPub)
          Verify the fingerprint of the remote host.
 boolean wantPTY()
          Return true if we need a PTY on the server
 boolean wantX11Forward()
          Return true if X11 forwarding is desired
 
Methods inherited from class com.mindbright.ssh.SSHInteractorAdapter
alert, askConfirmation, connected, disconnected, isVerbose, licenseDialog, open, promptLine, promptPassword, propsStateChanged, quietPrompts, report, sessionStarted, startNewSession
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

runWithPortFwd

public void runWithPortFwd()
                    throws java.net.UnknownHostException,
                           java.io.IOException
Start an SSH1 connection with port forward. Then demonstrate reading and writing on this portforward.

Throws:
java.net.UnknownHostException
java.io.IOException

runWithCommand

public void runWithCommand(java.lang.String command)
                    throws java.io.IOException
Start a command over SSH1 connection and run a command and retrieve the output

Parameters:
command - Command to execute
Throws:
java.io.IOException

runWithCommandInShell

public void runWithCommandInShell(java.lang.String command)
                           throws java.io.IOException
Start a shell over SSH1 connection and run a command and retrieve the output

Parameters:
command - Command to execute
Throws:
java.io.IOException

runSCP

public void runSCP(java.lang.String remotefile)
            throws java.io.IOException
Transfer files with SCP

Parameters:
remotefile - File on remote system to transfer
Throws:
java.io.IOException

getUsername

public java.lang.String getUsername(SSHClientUser origin)
                             throws java.io.IOException
Get username to log in as

Specified by:
getUsername in interface SSHAuthenticator
Throws:
java.io.IOException

getPassword

public java.lang.String getPassword(SSHClientUser origin)
                             throws java.io.IOException
Get password to log in with

Specified by:
getPassword in interface SSHAuthenticator
Throws:
java.io.IOException

getChallengeResponse

public java.lang.String getChallengeResponse(SSHClientUser origin,
                                             java.lang.String challenge)
                                      throws java.io.IOException
Present challenge to user an return answer

Specified by:
getChallengeResponse in interface SSHAuthenticator
Throws:
java.io.IOException

getAuthTypes

public int[] getAuthTypes(SSHClientUser origin)
Get the authentication method the user wants to us

Specified by:
getAuthTypes in interface SSHAuthenticator

getCipher

public int getCipher(SSHClientUser origin)
Get desirect encryption algorithm

Specified by:
getCipher in interface SSHAuthenticator

getIdentityFile

public SSHRSAKeyFile getIdentityFile(SSHClientUser origin)
                              throws java.io.IOException
Return name of file containing private key for pubkey authentication

Specified by:
getIdentityFile in interface SSHAuthenticator
Throws:
java.io.IOException

getIdentityPassword

public java.lang.String getIdentityPassword(SSHClientUser origin)
                                     throws java.io.IOException
Return password protecting identify file

Specified by:
getIdentityPassword in interface SSHAuthenticator
Throws:
java.io.IOException

verifyKnownHosts

public boolean verifyKnownHosts(RSAPublicKey hostPub)
                         throws java.io.IOException
Verify the fingerprint of the remote host.

Specified by:
verifyKnownHosts in interface SSHAuthenticator
Parameters:
hostPub - public key of remote host
Returns:
true if the public key verifies
Throws:
java.io.IOException

getSrvHost

public java.lang.String getSrvHost()
                            throws java.io.IOException
Get host to connect to

Specified by:
getSrvHost in interface SSHClientUser
Throws:
java.io.IOException

getSrvPort

public int getSrvPort()
Get port number to connect to

Specified by:
getSrvPort in interface SSHClientUser

getProxyConnection

public java.net.Socket getProxyConnection()
                                   throws java.io.IOException
Return a connection to the server. This can be used to connect through proxies etc.

Specified by:
getProxyConnection in interface SSHClientUser
Throws:
java.io.IOException

getDisplay

public java.lang.String getDisplay()
Get the display for X11 forwardings

Specified by:
getDisplay in interface SSHClientUser

getMaxPacketSz

public int getMaxPacketSz()
get maximum packet size (0 = no limit)

Specified by:
getMaxPacketSz in interface SSHClientUser

getAliveInterval

public int getAliveInterval()
Get alive interval (0 = do not send keepalive packets)

Specified by:
getAliveInterval in interface SSHClientUser

getCompressionLevel

public int getCompressionLevel()
Get desired level of compression

Specified by:
getCompressionLevel in interface SSHClientUser

wantX11Forward

public boolean wantX11Forward()
Return true if X11 forwarding is desired

Specified by:
wantX11Forward in interface SSHClientUser

wantPTY

public boolean wantPTY()
Return true if we need a PTY on the server

Specified by:
wantPTY in interface SSHClientUser

getInteractor

public SSHInteractor getInteractor()
Get interactor which should handle the authentication phase

Specified by:
getInteractor in interface SSHClientUser

main

public static void main(java.lang.String[] argv)
Run the application