public abstract class AbstractClientSession extends AbstractSession implements ClientSession
ClientSession
related methodsAbstractCloseable.State
ClientSession.ClientSessionEvent
Session.TimeoutStatus
AttributeRepository.AttributeKey<T>
channelListenerProxy, channelListeners, clientProposal, clientVersion, currentService, decodeLock, decoderBuffer, decoderLength, decoderState, encodeLock, firstKexPacketFollows, ignorePacketDataLength, ignorePacketsCount, ignorePacketsFrequency, ignorePacketsVariance, inBlocksCount, inBytesCount, inCipher, inCipherSize, inCompression, inMac, inMacResult, inPacketsCount, 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, tunnelListenerProxy, tunnelListeners, uncompressBuffer
closeFuture, lock, state
log
REMOTE_COMMAND_WAIT_EVENTS
DEFAULT_SSH_VERSION_PREFIX, FALLBACK_SSH_VERSION_PREFIX, MAX_VERSION_LINE_LENGTH
EMPTY
NONE
CLOSE_WAIT_TIMEOUT, DEFAULT_CLOSE_WAIT_TIMEOUT
DEFAULT_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.
|
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.
|
AttributeRepository |
getConnectionContext() |
protected ConnectionService |
getConnectionService() |
ClientFactoryManager |
getFactoryManager() |
protected ForwardingFilter |
getForwardingFilter() |
KeyIdentityProvider |
getKeyIdentityProvider() |
PasswordIdentityProvider |
getPasswordIdentityProvider()
Retrieve
PasswordIdentityProvider used to provide password
candidates |
AuthenticationIdentitiesProvider |
getRegisteredIdentities() |
ServerKeyVerifier |
getServerKeyVerifier()
Retrieve the server key verifier to be used to check the key when connecting
to an SSH server.
|
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 |
setKeyIdentityProvider(KeyIdentityProvider keyIdentityProvider) |
void |
setPasswordIdentityProvider(PasswordIdentityProvider provider) |
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, checkRekey, comparePreferredKexProposalOption, createBuffer, decode, doHandleMessage, doWritePacket, encode, getChannelListenerProxy, getCipherInformation, getClientKexData, getClientVersion, getCompressionInformation, getInnerCloseable, getKex, getMacInformation, getNegotiatedKexParameter, getPortForwardingEventListenerProxy, getServerKexData, getServerVersion, getService, getServices, getSession, getSession, getSessionId, getSessionListenerProxy, handleFirstKexPacketFollows, handleKexInit, handleKexMessage, handleMessage, handleNewKeys, handleServiceAccept, handleServiceAccept, handleServiceRequest, handleServiceRequest, isRekeyBlocksCountExceeded, isRekeyDataSizeExceeded, isRekeyPacketCountsExceeded, isRekeyRequired, isRekeyTimeIntervalExceeded, messageReceived, negotiate, notImplemented, preClose, prepareBuffer, receiveKexInit, receiveKexInit, receiveNewKeys, reExchangeKeys, refreshConfiguration, removeChannelListener, removePortForwardingEventListener, removeSessionListener, request, requestFailure, requestNewKeysExchange, requestSuccess, resolveAvailableSignaturesProposal, resolveIgnoreBufferDataLength, sendKexInit, sendPendingPackets, setClientKexData, setNegotiationResult, setServerKexData, validateKexState, validateTargetBuffer, writePacket
attributeKeys, calculateNextIgnorePacketCount, checkAuthenticationTimeout, checkForTimeouts, checkIdleTimeout, clearAttributes, computeAttributeIfAbsent, createProposal, disconnect, doReadIdentification, exceptionCaught, getAttribute, getAttributesCount, getAuthTimeout, getAuthTimeoutStart, getBoundLocalPortForward, getBoundRemotePortForward, getChannelStreamPacketWriterResolver, getIdleTimeout, getIdleTimeoutStart, getIoSession, getLocalForwardsBindings, getLock, getParentPropertyResolver, getProperties, getRemoteForwardsBindings, getReservedSessionMessagesHandler, getStartedLocalPortForwards, getStartedRemotePortForwards, getTimeoutStatus, getUnknownChannelReferenceHandler, getUsername, handleDebug, handleDisconnect, handleDisconnect, handleIgnore, handleUnimplemented, invokeSessionSignaller, isAuthenticated, isLocalPortForwardingStartedForPort, isRemotePortForwardingStartedForPort, isServerSession, mergeProposals, removeAttribute, resetAuthTimeout, resetIdleTimeout, resizeKey, resolveChannelStreamPacketWriterResolver, resolveIdentificationString, resolvePeerAddress, resolveReservedSessionMessagesHandler, resolveUnknownChannelReferenceHandler, sendDebugMessage, sendIdentification, sendIgnoreMessage, sendNewKeys, sendNotImplemented, setAttribute, setAuthenticated, setChannelStreamPacketWriterResolver, setReservedSessionMessagesHandler, setUnknownChannelReferenceHandler, setUsername, signalDisconnect, signalDisconnect, signalExceptionCaught, signalExceptionCaught, signalNegotiationEnd, signalNegotiationEnd, signalNegotiationStart, signalNegotiationStart, signalSessionClosed, signalSessionClosed, signalSessionCreated, signalSessionCreated, signalSessionEvent, signalSessionEvent, toString, writePacket
getCipherFactories, getCompressionFactories, getDelegate, getKeyExchangeFactories, getMacFactories, getSignatureFactories, resolveEffectiveFactories, resolveEffectiveProvider, setCipherFactories, setCompressionFactories, setKeyExchangeFactories, setMacFactories, setSignatureFactories
doCloseGracefully, doCloseImmediately
addCloseFutureListener, builder, close, isClosed, isClosing, removeCloseFutureListener
getSimplifiedLogger
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
auth, createDynamicPortForwardingTracker, createLocalPortForwardingTracker, createRemotePortForwardingTracker, executeRemoteCommand, executeRemoteCommand, executeRemoteCommand, getMetadataMap, passwordIteratorOf, providerOf, waitFor
createBuffer, createBuffer, disconnect, exceptionCaught, getAuthTimeout, getAuthTimeoutStart, getCipherInformation, getCompressionInformation, getIdleTimeout, getIdleTimeoutStart, getIoSession, getKex, getLocalAddress, getMacInformation, getNegotiatedKexParameter, getRemoteAddress, getService, getTimeoutStatus, prepareBuffer, reExchangeKeys, request, resetAuthTimeout, resetIdleTimeout, resolveAttribute, resolveAttribute, sendDebugMessage, sendIgnoreMessage, setAuthenticated, writePacket
getClientVersion, getServerVersion, getSessionId, isAuthenticated, isValidVersionPrefix
getBoolean, getBooleanProperty, getInteger, getIntProperty, getLong, getLongProperty, getObject, getParentPropertyResolver, getProperties, getString, getStringProperty
clearAttributes, computeAttributeIfAbsent, removeAttribute, setAttribute
attributeKeys, getAttribute, getAttributesCount, ofAttributesMap, ofKeyValuePair
setUsername
getUsername
getCipherFactories, getCipherFactoriesNameList, getCipherFactoriesNames, getCompressionFactories, getCompressionFactoriesNameList, getCompressionFactoriesNames, getKeyExchangeFactories, getMacFactories, getMacFactoriesNameList, getMacFactoriesNames, setCipherFactories, setCipherFactoriesNameList, setCipherFactoriesNames, setCipherFactoriesNames, setCompressionFactories, setCompressionFactoriesNameList, setCompressionFactoriesNames, setCompressionFactoriesNames, setKeyExchangeFactories, setMacFactories, setMacFactoriesNameList, setMacFactoriesNames, setMacFactoriesNames
getSignatureFactories, getSignatureFactories, getSignatureFactoriesNameList, getSignatureFactoriesNames, resolveSignatureFactories, setSignatureFactories, setSignatureFactoriesNameList, setSignatureFactoriesNames, setSignatureFactoriesNames
addSessionListener, getSessionListenerProxy, removeSessionListener
getReservedSessionMessagesHandler, setReservedSessionMessagesHandler
addChannelListener, getChannelListenerProxy, removeChannelListener
getChannelStreamPacketWriterResolver, resolveChannelStreamPacketWriter, resolveChannelStreamPacketWriterResolver, setChannelStreamPacketWriterResolver
addPortForwardingEventListener, getPortForwardingEventListenerProxy, removePortForwardingEventListener
getUnknownChannelReferenceHandler, resolveUnknownChannelReferenceHandler, setUnknownChannelReferenceHandler
writePacket
addCloseFutureListener, close, close, close, getMaxCloseWaitTime, isClosed, isClosing, isOpen, removeCloseFutureListener
getUserAuthFactoriesNameList, getUserAuthFactoriesNames, setUserAuthFactoriesNameList, setUserAuthFactoriesNames, setUserAuthFactoriesNames
getBoundLocalPortForward, getBoundRemotePortForward, getLocalForwardsBindings, getRemoteForwardsBindings, getStartedLocalPortForwards, getStartedRemotePortForwards, isLocalPortForwardingStartedForPort, isRemotePortForwardingStartedForPort
protected AbstractClientSession(ClientFactoryManager factoryManager, IoSession ioSession)
public AttributeRepository getConnectionContext()
getConnectionContext
in interface ClientSession
null
if none.public ClientFactoryManager getFactoryManager()
getFactoryManager
in interface ClientSession
getFactoryManager
in interface FactoryManagerHolder
getFactoryManager
in class SessionHelper
FactoryManager
public SocketAddress getConnectAddress()
ClientSession
Session.getIoSession()
report of the
remote peergetConnectAddress
in interface ClientSession
public void setConnectAddress(SocketAddress connectAddress)
public ServerKeyVerifier getServerKeyVerifier()
ClientAuthenticationManager
getServerKeyVerifier
in interface ClientAuthenticationManager
ServerKeyVerifier
to use - never null
public void setServerKeyVerifier(ServerKeyVerifier serverKeyVerifier)
setServerKeyVerifier
in interface ClientAuthenticationManager
public UserInteraction getUserInteraction()
getUserInteraction
in interface ClientAuthenticationManager
UserInteraction
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 ClientAuthenticationManager
public List<NamedFactory<UserAuth>> getUserAuthFactories()
getUserAuthFactories
in interface ClientAuthenticationManager
List
of UserAuth
NamedFactory
-ies - never
null
/emptypublic void setUserAuthFactories(List<NamedFactory<UserAuth>> userAuthFactories)
setUserAuthFactories
in interface ClientAuthenticationManager
public AuthenticationIdentitiesProvider getRegisteredIdentities()
getRegisteredIdentities
in interface ClientAuthenticationManager
AuthenticationIdentitiesProvider
to be used for attempting
password or public key authenticationpublic PasswordIdentityProvider getPasswordIdentityProvider()
ClientAuthenticationManager
PasswordIdentityProvider
used to provide password
candidatesgetPasswordIdentityProvider
in interface ClientAuthenticationManager
PasswordIdentityProvider
instance - ignored if null
(i.e., no passwords available).ClientAuthenticationManager.addPasswordIdentity(String)
public void setPasswordIdentityProvider(PasswordIdentityProvider provider)
setPasswordIdentityProvider
in interface ClientAuthenticationManager
public KeyIdentityProvider getKeyIdentityProvider()
getKeyIdentityProvider
in interface KeyIdentityProviderHolder
KeyIdentityProvider
used to provide key-pair(s)
for public key authenticationpublic void setKeyIdentityProvider(KeyIdentityProvider keyIdentityProvider)
setKeyIdentityProvider
in interface KeyIdentityProviderHolder
public ClientProxyConnector getClientProxyConnector()
getClientProxyConnector
in interface ClientProxyConnectorHolder
public void setClientProxyConnector(ClientProxyConnector proxyConnector)
setClientProxyConnector
in interface ClientProxyConnectorHolder
public void addPasswordIdentity(String password)
addPasswordIdentity
in interface ClientAuthenticationManager
password
- 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 ClientAuthenticationManager
password
- The password to remove - ignored if null
/emptyClientAuthenticationManager.addPasswordIdentity(String)
- or null
if no
match foundpublic void addPublicKeyIdentity(KeyPair kp)
addPublicKeyIdentity
in interface ClientAuthenticationManager
kp
- 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 ClientAuthenticationManager
kp
- The KeyPair
to remove - ignored if null
KeyPair
- same one that was added via
ClientAuthenticationManager.addPublicKeyIdentity(KeyPair)
- or null
if no
match foundprotected IoWriteFuture sendClientIdentification() throws Exception
Exception
public ClientChannel createChannel(String type) throws IOException
ClientSession
createChannel(type, null)
.createChannel
in interface ClientSession
type
- The channel typeClientChannel
IOException
- If failed to create the requested channelpublic ClientChannel createChannel(String type, String subType) throws IOException
ClientSession
createChannel
in interface ClientSession
type
- The channel typesubType
- The channel sub-typeClientChannel
IOException
- If failed to create the requested channelpublic ChannelExec createExecChannel(String command) throws IOException
ClientSession
createExecChannel
in interface ClientSession
command
- The command to executeChannelExec
IOException
- If failed to create the requested channelpublic ChannelSubsystem createSubsystemChannel(String subsystem) throws IOException
ClientSession
createSubsystemChannel
in interface ClientSession
subsystem
- The subsystem nameChannelSubsystem
IOException
- If failed to create the requested channelpublic ChannelDirectTcpip createDirectTcpipChannel(SshdSocketAddress local, SshdSocketAddress remote) throws IOException
ClientSession
createDirectTcpipChannel
in interface ClientSession
local
- The local addressremote
- The remote addressChannelDirectTcpip
IOException
- If failed to create the requested channelprotected ClientUserAuthService getUserAuthService()
protected ConnectionService getConnectionService()
getConnectionService
in class SessionHelper
public SshdSocketAddress startLocalPortForwarding(SshdSocketAddress local, SshdSocketAddress remote) throws IOException
PortForwardingManager
startLocalPortForwarding
in interface PortForwardingManager
local
- The local addressremote
- The remote addressSshdSocketAddress
IOException
- If failed to create the requested bindingpublic void stopLocalPortForwarding(SshdSocketAddress local) throws IOException
PortForwardingManager
stopLocalPortForwarding
in interface PortForwardingManager
local
- The local addressIOException
- If failed to cancel the requested bindingpublic SshdSocketAddress startRemotePortForwarding(SshdSocketAddress remote, SshdSocketAddress local) throws IOException
PortForwardingManager
Start 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 PortForwardingManager
remote
- The remote addresslocal
- The local addressSshdSocketAddress
IOException
- If failed to create the requested bindingpublic void stopRemotePortForwarding(SshdSocketAddress remote) throws IOException
PortForwardingManager
stopRemotePortForwarding
in interface PortForwardingManager
remote
- The remote addressIOException
- If failed to cancel the requested bindingpublic SshdSocketAddress startDynamicPortForwarding(SshdSocketAddress local) throws IOException
PortForwardingManager
startDynamicPortForwarding
in interface PortForwardingManager
local
- The local addressSshdSocketAddress
IOException
- If failed to create the requested bindingpublic void stopDynamicPortForwarding(SshdSocketAddress local) throws IOException
PortForwardingManager
stopDynamicPortForwarding
in interface PortForwardingManager
local
- The local addressIOException
- If failed to cancel the requested bindingprotected ForwardingFilter getForwardingFilter()
getForwardingFilter
in class SessionHelper
protected String resolveAvailableSignaturesProposal(FactoryManager manager)
resolveAvailableSignaturesProposal
in class AbstractSession
manager
- The FactoryManager
null
/empty if no proposalpublic void startService(String name) throws Exception
startService
in interface Session
name
- Service nameException
- If failed to start itpublic ChannelShell createShellChannel() throws IOException
ClientSession
createShellChannel
in interface ClientSession
ChannelShell
IOException
- If failed to create the requested channelprotected boolean readIdentification(Buffer buffer) throws IOException
AbstractSession
SessionHelper.doReadIdentification(Buffer, boolean)
and
store the result in the needed property.readIdentification
in class AbstractSession
buffer
- 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
IOException
protected byte[] sendKexInit(Map<KexProposalOption,String> proposal) throws IOException
AbstractSession
sendKexInit
in class AbstractSession
proposal
- our proposal for key exchange negotiationIOException
- if an error occurred sending the packetprotected void setKexSeed(byte... seed)
setKexSeed
in class AbstractSession
seed
- 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 AbstractSession
IOException
protected void checkKeys() throws SshException
AbstractSession
checkKeys
in class AbstractSession
SshException
public KeyExchangeFuture switchToNoneCipher() throws IOException
ClientSession
Switch 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 ClientSession
KeyExchangeFuture
that can be used to wait for the exchange
to be finishedIOException
- if a key exchange is already runningCopyright © 2008–2022 The Apache Software Foundation. All rights reserved.