public class TransportProtocol extends ExecutorOperationSupport<Ssh2Context> implements SshMessageReader, AbstractClientTransport
Main implementation of the SSH Transport Protocol. The transport is designed to run over a provider such as a Socket or StreamConnection. To use first create an instance of the protocol and set its parameters and when ready start the protocol using startTransportProtocol supplying a TransportProvider instance. This example uses the SocketProvider example implementation demonstrated in TransportProvider Help File.
TransportProtocol transport = new TransportProtocol(); transport.ignoreHostKeyVerification(true); transport.startTransportProtocol(new SocketProvider("titan", 22));
Host key verification is recommended and a callback interface is provided by HostKeyVerifcation. To force verification use setHostKeyVerification() before starting the protocol. This is required by default but can be ignored with ignoreHostKeyVerification(boolean ignore).
Additional cipher, message authentication and compression components can be supported by providing a custom TransportContext. The default context provides all the required components of the protocol but others can be added by creating an instance and adding the various implementations to the component factories.
TransportContext context = new TransportContext(); context.supportedCiphers().add("blowfish-cbc", "com.mycrypt.Blowfish"); TransportProtocol transport = new TransportProtocol( TransportProtocol.CLIENT_MODE, context);
The context can also be used to specify the preferred methods of encryption for the connection which you may want to use should you add a new method to the context.
context.setPreferredCipherCS("blowfish-cbc");
TransportProvider
Modifier and Type | Field and Description |
---|---|
static int |
AUTH_CANCELLED_BY_USER
Disconnect reason: Authentication was cancelled
|
static int |
BY_APPLICATION
Disconnect reason: The application disconnected
|
static 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 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 |
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 and Description |
---|
TransportProtocol(boolean buffered,
boolean managedSecurity)
Create a default transport protocol instance in CLIENT_MODE.
|
Modifier and Type | Method and Description |
---|---|
void |
addListener(TransportProtocolListener listener) |
void |
debug(org.slf4j.Logger log,
String msg,
Object... args) |
void |
debug(String msg,
Object... args) |
void |
disconnect(int reason,
String disconnectReason)
Disconnect from the remote host.
|
void |
error(org.slf4j.Logger log,
String msg,
Exception e) |
Ssh2Client |
getClient()
Get the SshClient instance that created this transport.
|
Ssh2Context |
getContext() |
ExecutorService |
getExecutorService() |
String |
getHost() |
String |
getHostname() |
String |
getIdent() |
boolean |
getIgnoreHostKeyifEmpty() |
SshKeyExchangeClient |
getKeyExchange() |
String |
getKnownHostName() |
Throwable |
getLastError()
Returns the last error detected by the protocol.
|
String[] |
getLocalCiphersCS() |
String[] |
getLocalCiphersSC() |
String[] |
getLocalCompressionsCS() |
String[] |
getLocalCompressionsSC() |
String[] |
getLocalKeyExchanges() |
String[] |
getLocalMacsCS() |
String[] |
getLocalMacsSC() |
String[] |
getLocalPublicKeys() |
protected String |
getName() |
SshTransport |
getProvider() |
String[] |
getRemoteCiphersCS() |
String[] |
getRemoteCiphersSC() |
String[] |
getRemoteCompressionsCS() |
String[] |
getRemoteCompressionsSC() |
String |
getRemoteIdentification()
Get the identification string sent by the server during protocol
negotiation
|
String[] |
getRemoteKeyExchanges() |
String[] |
getRemoteMacsCS() |
String[] |
getRemoteMacsSC() |
String[] |
getRemotePublicKeys() |
byte[] |
getSessionIdentifier()
Get the session identifier
|
String |
getUuid() |
void |
info(org.slf4j.Logger log,
String msg,
Object... args) |
void |
info(String msg,
Object... args) |
boolean |
isConnected()
Returns the connected state
|
byte[] |
makeSshKey(char chr,
int sizeRequired) |
byte[] |
nextMessage(long timeout)
Get the next message.
|
boolean |
processMessage(byte[] msg)
Process a message.
|
void |
sendMessage(byte[] msg,
boolean isActivity)
Send a transport protocol message.
|
void |
setIgnoreHostKeyifEmpty(boolean ignoreHostKeyifEmpty) |
void |
startService(String servicename)
Request that the remote server starts a transport protocol service.
|
void |
startTransportProtocol(SshTransport provider,
Ssh2Context context,
String localIdentification,
String remoteIdentification,
Ssh2Client client)
Starts the protocol on the provider.
|
addOperationListener, addTask, cleanupOperations, clearQueue, endExecution, getOperationsCount, removeOperationListener, startExecution, startTask, taskAdded
public static String CHARSET_ENCODING
public static final int NEGOTIATING_PROTOCOL
public static final int PERFORMING_KEYEXCHANGE
public static final int CONNECTED
public static final int DISCONNECTED
getLastError()
,
Constant Field Valuespublic static final int HOST_NOT_ALLOWED
public static final int PROTOCOL_ERROR
public static final int KEY_EXCHANGE_FAILED
public static final int RESERVED
public static final int MAC_ERROR
public static final int COMPRESSION_ERROR
public static final int SERVICE_NOT_AVAILABLE
public static final int PROTOCOL_VERSION_NOT_SUPPORTED
public static final int HOST_KEY_NOT_VERIFIABLE
public static final int CONNECTION_LOST
public static final int BY_APPLICATION
public static final int TOO_MANY_CONNECTIONS
public static final int AUTH_CANCELLED_BY_USER
public static final int NO_MORE_AUTH_METHODS_AVAILABLE
public static final int ILLEGAL_USER_NAME
public TransportProtocol(boolean buffered, boolean managedSecurity)
IOException
public SshTransport getProvider()
public void addListener(TransportProtocolListener listener)
public Ssh2Client getClient()
protected String getName()
getName
in class ExecutorOperationSupport<Ssh2Context>
public boolean isConnected()
isConnected
in interface SshMessageReader
public Throwable getLastError()
public Ssh2Context getContext()
getContext
in interface AbstractClientTransport
getContext
in class ExecutorOperationSupport<Ssh2Context>
public boolean getIgnoreHostKeyifEmpty()
public void setIgnoreHostKeyifEmpty(boolean ignoreHostKeyifEmpty)
public String getHostname()
getHostname
in interface SshMessageReader
public void startTransportProtocol(SshTransport provider, Ssh2Context context, String localIdentification, String remoteIdentification, Ssh2Client client) throws SshException
SshException
public String getRemoteIdentification()
public byte[] getSessionIdentifier()
public void disconnect(int reason, String disconnectReason)
disconnect
in interface AbstractClientTransport
reason
- disconnectReason
- , descriptionIOException
public void sendMessage(byte[] msg, boolean isActivity) throws SshException
Send a transport protocol message. The format of the message should be:
byte Message ID byte[] Payload
sendMessage
in interface AbstractClientTransport
msgdata
- IOException
SshException
public void info(org.slf4j.Logger log, String msg, Object... args)
info
in interface AbstractClientTransport
public void debug(org.slf4j.Logger log, String msg, Object... args)
debug
in interface AbstractClientTransport
public void error(org.slf4j.Logger log, String msg, Exception e)
error
in interface AbstractClientTransport
public byte[] nextMessage(long timeout) throws SshException
nextMessage
in interface SshMessageReader
nextMessage
in interface AbstractClientTransport
IOException
SshException
public SshKeyExchangeClient getKeyExchange()
public String getKnownHostName()
public void startService(String servicename) throws SshException
servicename
- IOException
SshException
public boolean processMessage(byte[] msg) throws SshException
msg
- true
if the message was processed by the transport
and can be discarded, otherwise false
.SshException
public byte[] makeSshKey(char chr, int sizeRequired) throws IOException
IOException
public ExecutorService getExecutorService()
getExecutorService
in interface SshMessageReader
public String[] getRemoteKeyExchanges()
public String[] getRemotePublicKeys()
public String[] getRemoteCiphersCS()
public String[] getRemoteCiphersSC()
public String[] getRemoteMacsCS()
public String[] getRemoteMacsSC()
public String[] getRemoteCompressionsCS()
public String[] getRemoteCompressionsSC()
public String[] getLocalKeyExchanges()
public String[] getLocalPublicKeys()
public String[] getLocalCiphersCS()
public String[] getLocalCiphersSC()
public String[] getLocalMacsCS()
public String[] getLocalMacsSC()
public String[] getLocalCompressionsCS()
public String[] getLocalCompressionsSC()
public String getIdent()
getIdent
in interface SshMessageReader
getIdent
in interface AbstractClientTransport
public String getHost()
getHost
in interface AbstractClientTransport
public String getUuid()
getUuid
in interface SshMessageReader
Copyright © 2024. All rights reserved.