com.maverick.sshd
Class SshContext

java.lang.Object
  extended by com.maverick.nio.ProtocolContext
      extended by com.maverick.sshd.SshContext
All Implemented Interfaces:
Cloneable

public class SshContext
extends ProtocolContext
implements Cloneable

This class defines an SSH context for listening interfaces on the Daemon.

Author:
Lee David Painter

Field Summary
static int ANY
           
static String CIPHER_AES128_CBC
          The AES 128 bit cipher
static String CIPHER_AES192_CBC
          The AES 192 bit cipher
static String CIPHER_AES256_CBC
          The AES 128 bit cipher
static String CIPHER_BLOWFISH_CBC
          The Blowfish CBC cipher
static String CIPHER_TRIPLEDES_CBC
          The 3DES CBC cipher
static String COMPRESSION_NONE
          Compression off
static String COMPRESSION_ZLIB
          ZLIB compression
static String HMAC_MD5
          MD5 message authentication
static String HMAC_SHA1
          SHA1 message authentication
static String KEX_DIFFIE_HELLMAN_GROUP_EXCHANGE_SHA1
          Constant for the algorithm name "diffie-hellman-group-exchange-sha1".
static String KEX_DIFFIE_HELLMAN_GROUP1_SHA1
          Constant for the algorithm name "diffie-hellman-group1-sha1".
static String KEX_DIFFIE_HELLMAN_GROUP14_SHA1
          Constant for the algorithm name "diffie-hellman-group14-sha1".
static int KEYBOARD_INTERACTIVE
           
static String KEYBOARD_INTERACTIVE_AUTHENTICATION
           
static int PASSWORD
           
static String PASSWORD_AUTHENTICATION
          Identifier for password authentication
static int PUBLIC_KEY
           
static String PUBLIC_KEY_SSHDSS
          SSH2 DSA Public Key
static String PUBLIC_KEY_SSHRSA
          SSH2 RSA Public Key
static int PUBLIC_KEYandPASSWORD
           
static String PUBLICKEY_AUTHENTICATION
          Identifier for public key authentication
 
Fields inherited from class com.maverick.nio.ProtocolContext
keepAlive, receiveBufferSize, reuseAddress, sendBufferSize, tcpNoDelay
 
Constructor Summary
SshContext()
          Constructs a default context but does not set the daemon
SshContext(Daemon daemon)
          Constructs a default context
 
Method Summary
 void addGlobalRequestHandler(GlobalRequestHandler handler)
           
 void addHostKey(com.maverick.ssh.components.SshKeyPair keyPair)
           Add a host key to the configuration.
 void addRequiredAuthentication(String method)
           Set an authentication method as required.
 Object clone()
           
 ProtocolEngine createEngine()
           
static com.maverick.ssh.components.SshKeyPair GenerateKeyFiles(File keyFilename, String type, int bitlength, int privateKeyFormat, int publicKeyFormat)
          Generate a public and private key pair, save them to keyFilename and keyFilename.pub, return the key pair
 AccessManager getAccessManager()
          Get the current AccessManager for this configuration.
 boolean getAllowDeniedKEX()
           
 AuthenticationProvider getAuthenticationProvider()
          Get the AuthenticationProvider for this SSHD instance.
 String getBannerMessage()
          Get the authentication banner to display to connecting clients.
 int getChannelLimit()
          Get the maximum number of open channels allowed by each client.
 String getCiphersCS()
           
 String getCiphersSC()
          Get the ciphers for the Server->Client stream.
 int getCompressionLevel()
          Get the current compression level
 String getDefaultTerminal()
           Get the default terminal to execute when the user requests to start a shell.
 FileSystemFactory getFileSystemProvider()
          Get the FileSystem for this SSHD instance.
 ForwardingCallback getForwardingCallback()
          Get the forwarding callback implementation for this server context.
 GlobalRequestHandler getGlobalRequestHandler(String requestname)
           
 com.maverick.ssh.components.SshKeyPair getHostKey(String algorithm)
          Get the SSHD host key for a given algorithm.
 com.maverick.ssh.components.SshKeyPair[] getHostKeys()
          Get all the hosts keys.
 int getIdleConnectionTimeoutSeconds()
          The number of seconds before an idle connection is dropped.
 int getKeepAliveDataMaxLength()
          Get the maximum data length for the keep-alive packet.
 int getKeepAliveInterval()
          Get the current keep-alive interval (in seconds).
 Configuration getKerberosConfiguration()
          Get the custom Kerberos configuration.
 String getKerberosDC()
          Get the Kerberos domain controller address .
 String getKerberosRealm()
          Get the realm name to use for GSSAPI Kerberos authentication.
 char[] getKerberosServicePassword()
          Get the Kerberos service account password.
 String getKerberosServicePrincipal()
          Get the Kerberos service account password.
 KeyboardInteractiveProviderFactory getKeyboardInteractiveProviderFactory()
          Get the current provider for keyboard-interactive authentication
 int getKeyExchangePacketLimit()
          Get the number of packets to send before a key exchange is forced
 String getKeyExchanges()
          Get the ciphers for the Server->Client stream.
 int getKeyExchangeTransferLimit()
          Get the number of bytes to transfer before a key exchange is forced.
 String getMacsCS()
          Get the ciphers for the Client->Server stream.
 String getMacsSC()
          Get the ciphers for the Server->Client stream.
 int getMaxAuthentications()
          Get the maximum number of failed authentications allowed for each connection.
 int getMaximumConnections()
          Get the maximum number of connections allowed at any one time.
 int getMaximumPacketLength()
          Get the maximum supported length of an SSH packet.
 int getMaximumPublicKeyVerificationAttempts()
          Get the number of public keys that each user can attempt to verify for public key authentication.
 int getMaximumSocketsBacklogPerRemotelyForwardedConnection()
           
 String getPreferredCipherCS()
          Get the currently preferred cipher for the Client->Server stream.
 String getPreferredCipherSC()
          Get the currently preferred cipher for the Server->Client stream.
 String getPreferredCompressionCS()
          Get the currently preferred compression for the Client->Server stream.
 String getPreferredCompressionSC()
          Get the currently preferred compression for the Server->Client stream.
 String getPreferredKeyExchange()
          Get the currently preferred key exchange method.
 String getPreferredMacCS()
          Get the currently preferred mac for the Client->Server stream.
 String getPreferredMacSC()
          Get the currently supported mac for the Server-Client stream.
 String getPreferredPublicKey()
          Get the currently preferred public key algorithm.
 String getPublicKeys()
          Get the ciphers for the Server->Client stream.
 PublicKeyStore getPublicKeyStore()
          Get the currently configured public key store for authorizing public keys
 boolean getRemoteForwardingCancelKillsTunnels()
          Determines whether the cancellation of a remote forwarding drops currently active tunnels
 Class getRemoteForwardingFactoryImpl()
           
 Class getRemoteForwardingManagerImpl()
           
 String[] getRequiredAuthentications()
          Lists the required authentication methods.
 Daemon getServer()
          Get the instance of the SSHD for this context.
 int getSessionTimeout()
          Returns the session timeout in seconds
 String getSFTPCharsetEncoding()
          Get the current encoding value for filenames in SFTP sessions.
 String getSoftwareVersionComments()
          Get the software/version/comments field that is to be used in the SSH protocols negotiation procedure.
 String getSupportedPublicKeys()
          Returns a comma delimited string containing installed public key types.
 String getTooManyConnectionsText()
           
 boolean hasPublicKey(String algorithm)
          Determine if the server has a host key configured.
 void init(Daemon daemon)
          Initialise the SshContext by setting the daemon
 boolean isFileSystemAsynchronous()
          Get the file system operation mode; asynchronous (spawn a thread for each SFTP session so that file operations are not performed on the selector thread) or synchronous (use the selector thread - may affect performance on slow file systems (e.g.
 com.maverick.ssh.components.SshKeyPair loadKey(File key, String passPhrase)
           
 void loadKeystore(File keystoreFile, String alias, String storePassphrase, String keyPassphrase)
          Load a keystore for use as an SSH host key.
 void loadOrGenerateHostKey(File key, String type, int bitlength)
          Load a host key from file, if the file does not exist then generate the key.
 void loadOrGenerateHostKey(File key, String type, int bitlength, int privateKeyFormat, int publicKeyFormat, String passPhrase)
          Load a host key from file, if the file does not exist then generate the key.
 void loadOrGenerateHostKey(File key, String type, int bitlength, String passPhrase)
           
 void setAccessManager(AccessManager accessManager)
          If you want to control access to individual SSH features then add an instance of the AccessManager here.
 void setAllowDeniedKEX(boolean allowKeyExchangeForDeniedConnection)
           
 void setAsynchronousFileOperations(boolean asynchronousFileOperations)
          Tell the server which file system operation mode to use; asynchronous (spawn a thread for each SFTP session so that file operations are not performed on the selector thread) or synchronous (use the selector thread - may affect performance on slow file systems (e.g networked))
 void setAuthenticationProvider(AuthenticationProvider authenticationProvider)
           Set the AuthenticationProvider for this SSHD instance.
 void setBannerMessage(String authenticationBanner)
          Set the banner message that is displayed to all connecing clients prior to authentication.
 void setChannelLimit(int maxChannels)
          Set the maximum number of open channels allowed by each client (defaults to 100).
 void setCipherPreferredPositionCS(String name, int position)
           
 void setCipherPreferredPositionSC(String name, int position)
           
 void setCompressionLevel(int compressionLevel)
          Set the compression level to use if compression is enabled
 void setDefaultTerminal(String defaultTerminal)
           Set the default terminal to execute when the user requests to start a shell.
 void setFileSystemFactory(FileSystemFactory filesystemFactory)
           Set the FileSystem for this SSHD instance.
 void setForwardingCallback(ForwardingCallback forwardingCallback)
          Set the forwarding callback implementation for this server context.
 void setIdleConnectionTimeoutSeconds(int idleConnectionTimeout)
          Set the number of seconds before an idle connection is dropped.
 void setKeepAliveDataMaxLength(int keepAliveDataMaxLength)
          Set the maximum data length for the keep-alive packet.
 void setKeepAliveInterval(int keepAliveInterval)
          Set the keep-alive interval (in seconds).
 void setKerberosConfiguration(Configuration kerberosConfiguration)
          Set the custom Kerberos configuration.
 void setKerberosDC(String kerberosDC)
          Set the Kerberos domain controller address .
 void setKerberosRealm(String kerberosRealm)
          Set the realm name to use for GSSAPI Kerberos authentication.
 void setKerberosServicePassword(char[] kerberosServicePassword)
          Set the Kerberos service account password.
 void setKerberosServicePrincipal(String kerberosServicePrincipal)
          Set the Kerberos service account princial.
 void setKeyboardInteractiveProvider(KeyboardInteractiveProviderFactory kbiFactory)
          Set the provider for keyboard-interactive authentication.
 void setKeyExchangePacketLimit(int MAX_NUM_PACKETS_BEFORE_REKEY)
          This tells the server how many packets to use before a key exchange.
 void setKeyExchangePreferredPosition(String name, int position)
           
 void setKeyExchangeTransferLimit(int MAX_NUM_BYTES_BEFORE_REKEY)
          This limit tells the server when to force a key exchange.
 void setMacPreferredPositionCS(String name, int position)
           
 void setMacPreferredPositionSC(String name, int position)
           
 void setMaxAuthentications(int maxAuthentications)
          Set the maximum number of failed authentications allowed for each connection.
 void setMaximumConnections(int maximumConnections)
          Set the maximum number of connections allowed at any one time.
 void setMaximumPacketLength(int maximumPacketLength)
          Set the maximum supported length of an SSH packet.
 void setMaximumPublicKeyVerificationAttempts(int maximumPublicKeyVerificationAttempts)
          Set the number of public keys that a user can verify for public key authentication.
 void setMaximumSocketsBacklogPerRemotelyForwardedConnection(int maximumSocketsBacklogPerRemotelyForwardedConnection)
           
 void setPreferredCipherCS(int[] order)
          Set the preferred SC cipher order
 void setPreferredCipherCS(String name)
           Set the preferred cipher for the Client->Server stream.
 void setPreferredCipherSC(int[] order)
          Set the preferred SC cipher order
 void setPreferredCipherSC(String name)
           Set the preferred cipher for the Server->Client stream.
 void setPreferredCompressionCS(String name)
           Set the preferred compression for the Client->Server stream.
 void setPreferredCompressionSC(String name)
           Set the preferred compression for the Server->Client stream.
 void setPreferredKeyExchange(String name)
           Set the preferred key exchange method.
 void setPreferredMacCS(int[] order)
          Set the preferred CS Mac order
 void setPreferredMacCS(String name)
           Set the preferred MAC for the Client->Server stream.
 void setPreferredMacSC(int[] order)
          Set the preferred SC Mac order
 void setPreferredMacSC(String name)
           Set the preferred mac for the Server->Client stream.
 void setPreferredPublicKey(String name)
           Set the preferred public key algorithm.
 void setPublicKeyPreferredPosition(String name, int position)
           
 void setPublicKeyStore(PublicKeyStore publicKeyStore)
          For publickey authentication you can optionally provide an alternative key store implementation.
 void setRemoteForwardingCancelKillsTunnels(boolean killTunnelsOnRemoteForwardingCancel)
          When the user cancels a remote forwarding should active tunnels be dropped?
 void setRemoteForwardingFactoryImpl(Class remoteForwardingChannelFactory)
           
 void setRemoteForwardingManagerImpl(Class remoteForwardingManagerImpl)
           
 void setRequiredAuthenticationMethods(int authmethods)
           
 void setSessionTimeout(int sessionTimeoutSeconds)
          Sets the session timeout in seconds
 void setSFTPCharsetEncoding(String sftpCharsetEncoding)
          Set the default encoding for filenames in SFTP sessions.
 void setSoftwareVersionComments(String softwareVersionComments)
          Set the current implementations software/version/comments field that is used during the SSH protocols negotiation procedure.
 void setTooManyConnectionsText(String tooManyConnectionsText)
           
 com.maverick.ssh.components.ComponentFactory supportedAuthenticationMechanisms()
           Get the supported authentication mechanisms.
 com.maverick.ssh.components.ComponentFactory supportedChannels()
           Get the supported Channel's for this SSHD instance.
 com.maverick.ssh.components.ComponentFactory supportedCiphersCS()
           Returns a factory implementation that enables configuration of the available ciphers.
 com.maverick.ssh.components.ComponentFactory supportedCiphersSC()
           
 com.maverick.ssh.components.ComponentFactory supportedCommands()
          Get the supported ExecutableCommand's for this context.
 com.maverick.ssh.components.ComponentFactory supportedCompressionsCS()
           Get the supported compression algorithms.
 com.maverick.ssh.components.ComponentFactory supportedCompressionsSC()
           
 com.maverick.ssh.components.ComponentFactory supportedKeyExchanges()
           Get the supported key exchange methods.
 com.maverick.ssh.components.ComponentFactory supportedMacsCS()
           Get the supported message authentication algorithms.
 com.maverick.ssh.components.ComponentFactory supportedMacsSC()
           
 com.maverick.ssh.components.ComponentFactory supportedPublicKeys()
           
 com.maverick.ssh.components.ComponentFactory supportedSubsystems()
           Get the supported Subsystem's for this SSHD instance.
 
Methods inherited from class com.maverick.nio.ProtocolContext
createConnection, createConnectionImpl, getReceiveBufferSize, getSendBufferSize, getSocketOptionKeepAlive, getSocketOptionReuseAddress, getSocketOptionTcpNoDelay, setReceiveBufferSize, setSendBufferSize, setSocketHandlerImpl, setSocketOptionKeepAlive, setSocketOptionReuseAddress, setSocketOptionTcpNoDelay
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CIPHER_TRIPLEDES_CBC

public static final String CIPHER_TRIPLEDES_CBC
The 3DES CBC cipher

See Also:
Constant Field Values

CIPHER_BLOWFISH_CBC

public static final String CIPHER_BLOWFISH_CBC
The Blowfish CBC cipher

See Also:
Constant Field Values

CIPHER_AES128_CBC

public static final String CIPHER_AES128_CBC
The AES 128 bit cipher

See Also:
Constant Field Values

CIPHER_AES192_CBC

public static final String CIPHER_AES192_CBC
The AES 192 bit cipher

See Also:
Constant Field Values

CIPHER_AES256_CBC

public static final String CIPHER_AES256_CBC
The AES 128 bit cipher

See Also:
Constant Field Values

HMAC_SHA1

public static final String HMAC_SHA1
SHA1 message authentication

See Also:
Constant Field Values

HMAC_MD5

public static final String HMAC_MD5
MD5 message authentication

See Also:
Constant Field Values

COMPRESSION_NONE

public static final String COMPRESSION_NONE
Compression off

See Also:
Constant Field Values

COMPRESSION_ZLIB

public static final String COMPRESSION_ZLIB
ZLIB compression

See Also:
Constant Field Values

KEX_DIFFIE_HELLMAN_GROUP1_SHA1

public static final String KEX_DIFFIE_HELLMAN_GROUP1_SHA1
Constant for the algorithm name "diffie-hellman-group1-sha1".

See Also:
Constant Field Values

KEX_DIFFIE_HELLMAN_GROUP_EXCHANGE_SHA1

public static final String KEX_DIFFIE_HELLMAN_GROUP_EXCHANGE_SHA1
Constant for the algorithm name "diffie-hellman-group-exchange-sha1".

See Also:
Constant Field Values

KEX_DIFFIE_HELLMAN_GROUP14_SHA1

public static final String KEX_DIFFIE_HELLMAN_GROUP14_SHA1
Constant for the algorithm name "diffie-hellman-group14-sha1".

See Also:
Constant Field Values

PUBLIC_KEY_SSHDSS

public static final String PUBLIC_KEY_SSHDSS
SSH2 DSA Public Key

See Also:
Constant Field Values

PUBLIC_KEY_SSHRSA

public static final String PUBLIC_KEY_SSHRSA
SSH2 RSA Public Key

See Also:
Constant Field Values

PASSWORD_AUTHENTICATION

public static final String PASSWORD_AUTHENTICATION
Identifier for password authentication

See Also:
Constant Field Values

PUBLICKEY_AUTHENTICATION

public static final String PUBLICKEY_AUTHENTICATION
Identifier for public key authentication

See Also:
Constant Field Values

KEYBOARD_INTERACTIVE_AUTHENTICATION

public static final String KEYBOARD_INTERACTIVE_AUTHENTICATION
See Also:
Constant Field Values

ANY

public static final int ANY
See Also:
Constant Field Values

PUBLIC_KEY

public static final int PUBLIC_KEY
See Also:
Constant Field Values

PASSWORD

public static final int PASSWORD
See Also:
Constant Field Values

PUBLIC_KEYandPASSWORD

public static final int PUBLIC_KEYandPASSWORD
See Also:
Constant Field Values

KEYBOARD_INTERACTIVE

public static final int KEYBOARD_INTERACTIVE
See Also:
Constant Field Values
Constructor Detail

SshContext

public SshContext()
           throws IOException
Constructs a default context but does not set the daemon

Throws:
IOException

SshContext

public SshContext(Daemon daemon)
           throws IOException
Constructs a default context

Throws:
IOException
Method Detail

getKerberosRealm

public String getKerberosRealm()
Get the realm name to use for GSSAPI Kerberos authentication. The realm should be in UPPER case, for example EXAMPLE.COM. This is not used if a custom Configuration has been set using setKerberosConfiguration(Configuration).

Returns:
kerberos realm

setKerberosRealm

public void setKerberosRealm(String kerberosRealm)
Set the realm name to use for GSSAPI Kerberos authentication. The realm should be in UPPER case, for example EXAMPLE.COM.

Parameters:
kerberosRealm - kerberos realm

getKerberosDC

public String getKerberosDC()
Get the Kerberos domain controller address . This may be a hostname or IP address.

Returns:
kerberos domain controller

setKerberosDC

public void setKerberosDC(String kerberosDC)
Set the Kerberos domain controller address . This may be a hostname or IP address.

Parameters:
kerberosDC - kerberos domain controller

getKerberosServicePassword

public char[] getKerberosServicePassword()
Get the Kerberos service account password. By default, this will only be needed if the service does not already have a valid ticket in the keytab.

Returns:
kerberos service password

setKerberosServicePassword

public void setKerberosServicePassword(char[] kerberosServicePassword)
Set the Kerberos service account password. By default, this will only be needed if the service does not already have a valid ticket in the keytab.

Parameters:
kerberosServicePassword - param kerberos service account password

getKerberosServicePrincipal

public String getKerberosServicePrincipal()
Get the Kerberos service account password. By default, this will only be needed if the service does not already have a valid ticket in the keytab. This is not used if a custom Configuration has been set using setKerberosConfiguration(Configuration).

Returns:

setKerberosServicePrincipal

public void setKerberosServicePrincipal(String kerberosServicePrincipal)
Set the Kerberos service account princial. By default, this will only be needed if the service does not already have a valid ticket in the keytab or if there is more than one. This is not used if a custom Configuration has been set using setKerberosConfiguration(Configuration).

Parameters:
kerberosServicePrincipal - kerberos service account principal

getKerberosConfiguration

public Configuration getKerberosConfiguration()
Get the custom Kerberos configuration. By default this will return null.

Returns:
kerberos configuration

setKerberosConfiguration

public void setKerberosConfiguration(Configuration kerberosConfiguration)
Set the custom Kerberos configuration. By default this will return null.

Parameters:
kerberosConfiguration - kerberos configuration

init

public void init(Daemon daemon)
Initialise the SshContext by setting the daemon


createEngine

public ProtocolEngine createEngine()
                            throws IOException
Specified by:
createEngine in class ProtocolContext
Throws:
IOException

loadOrGenerateHostKey

public void loadOrGenerateHostKey(File key,
                                  String type,
                                  int bitlength)
                           throws IOException,
                                  com.sshtools.publickey.InvalidPassphraseException,
                                  com.maverick.ssh.SshException
Load a host key from file, if the file does not exist then generate the key.

Parameters:
key - the key file
type - the type of key; acceptable values are SshKeyPairGenerator.SSH2_RSA or SshKeyPairGenerator.SSH2_DSA
bitlength - the bit length of the key
Throws:
IOException
com.maverick.ssh.SshException
com.sshtools.publickey.InvalidPassphraseException

loadOrGenerateHostKey

public void loadOrGenerateHostKey(File key,
                                  String type,
                                  int bitlength,
                                  String passPhrase)
                           throws IOException,
                                  com.sshtools.publickey.InvalidPassphraseException,
                                  com.maverick.ssh.SshException
Throws:
IOException
com.sshtools.publickey.InvalidPassphraseException
com.maverick.ssh.SshException

loadOrGenerateHostKey

public void loadOrGenerateHostKey(File key,
                                  String type,
                                  int bitlength,
                                  int privateKeyFormat,
                                  int publicKeyFormat,
                                  String passPhrase)
                           throws IOException,
                                  com.sshtools.publickey.InvalidPassphraseException,
                                  com.maverick.ssh.SshException
Load a host key from file, if the file does not exist then generate the key.

Parameters:
key - the key file
type - the type of key; acceptable values are SshKeyPairGenerator.SSH2_RSA or SshKeyPairGenerator.SSH2_DSA
bitlength - the bit length of the key
privateKeyFormat - the format of the private key, SshPrivateKeyFileFactory
publicKeyFormat - the format of the public key, {see com.sshtools.publickey.SshPublicKeyFileFactory}
passPhrase - the passPhrase of an existing host key
Throws:
IOException
com.maverick.ssh.SshException
com.sshtools.publickey.InvalidPassphraseException

loadKey

public com.maverick.ssh.components.SshKeyPair loadKey(File key,
                                                      String passPhrase)
                                               throws IOException,
                                                      com.sshtools.publickey.InvalidPassphraseException
Throws:
IOException
com.sshtools.publickey.InvalidPassphraseException

GenerateKeyFiles

public static com.maverick.ssh.components.SshKeyPair GenerateKeyFiles(File keyFilename,
                                                                      String type,
                                                                      int bitlength,
                                                                      int privateKeyFormat,
                                                                      int publicKeyFormat)
                                                               throws IOException,
                                                                      com.maverick.ssh.SshException
Generate a public and private key pair, save them to keyFilename and keyFilename.pub, return the key pair

Parameters:
keyFilename -
type -
bitlength -
privateKeyFormat -
publicKeyFormat -
Returns:
SshKeyPair generated.
Throws:
IOException
com.maverick.ssh.SshException

loadKeystore

public void loadKeystore(File keystoreFile,
                         String alias,
                         String storePassphrase,
                         String keyPassphrase)
                  throws IOException
Load a keystore for use as an SSH host key. This will create a public key using the X509V3_SIGN_RSA and X509V3_SIGN_RSA_SHA1 host key types. DSA keys are currently not supported.

Parameters:
keystoreFile - path to the keystore file
alias - the alias of the key in the keystore
storePassphrase - the passphrase of the keystore
keyPassphrase - the passphrase of the key
Throws:
IOException

addGlobalRequestHandler

public void addGlobalRequestHandler(GlobalRequestHandler handler)

getGlobalRequestHandler

public GlobalRequestHandler getGlobalRequestHandler(String requestname)

getRemoteForwardingFactoryImpl

public Class getRemoteForwardingFactoryImpl()

getRemoteForwardingManagerImpl

public Class getRemoteForwardingManagerImpl()

setRemoteForwardingFactoryImpl

public void setRemoteForwardingFactoryImpl(Class remoteForwardingChannelFactory)
                                    throws IOException
Throws:
IOException

setRemoteForwardingManagerImpl

public void setRemoteForwardingManagerImpl(Class remoteForwardingManagerImpl)
                                    throws IOException
Throws:
IOException

setPublicKeyStore

public void setPublicKeyStore(PublicKeyStore publicKeyStore)
For publickey authentication you can optionally provide an alternative key store implementation. This allows you to change the default behaviour of reading keys from the users .ssh/authorized_keys file.

Parameters:
publicKeyStore - PublicKeyStore

getPublicKeyStore

public PublicKeyStore getPublicKeyStore()
Get the currently configured public key store for authorizing public keys

Returns:
PublicKeyStore

getRequiredAuthentications

public String[] getRequiredAuthentications()
Lists the required authentication methods.

Returns:
String[]

addRequiredAuthentication

public void addRequiredAuthentication(String method)

Set an authentication method as required. You can have multiple required authentications but by default none are required, although at least one authentication MUST be performed. For example to require both password and publickey authentication use the following statements in the SshDaemon#configure(ConfigurationContext) method.

 context.addRequiredAuthentication(ConfigurationContext.PUBLICKEY_AUTHENTICATION);
 context.addRequiredAuthentication(ConfigurationContext.PASSWORD_AUTHENTICATION);
 

Parameters:
method - String

getBannerMessage

public String getBannerMessage()
Get the authentication banner to display to connecting clients.

Returns:
String

getServer

public Daemon getServer()
Get the instance of the SSHD for this context.

Returns:
Daemon

getSFTPCharsetEncoding

public String getSFTPCharsetEncoding()
Get the current encoding value for filenames in SFTP sessions.

Returns:
String

setSFTPCharsetEncoding

public void setSFTPCharsetEncoding(String sftpCharsetEncoding)
Set the default encoding for filenames in SFTP sessions. The default encoding for the currently supported SFTP protocol is ISO-8859-1.

Parameters:
sftpCharsetEncoding - String

getSessionTimeout

public int getSessionTimeout()
Returns the session timeout in seconds

Returns:
int

setSessionTimeout

public void setSessionTimeout(int sessionTimeoutSeconds)
Sets the session timeout in seconds

Parameters:
sessionTimeoutSeconds - int

setChannelLimit

public void setChannelLimit(int maxChannels)
Set the maximum number of open channels allowed by each client (defaults to 100).

Parameters:
maxChannels -

getChannelLimit

public int getChannelLimit()
Get the maximum number of open channels allowed by each client.

Returns:
int

getMaxAuthentications

public int getMaxAuthentications()
Get the maximum number of failed authentications allowed for each connection.

Returns:
int

setMaxAuthentications

public void setMaxAuthentications(int maxAuthentications)
Set the maximum number of failed authentications allowed for each connection.

Parameters:
maxAuthentications -

setMaximumConnections

public void setMaximumConnections(int maximumConnections)
Set the maximum number of connections allowed at any one time.

Parameters:
maximumConnections - int

getMaximumConnections

public int getMaximumConnections()
Get the maximum number of connections allowed at any one time.

Returns:
int

supportedCiphersCS

public com.maverick.ssh.components.ComponentFactory supportedCiphersCS()

Returns a factory implementation that enables configuration of the available ciphers.

The standard default ciphers installed are 3DES and Blowfish, however the J2SSH Maverick API on which this server is based also supports a number of optional ciphers AES, CAST and Twofish. These can be installed by adding the sshtools-cipher.jar to your class path and using the following code within your SSHD SshDaemon#configure(ConfigurationContext) method.

 // import the cipher package
 import com.sshtools.cipher.*;
 
 // Add AES
 context.supportedCiphers().add(AES128Cbc.AES128_CBC, AES128Cbc.class);
 context.supportedCiphers().add(AES192Cbc.AES192_CBC, AES192Cbc.class);
 context.supportedCiphers().add(AES256Cbc.AES256_CBC, AES256Cbc.class);
 
 // Add Twofish - note the 256 bit cipher has two different entries to maintain backwards compatibility
 context.supportedCiphers().add(Twofish128Cbc.TWOFISH128_CBC, Twofish128Cbc.class);
 context.supportedCiphers().add(Twofish192Cbc.TWOFISH192_CBC, Twofish192Cbc.class);
 context.supportedCiphers().add(Twofish256Cbc.TWOFISH256_CBC, Twofish256Cbc.class);
 context.supportedCiphers().add(Twofish256Cbc.TWOFISH_CBC, Twofish256Cbc.class);
 
 // Add CAST
  context.supportedCiphers().add(CAST128Cbc.CAST128_CBC, CAST128Cbc.class);
 

Returns:
the component factory

supportedCiphersSC

public com.maverick.ssh.components.ComponentFactory supportedCiphersSC()

setAsynchronousFileOperations

public void setAsynchronousFileOperations(boolean asynchronousFileOperations)
Tell the server which file system operation mode to use; asynchronous (spawn a thread for each SFTP session so that file operations are not performed on the selector thread) or synchronous (use the selector thread - may affect performance on slow file systems (e.g networked))

Parameters:
asynchronousFileOperations -

isFileSystemAsynchronous

public boolean isFileSystemAsynchronous()
Get the file system operation mode; asynchronous (spawn a thread for each SFTP session so that file operations are not performed on the selector thread) or synchronous (use the selector thread - may affect performance on slow file systems (e.g. networked))

Returns:
boolean

getPreferredCipherCS

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

Returns:
the preferred Client-Server cipher

setPreferredCipherCS

public void setPreferredCipherCS(String name)
                          throws IOException,
                                 com.maverick.ssh.SshException

Set the preferred cipher for the Client->Server stream.

Use the static fields available within this class (or the com.sshtools.cipher classes) to identify the correct cipher.

context.setPreferredCipherCS(ConfigurationContext.CIPHER_BLOWFISH_CBC);

The default cipher is AES 128 bit

Parameters:
name -
Throws:
IOException - if the cipher is not supported
com.maverick.ssh.SshException

setAccessManager

public void setAccessManager(AccessManager accessManager)
If you want to control access to individual SSH features then add an instance of the AccessManager here. The AccessManager is consulted before a user is allowed to connect, start a shell, execute a command or start a port forwarding connection.

Parameters:
accessManager -

getAccessManager

public AccessManager getAccessManager()
Get the current AccessManager for this configuration.

Returns:
AccessManager

setBannerMessage

public void setBannerMessage(String authenticationBanner)
Set the banner message that is displayed to all connecing clients prior to authentication. If this method is used then com.maverick.sshd.NoneAuthentication.getBannerForUser(String) should not be overridden.

Parameters:
authenticationBanner -

getPreferredCipherSC

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

Returns:
the preferred Server-Client cipher

getSoftwareVersionComments

public String getSoftwareVersionComments()
Get the software/version/comments field that is to be used in the SSH protocols negotiation procedure.

Returns:
String

setSoftwareVersionComments

public void setSoftwareVersionComments(String softwareVersionComments)
Set the current implementations software/version/comments field that is used during the SSH protocols negotiation procedure. This value MUST consist of printable US-ASCII characters with the exception of whitespace and the minus sign (-) and be no longer than 200 characters.

Parameters:
softwareVersionComments -

setPreferredCipherSC

public void setPreferredCipherSC(String name)
                          throws IOException,
                                 com.maverick.ssh.SshException

Set the preferred cipher for the Server->Client stream.

Use the static fields available within this class (or the com.sshtools.cipher classes) to identify the correct cipher.

context.setPreferredCipherSC(ConfigurationContext.CIPHER_BLOWFISH_CBC);

The default cipher is AES 128 bit

Parameters:
name -
Throws:
IOException
com.maverick.ssh.SshException

supportedMacsCS

public com.maverick.ssh.components.ComponentFactory supportedMacsCS()

Get the supported message authentication algorithms.

There are no optional MAC algorithms currently available and this method is supplied in preperation for future enhancements.

Returns:
the component factory

supportedMacsSC

public com.maverick.ssh.components.ComponentFactory supportedMacsSC()

getPreferredMacCS

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

Returns:
the preferred Client-Server mac

setPreferredMacCS

public void setPreferredMacCS(String name)
                       throws IOException,
                              com.maverick.ssh.SshException

Set the preferred MAC for the Client->Server stream.

Use the static fields available within this class to identify the correct MAC.

context.setPreferredMacCS(ConfigurationContext.HMAC_MD5);

The default MAC is HMAC_SHA1

Parameters:
name -
Throws:
IOException
com.maverick.ssh.SshException

getPreferredMacSC

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

Returns:
the preferred Server-Client mac

setRemoteForwardingCancelKillsTunnels

public void setRemoteForwardingCancelKillsTunnels(boolean killTunnelsOnRemoteForwardingCancel)
When the user cancels a remote forwarding should active tunnels be dropped?

Parameters:
killTunnelsOnRemoteForwardingCancel - boolean

getRemoteForwardingCancelKillsTunnels

public boolean getRemoteForwardingCancelKillsTunnels()
Determines whether the cancellation of a remote forwarding drops currently active tunnels

Returns:
boolean

getMaximumPublicKeyVerificationAttempts

public int getMaximumPublicKeyVerificationAttempts()
Get the number of public keys that each user can attempt to verify for public key authentication. If the user exceeds this limit the connection is terminated.

Returns:
int

setMaximumPublicKeyVerificationAttempts

public void setMaximumPublicKeyVerificationAttempts(int maximumPublicKeyVerificationAttempts)
Set the number of public keys that a user can verify for public key authentication. If the user exceeds this limit the connection is terminated.

Parameters:
maximumPublicKeyVerificationAttempts - int

setPreferredMacSC

public void setPreferredMacSC(String name)
                       throws IOException,
                              com.maverick.ssh.SshException

Set the preferred mac for the Server->Client stream.

Use the static fields available within this class to identify the correct MAC.

context.setPreferredMacCS(ConfigurationContext.HMAC_MD5);

The default MAC is HMAC_SHA1

Parameters:
name -
Throws:
IOException
com.maverick.ssh.SshException

supportedCompressionsCS

public com.maverick.ssh.components.ComponentFactory supportedCompressionsCS()

Get the supported compression algorithms.

There are no optional compression algorithms currently available and this method is supplied in preperation for future enhancements.

Returns:
the component factory

supportedCompressionsSC

public com.maverick.ssh.components.ComponentFactory supportedCompressionsSC()

getPreferredCompressionCS

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

Returns:
the preferred Client-Server compression

setPreferredCompressionCS

public void setPreferredCompressionCS(String name)
                               throws IOException

Set the preferred compression for the Client->Server stream.

It is recommended that you do not set the preferred compression so that the client has control over the compression selection.

Parameters:
name -
Throws:
IOException

getPreferredCompressionSC

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

Returns:
the preferred Server->Client compression

setPreferredCompressionSC

public void setPreferredCompressionSC(String name)
                               throws IOException

Set the preferred compression for the Server->Client stream.

It is recommended that you do not set the preferred compression so that the client has control over the compression selection.

Parameters:
name -
Throws:
IOException

supportedKeyExchanges

public com.maverick.ssh.components.ComponentFactory supportedKeyExchanges()

Get the supported key exchange methods.

There are no optional key exchange algorithms currently available and this method is supplied in preperation for future enhancements.

Returns:
the component factory

getPreferredKeyExchange

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

Returns:
the preferred key exhcange

setPreferredKeyExchange

public void setPreferredKeyExchange(String name)
                             throws IOException,
                                    com.maverick.ssh.SshException

Set the preferred key exchange method.

There is only one supported key exchange algorithm and as such this method is supplied in preperation for future enhancements.

Parameters:
name -
Throws:
IOException
com.maverick.ssh.SshException

getPreferredPublicKey

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

Returns:
the preferred public key

getSupportedPublicKeys

public String getSupportedPublicKeys()
Returns a comma delimited string containing installed public key types.

Returns:
String

setPreferredPublicKey

public void setPreferredPublicKey(String name)
                           throws IOException,
                                  com.maverick.ssh.SshException

Set the preferred public key algorithm.

This value must be one of the installed public key algorithm names. You will be able to obtain these from the public keys that you installed using ?????? and an example of how to do this is provided in the ConfigurationContext#addHostKey(SshKeyPair) method description.

Parameters:
name -
Throws:
IOException
com.maverick.ssh.SshException

getHostKeys

public com.maverick.ssh.components.SshKeyPair[] getHostKeys()
Get all the hosts keys.

Returns:
SshPublicKey[]

getHostKey

public com.maverick.ssh.components.SshKeyPair getHostKey(String algorithm)
                                                  throws IOException
Get the SSHD host key for a given algorithm.

Parameters:
algorithm -
Returns:
SshKeyPair
Throws:
IOException

addHostKey

public void addHostKey(com.maverick.ssh.components.SshKeyPair keyPair)
                throws IOException

Add a host key to the configuration.

A host key provides a mechanism for a client to authenticate the server. If the client knows the public key of the server it can validate the signature that the server generated using its private key with the known public key of the server. In order for your server to operate you need to generate and install at least one host key.

It is now recommended to use the SshDaemon#loadOrGenerateHostKey(File, String, int, ConfigurationContext) method for generating and loading a host key.

Parameters:
keyPair -
Throws:
IOException

hasPublicKey

public boolean hasPublicKey(String algorithm)
Determine if the server has a host key configured.

Parameters:
algorithm -
Returns:
boolean

supportedAuthenticationMechanisms

public com.maverick.ssh.components.ComponentFactory supportedAuthenticationMechanisms()

Get the supported authentication mechanisms.

If you have implemented your own AuthenticationMechanism you can add it to the factory object returned by this method.

 context.supportedAuthenticationMechanisms().add("secureID", SecureIDAuthentication.class);
 

Returns:
AbstractComponentFactory

setAuthenticationProvider

public void setAuthenticationProvider(AuthenticationProvider authenticationProvider)

Set the AuthenticationProvider for this SSHD instance.

Parameters:
authenticationProvider -

getAuthenticationProvider

public AuthenticationProvider getAuthenticationProvider()
Get the AuthenticationProvider for this SSHD instance.

Returns:
AuthenticationProvider

setFileSystemFactory

public void setFileSystemFactory(FileSystemFactory filesystemFactory)

Set the FileSystem for this SSHD instance.

This uses a class object rather so that the server can manage the creation of instances of this class.

Parameters:
filesystemProvider -

getFileSystemProvider

public FileSystemFactory getFileSystemProvider()
Get the FileSystem for this SSHD instance.

Returns:
Class

getDefaultTerminal

public String getDefaultTerminal()

Get the default terminal to execute when the user requests to start a shell.

This setting is not used explicitly by the server but is available from the context so that a session implementation can obtain it through the protected ConnectionProtocol instance.

Returns:
String

setDefaultTerminal

public void setDefaultTerminal(String defaultTerminal)

Set the default terminal to execute when the user requests to start a shell.

This setting is not used explicitly by the server but is available from the context so that a session implementation can obtain it through the protected ConnectionProtocol instance.

Parameters:
defaultTerminal -

supportedChannels

public com.maverick.ssh.components.ComponentFactory supportedChannels()

Get the supported Channel's for this SSHD instance.

If you have implemented a custom channel you can use the factory object returned by this method to install the channel.

 context.supportedChannels().add("mychannel", MyChannel.class);
 

Returns:
AbstractComponentFactory

supportedCommands

public com.maverick.ssh.components.ComponentFactory supportedCommands()
Get the supported ExecutableCommand's for this context.

Returns:

supportedSubsystems

public com.maverick.ssh.components.ComponentFactory supportedSubsystems()

Get the supported Subsystem's for this SSHD instance.

If you have implemented a custom subsystem you can use the factory object returned by this method to install the new subsystem.

 context.supportedSubsystems().add("mysubsystem", MySubsystem.class);
 

Returns:
AbstractComponentFactory

setCompressionLevel

public void setCompressionLevel(int compressionLevel)
Set the compression level to use if compression is enabled

Parameters:
compressionLevel - int

getCompressionLevel

public int getCompressionLevel()
Get the current compression level

Returns:
int

setAllowDeniedKEX

public void setAllowDeniedKEX(boolean allowKeyExchangeForDeniedConnection)

setRequiredAuthenticationMethods

public void setRequiredAuthenticationMethods(int authmethods)

getAllowDeniedKEX

public boolean getAllowDeniedKEX()

getMaximumSocketsBacklogPerRemotelyForwardedConnection

public int getMaximumSocketsBacklogPerRemotelyForwardedConnection()

setMaximumSocketsBacklogPerRemotelyForwardedConnection

public void setMaximumSocketsBacklogPerRemotelyForwardedConnection(int maximumSocketsBacklogPerRemotelyForwardedConnection)

getTooManyConnectionsText

public String getTooManyConnectionsText()

setTooManyConnectionsText

public void setTooManyConnectionsText(String tooManyConnectionsText)

getCiphersSC

public String getCiphersSC()
Get the ciphers for the Server->Client stream.

Returns:
the Server-Client ciphers in order of preference

getCiphersCS

public String getCiphersCS()

getMacsCS

public String getMacsCS()
Get the ciphers for the Client->Server stream.

Returns:
the Client-Server ciphers in order of preference

getMacsSC

public String getMacsSC()
Get the ciphers for the Server->Client stream.

Returns:
the Server-Client ciphers in order of preference

getPublicKeys

public String getPublicKeys()
Get the ciphers for the Server->Client stream.

Returns:
the Server-Client ciphers in order of preference

getKeyExchanges

public String getKeyExchanges()
Get the ciphers for the Server->Client stream.

Returns:
the Server-Client ciphers in order of preference

setPreferredCipherSC

public void setPreferredCipherSC(int[] order)
                          throws com.maverick.ssh.SshException
Set the preferred SC cipher order

Parameters:
order - , list of indices to be moved to the top.
Throws:
com.maverick.ssh.SshException

setPreferredCipherCS

public void setPreferredCipherCS(int[] order)
                          throws com.maverick.ssh.SshException
Set the preferred SC cipher order

Parameters:
order - , list of indices to be moved to the top.
Throws:
com.maverick.ssh.SshException

setPreferredMacSC

public void setPreferredMacSC(int[] order)
                       throws com.maverick.ssh.SshException
Set the preferred SC Mac order

Parameters:
order - , list of indices to be moved to the top.
Throws:
com.maverick.ssh.SshException

setPreferredMacCS

public void setPreferredMacCS(int[] order)
                       throws com.maverick.ssh.SshException
Set the preferred CS Mac order

Parameters:
order - , list of indices to be moved to the top.
Throws:
com.maverick.ssh.SshException

setCipherPreferredPositionCS

public void setCipherPreferredPositionCS(String name,
                                         int position)
                                  throws com.maverick.ssh.SshException
Throws:
com.maverick.ssh.SshException

setCipherPreferredPositionSC

public void setCipherPreferredPositionSC(String name,
                                         int position)
                                  throws com.maverick.ssh.SshException
Throws:
com.maverick.ssh.SshException

setMacPreferredPositionSC

public void setMacPreferredPositionSC(String name,
                                      int position)
                               throws com.maverick.ssh.SshException
Throws:
com.maverick.ssh.SshException

setMacPreferredPositionCS

public void setMacPreferredPositionCS(String name,
                                      int position)
                               throws com.maverick.ssh.SshException
Throws:
com.maverick.ssh.SshException

setPublicKeyPreferredPosition

public void setPublicKeyPreferredPosition(String name,
                                          int position)
                                   throws com.maverick.ssh.SshException
Throws:
com.maverick.ssh.SshException

setKeyExchangePreferredPosition

public void setKeyExchangePreferredPosition(String name,
                                            int position)
                                     throws com.maverick.ssh.SshException
Throws:
com.maverick.ssh.SshException

setForwardingCallback

public void setForwardingCallback(ForwardingCallback forwardingCallback)
Set the forwarding callback implementation for this server context.

Parameters:
forwardingCallback - NNForwardingCallback

getForwardingCallback

public ForwardingCallback getForwardingCallback()
Get the forwarding callback implementation for this server context.

Returns:
ForwardingCallback

setMaximumPacketLength

public void setMaximumPacketLength(int maximumPacketLength)
Set the maximum supported length of an SSH packet.

Parameters:
maximumPacketLength - int

getMaximumPacketLength

public int getMaximumPacketLength()
Get the maximum supported length of an SSH packet.

Returns:
int

setKeyExchangeTransferLimit

public void setKeyExchangeTransferLimit(int MAX_NUM_BYTES_BEFORE_REKEY)
This limit tells the server when to force a key exchange.

Parameters:
MAX_NUM_BYTES_BEFORE_REKEY - int

setKeyExchangePacketLimit

public void setKeyExchangePacketLimit(int MAX_NUM_PACKETS_BEFORE_REKEY)
This tells the server how many packets to use before a key exchange.

Parameters:
MAX_NUM_PACKETS_BEFORE_REKEY - int

getKeyExchangeTransferLimit

public int getKeyExchangeTransferLimit()
Get the number of bytes to transfer before a key exchange is forced.

Returns:
int

getKeyExchangePacketLimit

public int getKeyExchangePacketLimit()
Get the number of packets to send before a key exchange is forced

Returns:
int

getIdleConnectionTimeoutSeconds

public int getIdleConnectionTimeoutSeconds()
The number of seconds before an idle connection is dropped.

Returns:

setIdleConnectionTimeoutSeconds

public void setIdleConnectionTimeoutSeconds(int idleConnectionTimeout)
Set the number of seconds before an idle connection is dropped. Setting this to zero means the connection will never be dropped due to an idle connection.

Parameters:
idleConnectionTimeout -

getKeyboardInteractiveProviderFactory

public KeyboardInteractiveProviderFactory getKeyboardInteractiveProviderFactory()
Get the current provider for keyboard-interactive authentication

Returns:

setKeyboardInteractiveProvider

public void setKeyboardInteractiveProvider(KeyboardInteractiveProviderFactory kbiFactory)
Set the provider for keyboard-interactive authentication. Requires an implementation of KeyboardInteractiveProvider

Parameters:
keyboardInteractiveProvider - TODO: Convert to use a factory for possible session by session configuration of keyboard

supportedPublicKeys

public com.maverick.ssh.components.ComponentFactory supportedPublicKeys()

getKeepAliveInterval

public int getKeepAliveInterval()
Get the current keep-alive interval (in seconds). The server sends an SSH_MSG_IGNORE every n seconds after no activity on a connection.

Returns:

setKeepAliveInterval

public void setKeepAliveInterval(int keepAliveInterval)
Set the keep-alive interval (in seconds). The server sends an SSH_MSG_IGNORE message every n seconds after no activity on a connection.

Parameters:
keepAliveInterval -

getKeepAliveDataMaxLength

public int getKeepAliveDataMaxLength()
Get the maximum data length for the keep-alive packet.

Returns:

setKeepAliveDataMaxLength

public void setKeepAliveDataMaxLength(int keepAliveDataMaxLength)
Set the maximum data length for the keep-alive packet. Default is 128, the actual number of bytes is random up to this maximum.

Parameters:
keepAliveDataMaxLength -

clone

public Object clone()
             throws CloneNotSupportedException
Overrides:
clone in class ProtocolContext
Throws:
CloneNotSupportedException


Copyright © 2012. All Rights Reserved.