Class SshKeyScanMain

java.lang.Object
org.apache.sshd.cli.client.SshKeyScanMain
All Implemented Interfaces:
Closeable, AutoCloseable, Channel, Callable<Void>, EventListener, org.apache.sshd.client.keyverifier.ServerKeyVerifier, org.apache.sshd.common.session.SessionListener, org.apache.sshd.common.util.logging.SimplifiedLog, org.apache.sshd.common.util.SshdEventListener

public class SshKeyScanMain extends Object implements Channel, Callable<Void>, org.apache.sshd.client.keyverifier.ServerKeyVerifier, org.apache.sshd.common.session.SessionListener, org.apache.sshd.common.util.logging.SimplifiedLog
A naive implementation of ssh-keyscan(1)
  • Field Details

    • DEFAULT_KEY_TYPES

      public static final List<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 Level DEFAULT_LEVEL
    • open

      private final AtomicBoolean open
    • client

      private org.apache.sshd.client.SshClient client
    • port

      private int port
    • timeout

      private long timeout
    • keyTypes

      private List<String> keyTypes
    • input

      private InputStream input
    • level

      private Level level
    • currentHostFingerprints

      private final Map<String,String> currentHostFingerprints
  • Constructor Details

    • SshKeyScanMain

      public SshKeyScanMain()
  • Method Details

    • getPort

      public int getPort()
    • setPort

      public void setPort(int port)
    • getInputStream

      public InputStream getInputStream()
    • setInputStream

      public void setInputStream(InputStream input)
    • getKeyTypes

      public List<String> getKeyTypes()
    • setKeyTypes

      public void setKeyTypes(List<String> keyTypes)
    • getTimeout

      public long getTimeout()
    • setTimeout

      public void setTimeout(long timeout)
    • getLogLevel

      public Level getLogLevel()
    • setLogLevel

      public void setLogLevel(Level level)
    • log

      public void log(Level level, Object message, Throwable t)
      Specified by:
      log in interface org.apache.sshd.common.util.logging.SimplifiedLog
    • isEnabledLevel

      public boolean isEnabledLevel(Level level)
      Specified by:
      isEnabledLevel in interface org.apache.sshd.common.util.logging.SimplifiedLog
    • call

      public Void call() throws Exception
      Specified by:
      call in interface Callable<Void>
      Throws:
      Exception
    • resolveServerKeys

      protected void resolveServerKeys(org.apache.sshd.client.SshClient client, String host, Map<String,List<KeyPair>> pairsMap, Map<String,List<org.apache.sshd.common.NamedFactory<org.apache.sshd.common.signature.Signature>>> sigFactories) throws IOException
      Throws:
      IOException
    • resolveServerKeys

      protected void resolveServerKeys(org.apache.sshd.client.SshClient client, String host, String kt, List<KeyPair> ids) throws Exception
      Throws:
      Exception
    • sessionCreated

      public void sessionCreated(org.apache.sshd.common.session.Session session)
      Specified by:
      sessionCreated in interface org.apache.sshd.common.session.SessionListener
    • sessionEvent

      public void sessionEvent(org.apache.sshd.common.session.Session session, org.apache.sshd.common.session.SessionListener.Event event)
      Specified by:
      sessionEvent in interface org.apache.sshd.common.session.SessionListener
    • sessionException

      public void sessionException(org.apache.sshd.common.session.Session session, Throwable t)
      Specified by:
      sessionException in interface org.apache.sshd.common.session.SessionListener
    • sessionClosed

      public void sessionClosed(org.apache.sshd.common.session.Session session)
      Specified by:
      sessionClosed in interface org.apache.sshd.common.session.SessionListener
    • sessionNegotiationStart

      public void sessionNegotiationStart(org.apache.sshd.common.session.Session session, Map<org.apache.sshd.common.kex.KexProposalOption,String> clientProposal, Map<org.apache.sshd.common.kex.KexProposalOption,String> serverProposal)
      Specified by:
      sessionNegotiationStart in interface org.apache.sshd.common.session.SessionListener
    • logNegotiationProposal

      protected void logNegotiationProposal(String type, Map<org.apache.sshd.common.kex.KexProposalOption,String> proposal)
    • sessionNegotiationEnd

      public void sessionNegotiationEnd(org.apache.sshd.common.session.Session session, Map<org.apache.sshd.common.kex.KexProposalOption,String> clientProposal, Map<org.apache.sshd.common.kex.KexProposalOption,String> serverProposal, Map<org.apache.sshd.common.kex.KexProposalOption,String> negotiatedOptions, Throwable reason)
      Specified by:
      sessionNegotiationEnd in interface org.apache.sshd.common.session.SessionListener
    • logSessionEvent

      protected void logSessionEvent(org.apache.sshd.common.session.Session session, Object event)
    • verifyServerKey

      public boolean verifyServerKey(org.apache.sshd.client.session.ClientSession sshClientSession, SocketAddress remoteAddress, PublicKey serverKey)
      Specified by:
      verifyServerKey in interface org.apache.sshd.client.keyverifier.ServerKeyVerifier
    • writeServerKey

      protected void writeServerKey(String remoteLocation, String keyType, PublicKey serverKey) throws Exception
      Throws:
      Exception
    • toString

      private static String toString(SocketAddress addr)
    • resolveSignatureFactories

      protected List<org.apache.sshd.common.NamedFactory<org.apache.sshd.common.signature.Signature>> resolveSignatureFactories(String keyType) throws GeneralSecurityException
      Throws:
      GeneralSecurityException
    • createKeyPairs

      protected Map<String,List<KeyPair>> createKeyPairs(Collection<String> typeNames) throws GeneralSecurityException
      Throws:
      GeneralSecurityException
    • createKeyPairs

      protected List<KeyPair> createKeyPairs(String keyType) throws GeneralSecurityException
      Throws:
      GeneralSecurityException
    • isOpen

      public boolean isOpen()
      Specified by:
      isOpen in interface Channel
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Channel
      Specified by:
      close in interface Closeable
      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

      public static void main(String[] args) throws Exception
      Throws:
      Exception