Class AbstractClientSession

java.lang.Object
org.apache.sshd.common.util.logging.AbstractLoggingBean
org.apache.sshd.common.util.closeable.IoBaseCloseable
org.apache.sshd.common.util.closeable.AbstractCloseable
org.apache.sshd.common.util.closeable.AbstractInnerCloseable
All Implemented Interfaces:
Closeable, AutoCloseable, Channel, ClientAuthenticationManager, ClientSession, org.apache.sshd.common.AttributeRepository, org.apache.sshd.common.AttributeStore, org.apache.sshd.common.auth.MutableUserHolder, org.apache.sshd.common.auth.UserAuthFactoriesManager<ClientSession, UserAuth, UserAuthFactory>, org.apache.sshd.common.auth.UsernameHolder, ChannelListenerManager, ChannelStreamWriterResolver, ChannelStreamWriterResolverManager, org.apache.sshd.common.Closeable, FactoryManagerHolder, PortForwardingEventListenerManager, PortForwardingInformationProvider, PortForwardingManager, KexExtensionHandlerManager, KexFactoryManager, org.apache.sshd.common.keyprovider.KeyIdentityProviderHolder, org.apache.sshd.common.PropertyResolver, ReservedSessionMessagesManager, Session, org.apache.sshd.common.session.SessionContext, SessionDisconnectHandlerManager, org.apache.sshd.common.session.SessionHeartbeatController, SessionListenerManager, UnknownChannelReferenceHandlerManager, org.apache.sshd.common.signature.SignatureFactoriesHolder, org.apache.sshd.common.signature.SignatureFactoriesManager, org.apache.sshd.common.util.net.ConnectionEndpointsIndicator
Direct Known Subclasses:
ClientSessionImpl

public abstract class AbstractClientSession extends AbstractSession implements ClientSession
Provides default implementations of ClientSession related methods
Author:
Apache MINA SSHD Project
  • Field Details

    • HOST_CONFIG_ENTRY

      public static final org.apache.sshd.common.AttributeRepository.AttributeKey<org.apache.sshd.client.config.hosts.HostConfigEntry> HOST_CONFIG_ENTRY
    • PROXY_DATA

      public static final org.apache.sshd.common.AttributeRepository.AttributeKey<ProxyData> PROXY_DATA
    • sendImmediateClientIdentification

      protected final boolean sendImmediateClientIdentification
    • sendImmediateKexInit

      protected final boolean sendImmediateKexInit
  • Constructor Details

    • AbstractClientSession

      protected AbstractClientSession(ClientFactoryManager factoryManager, org.apache.sshd.common.io.IoSession ioSession)
  • Method Details

    • setupFilterChain

      protected void setupFilterChain()
      Overrides:
      setupFilterChain in class AbstractSession
    • getHostConfigEntry

      public org.apache.sshd.client.config.hosts.HostConfigEntry getHostConfigEntry()
      Description copied from interface: ClientSession
      Retrieves the HostConfigEntry that was used to create this session.
      Specified by:
      getHostConfigEntry in interface ClientSession
      Returns:
      the HostConfigEntry; or null if none
    • getConnectionContext

      public org.apache.sshd.common.AttributeRepository getConnectionContext()
      Specified by:
      getConnectionContext in interface ClientSession
      Returns:
      The "context" data provided when session connection was established - null if none.
    • getFactoryManager

      public ClientFactoryManager getFactoryManager()
      Specified by:
      getFactoryManager in interface ClientSession
      Specified by:
      getFactoryManager in interface FactoryManagerHolder
      Overrides:
      getFactoryManager in class SessionHelper
      Returns:
      The currently associated FactoryManager
    • getConnectAddress

      public SocketAddress getConnectAddress()
      Description copied from interface: ClientSession
      Returns the original address (after having been translated through host configuration entries if any) that was request to connect. It contains the original host or address string that was used. Note: this may be different than the result of the Session.getIoSession() report of the remote peer
      Specified by:
      getConnectAddress in interface ClientSession
      Returns:
      The original requested address
    • setConnectAddress

      public void setConnectAddress(SocketAddress connectAddress)
    • getServerKey

      public PublicKey getServerKey()
      Description copied from interface: ClientSession
      Retrieves the server's host key: the one it presented in the last key exchange.
      Specified by:
      getServerKey in interface ClientSession
      Returns:
      the server's PublicKey; may be null if no key exchange has been completed yet
    • setServerKey

      public void setServerKey(PublicKey serverKey)
    • registerHostKey

      public void registerHostKey(PublicKey hostKey)
      Description copied from interface: ClientSession
      Explicitly registers a known host key for the session. Intended to be used if the server announces additional host keys as part of the OpenSSH "hostkeys-00@openssh.com" extension, but it can also be used to register any host key at any other time.

      If the server presents a host key that matches any of the ones registered in the session, the key will be accepted implicitly without consulting the ServerKeyVerifier.

      If the hostKey is a host certificate, the CA key will be registered. When the server presents a certificate, the certificate will be checked in any case and will be rejected if it is invalid or expired. If it is valid and not expired, it will be accepted implicitly if its CA key is already registered.

      Specified by:
      registerHostKey in interface ClientSession
      Parameters:
      hostKey - the host key to register
    • getRegisteredHostKeys

      public Collection<String> getRegisteredHostKeys()
      Description copied from interface: ClientSession
      Obtains a read-only collection of all currently registered server host keys is OpenSSH format, i.e. key type as a string, followed by the base64-encoded key, prefixed with "@cert-authority" if it's a CA key.

      For a normal key: "key-type AAAA..."; for a host certificate CA key "@cert-authority key-type AAAA...".

      Note that this is not quite the format used in a OpenSSH known_hosts file as there are no host patterns.

      Specified by:
      getRegisteredHostKeys in interface ClientSession
      Returns:
      all currently registered server host keys; never null but possibly empty, and never containing null
    • checkKeys

      protected void checkKeys() throws IOException
      Description copied from class: AbstractSession
      Indicates the the key exchange is completed and the exchanged keys can now be verified - e.g., client can verify the server's key
      Specified by:
      checkKeys in class AbstractSession
      Throws:
      IOException - If validation failed
    • getServerKeyVerifier

      public ServerKeyVerifier getServerKeyVerifier()
      Description copied from interface: ClientAuthenticationManager
      Retrieve the server key verifier to be used to check the key when connecting to an SSH server.
      Specified by:
      getServerKeyVerifier in interface ClientAuthenticationManager
      Returns:
      the ServerKeyVerifier to use - never null
    • setServerKeyVerifier

      public void setServerKeyVerifier(ServerKeyVerifier serverKeyVerifier)
      Specified by:
      setServerKeyVerifier in interface ClientAuthenticationManager
    • getUserInteraction

      public UserInteraction getUserInteraction()
      Specified by:
      getUserInteraction in interface ClientAuthenticationManager
      Returns:
      A UserInteraction object to communicate with the user (may be null to indicate that no such communication is allowed)
    • setUserInteraction

      public void setUserInteraction(UserInteraction userInteraction)
      Specified by:
      setUserInteraction in interface ClientAuthenticationManager
    • getPasswordAuthenticationReporter

      public PasswordAuthenticationReporter getPasswordAuthenticationReporter()
      Specified by:
      getPasswordAuthenticationReporter in interface ClientAuthenticationManager
    • setPasswordAuthenticationReporter

      public void setPasswordAuthenticationReporter(PasswordAuthenticationReporter reporter)
      Specified by:
      setPasswordAuthenticationReporter in interface ClientAuthenticationManager
    • getUserAuthFactories

      public List<UserAuthFactory> getUserAuthFactories()
      Specified by:
      getUserAuthFactories in interface org.apache.sshd.common.auth.UserAuthFactoriesManager<ClientSession, UserAuth, UserAuthFactory>
    • setUserAuthFactories

      public void setUserAuthFactories(List<UserAuthFactory> userAuthFactories)
      Specified by:
      setUserAuthFactories in interface org.apache.sshd.common.auth.UserAuthFactoriesManager<ClientSession, UserAuth, UserAuthFactory>
    • getRegisteredIdentities

      public org.apache.sshd.client.auth.AuthenticationIdentitiesProvider getRegisteredIdentities()
      Specified by:
      getRegisteredIdentities in interface ClientAuthenticationManager
      Returns:
      The AuthenticationIdentitiesProvider to be used for attempting password or public key authentication
    • getPasswordIdentityProvider

      public org.apache.sshd.client.auth.password.PasswordIdentityProvider getPasswordIdentityProvider()
      Description copied from interface: ClientAuthenticationManager
      Retrieve PasswordIdentityProvider used to provide password candidates
      Specified by:
      getPasswordIdentityProvider in interface ClientAuthenticationManager
      Returns:
      The PasswordIdentityProvider instance - ignored if null (i.e., no passwords available).
      See Also:
    • setPasswordIdentityProvider

      public void setPasswordIdentityProvider(org.apache.sshd.client.auth.password.PasswordIdentityProvider provider)
      Specified by:
      setPasswordIdentityProvider in interface ClientAuthenticationManager
    • getKeyIdentityProvider

      public org.apache.sshd.common.keyprovider.KeyIdentityProvider getKeyIdentityProvider()
      Specified by:
      getKeyIdentityProvider in interface org.apache.sshd.common.keyprovider.KeyIdentityProviderHolder
    • setKeyIdentityProvider

      public void setKeyIdentityProvider(org.apache.sshd.common.keyprovider.KeyIdentityProvider keyIdentityProvider)
      Specified by:
      setKeyIdentityProvider in interface org.apache.sshd.common.keyprovider.KeyIdentityProviderHolder
    • getPublicKeyAuthenticationReporter

      public PublicKeyAuthenticationReporter getPublicKeyAuthenticationReporter()
      Specified by:
      getPublicKeyAuthenticationReporter in interface ClientAuthenticationManager
    • setPublicKeyAuthenticationReporter

      public void setPublicKeyAuthenticationReporter(PublicKeyAuthenticationReporter reporter)
      Specified by:
      setPublicKeyAuthenticationReporter in interface ClientAuthenticationManager
    • getHostBasedAuthenticationReporter

      public HostBasedAuthenticationReporter getHostBasedAuthenticationReporter()
      Specified by:
      getHostBasedAuthenticationReporter in interface ClientAuthenticationManager
    • setHostBasedAuthenticationReporter

      public void setHostBasedAuthenticationReporter(HostBasedAuthenticationReporter reporter)
      Specified by:
      setHostBasedAuthenticationReporter in interface ClientAuthenticationManager
    • addPasswordIdentity

      public void addPasswordIdentity(String password)
      Specified by:
      addPasswordIdentity in interface ClientAuthenticationManager
      Parameters:
      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)
    • removePasswordIdentity

      public String removePasswordIdentity(String password)
      Specified by:
      removePasswordIdentity in interface ClientAuthenticationManager
      Parameters:
      password - The password to remove - ignored if null/empty
      Returns:
      The removed password - same one that was added via ClientAuthenticationManager.addPasswordIdentity(String) - or null if no match found
    • addPublicKeyIdentity

      public void addPublicKeyIdentity(KeyPair kp)
      Specified by:
      addPublicKeyIdentity in interface ClientAuthenticationManager
      Parameters:
      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)
    • removePublicKeyIdentity

      public KeyPair removePublicKeyIdentity(KeyPair kp)
      Specified by:
      removePublicKeyIdentity in interface ClientAuthenticationManager
      Parameters:
      kp - The KeyPair to remove - ignored if null
      Returns:
      The removed KeyPair - same one that was added via ClientAuthenticationManager.addPublicKeyIdentity(KeyPair) - or null if no match found
    • createChannel

      public ClientChannel createChannel(String type) throws IOException
      Description copied from interface: ClientSession
      Create a channel of the given type. Same as calling createChannel(type, null).
      Specified by:
      createChannel in interface ClientSession
      Parameters:
      type - The channel type
      Returns:
      The created ClientChannel
      Throws:
      IOException - If failed to create the requested channel
    • createChannel

      public ClientChannel createChannel(String type, String subType) throws IOException
      Description copied from interface: ClientSession
      Create a channel of the given type and sub-type.
      Specified by:
      createChannel in interface ClientSession
      Parameters:
      type - The channel type
      subType - The channel sub-type
      Returns:
      The created ClientChannel
      Throws:
      IOException - If failed to create the requested channel
    • createExecChannel

      public ChannelExec createExecChannel(String command, Charset charset, org.apache.sshd.common.channel.PtyChannelConfigurationHolder ptyConfig, Map<String,?> env) throws IOException
      Description copied from interface: ClientSession
      Create a channel to execute a command using specific PTY settings and/or environment.
      Specified by:
      createExecChannel in interface ClientSession
      Parameters:
      command - The command to execute
      charset - The Charset to use for sending the command string
      ptyConfig - The PTY configuration to use - if null then internal defaults are used
      env - Extra environment configuration to be transmitted to the server - ignored if null/empty.
      Returns:
      The created ChannelExec
      Throws:
      IOException - If failed to create the requested channel
    • createExecChannel

      public ChannelExec createExecChannel(byte[] command, org.apache.sshd.common.channel.PtyChannelConfigurationHolder ptyConfig, Map<String,?> env) throws IOException
      Description copied from interface: ClientSession
      Create a channel to execute a command using specific PTY settings and/or environment.
      Specified by:
      createExecChannel in interface ClientSession
      Parameters:
      command - The command to execute
      ptyConfig - The PTY configuration to use - if null then internal defaults are used
      env - Extra environment configuration to be transmitted to the server - ignored if null/empty.
      Returns:
      The created ChannelExec
      Throws:
      IOException - If failed to create the requested channel
    • createSubsystemChannel

      public ChannelSubsystem createSubsystemChannel(String subsystem) throws IOException
      Description copied from interface: ClientSession
      Create a subsystem channel.
      Specified by:
      createSubsystemChannel in interface ClientSession
      Parameters:
      subsystem - The subsystem name
      Returns:
      The created ChannelSubsystem
      Throws:
      IOException - If failed to create the requested channel
    • createDirectTcpipChannel

      public ChannelDirectTcpip createDirectTcpipChannel(org.apache.sshd.common.util.net.SshdSocketAddress local, org.apache.sshd.common.util.net.SshdSocketAddress remote) throws IOException
      Description copied from interface: ClientSession
      Create a direct tcp-ip channel which can be used to stream data to a remote port from the server.
      Specified by:
      createDirectTcpipChannel in interface ClientSession
      Parameters:
      local - The local address
      remote - The remote address
      Returns:
      The created ChannelDirectTcpip
      Throws:
      IOException - If failed to create the requested channel
    • getUserAuthService

      protected ClientUserAuthService getUserAuthService()
    • getConnectionService

      protected ConnectionService getConnectionService()
      Specified by:
      getConnectionService in class SessionHelper
    • startLocalPortForwarding

      public org.apache.sshd.common.util.net.SshdSocketAddress startLocalPortForwarding(org.apache.sshd.common.util.net.SshdSocketAddress local, org.apache.sshd.common.util.net.SshdSocketAddress remote) throws IOException
      Description copied from interface: PortForwardingManager
      Start forwarding the given local address on the client to the given address on the server.
      Specified by:
      startLocalPortForwarding in interface PortForwardingManager
      Parameters:
      local - The local address
      remote - The remote address
      Returns:
      The bound SshdSocketAddress
      Throws:
      IOException - If failed to create the requested binding
    • stopLocalPortForwarding

      public void stopLocalPortForwarding(org.apache.sshd.common.util.net.SshdSocketAddress local) throws IOException
      Description copied from interface: PortForwardingManager
      Stop forwarding the given local address.
      Specified by:
      stopLocalPortForwarding in interface PortForwardingManager
      Parameters:
      local - The local address
      Throws:
      IOException - If failed to cancel the requested binding
    • startRemotePortForwarding

      public org.apache.sshd.common.util.net.SshdSocketAddress startRemotePortForwarding(org.apache.sshd.common.util.net.SshdSocketAddress remote, org.apache.sshd.common.util.net.SshdSocketAddress local) throws IOException
      Description copied from interface: 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:
      • "" means that connections are to be accepted on all protocol families supported by the SSH implementation
      • "0.0.0.0" means to listen on all IPv4 addresses
      • "::" means to listen on all IPv6 addresses
      • "localhost" means to listen on all protocol families supported by the SSH implementation on loopback addresses only, [RFC3330] and RFC3513]
      • "127.0.0.1" and "::1" indicate listening on the loopback interfaces for IPv4 and IPv6 respectively
      Specified by:
      startRemotePortForwarding in interface PortForwardingManager
      Parameters:
      remote - The remote address
      local - The local address
      Returns:
      The bound SshdSocketAddress
      Throws:
      IOException - If failed to create the requested binding
    • stopRemotePortForwarding

      public void stopRemotePortForwarding(org.apache.sshd.common.util.net.SshdSocketAddress remote) throws IOException
      Description copied from interface: PortForwardingManager
      Stop forwarding of the given remote address.
      Specified by:
      stopRemotePortForwarding in interface PortForwardingManager
      Parameters:
      remote - The remote address
      Throws:
      IOException - If failed to cancel the requested binding
    • startDynamicPortForwarding

      public org.apache.sshd.common.util.net.SshdSocketAddress startDynamicPortForwarding(org.apache.sshd.common.util.net.SshdSocketAddress local) throws IOException
      Description copied from interface: PortForwardingManager
      Start dynamic local port forwarding using a SOCKS proxy.
      Specified by:
      startDynamicPortForwarding in interface PortForwardingManager
      Parameters:
      local - The local address
      Returns:
      The bound SshdSocketAddress
      Throws:
      IOException - If failed to create the requested binding
    • stopDynamicPortForwarding

      public void stopDynamicPortForwarding(org.apache.sshd.common.util.net.SshdSocketAddress local) throws IOException
      Description copied from interface: PortForwardingManager
      Stop a previously started dynamic port forwarding.
      Specified by:
      stopDynamicPortForwarding in interface PortForwardingManager
      Parameters:
      local - The local address
      Throws:
      IOException - If failed to cancel the requested binding
    • getForwarder

      protected Forwarder getForwarder()
      Overrides:
      getForwarder in class SessionHelper
    • resolveAvailableSignaturesProposal

      protected String resolveAvailableSignaturesProposal(FactoryManager manager)
      Description copied from class: SessionHelper
      Computes the list of available host key signature algorithms supported.
      Specified by:
      resolveAvailableSignaturesProposal in class SessionHelper
      Parameters:
      manager - The FactoryManager
      Returns:
      A comma-separated list of all the signature protocols to be included in the proposal - null/empty if no proposal
    • startService

      public void startService(String name, org.apache.sshd.common.util.buffer.Buffer buffer) throws Exception
      Specified by:
      startService in interface Session
      Parameters:
      name - Service name
      buffer - Extra information provided when the service start request was received
      Throws:
      Exception - If failed to start it
    • createShellChannel

      public ChannelShell createShellChannel(org.apache.sshd.common.channel.PtyChannelConfigurationHolder ptyConfig, Map<String,?> env) throws IOException
      Description copied from interface: ClientSession
      Create a channel to start a shell using specific PTY settings and/or environment.
      Specified by:
      createShellChannel in interface ClientSession
      Parameters:
      ptyConfig - The PTY configuration to use - if null then internal defaults are used
      env - Extra environment configuration to be transmitted to the server - ignored if null/empty.
      Returns:
      The created ChannelShell
      Throws:
      IOException - If failed to create the requested channel
    • readIdentification

      protected boolean readIdentification(org.apache.sshd.common.util.buffer.Buffer buffer) throws Exception
      Description copied from class: AbstractSession
      Read the other side identification. This method is specific to the client or server side, but both should call SessionHelper.doReadIdentification(Buffer, boolean) and store the result in the needed property.
      Specified by:
      readIdentification in class AbstractSession
      Parameters:
      buffer - The Buffer containing the remote identification
      Returns:
      true if the identification has been fully read or false if more data is needed
      Throws:
      Exception - if an error occurs such as a bad protocol version or unsuccessful KEX was involved
    • signalExtraServerVersionInfo

      protected void signalExtraServerVersionInfo(String version, List<String> lines) throws Exception
      Throws:
      Exception
    • switchToNoneCipher

      public KeyExchangeFuture switchToNoneCipher() throws IOException
      Description copied from interface: 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.

      Specified by:
      switchToNoneCipher in interface ClientSession
      Returns:
      an KeyExchangeFuture that can be used to wait for the exchange to be finished
      Throws:
      IOException - if a key exchange is already running
    • getKexProposal

      protected Map<org.apache.sshd.common.kex.KexProposalOption, String> getKexProposal() throws Exception
      Description copied from class: SessionHelper
      Retrieves this side's initial proposal for KEX negotiation. If no proposal exists yet, one is created and passed though the KexExtensionHandler and the SessionListener for customization, otherwise the previously created proposal for the session is returned.
      Overrides:
      getKexProposal in class SessionHelper
      Returns:
      the proposal Map
      Throws:
      Exception - when no proposal can be created