Package org.apache.sshd.cli.client
Class SshKeyScanMain
java.lang.Object
org.apache.sshd.cli.client.SshKeyScanMain
- All Implemented Interfaces:
Closeable,AutoCloseable,Channel,Callable<Void>,EventListener,ServerKeyVerifier,SessionListener,SimplifiedLog,SshdEventListener
public class SshKeyScanMain
extends Object
implements Channel, Callable<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
FieldsModifier and TypeFieldDescriptionprivate SshClientDefault key types if not overridden from the command linestatic final Levelstatic final longprivate InputStreamprivate Levelprivate final AtomicBooleanprivate intprivate longFields inherited from interface org.apache.sshd.common.util.logging.SimplifiedLog
EMPTY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptioncall()voidclose()createKeyPairs(String keyType) createKeyPairs(Collection<String> typeNames) intgetPort()longstatic <S extends SshKeyScanMain>
SinitializeScanner(S scanner, Collection<String> hosts) booleanisEnabledLevel(Level level) booleanisOpen()voidprotected voidlogNegotiationProposal(String type, Map<KexProposalOption, String> proposal) protected voidlogSessionEvent(Session session, Object event) static voidparseCommandLineArguments(SshKeyScanMain scanner, String... args) protected voidprotected voidresolveServerKeys(SshClient client, String host, Map<String, List<KeyPair>> pairsMap, Map<String, List<NamedFactory<Signature>>> sigFactories) protected List<NamedFactory<Signature>>resolveSignatureFactories(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, Throwable t) An exception was caught and the session will be closed (if not already so).voidsessionNegotiationEnd(Session session, Map<KexProposalOption, String> clientProposal, Map<KexProposalOption, String> serverProposal, Map<KexProposalOption, String> negotiatedOptions, Throwable reason) Signals the end of the negotiation options handlingvoidsessionNegotiationStart(Session session, Map<KexProposalOption, String> clientProposal, Map<KexProposalOption, String> serverProposal) Signals the start of the negotiation options handlingvoidsetInputStream(InputStream input) static <S extends SshKeyScanMain>
SsetInputStream(S scanner, Collection<String> hosts) voidsetKeyTypes(List<String> keyTypes) voidsetLogLevel(Level level) voidsetPort(int port) voidsetTimeout(long timeout) private static StringtoString(SocketAddress addr) booleanverifyServerKey(ClientSession sshClientSession, SocketAddress remoteAddress, PublicKey serverKey) Verify that the server key provided is really the one of the host.protected voidwriteServerKey(String remoteLocation, String keyType, PublicKey serverKey) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.apache.sshd.common.session.SessionListener
sessionDisconnect, sessionEstablished, sessionNegotiationOptionsCreated, sessionPeerIdentificationLine, sessionPeerIdentificationReceived, sessionPeerIdentificationSendMethods 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 Details
-
DEFAULT_KEY_TYPES
Default key types if not overridden from the command line -
DEFAULT_TIMEOUT
public static final long DEFAULT_TIMEOUT -
DEFAULT_LEVEL
-
open
-
client
-
port
private int port -
timeout
private long timeout -
keyTypes
-
input
-
level
-
currentHostFingerprints
-
-
Constructor Details
-
SshKeyScanMain
public SshKeyScanMain()
-
-
Method Details
-
getPort
public int getPort() -
setPort
public void setPort(int port) -
getInputStream
-
setInputStream
-
getKeyTypes
-
setKeyTypes
-
getTimeout
public long getTimeout() -
setTimeout
public void setTimeout(long timeout) -
getLogLevel
-
setLogLevel
-
log
- Specified by:
login interfaceSimplifiedLog
-
isEnabledLevel
- Specified by:
isEnabledLevelin interfaceSimplifiedLog
-
call
-
resolveServerKeys
protected void resolveServerKeys(SshClient client, String host, Map<String, List<KeyPair>> pairsMap, Map<String, throws IOExceptionList<NamedFactory<Signature>>> sigFactories) - Throws:
IOException
-
resolveServerKeys
protected void resolveServerKeys(SshClient client, String host, String kt, List<KeyPair> ids) throws Exception - Throws:
Exception
-
sessionCreated
Description copied from interface:SessionListenerA new session just been created- Specified by:
sessionCreatedin interfaceSessionListener- Parameters:
session- The createdSession
-
sessionEvent
Description copied from interface:SessionListenerAn event has been triggered- Specified by:
sessionEventin interfaceSessionListener- Parameters:
session- The referencedSessionevent- The generatedSessionListener.Event
-
sessionException
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
Description copied from interface:SessionListenerA session has been closed- Specified by:
sessionClosedin interfaceSessionListener- Parameters:
session- The closedSession
-
sessionNegotiationStart
public void sessionNegotiationStart(Session session, Map<KexProposalOption, String> clientProposal, Map<KexProposalOption, 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
-
sessionNegotiationEnd
public void sessionNegotiationEnd(Session session, Map<KexProposalOption, String> clientProposal, Map<KexProposalOption, String> serverProposal, Map<KexProposalOption, String> negotiatedOptions, 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
-
verifyServerKey
public boolean verifyServerKey(ClientSession sshClientSession, SocketAddress remoteAddress, 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(String remoteLocation, String keyType, PublicKey serverKey) throws Exception - Throws:
Exception
-
toString
-
resolveSignatureFactories
protected List<NamedFactory<Signature>> resolveSignatureFactories(String keyType) throws GeneralSecurityException - Throws:
GeneralSecurityException
-
createKeyPairs
protected Map<String,List<KeyPair>> createKeyPairs(Collection<String> typeNames) throws GeneralSecurityException - Throws:
GeneralSecurityException
-
createKeyPairs
- Throws:
GeneralSecurityException
-
isOpen
public boolean isOpen() -
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceChannel- Specified by:
closein interfaceCloseable- Throws:
IOException
-
parseCommandLineArguments
public static List<String> parseCommandLineArguments(SshKeyScanMain scanner, String... args) throws IOException - Throws:
IOException
-
setInputStream
public static <S extends SshKeyScanMain> S setInputStream(S scanner, Collection<String> hosts) throws IOException - Throws:
IOException
-
initializeScanner
public static <S extends SshKeyScanMain> S initializeScanner(S scanner, Collection<String> hosts) throws IOException - Throws:
IOException
-
main
- Throws:
Exception
-