Package org.apache.sshd.cli.client
Class SshKeyScanMain
- java.lang.Object
-
- org.apache.sshd.cli.client.SshKeyScanMain
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,java.nio.channels.Channel,java.util.concurrent.Callable<java.lang.Void>,java.util.EventListener,ServerKeyVerifier,SessionListener,SimplifiedLog,SshdEventListener
public class SshKeyScanMain extends java.lang.Object implements java.nio.channels.Channel, java.util.concurrent.Callable<java.lang.Void>, ServerKeyVerifier, SessionListener, SimplifiedLog
A naive implementation of ssh-keyscan(1)
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.sshd.common.session.SessionListener
SessionListener.Event
-
-
Field Summary
Fields Modifier and Type Field Description private SshClientclientprivate java.util.Map<java.lang.String,java.lang.String>currentHostFingerprintsstatic java.util.List<java.lang.String>DEFAULT_KEY_TYPESDefault key types if not overridden from the command linestatic java.util.logging.LevelDEFAULT_LEVELstatic longDEFAULT_TIMEOUTprivate java.io.InputStreaminputprivate java.util.List<java.lang.String>keyTypesprivate java.util.logging.Levellevelprivate java.util.concurrent.atomic.AtomicBooleanopenprivate intportprivate longtimeout-
Fields inherited from interface org.apache.sshd.common.util.logging.SimplifiedLog
EMPTY
-
-
Constructor Summary
Constructors Constructor Description SshKeyScanMain()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Voidcall()voidclose()protected java.util.List<java.security.KeyPair>createKeyPairs(java.lang.String keyType)protected java.util.Map<java.lang.String,java.util.List<java.security.KeyPair>>createKeyPairs(java.util.Collection<java.lang.String> typeNames)java.io.InputStreamgetInputStream()java.util.List<java.lang.String>getKeyTypes()java.util.logging.LevelgetLogLevel()intgetPort()longgetTimeout()static <S extends SshKeyScanMain>
SinitializeScanner(S scanner, java.util.Collection<java.lang.String> hosts)booleanisEnabledLevel(java.util.logging.Level level)booleanisOpen()voidlog(java.util.logging.Level level, java.lang.Object message, java.lang.Throwable t)protected voidlogNegotiationProposal(java.lang.String type, java.util.Map<KexProposalOption,java.lang.String> proposal)protected voidlogSessionEvent(Session session, java.lang.Object event)static voidmain(java.lang.String[] args)static java.util.List<java.lang.String>parseCommandLineArguments(SshKeyScanMain scanner, java.lang.String... args)protected voidresolveServerKeys(SshClient client, java.lang.String host, java.lang.String kt, java.util.List<java.security.KeyPair> ids)protected voidresolveServerKeys(SshClient client, java.lang.String host, java.util.Map<java.lang.String,java.util.List<java.security.KeyPair>> pairsMap, java.util.Map<java.lang.String,java.util.List<NamedFactory<Signature>>> sigFactories)protected java.util.List<NamedFactory<Signature>>resolveSignatureFactories(java.lang.String keyType)voidsessionClosed(Session session)A session has been closedvoidsessionCreated(Session session)A new session just been createdvoidsessionEvent(Session session, SessionListener.Event event)An event has been triggeredvoidsessionException(Session session, java.lang.Throwable t)An exception was caught and the session will be closed (if not already so).voidsessionNegotiationEnd(Session session, java.util.Map<KexProposalOption,java.lang.String> clientProposal, java.util.Map<KexProposalOption,java.lang.String> serverProposal, java.util.Map<KexProposalOption,java.lang.String> negotiatedOptions, java.lang.Throwable reason)Signals the end of the negotiation options handlingvoidsessionNegotiationStart(Session session, java.util.Map<KexProposalOption,java.lang.String> clientProposal, java.util.Map<KexProposalOption,java.lang.String> serverProposal)Signals the start of the negotiation options handlingvoidsetInputStream(java.io.InputStream input)static <S extends SshKeyScanMain>
SsetInputStream(S scanner, java.util.Collection<java.lang.String> hosts)voidsetKeyTypes(java.util.List<java.lang.String> keyTypes)voidsetLogLevel(java.util.logging.Level level)voidsetPort(int port)voidsetTimeout(long timeout)private static java.lang.StringtoString(java.net.SocketAddress addr)booleanverifyServerKey(ClientSession sshClientSession, java.net.SocketAddress remoteAddress, java.security.PublicKey serverKey)Verify that the server key provided is really the one of the host.protected voidwriteServerKey(java.lang.String remoteLocation, java.lang.String keyType, java.security.PublicKey serverKey)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.sshd.common.session.SessionListener
sessionDisconnect, sessionEstablished, sessionNegotiationOptionsCreated, sessionPeerIdentificationLine, sessionPeerIdentificationReceived, sessionPeerIdentificationSend
-
Methods inherited from interface org.apache.sshd.common.util.logging.SimplifiedLog
debug, debug, error, error, info, info, isDebugEnabled, isErrorEnabled, isInfoEnabled, isTraceEnabled, isWarnEnabled, log, trace, trace, warn, warn
-
-
-
-
Field Detail
-
DEFAULT_KEY_TYPES
public static final java.util.List<java.lang.String> DEFAULT_KEY_TYPES
Default key types if not overridden from the command line
-
DEFAULT_TIMEOUT
public static final long DEFAULT_TIMEOUT
-
DEFAULT_LEVEL
public static final java.util.logging.Level DEFAULT_LEVEL
-
open
private final java.util.concurrent.atomic.AtomicBoolean open
-
client
private SshClient client
-
port
private int port
-
timeout
private long timeout
-
keyTypes
private java.util.List<java.lang.String> keyTypes
-
input
private java.io.InputStream input
-
level
private java.util.logging.Level level
-
currentHostFingerprints
private final java.util.Map<java.lang.String,java.lang.String> currentHostFingerprints
-
-
Method Detail
-
getPort
public int getPort()
-
setPort
public void setPort(int port)
-
getInputStream
public java.io.InputStream getInputStream()
-
setInputStream
public void setInputStream(java.io.InputStream input)
-
getKeyTypes
public java.util.List<java.lang.String> getKeyTypes()
-
setKeyTypes
public void setKeyTypes(java.util.List<java.lang.String> keyTypes)
-
getTimeout
public long getTimeout()
-
setTimeout
public void setTimeout(long timeout)
-
getLogLevel
public java.util.logging.Level getLogLevel()
-
setLogLevel
public void setLogLevel(java.util.logging.Level level)
-
log
public void log(java.util.logging.Level level, java.lang.Object message, java.lang.Throwable t)- Specified by:
login interfaceSimplifiedLog
-
isEnabledLevel
public boolean isEnabledLevel(java.util.logging.Level level)
- Specified by:
isEnabledLevelin interfaceSimplifiedLog
-
call
public java.lang.Void call() throws java.lang.Exception- Specified by:
callin interfacejava.util.concurrent.Callable<java.lang.Void>- Throws:
java.lang.Exception
-
resolveServerKeys
protected void resolveServerKeys(SshClient client, java.lang.String host, java.util.Map<java.lang.String,java.util.List<java.security.KeyPair>> pairsMap, java.util.Map<java.lang.String,java.util.List<NamedFactory<Signature>>> sigFactories) throws java.io.IOException
- Throws:
java.io.IOException
-
resolveServerKeys
protected void resolveServerKeys(SshClient client, java.lang.String host, java.lang.String kt, java.util.List<java.security.KeyPair> ids) throws java.lang.Exception
- Throws:
java.lang.Exception
-
sessionCreated
public void sessionCreated(Session session)
Description copied from interface:SessionListenerA new session just been created- Specified by:
sessionCreatedin interfaceSessionListener- Parameters:
session- The createdSession
-
sessionEvent
public void sessionEvent(Session session, SessionListener.Event event)
Description copied from interface:SessionListenerAn event has been triggered- Specified by:
sessionEventin interfaceSessionListener- Parameters:
session- The referencedSessionevent- The generatedSessionListener.Event
-
sessionException
public void sessionException(Session session, java.lang.Throwable t)
Description copied from interface:SessionListenerAn exception was caught and the session will be closed (if not already so). Note: the code makes no guarantee that at this stageSessionListener.sessionClosed(Session)will be called or perhaps has already been called- Specified by:
sessionExceptionin interfaceSessionListener- Parameters:
session- The referencedSessiont- The caught exception
-
sessionClosed
public void sessionClosed(Session session)
Description copied from interface:SessionListenerA session has been closed- Specified by:
sessionClosedin interfaceSessionListener- Parameters:
session- The closedSession
-
sessionNegotiationStart
public void sessionNegotiationStart(Session session, java.util.Map<KexProposalOption,java.lang.String> clientProposal, java.util.Map<KexProposalOption,java.lang.String> serverProposal)
Description copied from interface:SessionListenerSignals the start of the negotiation options handling- Specified by:
sessionNegotiationStartin interfaceSessionListener- Parameters:
session- The referencedSessionclientProposal- The client proposal options (un-modifiable)serverProposal- The server proposal options (un-modifiable)
-
logNegotiationProposal
protected void logNegotiationProposal(java.lang.String type, java.util.Map<KexProposalOption,java.lang.String> proposal)
-
sessionNegotiationEnd
public void sessionNegotiationEnd(Session session, java.util.Map<KexProposalOption,java.lang.String> clientProposal, java.util.Map<KexProposalOption,java.lang.String> serverProposal, java.util.Map<KexProposalOption,java.lang.String> negotiatedOptions, java.lang.Throwable reason)
Description copied from interface:SessionListenerSignals the end of the negotiation options handling- Specified by:
sessionNegotiationEndin interfaceSessionListener- Parameters:
session- The referencedSessionclientProposal- The client proposal options (un-modifiable)serverProposal- The server proposal options (un-modifiable)negotiatedOptions- The successfully negotiated options so far - even if exception occurred (un-modifiable)reason- Negotiation end reason -nullif successful
-
logSessionEvent
protected void logSessionEvent(Session session, java.lang.Object event)
-
verifyServerKey
public boolean verifyServerKey(ClientSession sshClientSession, java.net.SocketAddress remoteAddress, java.security.PublicKey serverKey)
Description copied from interface:ServerKeyVerifierVerify that the server key provided is really the one of the host.- Specified by:
verifyServerKeyin interfaceServerKeyVerifier- Parameters:
sshClientSession- the currentClientSessionremoteAddress- the host'sSocketAddressserverKey- the presented serverPublicKey- Returns:
trueif the key is accepted for the host
-
writeServerKey
protected void writeServerKey(java.lang.String remoteLocation, java.lang.String keyType, java.security.PublicKey serverKey) throws java.lang.Exception- Throws:
java.lang.Exception
-
toString
private static java.lang.String toString(java.net.SocketAddress addr)
-
resolveSignatureFactories
protected java.util.List<NamedFactory<Signature>> resolveSignatureFactories(java.lang.String keyType) throws java.security.GeneralSecurityException
- Throws:
java.security.GeneralSecurityException
-
createKeyPairs
protected java.util.Map<java.lang.String,java.util.List<java.security.KeyPair>> createKeyPairs(java.util.Collection<java.lang.String> typeNames) throws java.security.GeneralSecurityException- Throws:
java.security.GeneralSecurityException
-
createKeyPairs
protected java.util.List<java.security.KeyPair> createKeyPairs(java.lang.String keyType) throws java.security.GeneralSecurityException- Throws:
java.security.GeneralSecurityException
-
isOpen
public boolean isOpen()
- Specified by:
isOpenin interfacejava.nio.channels.Channel
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.nio.channels.Channel- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
parseCommandLineArguments
public static java.util.List<java.lang.String> parseCommandLineArguments(SshKeyScanMain scanner, java.lang.String... args) throws java.io.IOException
- Throws:
java.io.IOException
-
setInputStream
public static <S extends SshKeyScanMain> S setInputStream(S scanner, java.util.Collection<java.lang.String> hosts) throws java.io.IOException
- Throws:
java.io.IOException
-
initializeScanner
public static <S extends SshKeyScanMain> S initializeScanner(S scanner, java.util.Collection<java.lang.String> hosts) throws java.io.IOException
- Throws:
java.io.IOException
-
main
public static void main(java.lang.String[] args) throws java.lang.Exception- Throws:
java.lang.Exception
-
-