Class SessionHelper
- All Implemented Interfaces:
Closeable,AutoCloseable,Channel,AttributeRepository,AttributeStore,MutableUserHolder,UsernameHolder,ChannelListenerManager,ChannelStreamWriterResolver,ChannelStreamWriterResolverManager,Closeable,FactoryManagerHolder,PortForwardingEventListenerManager,PortForwardingInformationProvider,KexExtensionHandlerManager,KexFactoryManager,PropertyResolver,ReservedSessionMessagesManager,Session,SessionContext,SessionDisconnectHandlerManager,SessionHeartbeatController,SessionListenerManager,UnknownChannelReferenceHandlerManager,SignatureFactoriesHolder,SignatureFactoriesManager,ConnectionEndpointsIndicator
- Direct Known Subclasses:
AbstractSession
AbstractSession class smaller-
Nested Class Summary
Nested classes/interfaces inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
AbstractCloseable.StateNested classes/interfaces inherited from interface org.apache.sshd.common.AttributeRepository
AttributeRepository.AttributeKey<T>Nested classes/interfaces inherited from interface org.apache.sshd.common.session.SessionHeartbeatController
SessionHeartbeatController.HeartbeatType -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Map<AttributeRepository.AttributeKey<?>, Object> Session specific attributesprivate booleanBoolean indicating if this session has been authenticated or notprotected Instantprivate ChannelStreamWriterResolverprotected Instantprotected Map<KexProposalOption, String> Stores the initial KEX proposal after it has been run through the hooks allowing client code to modify it; seegetKexProposal().private final IoSessionThe underlying network sessionThe session specific propertiesprivate ReservedSessionMessagesHandlerprivate final booleanClient or server sideprivate SessionDisconnectHandlerprivate final AtomicReference<TimeoutIndicator> private UnknownChannelReferenceHandlerprivate StringThe name of the authenticated userFields inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
closeFuture, futureLock, stateFields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
logFields inherited from interface org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolver
NONEFields inherited from interface org.apache.sshd.common.PropertyResolver
EMPTYFields inherited from interface org.apache.sshd.common.session.SessionContext
DEFAULT_SSH_VERSION_PREFIX, FALLBACK_SSH_VERSION_PREFIX, MAX_VERSION_LINE_LENGTH -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedSessionHelper(boolean serverSession, FactoryManager factoryManager, IoSession ioSession) Create a new session. -
Method Summary
Modifier and TypeMethodDescriptionprotected longcalculateNextIgnorePacketCount(Random r, long freq, int variance) protected TimeoutIndicatorcheckAuthenticationTimeout(Instant now, Duration authTimeout) Checks if authentication timeout expiredprotected TimeoutIndicatorChecks whether the session has timed out (both authentication and idle timeouts are checked).protected TimeoutIndicatorcheckIdleTimeout(Instant now, Duration idleTimeout) Checks if idle timeout expiredvoidRemoves all currently stored user-defined attributes<T> TcomputeAttributeIfAbsent(AttributeRepository.AttributeKey<T> key, Function<? super AttributeRepository.AttributeKey<T>, ? extends T> resolver) If the specified key is not already associated with a value (or is mapped tonull), attempts to compute its value using the given mapping function and enters it into this map unlessnull.protected Map<KexProposalOption, String> createProposal(String hostKeyTypes) Create our proposal for SSH negotiationvoiddisconnect(int reason, String msg) Send a disconnect packet with the given reason and message.protected voiddoInvokeDebugMessageHandler(Buffer buffer) Invoked byhandleDebug(Buffer)after validating that the buffer structure seems well-formed and also resetting the idle timeout.protected voiddoInvokeIgnoreMessageHandler(Buffer buffer) Invoked byhandleDebug(Buffer)after validating that the buffer structure seems well-formed and also resetting the idle timeout.protected booleandoInvokeUnimplementedMessageHandler(int cmd, Buffer buffer) doReadIdentification(Buffer buffer, boolean server) Read the remote identification from this buffer.voidHandle any exceptions that occurred on this session.<T> TReturns the value of the user-defined attribute.intgetBoundLocalPortForwards(int port) getBoundRemotePortForward(int port) protected abstract ConnectionServiceprotected Forwarderprotected Map<KexProposalOption, String> Retrieves this side's initial proposal for KEX negotiation.A map of properties that can be used to configure the SSH server or client.Check if timeout has occurred.protected voidhandleDebug(Buffer buffer) protected voidhandleDisconnect(int code, String msg, String lang, Buffer buffer) protected voidhandleDisconnect(Buffer buffer) protected voidhandleIgnore(Buffer buffer) protected voidhandleUnimplemented(Buffer buffer) protected voidinvokeSessionSignaller(Invoker<SessionListener, Void> invoker) booleanbooleanisLocalPortForwardingStartedForPort(int port) Test if local port forwarding is startedbooleanisRemotePortForwardingStartedForPort(int port) Test if remote port forwarding is startedbooleanQuick indication if this is a server or client session (instead of having to askinstanceof).protected Map<KexProposalOption, String> mergeProposals(Map<KexProposalOption, String> current, Map<KexProposalOption, String> proposal) protected BufferpreProcessEncodeBuffer(int cmd, Buffer buffer) Invoked by the session before encoding the buffer in order to make sure that it is at least of sizeSSH_PACKET_HEADER_LEN.<T> TRemoves the user-defined attributeRe-start the authentication timeout timerRe-start idle timeout timerprotected byte[]Method used while putting new keys into use that will resize the key used to initialize the cipher to the needed length.protected StringComputes the list of available host key signature algorithms supported.protected abstract StringComputes the list of available host key signature algorithms supported.protected StringresolveIdentificationString(String configPropName) Resolves the identification to send to the peer session by consulting the associatedFactoryManager.protected SocketAddressresolvePeerAddress(SocketAddress knownAddress) protected ReservedSessionMessagesHandlerprotected StringresolveSessionKexProposal(String hostKeyTypes) Check if current manager has a specific handler set for it - if not, try and resolve one from the "parent" container (if any)sendDebugMessage(boolean display, Object msg, String lang) Sends anSSH_MSG_DEBUGto the peer sessionprotected IoWriteFuturesendIdentification(String version, List<String> extraLines) Send our identification.sendIgnoreMessage(byte... data) Sends anSSH_MSG_IGNOREto the peer sessionprotected IoWriteFuturesendNotImplemented(long seqNoValue) Sends aSSH_MSG_UNIMPLEMENTEDmessage<T> TsetAttribute(AttributeRepository.AttributeKey<T> key, T value) Sets a user-defined attribute.voidvoidvoidvoidsetSessionDisconnectHandler(SessionDisconnectHandler sessionDisconnectHandler) voidsetUnknownChannelReferenceHandler(UnknownChannelReferenceHandler unknownChannelReferenceHandler) voidsetUsername(String username) protected voidsignalDisconnect(int code, String msg, String lang, boolean initiator) protected voidsignalDisconnect(SessionListener listener, int code, String msg, String lang, boolean initiator) protected voidprotected voidsignalExceptionCaught(SessionListener listener, Throwable t) protected voidsignalNegotiationEnd(Map<KexProposalOption, String> c2sOptions, Map<KexProposalOption, String> s2cOptions, Map<KexProposalOption, String> negotiatedGuess, Throwable reason) protected voidsignalNegotiationEnd(SessionListener listener, Map<KexProposalOption, String> c2sOptions, Map<KexProposalOption, String> s2cOptions, Map<KexProposalOption, String> negotiatedGuess, Throwable reason) protected voidprotected voidsignalNegotiationOptionsCreated(SessionListener listener, Map<KexProposalOption, String> proposal) protected voidsignalNegotiationStart(Map<KexProposalOption, String> c2sOptions, Map<KexProposalOption, String> s2cOptions) protected voidsignalNegotiationStart(SessionListener listener, Map<KexProposalOption, String> c2sOptions, Map<KexProposalOption, String> s2cOptions) protected voidsignalPeerIdentificationReceived(String version, List<String> extraLines) protected voidsignalPeerIdentificationReceived(SessionListener listener, String version, List<String> extraLines) protected voidsignalReadPeerIdentificationLine(String line, List<String> extraLines) protected voidsignalReadPeerIdentificationLine(SessionListener listener, String version, List<String> extraLines) protected voidsignalSendIdentification(String version, List<String> extraLines) protected voidsignalSendIdentification(SessionListener listener, String version, List<String> extraLines) protected voidprotected voidsignalSessionClosed(SessionListener listener) protected voidsignalSessionCreated(IoSession ioSession) protected voidsignalSessionCreated(SessionListener listener) protected voidsignalSessionEstablished(IoSession ioSession) protected voidsignalSessionEstablished(SessionListener listener) protected voidSends a session event to all currently registered session listenersprotected voidsignalSessionEvent(SessionListener listener, SessionListener.Event event) toString()Methods inherited from class org.apache.sshd.common.kex.AbstractKexFactoryManager
getCipherFactories, getCompressionFactories, getDelegate, getKexExtensionHandler, getKeyExchangeFactories, getMacFactories, getSignatureFactories, resolveEffectiveFactories, resolveEffectiveProvider, setCipherFactories, setCompressionFactories, setKexExtensionHandler, setKeyExchangeFactories, setMacFactories, setSignatureFactoriesMethods inherited from class org.apache.sshd.common.util.closeable.AbstractInnerCloseable
doCloseGracefully, doCloseImmediately, getInnerCloseableMethods inherited from class org.apache.sshd.common.util.closeable.AbstractCloseable
addCloseFutureListener, builder, close, getFutureLock, isClosed, isClosing, preClose, removeCloseFutureListenerMethods inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
debug, debug, debug, debug, debug, error, error, error, error, error, getSimplifiedLogger, info, info, warn, warn, warn, warn, warn, warn, warn, warnMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.apache.sshd.common.channel.ChannelListenerManager
addChannelListener, getChannelListenerProxy, removeChannelListenerMethods inherited from interface org.apache.sshd.common.channel.throttle.ChannelStreamWriterResolverManager
resolveChannelStreamWriterMethods inherited from interface org.apache.sshd.common.Closeable
addCloseFutureListener, close, close, isClosed, isClosing, isOpen, removeCloseFutureListenerMethods inherited from interface org.apache.sshd.common.kex.extension.KexExtensionHandlerManager
getKexExtensionHandler, setKexExtensionHandlerMethods inherited from interface org.apache.sshd.common.kex.KexFactoryManager
getCipherFactories, getCipherFactoriesNameList, getCipherFactoriesNames, getCompressionFactories, getCompressionFactoriesNameList, getCompressionFactoriesNames, getKeyExchangeFactories, getMacFactories, getMacFactoriesNameList, getMacFactoriesNames, setCipherFactories, setCipherFactoriesNameList, setCipherFactoriesNames, setCipherFactoriesNames, setCompressionFactories, setCompressionFactoriesNameList, setCompressionFactoriesNames, setCompressionFactoriesNames, setKeyExchangeFactories, setMacFactories, setMacFactoriesNameList, setMacFactoriesNames, setMacFactoriesNamesMethods inherited from interface org.apache.sshd.common.forward.PortForwardingEventListenerManager
addPortForwardingEventListener, getPortForwardingEventListenerProxy, removePortForwardingEventListenerMethods inherited from interface org.apache.sshd.common.PropertyResolver
getBoolean, getBooleanProperty, getCharset, getInteger, getIntProperty, getLong, getLongProperty, getObject, getString, getStringProperty, isEmptyMethods inherited from interface org.apache.sshd.common.session.Session
createBuffer, createBuffer, getKex, getLocalAddress, getRemoteAddress, getService, prepareBuffer, reExchangeKeys, request, request, request, request, resolveAttribute, startService, writePacket, writePacket, writePacket, writePacketMethods inherited from interface org.apache.sshd.common.session.SessionContext
getCipherInformation, getClientKexProposals, getClientVersion, getCompressionInformation, getKexNegotiationResult, getKexState, getMacInformation, getNegotiatedKexParameter, getServerKexProposals, getServerVersion, getSessionIdMethods inherited from interface org.apache.sshd.common.session.SessionHeartbeatController
disableSessionHeartbeat, getSessionHeartbeatInterval, getSessionHeartbeatType, setSessionHeartbeat, setSessionHeartbeatMethods inherited from interface org.apache.sshd.common.session.SessionListenerManager
addSessionListener, getSessionListenerProxy, removeSessionListenerMethods inherited from interface org.apache.sshd.common.signature.SignatureFactoriesHolder
getSignatureFactories, getSignatureFactoriesNameList, getSignatureFactoriesNamesMethods inherited from interface org.apache.sshd.common.signature.SignatureFactoriesManager
setSignatureFactories, setSignatureFactoriesNameList, setSignatureFactoriesNames, setSignatureFactoriesNames
-
Field Details
-
authStart
-
idleStart
-
initialKexProposal
Stores the initial KEX proposal after it has been run through the hooks allowing client code to modify it; seegetKexProposal(). The same proposal is then used for the initial KEX and for any re-KEX. -
serverSession
private final boolean serverSessionClient or server side -
ioSession
The underlying network session -
properties
The session specific properties -
attributes
Session specific attributes -
timeoutStatus
-
reservedSessionMessagesHandler
-
sessionDisconnectHandler
-
unknownChannelReferenceHandler
-
channelStreamPacketWriterResolver
-
username
The name of the authenticated user -
authed
private volatile boolean authedBoolean indicating if this session has been authenticated or not
-
-
Constructor Details
-
SessionHelper
Create a new session.- Parameters:
serverSession-trueif this is a server session,falseif client onefactoryManager- the factory managerioSession- the underlying I/O session
-
-
Method Details
-
getIoSession
- Specified by:
getIoSessionin interfaceSession- Returns:
- The
IoSessionassociated to this session
-
isServerSession
public boolean isServerSession()Description copied from interface:SessionContextQuick indication if this is a server or client session (instead of having to askinstanceof).- Specified by:
isServerSessionin interfaceSessionContext- Returns:
trueif this is a server session
-
getFactoryManager
- Specified by:
getFactoryManagerin interfaceFactoryManagerHolder- Returns:
- The currently associated
FactoryManager
-
getParentPropertyResolver
- Specified by:
getParentPropertyResolverin interfacePropertyResolver- Returns:
- The parent resolver that can be used to query for missing properties -
nullif no parent
-
getProperties
Description copied from interface: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, thetoString()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 alongthen it will be parsed into one. Also, if the mapped value is anIntegerbut alongis expected, then it will be converted into one.- Specified by:
getPropertiesin interfacePropertyResolver- Returns:
- a valid
Mapcontaining configuration values, nevernull. Note: may be immutable.
-
getAttributesCount
public int getAttributesCount()- Specified by:
getAttributesCountin interfaceAttributeRepository- Returns:
- Current number of user-defined attributes stored in the repository
-
getAttribute
Description copied from interface:AttributeRepositoryReturns the value of the user-defined attribute.- Specified by:
getAttributein interfaceAttributeRepository- Type Parameters:
T- The generic attribute type- Parameters:
key- The key of the attribute; must not benull.- Returns:
nullif there is no value associated with the specified key
-
attributeKeys
- Specified by:
attributeKeysin interfaceAttributeRepository- Returns:
- A
Collectionsnapshot of all the currently registered attributes in the repository
-
computeAttributeIfAbsent
public <T> T computeAttributeIfAbsent(AttributeRepository.AttributeKey<T> key, Function<? super AttributeRepository.AttributeKey<T>, ? extends T> resolver) Description copied from interface:AttributeStoreIf the specified key is not already associated with a value (or is mapped tonull), attempts to compute its value using the given mapping function and enters it into this map unlessnull.- Specified by:
computeAttributeIfAbsentin interfaceAttributeStore- Type Parameters:
T- The generic attribute type- Parameters:
key- The key of the attribute; must not benull.resolver- The (nevernull) mapping function to use if value not already mapped. If returnsnullthen value is not mapped to the provided key.- Returns:
- The resolved value -
nullif value not mapped and resolver did not return a non-nullvalue for it
-
setAttribute
Description copied from interface:AttributeStoreSets a user-defined attribute.- Specified by:
setAttributein interfaceAttributeStore- Type Parameters:
T- The generic attribute type- Parameters:
key- The key of the attribute; must not benull.value- The value of the attribute; must not benull.- Returns:
- The old value of the attribute;
nullif it is new.
-
removeAttribute
Description copied from interface:AttributeStoreRemoves the user-defined attribute- Specified by:
removeAttributein interfaceAttributeStore- Type Parameters:
T- The generic attribute type- Parameters:
key- The key of the attribute; must not benull.- Returns:
- The removed value;
nullif no previous value
-
clearAttributes
public void clearAttributes()Description copied from interface:AttributeStoreRemoves all currently stored user-defined attributes- Specified by:
clearAttributesin interfaceAttributeStore
-
getUsername
- Specified by:
getUsernamein interfaceUsernameHolder- Returns:
- The attached username - may be
null/empty if holder not yet initialized
-
setUsername
- Specified by:
setUsernamein interfaceMutableUserHolder
-
isAuthenticated
public boolean isAuthenticated()- Specified by:
isAuthenticatedin interfaceSessionContext- Returns:
trueif session has successfully completed the authentication phase
-
setAuthenticated
- Specified by:
setAuthenticatedin interfaceSession- Throws:
IOException
-
checkForTimeouts
Checks whether the session has timed out (both authentication and idle timeouts are checked). If the session has timed out, a DISCONNECT message will be sent.- Returns:
- An indication whether timeout has been detected
- Throws:
IOException- If failed to check- See Also:
-
getAuthTimeoutStart
- Specified by:
getAuthTimeoutStartin interfaceSession- Returns:
- The timestamp value (milliseconds since EPOCH) when timer was started
-
resetAuthTimeout
Description copied from interface:SessionRe-start the authentication timeout timer- Specified by:
resetAuthTimeoutin interfaceSession- Returns:
- The timestamp value (milliseconds since EPOCH) when timer was started
- See Also:
-
checkAuthenticationTimeout
Checks if authentication timeout expired- Parameters:
now- The current time in millisauthTimeout- The configured timeout - if non-positive then no timeout- Returns:
- A
TimeoutIndicatorspecifying the timeout status and disconnect reason message if timeout expired,nullorNoTimeoutif no timeout occurred - See Also:
-
getIdleTimeoutStart
- Specified by:
getIdleTimeoutStartin interfaceSession- Returns:
- The timestamp value (milliseconds since EPOCH) when timer was started
-
checkIdleTimeout
Checks if idle timeout expired- Parameters:
now- The current time in millisidleTimeout- The configured timeout - if non-positive then no timeout- Returns:
- A
TimeoutIndicatorspecifying the timeout status and disconnect reason message if timeout expired,nullorNoTimeoutif no timeout occurred - See Also:
-
resetIdleTimeout
Description copied from interface:SessionRe-start idle timeout timer- Specified by:
resetIdleTimeoutin interfaceSession- Returns:
- The timestamp value (milliseconds since EPOCH) when timer was started
- See Also:
-
getTimeoutStatus
Description copied from interface:SessionCheck if timeout has occurred.- Specified by:
getTimeoutStatusin interfaceSession- Returns:
- the timeout status - never
null
-
getReservedSessionMessagesHandler
- Specified by:
getReservedSessionMessagesHandlerin interfaceReservedSessionMessagesManager- Returns:
- The currently registered
ReservedSessionMessagesHandler- may benull
-
setReservedSessionMessagesHandler
- Specified by:
setReservedSessionMessagesHandlerin interfaceReservedSessionMessagesManager- Parameters:
handler- TheReservedSessionMessagesHandlerto use - may benull
-
getSessionDisconnectHandler
- Specified by:
getSessionDisconnectHandlerin interfaceSessionDisconnectHandlerManager
-
setSessionDisconnectHandler
- Specified by:
setSessionDisconnectHandlerin interfaceSessionDisconnectHandlerManager
-
handleIgnore
- Throws:
Exception
-
doInvokeIgnoreMessageHandler
Invoked byhandleDebug(Buffer)after validating that the buffer structure seems well-formed and also resetting the idle timeout. By default, retrieves theReservedSessionMessagesHandlerand invokes itshandleIgnoreMessagemethod. -
sendNotImplemented
Sends aSSH_MSG_UNIMPLEMENTEDmessage- Parameters:
seqNoValue- The referenced sequence number- Returns:
- An
IoWriteFuturethat can be used to wait for packet write completion - Throws:
IOException- if an error occurred sending the packet
-
handleUnimplemented
- Throws:
Exception
-
doInvokeUnimplementedMessageHandler
- Parameters:
cmd- The unimplemented commandbuffer- The inputBuffer- Returns:
- Result of invoking
handleUnimplementedMessage - Throws:
Exception- if failed to handle the message
-
sendDebugMessage
Description copied from interface:SessionSends anSSH_MSG_DEBUGto the peer session- Specified by:
sendDebugMessagein interfaceSession- Parameters:
display-trueif OK to display the message at the peer as-ismsg- The message object whosetoString()value to be used - ifnullthen the "null" string is sentlang- The language -null/empty if some pre-agreed default is used- Returns:
- An
IoWriteFuturethat can be used to check when the packet has actually been sent - Throws:
IOException- if an error occurred when encoding or sending the packet- See Also:
-
handleDebug
- Throws:
Exception
-
doInvokeDebugMessageHandler
Invoked byhandleDebug(Buffer)after validating that the buffer structure seems well-formed and also resetting the idle timeout. By default, retrieves theReservedSessionMessagesHandlerand invokes itshandleDebugMessagemethod. -
resolveReservedSessionMessagesHandler
-
getUnknownChannelReferenceHandler
- Specified by:
getUnknownChannelReferenceHandlerin interfaceUnknownChannelReferenceHandlerManager- Returns:
- The
UnknownChannelReferenceHandlerManagerto use - ifnullthen any reference to unknown channel causes anSshChannelNotFoundException
-
setUnknownChannelReferenceHandler
public void setUnknownChannelReferenceHandler(UnknownChannelReferenceHandler unknownChannelReferenceHandler) - Specified by:
setUnknownChannelReferenceHandlerin interfaceUnknownChannelReferenceHandlerManager- Parameters:
unknownChannelReferenceHandler- TheUnknownChannelReferenceHandlerManagerto use - ifnullthen any reference to unknown channel causes anSshChannelNotFoundException
-
resolveUnknownChannelReferenceHandler
Description copied from interface:UnknownChannelReferenceHandlerManagerCheck if current manager has a specific handler set for it - if not, try and resolve one from the "parent" container (if any)- Specified by:
resolveUnknownChannelReferenceHandlerin interfaceUnknownChannelReferenceHandlerManager- Returns:
- The resolved handler instance
-
getChannelStreamWriterResolver
- Specified by:
getChannelStreamWriterResolverin interfaceChannelStreamWriterResolverManager
-
setChannelStreamWriterResolver
- Specified by:
setChannelStreamWriterResolverin interfaceChannelStreamWriterResolverManager
-
resolveChannelStreamWriterResolver
- Specified by:
resolveChannelStreamWriterResolverin interfaceChannelStreamWriterResolverManager
-
sendIgnoreMessage
Description copied from interface:SessionSends anSSH_MSG_IGNOREto the peer session- Specified by:
sendIgnoreMessagein interfaceSession- Parameters:
data- The message data- Returns:
- An
IoWriteFuturethat can be used to check when the packet has actually been sent - Throws:
IOException- if an error occurred when encoding or sending the packet- See Also:
-
signalSessionEstablished
- Throws:
Exception
-
signalSessionEstablished
-
signalSessionCreated
- Throws:
Exception
-
signalSessionCreated
-
signalSendIdentification
- Throws:
Exception
-
signalSendIdentification
protected void signalSendIdentification(SessionListener listener, String version, List<String> extraLines) -
signalReadPeerIdentificationLine
protected void signalReadPeerIdentificationLine(String line, List<String> extraLines) throws Exception - Throws:
Exception
-
signalReadPeerIdentificationLine
protected void signalReadPeerIdentificationLine(SessionListener listener, String version, List<String> extraLines) -
signalPeerIdentificationReceived
protected void signalPeerIdentificationReceived(String version, List<String> extraLines) throws Exception - Throws:
Exception
-
signalPeerIdentificationReceived
protected void signalPeerIdentificationReceived(SessionListener listener, String version, List<String> extraLines) -
signalSessionEvent
Sends a session event to all currently registered session listeners- Parameters:
event- The event to send- Throws:
Exception- If any of the registered listeners threw an exception.
-
signalSessionEvent
protected void signalSessionEvent(SessionListener listener, SessionListener.Event event) throws IOException - Throws:
IOException
-
invokeSessionSignaller
- Throws:
Throwable
-
resizeKey
Method used while putting new keys into use that will resize the key used to initialize the cipher to the needed length.- Parameters:
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 parameter- Returns:
- the resized key
- Throws:
Exception- if a problem occur while resizing the key
-
resolvePeerAddress
- Parameters:
knownAddress- Any externally set peer address - e.g., due to some proxy mechanism meta-data- Returns:
- The external address if not
nullotherwise, theIoSessionpeer address
-
calculateNextIgnorePacketCount
-
resolveIdentificationString
Resolves the identification to send to the peer session by consulting the associatedFactoryManager. If a value is set, then it is appended to the standardSessionContext.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"- Parameters:
configPropName- The property used to query the factory manager- Returns:
- The resolved identification value
-
sendIdentification
protected IoWriteFuture sendIdentification(String version, List<String> extraLines) throws Exception Send our identification.- Parameters:
version- our identification to sendextraLines- Extra lines to send - used only by server sessions- Returns:
IoWriteFuturethat can be used to wait for notification that identification has been send- Throws:
Exception- If failed to send the packet
-
doReadIdentification
Read the remote identification from this buffer. If more data is needed, the buffer will be reset to its original state and anullvalue will be returned. Else the identification string will be returned and the data read will be consumed from the buffer.- Parameters:
buffer- the buffer containing the identification stringserver-trueif it is called by the server session,falseif by the client session- Returns:
- A
Listof all received remote identification lines until the version line was read ornullif more data is needed. The identification line is the last one in the list - Throws:
Exception- if malformed identification found
-
resolveSessionKexProposal
- Throws:
IOException
-
resolveAvailableSignaturesProposal
Computes the list of available host key signature algorithms supported.- Returns:
- A comma-separated list of all the signature protocols to be included in the
proposal -
null/empty if no proposal - Throws:
IOException- If failed to read/parse the keys dataGeneralSecurityException- If failed to generate the keys- See Also:
-
resolveAvailableSignaturesProposal
protected abstract String resolveAvailableSignaturesProposal(FactoryManager manager) throws IOException, GeneralSecurityException Computes the list of available host key signature algorithms supported.- Parameters:
manager- TheFactoryManager- Returns:
- A comma-separated list of all the signature protocols to be included in the
proposal -
null/empty if no proposal - Throws:
IOException- If failed to read/parse the keys dataGeneralSecurityException- If failed to generate the keys
-
getKexProposal
Retrieves this side's initial proposal for KEX negotiation. If no proposal exists yet, one is created and passed though theKexExtensionHandlerand theSessionListenerfor customization, otherwise the previously created proposal for the session is returned. -
createProposal
Create our proposal for SSH negotiation- Parameters:
hostKeyTypes- The comma-separated list of supported host key types- Returns:
- The proposal
Map - Throws:
IOException- If internal problem - e.g., KEX extensions negotiation issue
-
mergeProposals
protected Map<KexProposalOption,String> mergeProposals(Map<KexProposalOption, String> current, Map<KexProposalOption, String> proposal) -
signalNegotiationOptionsCreated
-
signalNegotiationOptionsCreated
protected void signalNegotiationOptionsCreated(SessionListener listener, Map<KexProposalOption, String> proposal) -
signalNegotiationStart
protected void signalNegotiationStart(Map<KexProposalOption, String> c2sOptions, Map<KexProposalOption, String> s2cOptions) -
signalNegotiationStart
protected void signalNegotiationStart(SessionListener listener, Map<KexProposalOption, String> c2sOptions, Map<KexProposalOption, String> s2cOptions) -
signalNegotiationEnd
protected void signalNegotiationEnd(Map<KexProposalOption, String> c2sOptions, Map<KexProposalOption, String> s2cOptions, Map<KexProposalOption, String> negotiatedGuess, Throwable reason) -
signalNegotiationEnd
protected void signalNegotiationEnd(SessionListener listener, Map<KexProposalOption, String> c2sOptions, Map<KexProposalOption, String> s2cOptions, Map<KexProposalOption, String> negotiatedGuess, Throwable reason) -
preProcessEncodeBuffer
Invoked by the session before encoding the buffer in order to make sure that it is at least of sizeSSH_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.- Parameters:
cmd- The command stored in the bufferbuffer- The originalBuffer- assumed to be properly formatted and be of at least the required minimum length.- Returns:
- The adjusted
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. - Throws:
IOException- If failed to process the buffer
-
disconnect
Description copied from interface:SessionSend a disconnect packet with the given reason and message. Once the packet has been sent, the session will be closed asynchronously.- Specified by:
disconnectin interfaceSession- Parameters:
reason- the reason code for this disconnectmsg- the text message- Throws:
IOException- if an error occurred sending the packet
-
handleDisconnect
- Throws:
Exception
-
handleDisconnect
- Throws:
Exception
-
signalDisconnect
-
signalDisconnect
protected void signalDisconnect(SessionListener listener, int code, String msg, String lang, boolean initiator) -
exceptionCaught
Handle any exceptions that occurred on this session. The session will be closed and a disconnect packet will be sent before if the given exception is anSshException.- Specified by:
exceptionCaughtin interfaceSession- Parameters:
t- the exception to process
-
signalExceptionCaught
-
signalExceptionCaught
-
signalSessionClosed
protected void signalSessionClosed() -
signalSessionClosed
-
getConnectionService
-
getForwarder
-
getLocalForwardsBindings
- Specified by:
getLocalForwardsBindingsin interfacePortForwardingInformationProvider- Returns:
- A snapshot of the currently bound forwarded local ports as "pairs" of local/remote
SshdSocketAddress-es
-
isLocalPortForwardingStartedForPort
public boolean isLocalPortForwardingStartedForPort(int port) Description copied from interface:PortForwardingInformationProviderTest if local port forwarding is started- Specified by:
isLocalPortForwardingStartedForPortin interfacePortForwardingInformationProvider- Parameters:
port- The local port- Returns:
trueif local port forwarding is started- See Also:
-
getStartedLocalPortForwards
- Specified by:
getStartedLocalPortForwardsin interfacePortForwardingInformationProvider- Returns:
- A
Listsnapshot of the currently started local port forward bindings
-
getBoundLocalPortForwards
- Specified by:
getBoundLocalPortForwardsin interfacePortForwardingInformationProvider- Parameters:
port- The port number- Returns:
- The local bound
SshdSocketAddress-es for the port - See Also:
-
getRemoteForwardsBindings
- Specified by:
getRemoteForwardsBindingsin interfacePortForwardingInformationProvider- Returns:
- A snapshot of the currently bound forwarded remote ports as "pairs" of port + bound
SshdSocketAddress
-
isRemotePortForwardingStartedForPort
public boolean isRemotePortForwardingStartedForPort(int port) Description copied from interface:PortForwardingInformationProviderTest if remote port forwarding is started- Specified by:
isRemotePortForwardingStartedForPortin interfacePortForwardingInformationProvider- Parameters:
port- The remote port- Returns:
trueif remote port forwarding is started- See Also:
-
getStartedRemotePortForwards
- Specified by:
getStartedRemotePortForwardsin interfacePortForwardingInformationProvider- Returns:
- A
NavigableSetsnapshot of the currently started remote port forwards
-
getBoundRemotePortForward
- Specified by:
getBoundRemotePortForwardin interfacePortForwardingInformationProvider- Parameters:
port- The port number- Returns:
- The remote bound
SshdSocketAddressfor the port -nullif none bound - See Also:
-
getAuthTimeout
- Specified by:
getAuthTimeoutin interfaceSession- Returns:
- Timeout value in milliseconds for authentication stage
-
getIdleTimeout
- Specified by:
getIdleTimeoutin interfaceSession- Returns:
- Timeout value in milliseconds for communication
-
toString
-