Package com.sshtools.synergy.ssh
Class TransportProtocol<T extends SshContext>
java.lang.Object
com.sshtools.common.ssh.ExecutorOperationSupport<SshContext>
com.sshtools.synergy.ssh.TransportProtocol<T>
- All Implemented Interfaces:
IdleStateListener,ProtocolEngine,SshTransport<T>
public abstract class TransportProtocol<T extends SshContext>
extends ExecutorOperationSupport<SshContext>
implements ProtocolEngine, IdleStateListener, SshTransport<T>
This class implements the SSH Transport Protocol for the SSHD server.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Servicestatic final intDisconnect reason: Authentication was cancelledstatic final intDisconnect reason: The application disconnectedstatic StringCharacter set encoding.protected Stringprotected Stringprotected booleanstatic final intDisconnect reason: A compression error occurredprotected Stringprotected Stringprotected Connection<T>static final intProtocol state: The transport protocol is connected and services can be started or may already be active.static final intDisconnect reason: The connection was loststatic final intProtocol state: The transport protocol has disconnected.protected Dateprotected booleanprotected booleanstatic final intDisconnect reason: The host key supplied could not be verifiedstatic final intDisconnect reason: The host is not allowedprotected SshPublicKeystatic final intDisconnect reason: The user's name is illegalstatic final intDisconnect reason: Key exchange failedprotected Stringprotected Stringprotected byte[]static Objectstatic final intDisconnect reason: An error occurred verifying the MACprotected Stringprotected Stringstatic final intProtocol state: Negotation of the protocol versionstatic final intDisconnect reason: No more authentication methods are availablestatic final intProtocol state: The protocol is performing key exchangestatic final intDisconnect reason: A protocol error occurredstatic final intDisconnect reason: The protocol version is not supportedprotected Stringprotected booleanprotected StringBufferprotected byte[]static final intDisconnect reason: Reservedprotected booleanstatic final intDisconnect reason: The requested service is not availableprotected byte[]protected SocketConnectionstatic final intstatic final intprotected static final intprotected Tstatic final intDisconnect reason: Too many connections, try laterprotected UUIDFields inherited from class com.sshtools.common.ssh.ExecutorOperationSupport
CALLBACKS, EVENTS, MESSAGES_INCOMING, MESSAGES_OUTGOING -
Constructor Summary
ConstructorsConstructorDescriptionTransportProtocol(T sshContext, ConnectRequestFuture connectFuture) Create a default transport protocol instance in CLIENT_MODE. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddEventListener(TransportProtocolListener listener) protected abstract booleancanConnect(SocketConnection connection) protected booleanprotected voidcompleteKeyExchange(SshKeyExchange<T> keyExchange) voiddisconnect(int reason, String description) Disconnect from the remote host.protected abstract voidprotected voidprotected voidprotected voidprotected voidstatic byte[]protected abstract StringReturns the local address to which the remote socket is connected.intReturns the local port to which the remote socket is connected.getMacCS()getMacSC()intString[]String[]String[]String[]String[]String[]String[]intReturns the remote port of the connected socket.String[]getRND()Gets the secure random number generator for this transport.byte[]Get theSocketConnectionfor this connection.intgetState()getUUID()booleanbooleanidle()Called when the selector framework is idle.protected abstract voidinitializeKeyExchange(SshKeyExchange<T> keyExchange, boolean firstPacketFollows, boolean useFirstPacket) booleanDetermine if the protocol is still connectedbooleanGet if disconnecting has started but not yet complete.protected abstract booleanbooleanprotected abstract booleanprotected voidvoidkill()protected abstract voidprotected abstract voidprotected voidprotected abstract voidprotected abstract voidprotected abstract voidprotected voidonRemoteIdentificationReceived(String remoteIdentification) voidDisconnects everything internallyvoidonSocketConnect(SocketConnection connection) The socket is connected and the protocol can now start.booleanonSocketRead(ByteBuffer incomingData) Called when the socket channel is reported to be ready for reading.onSocketWrite(ByteBuffer outgoingMessage) Called when the socket channel is reported to be ready for writing.voidpostMessage(SshMessage msg) voidpostMessage(SshMessage msg, boolean kex) voidprocessMessage(byte[] msg, long sequenceNo) Process a message.protected voidprocessNegotiationString(String value) protected abstract booleanprocessTransportMessage(int msgid, byte[] msg) voidregisterIdleStateListener(IdleStateListener listener) voidremoveIdleStateListener(IdleStateListener listener) voidresetIdleState(IdleStateListener listener) protected StringselectNegotiatedComponent(String clientlist, String serverlist) voidprotected booleanprotected voidtransferState(TransportProtocol<? extends SshContext> transport) booleanDetermines whether the protocol wants to write to the socket.Methods inherited from class com.sshtools.common.ssh.ExecutorOperationSupport
addIncomingTask, addOutgoingTask, addTask, cleanupOperationsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.sshtools.synergy.nio.ProtocolEngine
getName
-
Field Details
-
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. -
localIdentification
-
remoteIdentification
-
receivedRemoteIdentification
protected boolean receivedRemoteIdentification -
sentLocalIdentification
protected boolean sentLocalIdentification -
localkex
protected byte[] localkex -
remotekex
protected byte[] remotekex -
sessionIdentifier
protected byte[] sessionIdentifier -
uuid
-
hasExtensionCapability
protected boolean hasExtensionCapability -
enableExtensionCapability
protected boolean enableExtensionCapability -
activeService
-
SSH_MSG_SERVICE_REQUEST
protected static final int SSH_MSG_SERVICE_REQUEST- See Also:
-
SSH_MSG_SERVICE_ACCEPT
public static final int SSH_MSG_SERVICE_ACCEPT- See Also:
-
SSH_MSG_EXT_INFO
public static final int SSH_MSG_EXT_INFO- See Also:
-
completedFirstKeyExchange
protected boolean completedFirstKeyExchange -
disconnectStarted
-
NEGOTIATING_PROTOCOL
public static final int NEGOTIATING_PROTOCOLProtocol state: Negotation of the protocol version- See Also:
-
PERFORMING_KEYEXCHANGE
public static final int PERFORMING_KEYEXCHANGEProtocol state: The protocol is performing key exchange- See Also:
-
CONNECTED
public static final int CONNECTEDProtocol state: The transport protocol is connected and services can be started or may already be active.- See Also:
-
DISCONNECTED
public static final int DISCONNECTEDProtocol state: The transport protocol has disconnected.- See Also:
-
#getLastError()- Constant Field Values
-
hostKey
-
cipherCS
-
cipherSC
-
macCS
-
macSC
-
compressionCS
-
compressionSC
-
keyExchangeAlgorithm
-
publicKey
-
con
-
HOST_NOT_ALLOWED
public static final int HOST_NOT_ALLOWEDDisconnect reason: The host is not allowed- See Also:
-
PROTOCOL_ERROR
public static final int PROTOCOL_ERRORDisconnect reason: A protocol error occurred- See Also:
-
KEY_EXCHANGE_FAILED
public static final int KEY_EXCHANGE_FAILEDDisconnect reason: Key exchange failed- See Also:
-
RESERVED
public static final int RESERVEDDisconnect reason: Reserved- See Also:
-
MAC_ERROR
public static final int MAC_ERRORDisconnect reason: An error occurred verifying the MAC- See Also:
-
COMPRESSION_ERROR
public static final int COMPRESSION_ERRORDisconnect reason: A compression error occurred- See Also:
-
SERVICE_NOT_AVAILABLE
public static final int SERVICE_NOT_AVAILABLEDisconnect reason: The requested service is not available- See Also:
-
PROTOCOL_VERSION_NOT_SUPPORTED
public static final int PROTOCOL_VERSION_NOT_SUPPORTEDDisconnect reason: The protocol version is not supported- See Also:
-
HOST_KEY_NOT_VERIFIABLE
public static final int HOST_KEY_NOT_VERIFIABLEDisconnect reason: The host key supplied could not be verified- See Also:
-
CONNECTION_LOST
public static final int CONNECTION_LOSTDisconnect reason: The connection was lost- See Also:
-
BY_APPLICATION
public static final int BY_APPLICATIONDisconnect reason: The application disconnected- See Also:
-
TOO_MANY_CONNECTIONS
public static final int TOO_MANY_CONNECTIONSDisconnect reason: Too many connections, try later- See Also:
-
AUTH_CANCELLED_BY_USER
public static final int AUTH_CANCELLED_BY_USERDisconnect reason: Authentication was cancelled- See Also:
-
NO_MORE_AUTH_METHODS_AVAILABLE
public static final int NO_MORE_AUTH_METHODS_AVAILABLEDisconnect reason: No more authentication methods are available- See Also:
-
ILLEGAL_USER_NAME
public static final int ILLEGAL_USER_NAMEDisconnect reason: The user's name is illegal- See Also:
-
sshContext
-
socketConnection
-
lock
-
-
Constructor Details
-
TransportProtocol
Create a default transport protocol instance in CLIENT_MODE.- Throws:
IOException
-
-
Method Details
-
transferState
-
getConnectFuture
- Specified by:
getConnectFuturein interfaceProtocolEngine
-
getDisconnectFuture
- Specified by:
getDisconnectFuturein interfaceProtocolEngine
-
getSocketConnection
Description copied from interface:ProtocolEngineGet theSocketConnectionfor this connection.- Specified by:
getSocketConnectionin interfaceProtocolEngine- Returns:
- SocketConnection
-
addEventListener
-
getRemoteAddress
-
getRemotePort
public int getRemotePort()Returns the remote port of the connected socket.- Returns:
- int
-
getContext
- Specified by:
getContextin interfaceProtocolEngine- Specified by:
getContextin interfaceSshTransport<T extends SshContext>- Specified by:
getContextin classExecutorOperationSupport<SshContext>
-
getConnection
- Specified by:
getConnectionin interfaceProtocolEngine
-
canConnect
-
onConnected
protected abstract void onConnected() -
onDisconnected
protected abstract void onDisconnected() -
onSocketConnect
Description copied from interface:ProtocolEngineThe socket is connected and the protocol can now start.- Specified by:
onSocketConnectin interfaceProtocolEngine- Parameters:
connection- SocketConnection
-
canSendKeyExchangeInit
protected boolean canSendKeyExchangeInit() -
onSocketRead
Called when the socket channel is reported to be ready for reading.- Specified by:
onSocketReadin interfaceProtocolEngine- Parameters:
incomingData- ByteBuffer- Returns:
- boolean to determine if protocol wants to write to the socket
-
isDisonnecting
public boolean isDisonnecting()Get if disconnecting has started but not yet complete.- Returns:
- disconnecting
-
isConnected
public boolean isConnected()Determine if the protocol is still connected- Specified by:
isConnectedin interfaceProtocolEngine- Returns:
- boolean
-
processNegotiationString
- Throws:
IOException
-
startBinaryProtocol
protected boolean startBinaryProtocol() -
onRemoteIdentificationReceived
-
wantsToWrite
public boolean wantsToWrite()Description copied from interface:ProtocolEngineDetermines 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:
wantsToWritein interfaceProtocolEngine- Returns:
- boolean
-
getQueueSizes
public int getQueueSizes() -
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:
idlein interfaceIdleStateListener
-
onSocketWrite
Called when the socket channel is reported to be ready for writing.- Specified by:
onSocketWritein interfaceProtocolEngine- Parameters:
outgoingMessage- ByteBuffer
-
getState
public int getState() -
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
-
getUUID
-
disconnect
Disconnect from the remote host. No more messages can be sent after this method has been called.- Specified by:
disconnectin interfaceProtocolEngine- Specified by:
disconnectin interfaceSshTransport<T extends SshContext>- Parameters:
reason-description-- Throws:
IOException
-
onSocketClose
public void onSocketClose()Disconnects everything internally- Specified by:
onSocketClosein interfaceProtocolEngine
-
getRND
Gets the secure random number generator for this transport.- Returns:
- the secure RND
-
initializeKeyExchange
protected abstract void initializeKeyExchange(SshKeyExchange<T> keyExchange, boolean firstPacketFollows, boolean useFirstPacket) throws IOException, SshException - Throws:
IOExceptionSshException
-
getExtensionNegotiationString
-
isExtensionNegotiationSupported
protected abstract boolean isExtensionNegotiationSupported() -
onKeyExchangeInit
- Throws:
SshException
-
keyExchangeInitialized
protected void keyExchangeInitialized() -
disconnected
protected abstract void disconnected() -
onNewKeysReceived
protected abstract void onNewKeysReceived() -
processTransportMessage
protected abstract boolean processTransportMessage(int msgid, byte[] msg) throws IOException, SshException - Throws:
IOExceptionSshException
-
processMessage
public void processMessage(byte[] msg, long sequenceNo) throws SshException, IOException, WriteOperationRequest Process a message. This should be called when reading messages from outside of the transport protocol so that the transport protocol can parse its own messages.- Parameters:
msg-- Throws:
IOExceptionSshExceptionWriteOperationRequest
-
onNewKeysSent
protected abstract void onNewKeysSent() -
sendNewKeys
public void sendNewKeys()- Specified by:
sendNewKeysin interfaceSshTransport<T extends SshContext>
-
getSshContext
-
selectNegotiatedComponent
- Throws:
IOException
-
onKeyExchangeComplete
protected void onKeyExchangeComplete() -
completeKeyExchange
-
generateNewKeysServerOut
protected void generateNewKeysServerOut() -
generateNewKeysServerIn
protected void generateNewKeysServerIn() -
generateNewKeysClientOut
protected void generateNewKeysClientOut() -
generateNewKeysClientIn
protected void generateNewKeysClientIn() -
isServerMode
protected abstract boolean isServerMode() -
getCipherCS
-
getCipherSC
-
getMacCS
-
getMacSC
-
getCompressionCS
-
getCompressionSC
-
postMessage
- Specified by:
postMessagein interfaceSshTransport<T extends SshContext>
-
postMessage
- Specified by:
postMessagein interfaceSshTransport<T extends SshContext>
-
getSessionKey
public byte[] getSessionKey() -
getBytes
-
kill
public void kill() -
getHostKeyAlgorithm
-
getHostKey
-
getKeyExchangeAlgorithm
-
getRemoteKeyExchanges
-
getRemotePublicKeys
-
getRemoteCiphersCS
-
getRemoteCiphersSC
-
getRemoteMacsCS
-
getRemoteMacsSC
-
getRemoteCompressionsCS
-
getRemoteCompressionsSC
-
hasCompletedKeyExchange
public boolean hasCompletedKeyExchange() -
getExecutor
- Specified by:
getExecutorin interfaceProtocolEngine
-
registerIdleStateListener
-
removeIdleStateListener
-
resetIdleState
-
isSelectorThread
public boolean isSelectorThread() -
getKeyExchangeInUse
-
getHostKeyInUse
-
getLocalIdentification
-
getAuthenticatedFuture
-