com.maverick.ssh2
Class Ssh2Context

java.lang.Object
  extended bycom.maverick.ssh2.Ssh2Context
All Implemented Interfaces:
SshContext

public final class Ssh2Context
extends java.lang.Object
implements SshContext

This class implements SshContextto provide SSH2 connection configuration through the SshConnector class.

To configure an authentication banner for SSH2 connections see BannerDisplay.

The preferred message authentication algorithm for each data stream can be set using:

		SshConnector con = SshConnector.getInstance();
		Ssh2Context context = (Ssh2Context) con.getContext(SshConnector.SSH2);

		context.setPreferredMacCS(Ssh2Context.HMAC_MD5); // Client->Server data stream
		context.setPreferredMacSC(Ssh2Context.HMAC_MD5); // Server->Client data stream
 
Once further cipher, public key and compression algorithms have been implemented the same process will apply.

Author:
Lee David Painter

Field Summary
static java.lang.String CIPHER_BLOWFISH_CBC
          The Blowfish CBC cipher
static java.lang.String CIPHER_TRIPLEDES_CBC
          The 3DES CBC cipher
static java.lang.String COMPRESSION_NONE
          Compression off
static java.lang.String COMPRESSION_ZLIB
          Optional zlib compression (requires sshtools-zlib.jar in classpath)
static java.lang.String HMAC_MD5
          MD5 message authentication
static java.lang.String HMAC_MD5_96
          MD5 96 bit message authentication
static java.lang.String HMAC_SHA1
          SHA1 message authentication
static java.lang.String HMAC_SHA1_96
          SHA1 96 bit message authentication
static java.lang.String KEX_DIFFIE_HELLMAN_GROUP_EXCHANGE_SHA1
          Optional key exchange mechanism in which the server maintains a list of acceptable generators and primes
static java.lang.String KEX_DIFFIE_HELLMAN_GROUP1_SHA1
          The required key exchange method
static java.lang.String KEX_DIFFIE_HELLMAN_GROUP14_SHA1
           
static java.lang.String PUBLIC_KEY_SSHDSS
          SSH2 DSA Public Key
static java.lang.String PUBLIC_KEY_SSHRSA
          SSH2 RSA Public Key
 
Constructor Summary
Ssh2Context()
          Contructs a default context
 
Method Summary
 BannerDisplay getBannerDisplay()
          Get the contexts banner display
 int getChannelLimit()
          Get the maximum number of channels that are allowed open at any one time.
 HostKeyVerification getHostKeyVerification()
          Get the host key verification implementation
 int getMaximumPacketLength()
          Get the maximim packet size supported by the transport layer.
 int getPartialMessageTimeout()
           
 java.lang.String getPreferredCipherCS()
          Get the currently preferred cipher for the Client->Server stream.
 java.lang.String getPreferredCipherSC()
          Get the currently preferred cipher for the Server->Client stream.
 java.lang.String getPreferredCompressionCS()
          Get the currently preferred compression for the Client->Server stream.
 java.lang.String getPreferredCompressionSC()
          Get the currently preferred compression for the Server->Client stream.
 java.lang.String getPreferredKeyExchange()
          Get the currently preferred key exchange method.
 java.lang.String getPreferredMacCS()
          Get the currently preferred mac for the Client->Server stream.
 java.lang.String getPreferredMacSC()
          Get the currently supported mac for the Server-Client stream.
 java.lang.String getPreferredPublicKey()
          Get the currently preferred public key algorithm.
 java.lang.String getSFTPProvider()
          Get the path to the SFTP provider.
 byte[] getX11AuthenticationCookie()
          Get a fake random cookie for X11 authentication
 java.lang.String getX11Display()
          Get the currently configured XDisplay setting which will be null if no display is currently set.
 byte[] getX11RealCookie()
          Get the real X11 authentication cookie, if not cookie has been set the fake cookie will be returned.
 ForwardingRequestListener getX11RequestListener()
          Get the X11 forwarding request listener.
 void setBannerDisplay(BannerDisplay bannerdisplay)
          Set a banner display for callback of authentication banners
 void setChannelLimit(int maxChannels)
          Set the maximum number of channels that are allowed open at any one time.
 void setHostKeyVerification(HostKeyVerification verify)
          Set the host key verification implementation
 void setMaximumPacketLength(int maxPacketLength)
          Set the maximum packet size supported by the transport layer.
 void setPartialMessageTimeout(int partialMessageTimeout)
           
 void setPreferredCipherCS(java.lang.String name)
          Set the preferred cipher for the Client->Server stream.
 void setPreferredCipherSC(java.lang.String name)
          Set the preferred cipher for the Server->Client stream.
 void setPreferredCompressionCS(java.lang.String name)
          Set the preferred compression for the Client->Server stream.
 void setPreferredCompressionSC(java.lang.String name)
          Set the preferred compression for the Server->Client stream.
 void setPreferredKeyExchange(java.lang.String name)
          Set the preferred key exchange method.
 void setPreferredMacCS(java.lang.String name)
          Set the preferred mac for the Client->Server stream.
 void setPreferredMacSC(java.lang.String name)
          Set the preferred mac for the Server->Client stream.
 void setPreferredPublicKey(java.lang.String name)
          Set the preferred public key algorithm.
 void setSFTPProvider(java.lang.String sftpProvider)
          Set the path to the SFTP provider.
 void setX11Display(java.lang.String xDisplay)
          Set the DISPLAY variable for the SSH connection.
 void setX11RealCookie(byte[] x11RealCookie)
          Sets the real X11 authentication cookie which can be obtained from the users $HOME/.Xauthority file.
 void setX11RequestListener(ForwardingRequestListener x11Listener)
          Set the listener to which X11 forwarding requests will be processed.
 AbstractComponentFactory supportedCiphers()
          Returns this context's supported cipher algorithms.
 AbstractComponentFactory supportedCompressions()
          Get this context's supported compression algorithms.
 AbstractComponentFactory supportedKeyExchanges()
          Get this context's supported key exchange methods.
 AbstractComponentFactory supportedMacs()
          Get this context's supported message authentication algorithms.
 AbstractComponentFactory supportedPublicKeys()
          Get this context's supported public keys.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CIPHER_TRIPLEDES_CBC

public static final java.lang.String CIPHER_TRIPLEDES_CBC
The 3DES CBC cipher

See Also:
Constant Field Values

CIPHER_BLOWFISH_CBC

public static final java.lang.String CIPHER_BLOWFISH_CBC
The Blowfish CBC cipher

See Also:
Constant Field Values

HMAC_SHA1

public static final java.lang.String HMAC_SHA1
SHA1 message authentication

See Also:
Constant Field Values

HMAC_SHA1_96

public static final java.lang.String HMAC_SHA1_96
SHA1 96 bit message authentication

See Also:
Constant Field Values

HMAC_MD5

public static final java.lang.String HMAC_MD5
MD5 message authentication

See Also:
Constant Field Values

HMAC_MD5_96

public static final java.lang.String HMAC_MD5_96
MD5 96 bit message authentication

See Also:
Constant Field Values

COMPRESSION_NONE

public static final java.lang.String COMPRESSION_NONE
Compression off

See Also:
Constant Field Values

COMPRESSION_ZLIB

public static final java.lang.String COMPRESSION_ZLIB
Optional zlib compression (requires sshtools-zlib.jar in classpath)

See Also:
Constant Field Values

KEX_DIFFIE_HELLMAN_GROUP1_SHA1

public static final java.lang.String KEX_DIFFIE_HELLMAN_GROUP1_SHA1
The required key exchange method

See Also:
Constant Field Values

KEX_DIFFIE_HELLMAN_GROUP14_SHA1

public static final java.lang.String KEX_DIFFIE_HELLMAN_GROUP14_SHA1
See Also:
Constant Field Values

KEX_DIFFIE_HELLMAN_GROUP_EXCHANGE_SHA1

public static final java.lang.String KEX_DIFFIE_HELLMAN_GROUP_EXCHANGE_SHA1
Optional key exchange mechanism in which the server maintains a list of acceptable generators and primes

See Also:
Constant Field Values

PUBLIC_KEY_SSHDSS

public static final java.lang.String PUBLIC_KEY_SSHDSS
SSH2 DSA Public Key

See Also:
Constant Field Values

PUBLIC_KEY_SSHRSA

public static final java.lang.String PUBLIC_KEY_SSHRSA
SSH2 RSA Public Key

See Also:
Constant Field Values
Constructor Detail

Ssh2Context

public Ssh2Context()
            throws SshException
Contructs a default context

Throws:
SshException
Method Detail

getMaximumPacketLength

public int getMaximumPacketLength()
Get the maximim packet size supported by the transport layer.

Returns:
int

setMaximumPacketLength

public void setMaximumPacketLength(int maxPacketLength)
Set the maximum packet size supported by the transport layer. This would not normally require changing but some servers may support larger packets. The default and minimum size is 35,000 bytes.

Parameters:
maxPacketLength - int

setChannelLimit

public void setChannelLimit(int maxChannels)
Description copied from interface: SshContext
Set the maximum number of channels that are allowed open at any one time.

Specified by:
setChannelLimit in interface SshContext
Parameters:
maxChannels -

getChannelLimit

public int getChannelLimit()
Description copied from interface: SshContext
Get the maximum number of channels that are allowed open at any one time.

Specified by:
getChannelLimit in interface SshContext
Returns:
the maximum number of channels

setX11Display

public void setX11Display(java.lang.String xDisplay)
Description copied from interface: SshContext
Set the DISPLAY variable for the SSH connection. If this is set the SSH sessions will have their DISPLAY variable set and X sessions will be forwarded over the SSH connection to the display specified.

Specified by:
setX11Display in interface SshContext
Parameters:
xDisplay - the display in the form localhost:1

getX11Display

public java.lang.String getX11Display()
Description copied from interface: SshContext
Get the currently configured XDisplay setting which will be null if no display is currently set.

Specified by:
getX11Display in interface SshContext
Returns:

getX11AuthenticationCookie

public byte[] getX11AuthenticationCookie()
Description copied from interface: SshContext
Get a fake random cookie for X11 authentication

Specified by:
getX11AuthenticationCookie in interface SshContext
Returns:

setX11RealCookie

public void setX11RealCookie(byte[] x11RealCookie)
Description copied from interface: SshContext
Sets the real X11 authentication cookie which can be obtained from the users $HOME/.Xauthority file.

Specified by:
setX11RealCookie in interface SshContext
Parameters:
x11RealCookie -

getX11RealCookie

public byte[] getX11RealCookie()
Description copied from interface: SshContext
Get the real X11 authentication cookie, if not cookie has been set the fake cookie will be returned.

Specified by:
getX11RealCookie in interface SshContext
Returns:

setX11RequestListener

public void setX11RequestListener(ForwardingRequestListener x11Listener)
Description copied from interface: SshContext
Set the listener to which X11 forwarding requests will be processed.

Specified by:
setX11RequestListener in interface SshContext
Parameters:
x11Listener -

getX11RequestListener

public ForwardingRequestListener getX11RequestListener()
Description copied from interface: SshContext
Get the X11 forwarding request listener.

Specified by:
getX11RequestListener in interface SshContext
Returns:

getBannerDisplay

public BannerDisplay getBannerDisplay()
Get the contexts banner display

Returns:
the banner display, may be null

setBannerDisplay

public void setBannerDisplay(BannerDisplay bannerdisplay)
Set a banner display for callback of authentication banners

Parameters:
bannerdisplay - the banner display, may be null

supportedCiphers

public AbstractComponentFactory supportedCiphers()
Returns this context's supported cipher algorithms.

Returns:
the component factory

getPreferredCipherCS

public java.lang.String getPreferredCipherCS()
Get the currently preferred cipher for the Client->Server stream.

Returns:
the preferred Client-Server cipher

setPreferredCipherCS

public void setPreferredCipherCS(java.lang.String name)
                          throws SshException
Set the preferred cipher for the Client->Server stream.

Parameters:
name -
Throws:
SshException

getPreferredCipherSC

public java.lang.String getPreferredCipherSC()
Get the currently preferred cipher for the Server->Client stream.

Returns:
the preferred Server-Client cipher

setPreferredCipherSC

public void setPreferredCipherSC(java.lang.String name)
                          throws SshException
Set the preferred cipher for the Server->Client stream.

Parameters:
name -
Throws:
SshException

supportedMacs

public AbstractComponentFactory supportedMacs()
Get this context's supported message authentication algorithms.

Returns:
the component factory

getPreferredMacCS

public java.lang.String getPreferredMacCS()
Get the currently preferred mac for the Client->Server stream.

Returns:
the preferred Client-Server mac

setPreferredMacCS

public void setPreferredMacCS(java.lang.String name)
                       throws SshException
Set the preferred mac for the Client->Server stream.

Parameters:
name -
Throws:
SshException

getPreferredMacSC

public java.lang.String getPreferredMacSC()
Get the currently supported mac for the Server-Client stream.

Returns:
the preferred Server-Client mac

setPreferredMacSC

public void setPreferredMacSC(java.lang.String name)
                       throws SshException
Set the preferred mac for the Server->Client stream.

Parameters:
name -
Throws:
SshException

supportedCompressions

public AbstractComponentFactory supportedCompressions()
Get this context's supported compression algorithms.

Returns:
the component factory

getPreferredCompressionCS

public java.lang.String getPreferredCompressionCS()
Get the currently preferred compression for the Client->Server stream.

Returns:
the preferred Client-Server compression

setPreferredCompressionCS

public void setPreferredCompressionCS(java.lang.String name)
                               throws SshException
Set the preferred compression for the Client->Server stream.

Parameters:
name -
Throws:
SshException

getPreferredCompressionSC

public java.lang.String getPreferredCompressionSC()
Get the currently preferred compression for the Server->Client stream.

Returns:
the preferred Server->Client compression

setPreferredCompressionSC

public void setPreferredCompressionSC(java.lang.String name)
                               throws SshException
Set the preferred compression for the Server->Client stream.

Parameters:
name -
Throws:
SshException

supportedKeyExchanges

public AbstractComponentFactory supportedKeyExchanges()
Get this context's supported key exchange methods.

Returns:
the component factory

getPreferredKeyExchange

public java.lang.String getPreferredKeyExchange()
Get the currently preferred key exchange method.

Returns:
the preferred key exhcange

setPreferredKeyExchange

public void setPreferredKeyExchange(java.lang.String name)
                             throws SshException
Set the preferred key exchange method.

Parameters:
name -
Throws:
SshException

supportedPublicKeys

public AbstractComponentFactory supportedPublicKeys()
Get this context's supported public keys.

Returns:
the component factory

getPreferredPublicKey

public java.lang.String getPreferredPublicKey()
Get the currently preferred public key algorithm.

Returns:
the preferred public key

setPreferredPublicKey

public void setPreferredPublicKey(java.lang.String name)
                           throws SshException
Set the preferred public key algorithm.

Parameters:
name -
Throws:
SshException

setHostKeyVerification

public void setHostKeyVerification(HostKeyVerification verify)
Set the host key verification implementation

Specified by:
setHostKeyVerification in interface SshContext
Parameters:
verify -

getHostKeyVerification

public HostKeyVerification getHostKeyVerification()
Get the host key verification implementation

Specified by:
getHostKeyVerification in interface SshContext
Returns:

setSFTPProvider

public void setSFTPProvider(java.lang.String sftpProvider)
Description copied from interface: SshContext
Set the path to the SFTP provider. For SSH1 connections an attempt to execute this provider will be made as SSH1 does not support subsystems. For SSH2 connections an attempt will be made to execute this provider if the subsystem cannot be started.

Specified by:
setSFTPProvider in interface SshContext
Parameters:
sftpProvider -

getSFTPProvider

public java.lang.String getSFTPProvider()
Description copied from interface: SshContext
Get the path to the SFTP provider. For SSH1 connections an attempt to execute this provider will be made as SSH1 does not support subsystems. For SSH2 connections an attempt will be made to execute this provider if the subsystem cannot be started. The default is '/usr/libexec/sftp-server'

Specified by:
getSFTPProvider in interface SshContext
Returns:

setPartialMessageTimeout

public void setPartialMessageTimeout(int partialMessageTimeout)

getPartialMessageTimeout

public int getPartialMessageTimeout()


Copyright © 2003 3SP LTD. All Rights Reserved.