Package net.schmizz.sshj.transport
Interface Transport
-
- All Superinterfaces:
RemoteAddressProvider,SSHPacketHandler
- All Known Implementing Classes:
TransportImpl
public interface Transport extends SSHPacketHandler, RemoteAddressProvider
Transport layer of the SSH protocol.
-
-
Method Summary
Modifier and Type Method Description voidaddAlgorithmsVerifier(AlgorithmsVerifier verifier)Adds the specified verifier.voidaddHostKeyVerifier(HostKeyVerifier hkv)Adds the specified verifier.voiddie(java.lang.Exception e)Kill the transport in an exceptional way.voiddisconnect()Send a disconnection packet with reason asDisconnectReason.BY_APPLICATION, and closes this transport.voiddisconnect(DisconnectReason reason)Send a disconnect packet with the givenreason, and closes this transport.voiddisconnect(DisconnectReason reason, java.lang.String message)Send a disconnect packet with the givenreasonandmessage, and closes this transport.voiddoKex()Do key exchange and algorithm negotiation.java.util.List<KeyAlgorithm>getClientKeyAlgorithms(KeyType keyType)java.lang.StringgetClientVersion()ConfiggetConfig()DisconnectListenergetDisconnectListener()KeyAlgorithmgetHostKeyAlgorithm()java.lang.StringgetRemoteHost()intgetRemotePort()java.lang.StringgetServerVersion()Returns the version string as sent by the SSH server for identification purposes, e.g.ServicegetService()byte[]getSessionID()intgetTimeoutMs()voidinit(java.lang.String host, int port, java.io.InputStream in, java.io.OutputStream out)Sets the host information and the streams to be used by this transport.booleanisAuthenticated()booleanisKeyExchangeRequired()Is Key Exchange required based on current transport statusbooleanisRunning()voidjoin()Joins the thread calling this method to the transport's death.voidjoin(int timeout, java.util.concurrent.TimeUnit unit)Joins the thread calling this method to the transport's death.voidreqService(Service service)Request a SSH service represented by aServiceinstance.longsendUnimplemented()Sends SSH_MSG_UNIMPLEMENTED in response to the last packet received.voidsetAuthenticated()Informs this transport that authentication has been completed.voidsetDisconnectListener(DisconnectListener listener)Specify alistenerthat will be notified upon disconnection.voidsetService(Service service)Sets the currently activeService.voidsetTimeoutMs(int timeout)Set a timeout for methods that may block.longwrite(SSHPacket payload)Write a packet over this transport.-
Methods inherited from interface com.hierynomus.sshj.common.RemoteAddressProvider
getRemoteSocketAddress
-
Methods inherited from interface net.schmizz.sshj.common.SSHPacketHandler
handle
-
-
-
-
Method Detail
-
init
void init(java.lang.String host, int port, java.io.InputStream in, java.io.OutputStream out) throws TransportExceptionSets the host information and the streams to be used by this transport. Identification information is exchanged with the server. ATransportExceptionis thrown in case of SSH protocol version incompatibility.- Parameters:
host- server's hostnameport- server's portin- input stream for the connectionout- output stream for the connection- Throws:
TransportException- if there is an error during exchange of identification information
-
addHostKeyVerifier
void addHostKeyVerifier(HostKeyVerifier hkv)
Adds the specified verifier.- Parameters:
hkv- the host key verifier
-
addAlgorithmsVerifier
void addAlgorithmsVerifier(AlgorithmsVerifier verifier)
Adds the specified verifier.- Parameters:
verifier- The verifier to call with negotiated algorithms
-
doKex
void doKex() throws TransportExceptionDo key exchange and algorithm negotiation. This can be the initial one or for algorithm renegotiation.- Throws:
TransportException- if there was an error during key exchange
-
isKeyExchangeRequired
boolean isKeyExchangeRequired()
Is Key Exchange required based on current transport status- Returns:
- Key Exchange required status
-
getClientVersion
java.lang.String getClientVersion()
- Returns:
- the version string used by this client to identify itself to an SSH server, e.g. "SSHJ_3_0"
-
getTimeoutMs
int getTimeoutMs()
- Returns:
- the timeout that is currently set for blocking operations.
-
setTimeoutMs
void setTimeoutMs(int timeout)
Set a timeout for methods that may block.- Parameters:
timeout- the timeout in milliseconds
-
getRemoteHost
java.lang.String getRemoteHost()
- Returns:
- the hostname to which this transport is connected.
-
getRemotePort
int getRemotePort()
- Returns:
- the port number on the remote host to which this transport is connected.
-
getServerVersion
java.lang.String getServerVersion()
Returns the version string as sent by the SSH server for identification purposes, e.g. "OpenSSH_$version". If the transport has not yet been initialized viainit(java.lang.String, int, java.io.InputStream, java.io.OutputStream), it will benull.- Returns:
- server's version string (may be
null)
-
getSessionID
byte[] getSessionID()
- Returns:
- the session identifier assigned by server
-
reqService
void reqService(Service service) throws TransportException
Request a SSH service represented by aServiceinstance. A separate call tosetService(net.schmizz.sshj.Service)is not needed.- Parameters:
service- the SSH service to be requested- Throws:
TransportException- if the request failed for any reason
-
setService
void setService(Service service)
Sets the currently activeService. Handling of non-transport-layer packets isdelegatedto that service. For this method to be successful, at least one service request viareqService(net.schmizz.sshj.Service)must have been successful (not necessarily for the service being set).- Parameters:
service- (null-ok) theService
-
isAuthenticated
boolean isAuthenticated()
- Returns:
- whether the transport thinks it is authenticated.
-
setAuthenticated
void setAuthenticated()
Informs this transport that authentication has been completed. This method must be called after successful authentication, so that delayed compression may become effective if applicable.
-
sendUnimplemented
long sendUnimplemented() throws TransportExceptionSends SSH_MSG_UNIMPLEMENTED in response to the last packet received.- Returns:
- the sequence number of the packet sent
- Throws:
TransportException- if an error occurred sending the packet
-
isRunning
boolean isRunning()
- Returns:
- whether this transport is active.
The transport is considered to be running if it has been initialized without error via
init(java.lang.String, int, java.io.InputStream, java.io.OutputStream)and has not been disconnected.
-
join
void join() throws TransportException
Joins the thread calling this method to the transport's death.- Throws:
TransportException- if the transport dies of an exception
-
join
void join(int timeout, java.util.concurrent.TimeUnit unit) throws TransportExceptionJoins the thread calling this method to the transport's death.- Throws:
TransportException- if the transport dies of an exception
-
disconnect
void disconnect()
Send a disconnection packet with reason asDisconnectReason.BY_APPLICATION, and closes this transport.
-
disconnect
void disconnect(DisconnectReason reason)
Send a disconnect packet with the givenreason, and closes this transport.- Parameters:
reason- reason for disconnecting
-
disconnect
void disconnect(DisconnectReason reason, java.lang.String message)
Send a disconnect packet with the givenreasonandmessage, and closes this transport.- Parameters:
reason- the reason code for this disconnectmessage- the text message
-
write
long write(SSHPacket payload) throws TransportException
Write a packet over this transport. ThepayloadSSHPacketshould have 5 bytes free at the beginning to avoid a performance penalty associated with making space for header bytes (packet length, padding length).- Parameters:
payload- theSSHPacketcontaining data to send- Returns:
- sequence number of the sent packet
- Throws:
TransportException- if an error occurred sending the packet
-
setDisconnectListener
void setDisconnectListener(DisconnectListener listener)
Specify alistenerthat will be notified upon disconnection.- Parameters:
listener- Disconnect Listener to be configured
-
getDisconnectListener
DisconnectListener getDisconnectListener()
- Returns:
- the current disconnect listener.
-
die
void die(java.lang.Exception e)
Kill the transport in an exceptional way.- Parameters:
e- The exception that occurred.
-
getHostKeyAlgorithm
KeyAlgorithm getHostKeyAlgorithm()
-
getClientKeyAlgorithms
java.util.List<KeyAlgorithm> getClientKeyAlgorithms(KeyType keyType) throws TransportException
- Throws:
TransportException
-
-