Class UserAuthPublicKey

java.lang.Object
org.apache.sshd.common.util.logging.AbstractLoggingBean
org.apache.sshd.client.auth.AbstractUserAuth
org.apache.sshd.client.auth.pubkey.UserAuthPublicKey
All Implemented Interfaces:
UserAuth, ClientSessionHolder, org.apache.sshd.common.auth.UserAuthInstance<ClientSession>, org.apache.sshd.common.NamedResource, org.apache.sshd.common.signature.SignatureFactoriesHolder, org.apache.sshd.common.signature.SignatureFactoriesManager

public class UserAuthPublicKey extends AbstractUserAuth implements org.apache.sshd.common.signature.SignatureFactoriesManager
Implements the "publickey" authentication mechanism
Author:
Apache MINA SSHD Project
  • Field Details

    • NAME

      public static final String NAME
      See Also:
    • currentAlgorithms

      protected final Deque<String> currentAlgorithms
    • keys

      protected Iterator<org.apache.sshd.client.auth.pubkey.PublicKeyIdentity> keys
    • current

      protected org.apache.sshd.client.auth.pubkey.PublicKeyIdentity current
    • factories

      protected List<org.apache.sshd.common.NamedFactory<org.apache.sshd.common.signature.Signature>> factories
    • chosenAlgorithm

      protected String chosenAlgorithm
  • Constructor Details

    • UserAuthPublicKey

      public UserAuthPublicKey()
    • UserAuthPublicKey

      public UserAuthPublicKey(List<org.apache.sshd.common.NamedFactory<org.apache.sshd.common.signature.Signature>> factories)
  • Method Details

    • getSignatureFactories

      public List<org.apache.sshd.common.NamedFactory<org.apache.sshd.common.signature.Signature>> getSignatureFactories()
      Specified by:
      getSignatureFactories in interface org.apache.sshd.common.signature.SignatureFactoriesHolder
    • setSignatureFactories

      public void setSignatureFactories(List<org.apache.sshd.common.NamedFactory<org.apache.sshd.common.signature.Signature>> factories)
      Specified by:
      setSignatureFactories in interface org.apache.sshd.common.signature.SignatureFactoriesManager
    • init

      public void init(ClientSession session, String service) throws Exception
      Specified by:
      init in interface UserAuth
      Overrides:
      init in class AbstractUserAuth
      Parameters:
      session - The ClientSession
      service - The requesting service name
      Throws:
      Exception - If failed to initialize the mechanism
    • createPublicKeyIterator

      protected Iterator<org.apache.sshd.client.auth.pubkey.PublicKeyIdentity> createPublicKeyIterator(ClientSession session, org.apache.sshd.common.signature.SignatureFactoriesManager manager) throws Exception
      Throws:
      Exception
    • sendAuthDataRequest

      protected boolean sendAuthDataRequest(ClientSession session, String service) throws Exception
      Specified by:
      sendAuthDataRequest in class AbstractUserAuth
      Throws:
      Exception
    • resolveAttemptedPublicKeyIdentity

      protected org.apache.sshd.client.auth.pubkey.PublicKeyIdentity resolveAttemptedPublicKeyIdentity(ClientSession session, String service) throws Exception
      Throws:
      Exception
    • resolveAttemptedPublicKeyIdentity

      protected org.apache.sshd.client.auth.pubkey.PublicKeyIdentity resolveAttemptedPublicKeyIdentity(ClientSession session, String service, PublicKeyAuthenticationReporter reporter) throws Exception
      Throws:
      Exception
    • getDefaultSignatureAlgorithm

      protected String getDefaultSignatureAlgorithm(ClientSession session, String service, org.apache.sshd.client.auth.pubkey.PublicKeyIdentity identity, KeyPair keyPair, String keyType) throws Exception
      Determines a signature algorithm name to use for the authentication request if none could be determined from the installed signature factories. If a non-null non-empty string is returned, it is used as is in the authentication.

      This is mainly intended for use with identities from an SSH agent, where the SSH agent may be able to sign the request even if there is no appropriate signature factory present in Java. Whether it makes sense to allow this depends on the application logic and how it handles e.g. SSH config PubkeyAcceptedKeyTypes (or PubkeyAcceptedAlgorithms}.

      This default implementation always returns null, skipping the key.

      Parameters:
      session - ClientSession trying to authenticate
      service - SSH service name
      identity - PublicKeyIdentity considered to be used for authentication
      keyPair - KeyPair from identity
      keyType - the key type of keyPair
      Returns:
      null or an empty string to skip this key and consider another key, if any, to use for authentication, or a non-empty signature algorithm name to use for the authentication attempt using the given identity
      Throws:
      Exception - if an error occurs
      See Also:
    • processAuthDataRequest

      protected boolean processAuthDataRequest(ClientSession session, String service, org.apache.sshd.common.util.buffer.Buffer buffer) throws Exception
      Specified by:
      processAuthDataRequest in class AbstractUserAuth
      Throws:
      Exception
    • appendSignature

      protected byte[] appendSignature(ClientSession session, String service, String name, String username, String algo, PublicKey key, PublicKey serverKey, org.apache.sshd.common.util.buffer.Buffer buffer) throws Exception
      Throws:
      Exception
    • signalAuthMethodSuccess

      public void signalAuthMethodSuccess(ClientSession session, String service, org.apache.sshd.common.util.buffer.Buffer buffer) throws Exception
      Description copied from interface: UserAuth
      Signal reception of SSH_MSG_USERAUTH_SUCCESS message
      Specified by:
      signalAuthMethodSuccess in interface UserAuth
      Parameters:
      session - The ClientSession
      service - The requesting service name
      buffer - The Buffer containing the success message (after having consumed the relevant data from it)
      Throws:
      Exception - If failed to handle the callback - Note: may cause session close
    • signalAuthMethodFailure

      public void signalAuthMethodFailure(ClientSession session, String service, boolean partial, List<String> serverMethods, org.apache.sshd.common.util.buffer.Buffer buffer) throws Exception
      Description copied from interface: UserAuth
      Signals reception of SSH_MSG_USERAUTH_FAILURE message
      Specified by:
      signalAuthMethodFailure in interface UserAuth
      Parameters:
      session - The ClientSession
      service - The requesting service name
      partial - true if some partial authentication success so far
      serverMethods - The List of authentication methods that can continue
      buffer - The Buffer containing the failure message (after having consumed the relevant data from it)
      Throws:
      Exception - If failed to handle the callback - Note: may cause session close
    • destroy

      public void destroy()
      Description copied from interface: UserAuth
      Called to release any allocated resources
      Specified by:
      destroy in interface UserAuth
      Overrides:
      destroy in class AbstractUserAuth
    • releaseKeys

      protected void releaseKeys() throws IOException
      Throws:
      IOException