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
,UserAuthInstance<ClientSession>
,NamedResource
,SignatureFactoriesHolder
,SignatureFactoriesManager
public class UserAuthPublicKey extends AbstractUserAuth implements SignatureFactoriesManager
Implements the "publickey" authentication mechanism
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.String
chosenAlgorithm
protected PublicKeyIdentity
current
protected java.util.Deque<java.lang.String>
currentAlgorithms
protected java.util.List<NamedFactory<Signature>>
factories
static AttributeRepository.AttributeKey<java.lang.String>
IDENTITY_AGENT
Is set on aClientSession
when it is created; contains the value of theIdentityAgent
SSH config setting.protected java.util.Iterator<PublicKeyIdentity>
keys
static java.lang.String
NAME
static AttributeRepository.AttributeKey<java.lang.Boolean>
USE_DEFAULT_IDENTITIES
Is set on aClientSession
when it is created; ifBoolean.FALSE
, no default identities shall be used.-
Fields inherited from class org.apache.sshd.common.util.logging.AbstractLoggingBean
log
-
Fields inherited from interface org.apache.sshd.common.NamedResource
BY_NAME_COMPARATOR, NAME_EXTRACTOR
-
-
Constructor Summary
Constructors Constructor Description UserAuthPublicKey()
UserAuthPublicKey(java.util.List<NamedFactory<Signature>> factories)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected byte[]
appendSignature(ClientSession session, java.lang.String service, java.lang.String name, java.lang.String username, java.lang.String algo, java.security.PublicKey key, java.security.PublicKey serverKey, Buffer buffer)
protected java.util.Iterator<PublicKeyIdentity>
createPublicKeyIterator(ClientSession session, SignatureFactoriesManager manager)
void
destroy()
Called to release any allocated resourcesprotected java.lang.String
getDefaultSignatureAlgorithm(ClientSession session, java.lang.String service, PublicKeyIdentity identity, java.security.KeyPair keyPair, java.lang.String keyType)
Determines a signature algorithm name to use for the authentication request if none could be determined from the installed signature factories.java.util.List<NamedFactory<Signature>>
getSignatureFactories()
void
init(ClientSession session, java.lang.String service)
protected boolean
processAuthDataRequest(ClientSession session, java.lang.String service, Buffer buffer)
protected void
releaseKeys()
protected PublicKeyIdentity
resolveAttemptedPublicKeyIdentity(ClientSession session, java.lang.String service)
protected PublicKeyIdentity
resolveAttemptedPublicKeyIdentity(ClientSession session, java.lang.String service, PublicKeyAuthenticationReporter reporter)
protected boolean
sendAuthDataRequest(ClientSession session, java.lang.String service)
void
setSignatureFactories(java.util.List<NamedFactory<Signature>> factories)
void
signalAuthMethodFailure(ClientSession session, java.lang.String service, boolean partial, java.util.List<java.lang.String> serverMethods, Buffer buffer)
Signals reception ofSSH_MSG_USERAUTH_FAILURE
messagevoid
signalAuthMethodSuccess(ClientSession session, java.lang.String service, Buffer buffer)
Signal reception ofSSH_MSG_USERAUTH_SUCCESS
message-
Methods inherited from class org.apache.sshd.client.auth.AbstractUserAuth
getClientSession, getName, getService, getSession, process, toString
-
Methods 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, warn
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.apache.sshd.common.signature.SignatureFactoriesHolder
getSignatureFactoriesNameList, getSignatureFactoriesNames
-
Methods inherited from interface org.apache.sshd.common.signature.SignatureFactoriesManager
setSignatureFactoriesNameList, setSignatureFactoriesNames, setSignatureFactoriesNames
-
-
-
-
Field Detail
-
NAME
public static final java.lang.String NAME
- See Also:
- Constant Field Values
-
USE_DEFAULT_IDENTITIES
public static final AttributeRepository.AttributeKey<java.lang.Boolean> USE_DEFAULT_IDENTITIES
Is set on aClientSession
when it is created; ifBoolean.FALSE
, no default identities shall be used.
-
IDENTITY_AGENT
public static final AttributeRepository.AttributeKey<java.lang.String> IDENTITY_AGENT
Is set on aClientSession
when it is created; contains the value of theIdentityAgent
SSH config setting. May be the empty string if not specified in theHostConfigEntry
.
-
currentAlgorithms
protected final java.util.Deque<java.lang.String> currentAlgorithms
-
keys
protected java.util.Iterator<PublicKeyIdentity> keys
-
current
protected PublicKeyIdentity current
-
factories
protected java.util.List<NamedFactory<Signature>> factories
-
chosenAlgorithm
protected java.lang.String chosenAlgorithm
-
-
Constructor Detail
-
UserAuthPublicKey
public UserAuthPublicKey()
-
UserAuthPublicKey
public UserAuthPublicKey(java.util.List<NamedFactory<Signature>> factories)
-
-
Method Detail
-
getSignatureFactories
public java.util.List<NamedFactory<Signature>> getSignatureFactories()
- Specified by:
getSignatureFactories
in interfaceSignatureFactoriesHolder
- Returns:
- The list of named
Signature
factories
-
setSignatureFactories
public void setSignatureFactories(java.util.List<NamedFactory<Signature>> factories)
- Specified by:
setSignatureFactories
in interfaceSignatureFactoriesManager
-
init
public void init(ClientSession session, java.lang.String service) throws java.lang.Exception
- Specified by:
init
in interfaceUserAuth
- Overrides:
init
in classAbstractUserAuth
- Parameters:
session
- TheClientSession
service
- The requesting service name- Throws:
java.lang.Exception
- If failed to initialize the mechanism
-
createPublicKeyIterator
protected java.util.Iterator<PublicKeyIdentity> createPublicKeyIterator(ClientSession session, SignatureFactoriesManager manager) throws java.lang.Exception
- Throws:
java.lang.Exception
-
sendAuthDataRequest
protected boolean sendAuthDataRequest(ClientSession session, java.lang.String service) throws java.lang.Exception
- Specified by:
sendAuthDataRequest
in classAbstractUserAuth
- Throws:
java.lang.Exception
-
resolveAttemptedPublicKeyIdentity
protected PublicKeyIdentity resolveAttemptedPublicKeyIdentity(ClientSession session, java.lang.String service) throws java.lang.Exception
- Throws:
java.lang.Exception
-
resolveAttemptedPublicKeyIdentity
protected PublicKeyIdentity resolveAttemptedPublicKeyIdentity(ClientSession session, java.lang.String service, PublicKeyAuthenticationReporter reporter) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getDefaultSignatureAlgorithm
protected java.lang.String getDefaultSignatureAlgorithm(ClientSession session, java.lang.String service, PublicKeyIdentity identity, java.security.KeyPair keyPair, java.lang.String keyType) throws java.lang.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
(orPubkeyAcceptedAlgorithms
}.This default implementation always returns
null
, skipping the key.- Parameters:
session
-ClientSession
trying to authenticateservice
- SSH service nameidentity
-PublicKeyIdentity
considered to be used for authenticationkeyPair
-KeyPair
fromidentity
keyType
- the key type ofkeyPair
- 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 givenidentity
- Throws:
java.lang.Exception
- if an error occurs- See Also:
KeyAgentIdentity
-
processAuthDataRequest
protected boolean processAuthDataRequest(ClientSession session, java.lang.String service, Buffer buffer) throws java.lang.Exception
- Specified by:
processAuthDataRequest
in classAbstractUserAuth
- Throws:
java.lang.Exception
-
appendSignature
protected byte[] appendSignature(ClientSession session, java.lang.String service, java.lang.String name, java.lang.String username, java.lang.String algo, java.security.PublicKey key, java.security.PublicKey serverKey, Buffer buffer) throws java.lang.Exception
- Throws:
java.lang.Exception
-
signalAuthMethodSuccess
public void signalAuthMethodSuccess(ClientSession session, java.lang.String service, Buffer buffer) throws java.lang.Exception
Description copied from interface:UserAuth
Signal reception ofSSH_MSG_USERAUTH_SUCCESS
message- Specified by:
signalAuthMethodSuccess
in interfaceUserAuth
- Parameters:
session
- TheClientSession
service
- The requesting service namebuffer
- TheBuffer
containing the success message (after having consumed the relevant data from it)- Throws:
java.lang.Exception
- If failed to handle the callback - Note: may cause session close
-
signalAuthMethodFailure
public void signalAuthMethodFailure(ClientSession session, java.lang.String service, boolean partial, java.util.List<java.lang.String> serverMethods, Buffer buffer) throws java.lang.Exception
Description copied from interface:UserAuth
Signals reception ofSSH_MSG_USERAUTH_FAILURE
message- Specified by:
signalAuthMethodFailure
in interfaceUserAuth
- Parameters:
session
- TheClientSession
service
- The requesting service namepartial
-true
if some partial authentication success so farserverMethods
- TheList
of authentication methods that can continuebuffer
- TheBuffer
containing the failure message (after having consumed the relevant data from it)- Throws:
java.lang.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 interfaceUserAuth
- Overrides:
destroy
in classAbstractUserAuth
-
releaseKeys
protected void releaseKeys() throws java.io.IOException
- Throws:
java.io.IOException
-
-