public abstract class SessionHelper extends AbstractKexFactoryManager implements Session
AbstractSession class smallerAbstractCloseable.StateSessionHeartbeatController.HeartbeatTypeAttributeRepository.AttributeKey<T>| Modifier and Type | Field and Description |
|---|---|
protected Instant |
authStart |
protected Instant |
idleStart |
protected Object |
sessionLock
Session level lock for regulating access to sensitive data
|
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.
|
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, resolveAttribute, resolveAttribute, startService, writePacket, writePacket, writePacketgetCipherInformation, getClientKexProposals, getClientVersion, getCompressionInformation, getKexNegotiationResult, getKexState, getMacInformation, getNegotiatedKexParameter, getServerKexProposals, getServerVersion, getSessionId, isDataIntegrityTransport, isSecureSessionTransport, isValidVersionPrefixdisableSessionHeartbeat, 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 final Object sessionLock
protected Instant authStart
protected Instant idleStart
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()
isServerSession in interface SessionContextpublic FactoryManager getFactoryManager()
getFactoryManager in interface FactoryManagerHolderFactoryManagerpublic PropertyResolver getParentPropertyResolver()
getParentPropertyResolver in interface PropertyResolverpublic Map<String,Object> getProperties()
getProperties in interface PropertyResolverpublic int getAttributesCount()
getAttributesCount in interface AttributeRepositorypublic <T> T getAttribute(AttributeRepository.AttributeKey<T> key)
getAttribute in interface AttributeRepositorypublic Collection<AttributeRepository.AttributeKey<?>> attributeKeys()
attributeKeys in interface AttributeRepositorypublic <T> T computeAttributeIfAbsent(AttributeRepository.AttributeKey<T> key, Function<? super AttributeRepository.AttributeKey<T>,? extends T> resolver)
computeAttributeIfAbsent in interface AttributeStorepublic <T> T setAttribute(AttributeRepository.AttributeKey<T> key, T value)
setAttribute in interface AttributeStorepublic <T> T removeAttribute(AttributeRepository.AttributeKey<T> key)
removeAttribute in interface AttributeStorepublic void clearAttributes()
clearAttributes in interface AttributeStorepublic String getUsername()
getUsername in interface UsernameHolderpublic void setUsername(String username)
setUsername in interface MutableUserHolderpublic boolean isAuthenticated()
isAuthenticated in interface SessionContextpublic void setAuthenticated()
throws IOException
setAuthenticated in interface SessionIOExceptionprotected TimeoutIndicator checkForTimeouts() throws IOException
IOException - If failed to checkcheckAuthenticationTimeout(Instant, Duration),
checkIdleTimeout(Instant, Duration)public Instant getAuthTimeoutStart()
getAuthTimeoutStart in interface Sessionpublic Instant resetAuthTimeout()
SessionresetAuthTimeout in interface SessionSession.getAuthTimeoutStart()protected TimeoutIndicator checkAuthenticationTimeout(Instant now, 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 Instant getIdleTimeoutStart()
getIdleTimeoutStart in interface Sessionprotected TimeoutIndicator checkIdleTimeout(Instant now, 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 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 doInvokeIgnoreMessageHandler(Buffer buffer) throws 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.protected IoWriteFuture sendNotImplemented(long seqNoValue) throws IOException
SSH_MSG_UNIMPLEMENTED messageseqNoValue - The referenced sequence numberIoWriteFuture that can be used to wait for packet write completionIOException - if an error occurred sending the packetprotected void handleUnimplemented(Buffer buffer) throws Exception
Exceptionprotected boolean doInvokeUnimplementedMessageHandler(int cmd,
Buffer buffer)
throws Exception
cmd - The unimplemented commandbuffer - The input BufferhandleUnimplementedMessageException - if failed to handle the messagepublic IoWriteFuture sendDebugMessage(boolean display, Object msg, String lang) throws 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 sentIOException - if an error occurred when encoding or sending the packetprotected void doInvokeDebugMessageHandler(Buffer buffer) throws 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.protected 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 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 sentIOException - if an error occurred when encoding or sending the packetpublic IoWriteFuture writePacket(Buffer buffer, long timeout, TimeUnit unit) throws IOException
SessionIoWriteFuture will be set with a
TimeoutException exception to indicate a timeout.writePacket in interface Sessionbuffer - the buffer to encode and spendtimeout - the timeoutunit - the time unit of the timeout parameterIOException - if an error occurred when encoding or sending the packetprotected void signalSessionEstablished(IoSession ioSession) throws Exception
Exceptionprotected void signalSessionEstablished(SessionListener listener)
protected void signalSessionCreated(IoSession ioSession) throws Exception
Exceptionprotected void signalSessionCreated(SessionListener listener)
protected void signalSendIdentification(String version, List<String> extraLines) throws Exception
Exceptionprotected void signalSendIdentification(SessionListener listener, String version, List<String> extraLines)
protected void signalReadPeerIdentificationLine(String line, List<String> extraLines) throws Exception
Exceptionprotected void signalReadPeerIdentificationLine(SessionListener listener, String version, List<String> extraLines)
protected void signalPeerIdentificationReceived(String version, List<String> extraLines) throws Exception
Exceptionprotected void signalPeerIdentificationReceived(SessionListener listener, String version, List<String> extraLines)
protected void signalSessionEvent(SessionListener.Event event) throws Exception
event - The event to sendException - If any of the registered listeners threw an exception.protected void signalSessionEvent(SessionListener listener, SessionListener.Event event) throws IOException
IOExceptionprotected void invokeSessionSignaller(Invoker<SessionListener,Void> invoker) throws Throwable
Throwableprotected byte[] resizeKey(byte[] e,
int kdfSize,
Digest hash,
byte[] k,
byte[] h)
throws 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 parameterException - if a problem occur while resizing the keyprotected SocketAddress resolvePeerAddress(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 String resolveIdentificationString(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(String version, List<String> extraLines) throws 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
sendException - If failed to send the packetprotected List<String> doReadIdentification(Buffer buffer, boolean server) throws 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 listException - if malformed identification foundprotected String resolveSessionKexProposal(String hostKeyTypes) throws IOException
IOExceptionprotected Map<KexProposalOption,String> createProposal(String hostKeyTypes) throws IOException
hostKeyTypes - The comma-separated list of supported host key typesMapIOException - If internal problem - e.g., KEX extensions negotiation issueprotected Map<KexProposalOption,String> mergeProposals(Map<KexProposalOption,String> current, Map<KexProposalOption,String> proposal)
protected void signalNegotiationOptionsCreated(Map<KexProposalOption,String> proposal)
protected void signalNegotiationOptionsCreated(SessionListener listener, Map<KexProposalOption,String> proposal)
protected void signalNegotiationStart(Map<KexProposalOption,String> c2sOptions, Map<KexProposalOption,String> s2cOptions)
protected void signalNegotiationStart(SessionListener listener, Map<KexProposalOption,String> c2sOptions, Map<KexProposalOption,String> s2cOptions)
protected void signalNegotiationEnd(Map<KexProposalOption,String> c2sOptions, Map<KexProposalOption,String> s2cOptions, Map<KexProposalOption,String> negotiatedGuess, Throwable reason)
protected void signalNegotiationEnd(SessionListener listener, Map<KexProposalOption,String> c2sOptions, Map<KexProposalOption,String> s2cOptions, Map<KexProposalOption,String> negotiatedGuess, Throwable reason)
protected Buffer preProcessEncodeBuffer(int cmd, Buffer buffer) throws 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.IOException - If failed to process the bufferpublic void disconnect(int reason,
String msg)
throws IOException
Sessiondisconnect in interface Sessionreason - the reason code for this disconnectmsg - the text messageIOException - if an error occurred sending the packetprotected void handleDisconnect(int code,
String msg,
String lang,
Buffer buffer)
throws Exception
Exceptionprotected void signalDisconnect(int code,
String msg,
String lang,
boolean initiator)
protected void signalDisconnect(SessionListener listener, int code, String msg, String lang, boolean initiator)
public void exceptionCaught(Throwable t)
SshException.exceptionCaught in interface Sessiont - the exception to processprotected void signalExceptionCaught(Throwable t)
protected void signalExceptionCaught(SessionListener listener, Throwable t)
protected void signalSessionClosed()
protected void signalSessionClosed(SessionListener listener)
protected abstract ConnectionService getConnectionService()
protected Forwarder getForwarder()
public List<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 List<SshdSocketAddress> getStartedLocalPortForwards()
getStartedLocalPortForwards in interface PortForwardingInformationProviderList snapshot of the currently started local port forward bindingspublic List<SshdSocketAddress> getBoundLocalPortForwards(int port)
getBoundLocalPortForwards in interface PortForwardingInformationProviderport - The port numberSshdSocketAddress-es for the portisLocalPortForwardingStartedForPort,
PortForwardingInformationProvider.getStartedLocalPortForwards()public List<Map.Entry<Integer,SshdSocketAddress>> getRemoteForwardsBindings()
getRemoteForwardsBindings in interface PortForwardingInformationProviderSshdSocketAddresspublic boolean isRemotePortForwardingStartedForPort(int port)
PortForwardingInformationProviderisRemotePortForwardingStartedForPort in interface PortForwardingInformationProviderport - The remote porttrue if remote port forwarding is startedgetBoundRemotePortForwardpublic NavigableSet<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 Duration getAuthTimeout()
getAuthTimeout in interface Sessionpublic Duration getIdleTimeout()
getIdleTimeout in interface SessionCopyright © 2008–2021 The Apache Software Foundation. All rights reserved.