com.maverick.sshd
Class TransportProtocol

java.lang.Object
  extended bycom.maverick.sshd.TransportProtocol
All Implemented Interfaces:
IdleStateListener, ProtocolEngine

public class TransportProtocol
extends java.lang.Object
implements ProtocolEngine, IdleStateListener

This class implements the SSH Transport Protocol for the SSHD server.

Author:
Lee David Painter

Field Summary
static int AUTH_CANCELLED_BY_USER
          Disconnect reason: Authentication was cancelled
static int BY_APPLICATION
          Disconnect reason: The application disconnected
static java.lang.String CHARSET_ENCODING
          Character set encoding.
static int COMPRESSION_ERROR
          Disconnect reason: A compression error occurred
static int CONNECTED
          Protocol state: The transport protocol is connected and services can be started or may already be active.
static int CONNECTION_LOST
          Disconnect reason: The connection was lost
static int DISCONNECTED
          Protocol state: The transport protocol has disconnected.
static int HOST_KEY_NOT_VERIFIABLE
          Disconnect reason: The host key supplied could not be verified
static int HOST_NOT_ALLOWED
          Disconnect reason: The host is not allowed
static int ILLEGAL_USER_NAME
          Disconnect reason: The user's name is illegal
static int KEY_EXCHANGE_FAILED
          Disconnect reason: Key exchange failed
static java.lang.Object lock
           
static int MAC_ERROR
          Disconnect reason: An error occurred verifying the MAC
static int NEGOTIATING_PROTOCOL
          Protocol state: Negotation of the protocol version
static int NO_MORE_AUTH_METHODS_AVAILABLE
          Disconnect reason: No more authentication methods are available
static int numberOfConnections
           
static int PERFORMING_KEYEXCHANGE
          Protocol state: The protocol is performing key exchange
static int PROTOCOL_ERROR
          Disconnect reason: A protocol error occurred
static int PROTOCOL_VERSION_NOT_SUPPORTED
          Disconnect reason: The protocol version is not supported
static int RESERVED
          Disconnect reason: Reserved
static int SERVICE_NOT_AVAILABLE
          Disconnect reason: The requested service is not available
static int TOO_MANY_CONNECTIONS
          Disconnect reason: Too many connections, try later
 
Constructor Summary
TransportProtocol(SshContext sshContext)
          Create a default transport protocol instance in CLIENT_MODE.
 
Method Summary
 void addEventListener(TransportProtocolListener listener)
           
 void disconnect(int reason, java.lang.String description)
          Disconnect from the remote host.
 SshContext getContext()
           
 java.net.InetAddress getLocalAddress()
          Returns the local address to which the remote socket is connected.
 int getLocalPort()
          Returns the local port to which the remote socket is connected.
 java.net.SocketAddress getRemoteAddress()
           
 java.lang.String getRemoteIdentification()
           
 int getRemotePort()
          Returns the remote port of the connected socket.
 java.security.SecureRandom getRND()
          Gets the secure random number generator for this transport.
 byte[] getSessionIdentifier()
           
 SocketConnection getSocketConnection()
          Get the SocketConnection for this connection.
 SshContext getSshContext()
           
 int getState()
           
 boolean idle()
          Called when the selector framework is idle.
 boolean isConnected()
          Determine if the protocol is still connected
 void onSocketClose()
          Disconnects everything internally
 void onSocketConnect(SocketConnection connection)
          The socket is connected and the protocol can now start.
 boolean onSocketRead(java.nio.ByteBuffer incomingData)
          Called when the socket channel is reported to be ready for reading.
 void onSocketWrite(java.nio.ByteBuffer outgoingMessage)
          Called when the socket channel is reported to be ready for writing.
 void postMessage(SshMessage msg)
           
 void postMessage(SshMessage msg, boolean kex)
           
 void sendMessage(SshMessage msg)
          Deprecated. use #postMessage() instead.
 void sendNewKeys()
           
 boolean wantsToWrite()
          Determines whether the protocol wants to write to the socket.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHARSET_ENCODING

public static java.lang.String CHARSET_ENCODING
Character set encoding. All input/output strings created by the API are created with this encoding. The default is "UTF-8" and it may be changed, the results however are unknown.


NEGOTIATING_PROTOCOL

public static final int NEGOTIATING_PROTOCOL
Protocol state: Negotation of the protocol version

See Also:
Constant Field Values

PERFORMING_KEYEXCHANGE

public static final int PERFORMING_KEYEXCHANGE
Protocol state: The protocol is performing key exchange

See Also:
Constant Field Values

CONNECTED

public static final int CONNECTED
Protocol state: The transport protocol is connected and services can be started or may already be active.

See Also:
Constant Field Values

DISCONNECTED

public static final int DISCONNECTED
Protocol state: The transport protocol has disconnected.

See Also:
#getLastError(), Constant Field Values

HOST_NOT_ALLOWED

public static final int HOST_NOT_ALLOWED
Disconnect reason: The host is not allowed

See Also:
Constant Field Values

PROTOCOL_ERROR

public static final int PROTOCOL_ERROR
Disconnect reason: A protocol error occurred

See Also:
Constant Field Values

KEY_EXCHANGE_FAILED

public static final int KEY_EXCHANGE_FAILED
Disconnect reason: Key exchange failed

See Also:
Constant Field Values

RESERVED

public static final int RESERVED
Disconnect reason: Reserved

See Also:
Constant Field Values

MAC_ERROR

public static final int MAC_ERROR
Disconnect reason: An error occurred verifying the MAC

See Also:
Constant Field Values

COMPRESSION_ERROR

public static final int COMPRESSION_ERROR
Disconnect reason: A compression error occurred

See Also:
Constant Field Values

SERVICE_NOT_AVAILABLE

public static final int SERVICE_NOT_AVAILABLE
Disconnect reason: The requested service is not available

See Also:
Constant Field Values

PROTOCOL_VERSION_NOT_SUPPORTED

public static final int PROTOCOL_VERSION_NOT_SUPPORTED
Disconnect reason: The protocol version is not supported

See Also:
Constant Field Values

HOST_KEY_NOT_VERIFIABLE

public static final int HOST_KEY_NOT_VERIFIABLE
Disconnect reason: The host key supplied could not be verified

See Also:
Constant Field Values

CONNECTION_LOST

public static final int CONNECTION_LOST
Disconnect reason: The connection was lost

See Also:
Constant Field Values

BY_APPLICATION

public static final int BY_APPLICATION
Disconnect reason: The application disconnected

See Also:
Constant Field Values

TOO_MANY_CONNECTIONS

public static final int TOO_MANY_CONNECTIONS
Disconnect reason: Too many connections, try later

See Also:
Constant Field Values

AUTH_CANCELLED_BY_USER

public static final int AUTH_CANCELLED_BY_USER
Disconnect reason: Authentication was cancelled

See Also:
Constant Field Values

NO_MORE_AUTH_METHODS_AVAILABLE

public static final int NO_MORE_AUTH_METHODS_AVAILABLE
Disconnect reason: No more authentication methods are available

See Also:
Constant Field Values

ILLEGAL_USER_NAME

public static final int ILLEGAL_USER_NAME
Disconnect reason: The user's name is illegal

See Also:
Constant Field Values

numberOfConnections

public static int numberOfConnections

lock

public static java.lang.Object lock
Constructor Detail

TransportProtocol

public TransportProtocol(SshContext sshContext)
Create a default transport protocol instance in CLIENT_MODE.

Throws:
java.io.IOException
Method Detail

getSocketConnection

public SocketConnection getSocketConnection()
Description copied from interface: ProtocolEngine
Get the SocketConnection for this connection.

Specified by:
getSocketConnection in interface ProtocolEngine
Returns:
SocketConnection

addEventListener

public void addEventListener(TransportProtocolListener listener)

getRemoteAddress

public java.net.SocketAddress getRemoteAddress()

getRemotePort

public int getRemotePort()
Returns the remote port of the connected socket.

Returns:
int

getContext

public SshContext getContext()

onSocketConnect

public void onSocketConnect(SocketConnection connection)
Description copied from interface: ProtocolEngine
The socket is connected and the protocol can now start.

Specified by:
onSocketConnect in interface ProtocolEngine
Parameters:
connection - SocketConnection

onSocketRead

public boolean onSocketRead(java.nio.ByteBuffer incomingData)
Called when the socket channel is reported to be ready for reading.

Specified by:
onSocketRead in interface ProtocolEngine
Parameters:
incomingData - ByteBuffer
Returns:
boolean to determine if protocol wants to write to the socket

isConnected

public boolean isConnected()
Determine if the protocol is still connected

Specified by:
isConnected in interface ProtocolEngine
Returns:
boolean

wantsToWrite

public boolean wantsToWrite()
Description copied from interface: ProtocolEngine
Determines whether the protocol wants to write to the socket. The value of this method determines the write state of the socket. Only return a true value when the protocol needs to write data to the socket.

Specified by:
wantsToWrite in interface ProtocolEngine
Returns:
boolean

idle

public boolean idle()
Called when the selector framework is idle. We take the opportunity to send an SSH_MSG_IGNORE message in the hope that we can detect any sockets that may have closed.

Specified by:
idle in interface IdleStateListener
Returns:
true if this listener should be cancelled.

sendMessage

public void sendMessage(SshMessage msg)
Deprecated. use #postMessage() instead.

Send an SshMessage.

Parameters:
msg - SshMessage

onSocketWrite

public void onSocketWrite(java.nio.ByteBuffer outgoingMessage)
Called when the socket channel is reported to be ready for writing.

Specified by:
onSocketWrite in interface ProtocolEngine
Parameters:
outgoingMessage - ByteBuffer

getState

public int getState()

getLocalAddress

public java.net.InetAddress getLocalAddress()
Returns the local address to which the remote socket is connected.

Returns:
InetAddress

getLocalPort

public int getLocalPort()
Returns the local port to which the remote socket is connected.

Returns:
int

getRemoteIdentification

public java.lang.String getRemoteIdentification()

getSessionIdentifier

public byte[] getSessionIdentifier()

disconnect

public void disconnect(int reason,
                       java.lang.String description)
Disconnect from the remote host. No more messages can be sent after this method has been called.

Specified by:
disconnect in interface ProtocolEngine
Parameters:
reason -
description -
Throws:
java.io.IOException

onSocketClose

public void onSocketClose()
Disconnects everything internally

Specified by:
onSocketClose in interface ProtocolEngine

getRND

public java.security.SecureRandom getRND()
Gets the secure random number generator for this transport.

Returns:
the secure RND

sendNewKeys

public void sendNewKeys()

getSshContext

public SshContext getSshContext()

postMessage

public void postMessage(SshMessage msg)

postMessage

public void postMessage(SshMessage msg,
                        boolean kex)


Copyright © 2003-2008 SSHTools LTD. All Rights Reserved.