public abstract class AbstractClientSession extends AbstractSession implements ClientSession
ClientSession related methodsAbstractCloseable.StateClientSession.ClientSessionEventSession.TimeoutStatusAttributeStore.AttributeKey<T>authed, authTimeoutStart, channelListenerProxy, channelListeners, clientProposal, clientVersion, currentService, decodeLock, decoderBuffer, decoderLength, decoderState, encodeLock, firstKexPacketFollows, i_c, i_s, idleTimeoutStart, ignorePacketDataLength, ignorePacketsCount, ignorePacketsFrequency, ignorePacketsVariance, inBlocksCount, inBytesCount, inCipher, inCipherSize, inCompression, inMac, inMacResult, inPacketsCount, ioSession, isServer, kex, kexFutureHolder, kexState, lastKeyTimeValue, maxRekeyBlocks, maxRekeyBytes, maxRekeyInterval, maxRekyPackets, negotiationResult, outBlocksCount, outBytesCount, outCipher, outCipherSize, outCompression, outMac, outPacketsCount, pendingPackets, random, requestLock, seqi, seqo, serverProposal, serverVersion, SESSION, sessionId, sessionListenerProxy, sessionListeners, timeoutStatus, tunnelListenerProxy, tunnelListeners, uncompressBuffer, usernamecloseFuture, lock, statelogREMOTE_COMMAND_WAIT_EVENTSDEFAULT_SSH_VERSION_PREFIX, FALLBACK_SSH_VERSION_PREFIX, MAX_VERSION_LINE_LENGTHEMPTYCLOSE_WAIT_TIMEOUT, DEFAULT_CLOSE_WAIT_TIMEOUTDEFAULT_PASSWORD_PROMPTS, PASSWORD_PROMPTS, PREFERRED_AUTHS| Modifier | Constructor and Description |
|---|---|
protected |
AbstractClientSession(ClientFactoryManager factoryManager,
IoSession ioSession) |
| Modifier and Type | Method and Description |
|---|---|
void |
addPasswordIdentity(String password) |
void |
addPublicKeyIdentity(KeyPair kp) |
protected void |
checkKeys()
Indicates the the key exchange is completed and the exchanged keys
can now be verified - e.g., client can verify the server's key
|
ClientChannel |
createChannel(String type)
Create a channel of the given type.
|
ClientChannel |
createChannel(String type,
String subType)
Create a channel of the given type and sub-type.
|
ChannelDirectTcpip |
createDirectTcpipChannel(SshdSocketAddress local,
SshdSocketAddress remote)
Create a direct tcp-ip channel which can be used to stream data to a remote port from the server.
|
ChannelExec |
createExecChannel(String command)
Create a channel to execute a command.
|
ScpClient |
createScpClient(ScpFileOpener opener,
ScpTransferEventListener listener)
Create an SCP client from this session.
|
SftpClient |
createSftpClient(SftpVersionSelector selector)
Creates an SFTP client while allowing the selection of a specific version
|
FileSystem |
createSftpFileSystem() |
FileSystem |
createSftpFileSystem(int version) |
FileSystem |
createSftpFileSystem(int readBufferSize,
int writeBufferSize) |
FileSystem |
createSftpFileSystem(int version,
int readBufferSize,
int writeBufferSize) |
FileSystem |
createSftpFileSystem(SftpVersionSelector selector) |
FileSystem |
createSftpFileSystem(SftpVersionSelector selector,
int readBufferSize,
int writeBufferSize) |
ChannelShell |
createShellChannel()
Create a channel to start a shell.
|
ChannelSubsystem |
createSubsystemChannel(String subsystem)
Create a subsystem channel.
|
ClientProxyConnector |
getClientProxyConnector() |
SocketAddress |
getConnectAddress()
Returns the original address (after having been translated through host
configuration entries if any) that was request to connect.
|
protected ConnectionService |
getConnectionService() |
ClientFactoryManager |
getFactoryManager() |
PasswordIdentityProvider |
getPasswordIdentityProvider()
Retrieve
PasswordIdentityProvider used to provide password
candidates |
AuthenticationIdentitiesProvider |
getRegisteredIdentities() |
ScpFileOpener |
getScpFileOpener() |
ScpTransferEventListener |
getScpTransferEventListener() |
ServerKeyVerifier |
getServerKeyVerifier()
Retrieve the server key verifier to be used to check the key when connecting
to an SSH server.
|
protected TcpipForwarder |
getTcpipForwarder() |
List<NamedFactory<UserAuth>> |
getUserAuthFactories() |
protected ClientUserAuthService |
getUserAuthService() |
UserInteraction |
getUserInteraction() |
protected boolean |
readIdentification(Buffer buffer)
Read the other side identification.
|
protected void |
receiveKexInit(Map<KexProposalOption,String> proposal,
byte[] seed) |
String |
removePasswordIdentity(String password) |
KeyPair |
removePublicKeyIdentity(KeyPair kp) |
protected String |
resolveAvailableSignaturesProposal(FactoryManager manager) |
protected IoWriteFuture |
sendClientIdentification() |
protected byte[] |
sendKexInit(Map<KexProposalOption,String> proposal)
Send the key exchange initialization packet.
|
void |
setClientProxyConnector(ClientProxyConnector proxyConnector) |
void |
setConnectAddress(SocketAddress connectAddress) |
protected void |
setKexSeed(byte... seed) |
void |
setPasswordIdentityProvider(PasswordIdentityProvider provider) |
void |
setScpFileOpener(ScpFileOpener opener) |
void |
setScpTransferEventListener(ScpTransferEventListener listener) |
void |
setServerKeyVerifier(ServerKeyVerifier serverKeyVerifier) |
void |
setUserAuthFactories(List<NamedFactory<UserAuth>> userAuthFactories) |
void |
setUserInteraction(UserInteraction userInteraction) |
protected void |
signalExtraServerVersionInfo(List<String> lines) |
SshdSocketAddress |
startDynamicPortForwarding(SshdSocketAddress local)
Start dynamic local port forwarding using a SOCKS proxy.
|
SshdSocketAddress |
startLocalPortForwarding(SshdSocketAddress local,
SshdSocketAddress remote)
Start forwarding the given local address on the client to the given address on the server.
|
SshdSocketAddress |
startRemotePortForwarding(SshdSocketAddress remote,
SshdSocketAddress local)
Start forwarding tcpip from the given address on the server to the
given address on the client.
|
void |
startService(String name) |
void |
stopDynamicPortForwarding(SshdSocketAddress local)
Stop a previously started dynamic port forwarding.
|
void |
stopLocalPortForwarding(SshdSocketAddress local)
Stop forwarding the given local address.
|
void |
stopRemotePortForwarding(SshdSocketAddress remote)
Stop forwarding of the given remote address.
|
KeyExchangeFuture |
switchToNoneCipher()
Switch to a none cipher for performance.
|
addChannelListener, addPortForwardingEventListener, addSessionListener, attachSession, calculateNextIgnorePacketCount, checkAuthenticationTimeout, checkForTimeouts, checkIdleTimeout, checkRekey, comparePreferredKexProposalOption, createBuffer, createBuffer, createProposal, decode, disconnect, doHandleMessage, doReadIdentification, doWritePacket, encode, exceptionCaught, getAttribute, getAuthTimeout, getChannelListenerProxy, getCipherInformation, getClientVersion, getCompressionInformation, getIdleTimeout, getInnerCloseable, getIoSession, getKex, getLock, getMacInformation, getNegotiatedKexParameter, getParentPropertyResolver, getPortForwardingEventListenerProxy, getProperties, getReservedSessionMessagesHandler, getServerVersion, getService, getServices, getSession, getSession, getSessionId, getSessionListenerProxy, getTimeoutStatus, getUsername, handleDebug, handleDisconnect, handleDisconnect, handleFirstKexPacketFollows, handleIgnore, handleKexInit, handleKexMessage, handleMessage, handleNewKeys, handleServiceAccept, handleServiceAccept, handleServiceRequest, handleServiceRequest, handleUnimplemented, invokeSessionSignaller, isAuthenticated, isRekeyBlocksCountExceeded, isRekeyDataSizeExceeded, isRekeyPacketCountsExceeded, isRekeyRequired, isRekeyTimeIntervalExceeded, mergeProposals, messageReceived, negotiate, notImplemented, preClose, prepareBuffer, receiveKexInit, receiveKexInit, receiveNewKeys, reExchangeKeys, refreshConfiguration, removeAttribute, removeChannelListener, removePortForwardingEventListener, removeSessionListener, request, requestFailure, requestNewKeysExchange, requestSuccess, resetIdleTimeout, resizeKey, resolveAttribute, resolveAvailableSignaturesProposal, resolveIdentificationString, resolveIgnoreBufferDataLength, resolvePeerAddress, resolveReservedSessionMessagesHandler, sendDebugMessage, sendIdentification, sendIgnoreMessage, sendKexInit, sendNewKeys, sendNotImplemented, setAttribute, setAuthenticated, setNegotiationResult, setReservedSessionMessagesHandler, setUsername, signalExceptionCaught, signalExceptionCaught, signalNegotiationEnd, signalNegotiationEnd, signalNegotiationStart, signalNegotiationStart, signalSessionClosed, signalSessionClosed, signalSessionCreated, signalSessionCreated, signalSessionEvent, signalSessionEvent, toString, validateKexState, validateTargetBuffer, writePacket, writePacketgetCipherFactories, getCompressionFactories, getKeyExchangeFactories, getKeyPairProvider, getMacFactories, getSignatureFactories, resolveEffectiveFactories, resolveEffectiveProvider, setCipherFactories, setCompressionFactories, setKeyExchangeFactories, setKeyPairProvider, setMacFactories, setSignatureFactoriesdoCloseGracefully, doCloseImmediatelyaddCloseFutureListener, builder, close, isClosed, isClosing, removeCloseFutureListenergetSimplifiedLoggerclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitauth, createDynamicPortForwardingTracker, createLocalPortForwardingTracker, createRemotePortForwardingTracker, executeRemoteCommand, executeRemoteCommand, getMetadataMap, waitForcreateBuffer, createBuffer, disconnect, exceptionCaught, getAuthTimeout, getCipherInformation, getClientVersion, getCompressionInformation, getIdleTimeout, getIoSession, getKex, getMacInformation, getNegotiatedKexParameter, getServerVersion, getService, getSessionId, getTimeoutStatus, isAuthenticated, isValidVersionPrefix, prepareBuffer, reExchangeKeys, request, resetIdleTimeout, sendDebugMessage, sendIgnoreMessage, setAuthenticated, writePacket, writePacketgetCipherFactories, getCipherFactoriesNameList, getCipherFactoriesNames, getCompressionFactories, getCompressionFactoriesNameList, getCompressionFactoriesNames, getKeyExchangeFactories, getMacFactories, getMacFactoriesNameList, getMacFactoriesNames, setCipherFactories, setCipherFactoriesNameList, setCipherFactoriesNames, setCipherFactoriesNames, setCompressionFactories, setCompressionFactoriesNameList, setCompressionFactoriesNames, setCompressionFactoriesNames, setKeyExchangeFactories, setMacFactories, setMacFactoriesNameList, setMacFactoriesNames, setMacFactoriesNamesgetKeyPairProvider, setKeyPairProvidergetSignatureFactories, getSignatureFactories, getSignatureFactoriesNameList, getSignatureFactoriesNames, resolveSignatureFactories, setSignatureFactories, setSignatureFactoriesNameList, setSignatureFactoriesNames, setSignatureFactoriesNamesaddSessionListener, getSessionListenerProxy, removeSessionListenergetReservedSessionMessagesHandler, setReservedSessionMessagesHandleraddChannelListener, getChannelListenerProxy, removeChannelListeneraddPortForwardingEventListener, getPortForwardingEventListenerProxy, removePortForwardingEventListenergetBoolean, getBooleanProperty, getInteger, getIntProperty, getLong, getLongProperty, getObject, getParentPropertyResolver, getProperties, getString, getStringPropertygetAttribute, removeAttribute, resolveAttribute, resolveAttribute, resolveAttribute, resolveAttribute, setAttributeaddCloseFutureListener, close, close, close, getMaxCloseWaitTime, isClosed, isClosing, isOpen, removeCloseFutureListenersetUsernamegetUsernamecreateScpClient, createScpClient, createScpClientcreateSftpClient, createSftpClientgetUserAuthFactoriesNameList, getUserAuthFactoriesNames, setUserAuthFactoriesNameList, setUserAuthFactoriesNames, setUserAuthFactoriesNamesprotected AbstractClientSession(ClientFactoryManager factoryManager, IoSession ioSession)
public ClientFactoryManager getFactoryManager()
getFactoryManager in interface ClientSessiongetFactoryManager in interface FactoryManagerHoldergetFactoryManager in class AbstractSessionFactoryManagerpublic SocketAddress getConnectAddress()
ClientSessionSession.getIoSession() report of the
remote peergetConnectAddress in interface ClientSessionpublic void setConnectAddress(SocketAddress connectAddress)
public ServerKeyVerifier getServerKeyVerifier()
ClientAuthenticationManagergetServerKeyVerifier in interface ClientAuthenticationManagerServerKeyVerifier to use - never nullpublic void setServerKeyVerifier(ServerKeyVerifier serverKeyVerifier)
setServerKeyVerifier in interface ClientAuthenticationManagerpublic UserInteraction getUserInteraction()
getUserInteraction in interface ClientAuthenticationManagerUserInteraction object to communicate with the user
(may be null to indicate that no such communication is allowed)public void setUserInteraction(UserInteraction userInteraction)
setUserInteraction in interface ClientAuthenticationManagerpublic List<NamedFactory<UserAuth>> getUserAuthFactories()
getUserAuthFactories in interface ClientAuthenticationManagerList of UserAuth NamedFactory-ies - never
null/emptypublic void setUserAuthFactories(List<NamedFactory<UserAuth>> userAuthFactories)
setUserAuthFactories in interface ClientAuthenticationManagerpublic AuthenticationIdentitiesProvider getRegisteredIdentities()
getRegisteredIdentities in interface ClientAuthenticationManagerAuthenticationIdentitiesProvider to be used for attempting
password or public key authenticationpublic PasswordIdentityProvider getPasswordIdentityProvider()
ClientAuthenticationManagerPasswordIdentityProvider used to provide password
candidatesgetPasswordIdentityProvider in interface ClientAuthenticationManagerPasswordIdentityProvider instance - ignored if null
(i.e., no passwords available)public void setPasswordIdentityProvider(PasswordIdentityProvider provider)
setPasswordIdentityProvider in interface ClientAuthenticationManagerpublic ClientProxyConnector getClientProxyConnector()
getClientProxyConnector in interface ClientProxyConnectorHolderpublic void setClientProxyConnector(ClientProxyConnector proxyConnector)
setClientProxyConnector in interface ClientProxyConnectorHolderpublic void addPasswordIdentity(String password)
addPasswordIdentity in interface ClientAuthenticationManagerpassword - Password to be added - may not be null/empty.
Note: this password is in addition to whatever passwords
are available via the PasswordIdentityProvider (if any)public String removePasswordIdentity(String password)
removePasswordIdentity in interface ClientAuthenticationManagerpassword - The password to remove - ignored if null/emptyClientAuthenticationManager.addPasswordIdentity(String) - or null if no
match foundpublic void addPublicKeyIdentity(KeyPair kp)
addPublicKeyIdentity in interface ClientAuthenticationManagerkp - The KeyPair to add - may not be null
Note: this key is in addition to whatever keys
are available via the KeyIdentityProvider (if any)public KeyPair removePublicKeyIdentity(KeyPair kp)
removePublicKeyIdentity in interface ClientAuthenticationManagerkp - The KeyPair to remove - ignored if nullKeyPair - same one that was added via
ClientAuthenticationManager.addPublicKeyIdentity(KeyPair) - or null if no
match foundprotected IoWriteFuture sendClientIdentification() throws Exception
Exceptionpublic ClientChannel createChannel(String type) throws IOException
ClientSessioncreateChannel(type, null).createChannel in interface ClientSessiontype - The channel typeClientChannelIOException - If failed to create the requested channelpublic ClientChannel createChannel(String type, String subType) throws IOException
ClientSessioncreateChannel in interface ClientSessiontype - The channel typesubType - The channel sub-typeClientChannelIOException - If failed to create the requested channelpublic ChannelExec createExecChannel(String command) throws IOException
ClientSessioncreateExecChannel in interface ClientSessioncommand - The command to executeChannelExecIOException - If failed to create the requested channelpublic ChannelSubsystem createSubsystemChannel(String subsystem) throws IOException
ClientSessioncreateSubsystemChannel in interface ClientSessionsubsystem - The subsystem nameChannelSubsystemIOException - If failed to create the requested channelpublic ChannelDirectTcpip createDirectTcpipChannel(SshdSocketAddress local, SshdSocketAddress remote) throws IOException
ClientSessioncreateDirectTcpipChannel in interface ClientSessionlocal - The local addressremote - The remote addressChannelDirectTcpipIOException - If failed to create the requested channelprotected ClientUserAuthService getUserAuthService()
protected ConnectionService getConnectionService()
public ScpFileOpener getScpFileOpener()
getScpFileOpener in interface ScpFileOpenerHolderScpFileOpener set via call
to ScpFileOpenerHolder.setScpFileOpener(ScpFileOpener)public void setScpFileOpener(ScpFileOpener opener)
setScpFileOpener in interface ScpFileOpenerHolderopener - The default ScpFileOpener to use - if null
then a default opener is usedpublic ScpTransferEventListener getScpTransferEventListener()
getScpTransferEventListener in interface ScpClientCreatorScpTransferEventListener set via
ScpClientCreator.setScpTransferEventListener(ScpTransferEventListener)public void setScpTransferEventListener(ScpTransferEventListener listener)
setScpTransferEventListener in interface ScpClientCreatorlistener - A default ScpTransferEventListener that can be used
to receive information about the SCP operations - may be null
to indicate no more events are requiredScpClientCreator.createScpClient(ScpTransferEventListener)public ScpClient createScpClient(ScpFileOpener opener, ScpTransferEventListener listener)
ScpClientCreatorcreateScpClient in interface ScpClientCreatoropener - The ScpFileOpener to use to control how local files
are read/written. If null then a default opener is used.
Note: this opener is used instead of any instance
set via ScpFileOpenerHolder.setScpFileOpener(ScpFileOpener)listener - A ScpTransferEventListener that can be used
to receive information about the SCP operations - may be null
to indicate no more events are required. Note: this listener
is used instead of any listener set via ScpClientCreator.setScpTransferEventListener(ScpTransferEventListener)ScpClient instancepublic SftpClient createSftpClient(SftpVersionSelector selector) throws IOException
SftpClientCreatorcreateSftpClient in interface SftpClientCreatorselector - The SftpVersionSelector to use - Note:
if the server does not support versions re-negotiation then the
selector will be presented with only one "choice" - the
current versionSftpClientIOException - If failed to create the client or re-negotiatepublic FileSystem createSftpFileSystem() throws IOException
createSftpFileSystem in interface SftpClientCreatorIOExceptionpublic FileSystem createSftpFileSystem(int version) throws IOException
createSftpFileSystem in interface SftpClientCreatorIOExceptionpublic FileSystem createSftpFileSystem(SftpVersionSelector selector) throws IOException
createSftpFileSystem in interface SftpClientCreatorIOExceptionpublic FileSystem createSftpFileSystem(int version, int readBufferSize, int writeBufferSize) throws IOException
createSftpFileSystem in interface SftpClientCreatorIOExceptionpublic FileSystem createSftpFileSystem(int readBufferSize, int writeBufferSize) throws IOException
createSftpFileSystem in interface SftpClientCreatorIOExceptionpublic FileSystem createSftpFileSystem(SftpVersionSelector selector, int readBufferSize, int writeBufferSize) throws IOException
createSftpFileSystem in interface SftpClientCreatorIOExceptionpublic SshdSocketAddress startLocalPortForwarding(SshdSocketAddress local, SshdSocketAddress remote) throws IOException
PortForwardingManagerstartLocalPortForwarding in interface PortForwardingManagerlocal - The local addressremote - The remote addressSshdSocketAddressIOException - If failed to create the requested bindingpublic void stopLocalPortForwarding(SshdSocketAddress local) throws IOException
PortForwardingManagerstopLocalPortForwarding in interface PortForwardingManagerlocal - The local addressIOException - If failed to cancel the requested bindingpublic SshdSocketAddress startRemotePortForwarding(SshdSocketAddress remote, SshdSocketAddress local) throws IOException
PortForwardingManagerStart forwarding tcpip from the given address on the server to the given address on the client.
The remote host name is the address to bind to on the server:startRemotePortForwarding in interface PortForwardingManagerremote - The remote addresslocal - The local addressSshdSocketAddressIOException - If failed to create the requested bindingpublic void stopRemotePortForwarding(SshdSocketAddress remote) throws IOException
PortForwardingManagerstopRemotePortForwarding in interface PortForwardingManagerremote - The remote addressIOException - If failed to cancel the requested bindingpublic SshdSocketAddress startDynamicPortForwarding(SshdSocketAddress local) throws IOException
PortForwardingManagerstartDynamicPortForwarding in interface PortForwardingManagerlocal - The local addressSshdSocketAddressIOException - If failed to create the requested bindingpublic void stopDynamicPortForwarding(SshdSocketAddress local) throws IOException
PortForwardingManagerstopDynamicPortForwarding in interface PortForwardingManagerlocal - The local addressIOException - If failed to cancel the requested bindingprotected TcpipForwarder getTcpipForwarder()
protected String resolveAvailableSignaturesProposal(FactoryManager manager)
resolveAvailableSignaturesProposal in class AbstractSessionmanager - The FactoryManagernull/empty if no proposalpublic void startService(String name) throws Exception
startService in interface Sessionname - Service nameException - If failed to start itpublic ChannelShell createShellChannel() throws IOException
ClientSessioncreateShellChannel in interface ClientSessionChannelShellIOException - If failed to create the requested channelprotected boolean readIdentification(Buffer buffer) throws IOException
AbstractSessionAbstractSession.doReadIdentification(Buffer, boolean) and
store the result in the needed property.readIdentification in class AbstractSessionbuffer - The Buffer containing the remote identificationtrue if the identification has been fully read or
false if more data is neededIOException - if an error occurs such as a bad protocol versionprotected void signalExtraServerVersionInfo(List<String> lines) throws IOException
IOExceptionprotected byte[] sendKexInit(Map<KexProposalOption,String> proposal) throws IOException
AbstractSessionsendKexInit in class AbstractSessionproposal - our proposal for key exchange negotiationIOException - if an error occurred sending the packetprotected void setKexSeed(byte... seed)
setKexSeed in class AbstractSessionseed - The result of the KEXINIT handshake - required for correct
session key establishmentprotected void receiveKexInit(Map<KexProposalOption,String> proposal, byte[] seed) throws IOException
receiveKexInit in class AbstractSessionIOExceptionprotected void checkKeys()
throws SshException
AbstractSessioncheckKeys in class AbstractSessionSshExceptionpublic KeyExchangeFuture switchToNoneCipher() throws IOException
ClientSessionSwitch to a none cipher for performance.
This should be done after the authentication phase has been performed. After such a switch, interactive channels are not allowed anymore. Both client and server must have been configured to support the none cipher. If that's not the case, the returned future will be set with an exception.
switchToNoneCipher in interface ClientSessionKeyExchangeFuture that can be used to wait for the exchange
to be finishedIOException - if a key exchange is already runningCopyright © 2008–2017 The Apache Software Foundation. All rights reserved.