public abstract class SessionHelper extends AbstractKexFactoryManager implements Session
AbstractSession class smallerAbstractCloseable.StateSessionHeartbeatController.HeartbeatTypeAttributeRepository.AttributeKey<T>| Modifier and Type | Field and Description |
|---|---|
private java.util.Map<AttributeRepository.AttributeKey<?>,java.lang.Object> |
attributes
Session specific attributes
|
private boolean |
authed
Boolean indicating if this session has been authenticated or not
|
protected java.time.Instant |
authStart |
private ChannelStreamWriterResolver |
channelStreamPacketWriterResolver |
protected java.time.Instant |
idleStart |
protected java.util.Map<KexProposalOption,java.lang.String> |
initialKexProposal
Stores the initial KEX proposal after it has been run through the hooks allowing client code to modify it; see
getKexProposal(). |
private IoSession |
ioSession
The underlying network session
|
private java.util.Map<java.lang.String,java.lang.Object> |
properties
The session specific properties
|
private ReservedSessionMessagesHandler |
reservedSessionMessagesHandler |
private boolean |
serverSession
Client or server side
|
private SessionDisconnectHandler |
sessionDisconnectHandler |
private java.util.concurrent.atomic.AtomicReference<TimeoutIndicator> |
timeoutStatus |
private UnknownChannelReferenceHandler |
unknownChannelReferenceHandler |
private java.lang.String |
username
The name of the authenticated user
|
closeFuture, futureLock, statelogDEFAULT_SSH_VERSION_PREFIX, FALLBACK_SSH_VERSION_PREFIX, MAX_VERSION_LINE_LENGTHEMPTYNONE| Modifier | Constructor and Description |
|---|---|
protected |
SessionHelper(boolean serverSession,
FactoryManager factoryManager,
IoSession ioSession)
Create a new session.
|
| Modifier and Type | Method and Description |
|---|---|
java.util.Collection<AttributeRepository.AttributeKey<?>> |
attributeKeys() |
protected long |
calculateNextIgnorePacketCount(Random r,
long freq,
int variance) |
protected TimeoutIndicator |
checkAuthenticationTimeout(java.time.Instant now,
java.time.Duration authTimeout)
Checks if authentication timeout expired
|
protected TimeoutIndicator |
checkForTimeouts()
Checks whether the session has timed out (both authentication and idle timeouts are checked).
|
protected TimeoutIndicator |
checkIdleTimeout(java.time.Instant now,
java.time.Duration idleTimeout)
Checks if idle timeout expired
|
void |
clearAttributes()
Removes all currently stored user-defined attributes
|
<T> T |
computeAttributeIfAbsent(AttributeRepository.AttributeKey<T> key,
java.util.function.Function<? super AttributeRepository.AttributeKey<T>,? extends T> resolver)
If the specified key is not already associated with a value (or is mapped to
null), attempts to compute
its value using the given mapping function and enters it into this map unless null. |
protected java.util.Map<KexProposalOption,java.lang.String> |
createProposal(java.lang.String hostKeyTypes)
Create our proposal for SSH negotiation
|
void |
disconnect(int reason,
java.lang.String msg)
Send a disconnect packet with the given reason and message.
|
protected void |
doInvokeDebugMessageHandler(Buffer buffer)
Invoked by
handleDebug(Buffer) after validating that the buffer structure seems well-formed and also
resetting the idle timeout. |
protected void |
doInvokeIgnoreMessageHandler(Buffer buffer)
Invoked by
handleDebug(Buffer) after validating that the buffer structure seems well-formed and also
resetting the idle timeout. |
protected boolean |
doInvokeUnimplementedMessageHandler(int cmd,
Buffer buffer) |
protected java.util.List<java.lang.String> |
doReadIdentification(Buffer buffer,
boolean server)
Read the remote identification from this buffer.
|
void |
exceptionCaught(java.lang.Throwable t)
Handle any exceptions that occurred on this session.
|
<T> T |
getAttribute(AttributeRepository.AttributeKey<T> key)
Returns the value of the user-defined attribute.
|
int |
getAttributesCount() |
java.time.Duration |
getAuthTimeout() |
java.time.Instant |
getAuthTimeoutStart() |
java.util.List<SshdSocketAddress> |
getBoundLocalPortForwards(int port) |
SshdSocketAddress |
getBoundRemotePortForward(int port) |
ChannelStreamWriterResolver |
getChannelStreamWriterResolver() |
protected abstract ConnectionService |
getConnectionService() |
FactoryManager |
getFactoryManager() |
protected Forwarder |
getForwarder() |
java.time.Duration |
getIdleTimeout() |
java.time.Instant |
getIdleTimeoutStart() |
IoSession |
getIoSession() |
protected java.util.Map<KexProposalOption,java.lang.String> |
getKexProposal()
Retrieves this side's initial proposal for KEX negotiation.
|
java.util.List<java.util.Map.Entry<SshdSocketAddress,SshdSocketAddress>> |
getLocalForwardsBindings() |
PropertyResolver |
getParentPropertyResolver() |
java.util.Map<java.lang.String,java.lang.Object> |
getProperties()
A map of properties that can be used to configure the SSH server or client.
|
java.util.List<java.util.Map.Entry<java.lang.Integer,SshdSocketAddress>> |
getRemoteForwardsBindings() |
ReservedSessionMessagesHandler |
getReservedSessionMessagesHandler() |
SessionDisconnectHandler |
getSessionDisconnectHandler() |
java.util.List<SshdSocketAddress> |
getStartedLocalPortForwards() |
java.util.NavigableSet<java.lang.Integer> |
getStartedRemotePortForwards() |
TimeoutIndicator |
getTimeoutStatus()
Check if timeout has occurred.
|
UnknownChannelReferenceHandler |
getUnknownChannelReferenceHandler() |
java.lang.String |
getUsername() |
protected void |
handleDebug(Buffer buffer) |
protected void |
handleDisconnect(Buffer buffer) |
protected void |
handleDisconnect(int code,
java.lang.String msg,
java.lang.String lang,
Buffer buffer) |
protected void |
handleIgnore(Buffer buffer) |
protected void |
handleUnimplemented(Buffer buffer) |
protected void |
invokeSessionSignaller(Invoker<SessionListener,java.lang.Void> invoker) |
boolean |
isAuthenticated() |
boolean |
isLocalPortForwardingStartedForPort(int port)
Test if local port forwarding is started
|
boolean |
isRemotePortForwardingStartedForPort(int port)
Test if remote port forwarding is started
|
boolean |
isServerSession()
Quick indication if this is a server or client session (instead of having to ask
instanceof). |
protected java.util.Map<KexProposalOption,java.lang.String> |
mergeProposals(java.util.Map<KexProposalOption,java.lang.String> current,
java.util.Map<KexProposalOption,java.lang.String> proposal) |
protected Buffer |
preProcessEncodeBuffer(int cmd,
Buffer buffer)
Invoked by the session before encoding the buffer in order to make sure that it is at least of size
SSH_PACKET_HEADER_LEN. |
<T> T |
removeAttribute(AttributeRepository.AttributeKey<T> key)
Removes the user-defined attribute
|
java.time.Instant |
resetAuthTimeout()
Re-start the authentication timeout timer
|
java.time.Instant |
resetIdleTimeout()
Re-start idle timeout timer
|
protected byte[] |
resizeKey(byte[] e,
int kdfSize,
Digest hash,
byte[] k,
byte[] h)
Method used while putting new keys into use that will resize the key used to initialize the cipher to the needed
length.
|
protected java.lang.String |
resolveAvailableSignaturesProposal()
Computes the list of available host key signature algorithms supported.
|
protected abstract java.lang.String |
resolveAvailableSignaturesProposal(FactoryManager manager)
Computes the list of available host key signature algorithms supported.
|
ChannelStreamWriterResolver |
resolveChannelStreamWriterResolver() |
protected java.lang.String |
resolveIdentificationString(java.lang.String configPropName)
Resolves the identification to send to the peer session by consulting the associated
FactoryManager. |
protected java.net.SocketAddress |
resolvePeerAddress(java.net.SocketAddress knownAddress) |
protected ReservedSessionMessagesHandler |
resolveReservedSessionMessagesHandler() |
protected java.lang.String |
resolveSessionKexProposal(java.lang.String hostKeyTypes) |
UnknownChannelReferenceHandler |
resolveUnknownChannelReferenceHandler()
Check if current manager has a specific handler set for it - if not, try and resolve one from the
"parent" container (if any)
|
IoWriteFuture |
sendDebugMessage(boolean display,
java.lang.Object msg,
java.lang.String lang)
Sends an
SSH_MSG_DEBUG to the peer session |
protected IoWriteFuture |
sendIdentification(java.lang.String version,
java.util.List<java.lang.String> extraLines)
Send our identification.
|
IoWriteFuture |
sendIgnoreMessage(byte... data)
Sends an
SSH_MSG_IGNORE to the peer session |
protected IoWriteFuture |
sendNotImplemented(long seqNoValue)
Sends a
SSH_MSG_UNIMPLEMENTED message |
<T> T |
setAttribute(AttributeRepository.AttributeKey<T> key,
T value)
Sets a user-defined attribute.
|
void |
setAuthenticated() |
void |
setChannelStreamWriterResolver(ChannelStreamWriterResolver resolver) |
void |
setReservedSessionMessagesHandler(ReservedSessionMessagesHandler handler) |
void |
setSessionDisconnectHandler(SessionDisconnectHandler sessionDisconnectHandler) |
void |
setUnknownChannelReferenceHandler(UnknownChannelReferenceHandler unknownChannelReferenceHandler) |
void |
setUsername(java.lang.String username) |
protected void |
signalDisconnect(int code,
java.lang.String msg,
java.lang.String lang,
boolean initiator) |
protected void |
signalDisconnect(SessionListener listener,
int code,
java.lang.String msg,
java.lang.String lang,
boolean initiator) |
protected void |
signalExceptionCaught(SessionListener listener,
java.lang.Throwable t) |
protected void |
signalExceptionCaught(java.lang.Throwable t) |
protected void |
signalNegotiationEnd(java.util.Map<KexProposalOption,java.lang.String> c2sOptions,
java.util.Map<KexProposalOption,java.lang.String> s2cOptions,
java.util.Map<KexProposalOption,java.lang.String> negotiatedGuess,
java.lang.Throwable reason) |
protected void |
signalNegotiationEnd(SessionListener listener,
java.util.Map<KexProposalOption,java.lang.String> c2sOptions,
java.util.Map<KexProposalOption,java.lang.String> s2cOptions,
java.util.Map<KexProposalOption,java.lang.String> negotiatedGuess,
java.lang.Throwable reason) |
protected void |
signalNegotiationOptionsCreated(java.util.Map<KexProposalOption,java.lang.String> proposal) |
protected void |
signalNegotiationOptionsCreated(SessionListener listener,
java.util.Map<KexProposalOption,java.lang.String> proposal) |
protected void |
signalNegotiationStart(java.util.Map<KexProposalOption,java.lang.String> c2sOptions,
java.util.Map<KexProposalOption,java.lang.String> s2cOptions) |
protected void |
signalNegotiationStart(SessionListener listener,
java.util.Map<KexProposalOption,java.lang.String> c2sOptions,
java.util.Map<KexProposalOption,java.lang.String> s2cOptions) |
protected void |
signalPeerIdentificationReceived(SessionListener listener,
java.lang.String version,
java.util.List<java.lang.String> extraLines) |
protected void |
signalPeerIdentificationReceived(java.lang.String version,
java.util.List<java.lang.String> extraLines) |
protected void |
signalReadPeerIdentificationLine(SessionListener listener,
java.lang.String version,
java.util.List<java.lang.String> extraLines) |
protected void |
signalReadPeerIdentificationLine(java.lang.String line,
java.util.List<java.lang.String> extraLines) |
protected void |
signalSendIdentification(SessionListener listener,
java.lang.String version,
java.util.List<java.lang.String> extraLines) |
protected void |
signalSendIdentification(java.lang.String version,
java.util.List<java.lang.String> extraLines) |
protected void |
signalSessionClosed() |
protected void |
signalSessionClosed(SessionListener listener) |
protected void |
signalSessionCreated(IoSession ioSession) |
protected void |
signalSessionCreated(SessionListener listener) |
protected void |
signalSessionEstablished(IoSession ioSession) |
protected void |
signalSessionEstablished(SessionListener listener) |
protected void |
signalSessionEvent(SessionListener.Event event)
Sends a session event to all currently registered session listeners
|
protected void |
signalSessionEvent(SessionListener listener,
SessionListener.Event event) |
java.lang.String |
toString() |
getCipherFactories, getCompressionFactories, getDelegate, getKexExtensionHandler, getKeyExchangeFactories, getMacFactories, getSignatureFactories, resolveEffectiveFactories, resolveEffectiveProvider, setCipherFactories, setCompressionFactories, setKexExtensionHandler, setKeyExchangeFactories, setMacFactories, setSignatureFactoriesdoCloseGracefully, doCloseImmediately, getInnerCloseableaddCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, preClose, removeCloseFutureListenerdebug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warnclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitcreateBuffer, createBuffer, getKex, getLocalAddress, getRemoteAddress, getService, prepareBuffer, reExchangeKeys, request, request, request, request, resolveAttribute, resolveAttribute, startService, writePacket, writePacket, writePacket, writePacketgetCipherInformation, getClientKexProposals, getClientVersion, getCompressionInformation, getKexNegotiationResult, getKexState, getMacInformation, getNegotiatedKexParameter, getServerKexProposals, getServerVersion, getSessionId, isDataIntegrityTransport, isSecureSessionTransport, isValidSessionPayloadSize, isValidVersionPrefix, validateSessionPayloadSizedisableSessionHeartbeat, getSessionHeartbeatInterval, getSessionHeartbeatType, setSessionHeartbeat, setSessionHeartbeatgetBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getString, getStringProperty, isEmpty, isEmptyofAttributesMap, ofKeyValuePairaddCloseFutureListener, close, close, close, getMaxCloseWaitTime, isClosed, isClosing, isOpen, removeCloseFutureListenergetCipherFactories, getCipherFactoriesNameList, getCipherFactoriesNames, getCompressionFactories, getCompressionFactoriesNameList, getCompressionFactoriesNames, getKeyExchangeFactories, getMacFactories, getMacFactoriesNameList, getMacFactoriesNames, setCipherFactories, setCipherFactoriesNameList, setCipherFactoriesNames, setCipherFactoriesNames, setCompressionFactories, setCompressionFactoriesNameList, setCompressionFactoriesNames, setCompressionFactoriesNames, setKeyExchangeFactories, setMacFactories, setMacFactoriesNameList, setMacFactoriesNames, setMacFactoriesNamesgetSignatureFactories, resolveSignatureFactories, setSignatureFactories, setSignatureFactoriesNameList, setSignatureFactoriesNames, setSignatureFactoriesNamesgetSignatureFactories, getSignatureFactoriesNameList, getSignatureFactoriesNamesgetKexExtensionHandler, setKexExtensionHandleraddSessionListener, getSessionListenerProxy, removeSessionListeneraddChannelListener, getChannelListenerProxy, removeChannelListenerresolveChannelStreamWriteraddPortForwardingEventListener, getPortForwardingEventListenerProxy, removePortForwardingEventListenerprotected java.time.Instant authStart
protected java.time.Instant idleStart
protected java.util.Map<KexProposalOption,java.lang.String> initialKexProposal
getKexProposal(). The same proposal is then used for the initial KEX and for any re-KEX.private final boolean serverSession
private final IoSession ioSession
private final java.util.Map<java.lang.String,java.lang.Object> properties
private final java.util.Map<AttributeRepository.AttributeKey<?>,java.lang.Object> attributes
private final java.util.concurrent.atomic.AtomicReference<TimeoutIndicator> timeoutStatus
private ReservedSessionMessagesHandler reservedSessionMessagesHandler
private SessionDisconnectHandler sessionDisconnectHandler
private UnknownChannelReferenceHandler unknownChannelReferenceHandler
private ChannelStreamWriterResolver channelStreamPacketWriterResolver
private volatile java.lang.String username
private volatile boolean authed
protected SessionHelper(boolean serverSession,
FactoryManager factoryManager,
IoSession ioSession)
serverSession - true if this is a server session, false if client onefactoryManager - the factory managerioSession - the underlying I/O sessionpublic IoSession getIoSession()
getIoSession in interface SessionIoSession associated to this sessionpublic boolean isServerSession()
SessionContextinstanceof).isServerSession in interface SessionContexttrue if this is a server sessionpublic FactoryManager getFactoryManager()
getFactoryManager in interface FactoryManagerHolderFactoryManagerpublic PropertyResolver getParentPropertyResolver()
getParentPropertyResolver in interface PropertyResolvernull if no parentpublic java.util.Map<java.lang.String,java.lang.Object> getProperties()
PropertyResolverA map of properties that can be used to configure the SSH server or client. This map will never be changed by either the server or client and is not supposed to be changed at runtime (changes are not bound to have any effect on a running client or server), though it may affect the creation of sessions later as these values are usually not cached.
Note: the type of the mapped property should match the expected configuration value type -
Long, Integer, Boolean,
String, etc.... If it doesn't, the toString() result of the mapped value is used to convert it to the
required type. E.g., if the mapped value is the string "1234" and the expected value is a
long then it will be parsed into one. Also, if the mapped value is an Integer but a long
is expected, then it will be converted into one.
getProperties in interface PropertyResolverMap containing configuration values, never null. Note: may be
immutable.public int getAttributesCount()
getAttributesCount in interface AttributeRepositorypublic <T> T getAttribute(AttributeRepository.AttributeKey<T> key)
AttributeRepositorygetAttribute in interface AttributeRepositoryT - The generic attribute typekey - The key of the attribute; must not be null.null if there is no value associated with the specified keypublic java.util.Collection<AttributeRepository.AttributeKey<?>> attributeKeys()
attributeKeys in interface AttributeRepositoryCollection snapshot of all the currently registered attributes in the repositorypublic <T> T computeAttributeIfAbsent(AttributeRepository.AttributeKey<T> key, java.util.function.Function<? super AttributeRepository.AttributeKey<T>,? extends T> resolver)
AttributeStorenull), attempts to compute
its value using the given mapping function and enters it into this map unless null.computeAttributeIfAbsent in interface AttributeStoreT - The generic attribute typekey - The key of the attribute; must not be null.resolver - The (never null) mapping function to use if value not already mapped. If returns
null then value is not mapped to the provided key.null if value not mapped and resolver did not return a
non-null value for itpublic <T> T setAttribute(AttributeRepository.AttributeKey<T> key, T value)
AttributeStoresetAttribute in interface AttributeStoreT - The generic attribute typekey - The key of the attribute; must not be null.value - The value of the attribute; must not be null.null if it is new.public <T> T removeAttribute(AttributeRepository.AttributeKey<T> key)
AttributeStoreremoveAttribute in interface AttributeStoreT - The generic attribute typekey - The key of the attribute; must not be null.null if no previous valuepublic void clearAttributes()
AttributeStoreclearAttributes in interface AttributeStorepublic java.lang.String getUsername()
getUsername in interface UsernameHoldernull/empty if holder not yet initializedpublic void setUsername(java.lang.String username)
setUsername in interface MutableUserHolderpublic boolean isAuthenticated()
isAuthenticated in interface SessionContexttrue if session has successfully completed the authentication phasepublic void setAuthenticated()
throws java.io.IOException
setAuthenticated in interface Sessionjava.io.IOExceptionprotected TimeoutIndicator checkForTimeouts() throws java.io.IOException
java.io.IOException - If failed to checkcheckAuthenticationTimeout(Instant, Duration),
checkIdleTimeout(Instant, Duration)public java.time.Instant getAuthTimeoutStart()
getAuthTimeoutStart in interface Sessionpublic java.time.Instant resetAuthTimeout()
SessionresetAuthTimeout in interface SessionSession.getAuthTimeoutStart()protected TimeoutIndicator checkAuthenticationTimeout(java.time.Instant now, java.time.Duration authTimeout)
now - The current time in millisauthTimeout - The configured timeout - if non-positive then no timeoutTimeoutIndicator specifying the timeout status and disconnect reason message if
timeout expired, null or NoTimeout if no timeout occurredgetAuthTimeout()public java.time.Instant getIdleTimeoutStart()
getIdleTimeoutStart in interface Sessionprotected TimeoutIndicator checkIdleTimeout(java.time.Instant now, java.time.Duration idleTimeout)
now - The current time in millisidleTimeout - The configured timeout - if non-positive then no timeoutTimeoutIndicator specifying the timeout status and disconnect reason message if
timeout expired, null or NoTimeout if no timeout occurredgetIdleTimeout()public java.time.Instant resetIdleTimeout()
SessionresetIdleTimeout in interface SessionSession.getIdleTimeoutStart()public TimeoutIndicator getTimeoutStatus()
SessiongetTimeoutStatus in interface Sessionnullpublic ReservedSessionMessagesHandler getReservedSessionMessagesHandler()
getReservedSessionMessagesHandler in interface ReservedSessionMessagesManagerReservedSessionMessagesHandler - may be nullpublic void setReservedSessionMessagesHandler(ReservedSessionMessagesHandler handler)
setReservedSessionMessagesHandler in interface ReservedSessionMessagesManagerhandler - The ReservedSessionMessagesHandler to use - may be nullpublic SessionDisconnectHandler getSessionDisconnectHandler()
getSessionDisconnectHandler in interface SessionDisconnectHandlerManagerpublic void setSessionDisconnectHandler(SessionDisconnectHandler sessionDisconnectHandler)
setSessionDisconnectHandler in interface SessionDisconnectHandlerManagerprotected void handleIgnore(Buffer buffer) throws java.lang.Exception
java.lang.Exceptionprotected void doInvokeIgnoreMessageHandler(Buffer buffer) throws java.lang.Exception
handleDebug(Buffer) after validating that the buffer structure seems well-formed and also
resetting the idle timeout. By default, retrieves the ReservedSessionMessagesHandler and invokes its
handleIgnoreMessage method.buffer - The input Bufferjava.lang.Exception - if failed to handle the messageprotected IoWriteFuture sendNotImplemented(long seqNoValue) throws java.io.IOException
SSH_MSG_UNIMPLEMENTED messageseqNoValue - The referenced sequence numberIoWriteFuture that can be used to wait for packet write completionjava.io.IOException - if an error occurred sending the packetprotected void handleUnimplemented(Buffer buffer) throws java.lang.Exception
java.lang.Exceptionprotected boolean doInvokeUnimplementedMessageHandler(int cmd,
Buffer buffer)
throws java.lang.Exception
cmd - The unimplemented commandbuffer - The input BufferhandleUnimplementedMessagejava.lang.Exception - if failed to handle the messagepublic IoWriteFuture sendDebugMessage(boolean display, java.lang.Object msg, java.lang.String lang) throws java.io.IOException
SessionSSH_MSG_DEBUG to the peer sessionsendDebugMessage in interface Sessiondisplay - true if OK to display the message at the peer as-ismsg - The message object whose toString() value to be used - if null then the
"null" string is sentlang - The language - null/empty if some pre-agreed default is usedIoWriteFuture that can be used to check when the packet has actually been sentjava.io.IOException - if an error occurred when encoding or sending the packetprotected void handleDebug(Buffer buffer) throws java.lang.Exception
java.lang.Exceptionprotected void doInvokeDebugMessageHandler(Buffer buffer) throws java.lang.Exception
handleDebug(Buffer) after validating that the buffer structure seems well-formed and also
resetting the idle timeout. By default, retrieves the ReservedSessionMessagesHandler and invokes its
handleDebugMessage method.buffer - The input Bufferjava.lang.Exception - if failed to handle the messageprotected ReservedSessionMessagesHandler resolveReservedSessionMessagesHandler()
public UnknownChannelReferenceHandler getUnknownChannelReferenceHandler()
getUnknownChannelReferenceHandler in interface UnknownChannelReferenceHandlerManagerUnknownChannelReferenceHandlerManager to use - if null then any reference to unknown
channel causes an SshChannelNotFoundExceptionpublic void setUnknownChannelReferenceHandler(UnknownChannelReferenceHandler unknownChannelReferenceHandler)
setUnknownChannelReferenceHandler in interface UnknownChannelReferenceHandlerManagerunknownChannelReferenceHandler - The UnknownChannelReferenceHandlerManager to use - if null then any reference to
unknown channel causes an SshChannelNotFoundExceptionpublic UnknownChannelReferenceHandler resolveUnknownChannelReferenceHandler()
UnknownChannelReferenceHandlerManagerresolveUnknownChannelReferenceHandler in interface UnknownChannelReferenceHandlerManagerpublic ChannelStreamWriterResolver getChannelStreamWriterResolver()
getChannelStreamWriterResolver in interface ChannelStreamWriterResolverManagerpublic void setChannelStreamWriterResolver(ChannelStreamWriterResolver resolver)
setChannelStreamWriterResolver in interface ChannelStreamWriterResolverManagerpublic ChannelStreamWriterResolver resolveChannelStreamWriterResolver()
resolveChannelStreamWriterResolver in interface ChannelStreamWriterResolverManagerpublic IoWriteFuture sendIgnoreMessage(byte... data) throws java.io.IOException
SessionSSH_MSG_IGNORE to the peer sessionsendIgnoreMessage in interface Sessiondata - The message dataIoWriteFuture that can be used to check when the packet has actually been sentjava.io.IOException - if an error occurred when encoding or sending the packetprotected void signalSessionEstablished(IoSession ioSession) throws java.lang.Exception
java.lang.Exceptionprotected void signalSessionEstablished(SessionListener listener)
protected void signalSessionCreated(IoSession ioSession) throws java.lang.Exception
java.lang.Exceptionprotected void signalSessionCreated(SessionListener listener)
protected void signalSendIdentification(java.lang.String version,
java.util.List<java.lang.String> extraLines)
throws java.lang.Exception
java.lang.Exceptionprotected void signalSendIdentification(SessionListener listener, java.lang.String version, java.util.List<java.lang.String> extraLines)
protected void signalReadPeerIdentificationLine(java.lang.String line,
java.util.List<java.lang.String> extraLines)
throws java.lang.Exception
java.lang.Exceptionprotected void signalReadPeerIdentificationLine(SessionListener listener, java.lang.String version, java.util.List<java.lang.String> extraLines)
protected void signalPeerIdentificationReceived(java.lang.String version,
java.util.List<java.lang.String> extraLines)
throws java.lang.Exception
java.lang.Exceptionprotected void signalPeerIdentificationReceived(SessionListener listener, java.lang.String version, java.util.List<java.lang.String> extraLines)
protected void signalSessionEvent(SessionListener.Event event) throws java.lang.Exception
event - The event to sendjava.lang.Exception - If any of the registered listeners threw an exception.protected void signalSessionEvent(SessionListener listener, SessionListener.Event event) throws java.io.IOException
java.io.IOExceptionprotected void invokeSessionSignaller(Invoker<SessionListener,java.lang.Void> invoker) throws java.lang.Throwable
java.lang.Throwableprotected byte[] resizeKey(byte[] e,
int kdfSize,
Digest hash,
byte[] k,
byte[] h)
throws java.lang.Exception
e - the key to resizekdfSize - the cipher key-derivation-factor (in bytes)hash - the hash algorithmk - the key exchange k parameterh - the key exchange h parameterjava.lang.Exception - if a problem occur while resizing the keyprotected java.net.SocketAddress resolvePeerAddress(java.net.SocketAddress knownAddress)
knownAddress - Any externally set peer address - e.g., due to some proxy mechanism meta-datanull otherwise, the IoSession peer addressprotected long calculateNextIgnorePacketCount(Random r, long freq, int variance)
protected java.lang.String resolveIdentificationString(java.lang.String configPropName)
FactoryManager. If a
value is set, then it is appended to the standard SessionContext.DEFAULT_SSH_VERSION_PREFIX.
Otherwise a default value is returned consisting of the prefix and the core artifact name + version in
uppercase - e.g.,' "SSH-2.0-APACHE-SSHD-1.2.3.4"configPropName - The property used to query the factory managerprotected IoWriteFuture sendIdentification(java.lang.String version, java.util.List<java.lang.String> extraLines) throws java.lang.Exception
version - our identification to sendextraLines - Extra lines to send - used only by server sessionsIoWriteFuture that can be used to wait for notification that identification has been
sendjava.lang.Exception - If failed to send the packetprotected java.util.List<java.lang.String> doReadIdentification(Buffer buffer, boolean server) throws java.lang.Exception
null value will be returned. Else the identification string will be returned and the data
read will be consumed from the buffer.buffer - the buffer containing the identification stringserver - true if it is called by the server session, false if by the client sessionList of all received remote identification lines until the version line was read or
null if more data is needed. The identification line is the last one in the listjava.lang.Exception - if malformed identification foundprotected java.lang.String resolveSessionKexProposal(java.lang.String hostKeyTypes)
throws java.io.IOException
java.io.IOExceptionprotected java.lang.String resolveAvailableSignaturesProposal()
throws java.io.IOException,
java.security.GeneralSecurityException
null/empty if no proposaljava.io.IOException - If failed to read/parse the keys datajava.security.GeneralSecurityException - If failed to generate the keysgetFactoryManager(),
resolveAvailableSignaturesProposal(FactoryManager)protected abstract java.lang.String resolveAvailableSignaturesProposal(FactoryManager manager) throws java.io.IOException, java.security.GeneralSecurityException
manager - The FactoryManagernull/empty if no proposaljava.io.IOException - If failed to read/parse the keys datajava.security.GeneralSecurityException - If failed to generate the keysprotected java.util.Map<KexProposalOption,java.lang.String> getKexProposal() throws java.lang.Exception
KexExtensionHandler and the SessionListener for customization, otherwise the
previously created proposal for the session is returned.Mapjava.lang.Exception - when no proposal can be createdprotected java.util.Map<KexProposalOption,java.lang.String> createProposal(java.lang.String hostKeyTypes) throws java.io.IOException
hostKeyTypes - The comma-separated list of supported host key typesMapjava.io.IOException - If internal problem - e.g., KEX extensions negotiation issueprotected java.util.Map<KexProposalOption,java.lang.String> mergeProposals(java.util.Map<KexProposalOption,java.lang.String> current, java.util.Map<KexProposalOption,java.lang.String> proposal)
protected void signalNegotiationOptionsCreated(java.util.Map<KexProposalOption,java.lang.String> proposal)
protected void signalNegotiationOptionsCreated(SessionListener listener, java.util.Map<KexProposalOption,java.lang.String> proposal)
protected void signalNegotiationStart(java.util.Map<KexProposalOption,java.lang.String> c2sOptions, java.util.Map<KexProposalOption,java.lang.String> s2cOptions)
protected void signalNegotiationStart(SessionListener listener, java.util.Map<KexProposalOption,java.lang.String> c2sOptions, java.util.Map<KexProposalOption,java.lang.String> s2cOptions)
protected void signalNegotiationEnd(java.util.Map<KexProposalOption,java.lang.String> c2sOptions, java.util.Map<KexProposalOption,java.lang.String> s2cOptions, java.util.Map<KexProposalOption,java.lang.String> negotiatedGuess, java.lang.Throwable reason)
protected void signalNegotiationEnd(SessionListener listener, java.util.Map<KexProposalOption,java.lang.String> c2sOptions, java.util.Map<KexProposalOption,java.lang.String> s2cOptions, java.util.Map<KexProposalOption,java.lang.String> negotiatedGuess, java.lang.Throwable reason)
protected Buffer preProcessEncodeBuffer(int cmd, Buffer buffer) throws java.io.IOException
SSH_PACKET_HEADER_LEN. This is required in order to efficiently handle
the encoding. If necessary, it re-allocates a new buffer and returns it instead.cmd - The command stored in the bufferbuffer - The original Buffer - assumed to be properly formatted and be of at least the
required minimum length.Buffer. Note: users may use this method to totally alter the
contents of the buffer being sent but it is highly discouraged as it may have unexpected
results.java.io.IOException - If failed to process the bufferpublic void disconnect(int reason,
java.lang.String msg)
throws java.io.IOException
Sessiondisconnect in interface Sessionreason - the reason code for this disconnectmsg - the text messagejava.io.IOException - if an error occurred sending the packetprotected void handleDisconnect(Buffer buffer) throws java.lang.Exception
java.lang.Exceptionprotected void handleDisconnect(int code,
java.lang.String msg,
java.lang.String lang,
Buffer buffer)
throws java.lang.Exception
java.lang.Exceptionprotected void signalDisconnect(int code,
java.lang.String msg,
java.lang.String lang,
boolean initiator)
protected void signalDisconnect(SessionListener listener, int code, java.lang.String msg, java.lang.String lang, boolean initiator)
public void exceptionCaught(java.lang.Throwable t)
SshException.exceptionCaught in interface Sessiont - the exception to processprotected void signalExceptionCaught(java.lang.Throwable t)
protected void signalExceptionCaught(SessionListener listener, java.lang.Throwable t)
protected void signalSessionClosed()
protected void signalSessionClosed(SessionListener listener)
protected abstract ConnectionService getConnectionService()
protected Forwarder getForwarder()
public java.util.List<java.util.Map.Entry<SshdSocketAddress,SshdSocketAddress>> getLocalForwardsBindings()
getLocalForwardsBindings in interface PortForwardingInformationProviderSshdSocketAddress-espublic boolean isLocalPortForwardingStartedForPort(int port)
PortForwardingInformationProviderisLocalPortForwardingStartedForPort in interface PortForwardingInformationProviderport - The local porttrue if local port forwarding is startedgetBoundLocalPortForwardspublic java.util.List<SshdSocketAddress> getStartedLocalPortForwards()
getStartedLocalPortForwards in interface PortForwardingInformationProviderList snapshot of the currently started local port forward bindingspublic java.util.List<SshdSocketAddress> getBoundLocalPortForwards(int port)
getBoundLocalPortForwards in interface PortForwardingInformationProviderport - The port numberSshdSocketAddress-es for the portisLocalPortForwardingStartedForPort,
PortForwardingInformationProvider.getStartedLocalPortForwards()public java.util.List<java.util.Map.Entry<java.lang.Integer,SshdSocketAddress>> getRemoteForwardsBindings()
getRemoteForwardsBindings in interface PortForwardingInformationProviderSshdSocketAddresspublic boolean isRemotePortForwardingStartedForPort(int port)
PortForwardingInformationProviderisRemotePortForwardingStartedForPort in interface PortForwardingInformationProviderport - The remote porttrue if remote port forwarding is startedgetBoundRemotePortForwardpublic java.util.NavigableSet<java.lang.Integer> getStartedRemotePortForwards()
getStartedRemotePortForwards in interface PortForwardingInformationProviderNavigableSet snapshot of the currently started remote port forwardspublic SshdSocketAddress getBoundRemotePortForward(int port)
getBoundRemotePortForward in interface PortForwardingInformationProviderport - The port numberSshdSocketAddress for the port - null if none boundisRemotePortForwardingStartedForPort,
PortForwardingInformationProvider.getStartedRemotePortForwards()public java.time.Duration getAuthTimeout()
getAuthTimeout in interface Sessionpublic java.time.Duration getIdleTimeout()
getIdleTimeout in interface Sessionpublic java.lang.String toString()
toString in class java.lang.Object