Class SshKeyScanMain

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.Channel, java.util.concurrent.Callable<java.lang.Void>, java.util.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 java.lang.Object
    implements java.nio.channels.Channel, java.util.concurrent.Callable<java.lang.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)
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface org.apache.sshd.common.session.SessionListener

        org.apache.sshd.common.session.SessionListener.Event
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private org.apache.sshd.client.SshClient client  
      private java.util.Map<java.lang.String,​java.lang.String> currentHostFingerprints  
      static java.util.List<java.lang.String> DEFAULT_KEY_TYPES
      Default key types if not overridden from the command line
      static java.util.logging.Level DEFAULT_LEVEL  
      static long DEFAULT_TIMEOUT  
      private java.io.InputStream input  
      private java.util.List<java.lang.String> keyTypes  
      private java.util.logging.Level level  
      private java.util.concurrent.atomic.AtomicBoolean open  
      private int port  
      private long timeout  
      • 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.Void call()  
      void close()  
      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.InputStream getInputStream()  
      java.util.List<java.lang.String> getKeyTypes()  
      java.util.logging.Level getLogLevel()  
      int getPort()  
      long getTimeout()  
      static <S extends SshKeyScanMain>
      S
      initializeScanner​(S scanner, java.util.Collection<java.lang.String> hosts)  
      boolean isEnabledLevel​(java.util.logging.Level level)  
      boolean isOpen()  
      void log​(java.util.logging.Level level, java.lang.Object message, java.lang.Throwable t)  
      protected void logNegotiationProposal​(java.lang.String type, java.util.Map<org.apache.sshd.common.kex.KexProposalOption,​java.lang.String> proposal)  
      protected void logSessionEvent​(org.apache.sshd.common.session.Session session, java.lang.Object event)  
      static void main​(java.lang.String[] args)  
      static java.util.List<java.lang.String> parseCommandLineArguments​(SshKeyScanMain scanner, java.lang.String... args)  
      protected void resolveServerKeys​(org.apache.sshd.client.SshClient client, java.lang.String host, java.lang.String kt, java.util.List<java.security.KeyPair> ids)  
      protected void resolveServerKeys​(org.apache.sshd.client.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<org.apache.sshd.common.NamedFactory<org.apache.sshd.common.signature.Signature>>> sigFactories)  
      protected java.util.List<org.apache.sshd.common.NamedFactory<org.apache.sshd.common.signature.Signature>> resolveSignatureFactories​(java.lang.String keyType)  
      void sessionClosed​(org.apache.sshd.common.session.Session session)  
      void sessionCreated​(org.apache.sshd.common.session.Session session)  
      void sessionEvent​(org.apache.sshd.common.session.Session session, org.apache.sshd.common.session.SessionListener.Event event)  
      void sessionException​(org.apache.sshd.common.session.Session session, java.lang.Throwable t)  
      void sessionNegotiationEnd​(org.apache.sshd.common.session.Session session, java.util.Map<org.apache.sshd.common.kex.KexProposalOption,​java.lang.String> clientProposal, java.util.Map<org.apache.sshd.common.kex.KexProposalOption,​java.lang.String> serverProposal, java.util.Map<org.apache.sshd.common.kex.KexProposalOption,​java.lang.String> negotiatedOptions, java.lang.Throwable reason)  
      void sessionNegotiationStart​(org.apache.sshd.common.session.Session session, java.util.Map<org.apache.sshd.common.kex.KexProposalOption,​java.lang.String> clientProposal, java.util.Map<org.apache.sshd.common.kex.KexProposalOption,​java.lang.String> serverProposal)  
      void setInputStream​(java.io.InputStream input)  
      static <S extends SshKeyScanMain>
      S
      setInputStream​(S scanner, java.util.Collection<java.lang.String> hosts)  
      void setKeyTypes​(java.util.List<java.lang.String> keyTypes)  
      void setLogLevel​(java.util.logging.Level level)  
      void setPort​(int port)  
      void setTimeout​(long timeout)  
      private static java.lang.String toString​(java.net.SocketAddress addr)  
      boolean verifyServerKey​(org.apache.sshd.client.session.ClientSession sshClientSession, java.net.SocketAddress remoteAddress, java.security.PublicKey serverKey)  
      protected void writeServerKey​(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 org.apache.sshd.client.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
    • Constructor Detail

      • SshKeyScanMain

        public SshKeyScanMain()
    • 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:
        log in interface org.apache.sshd.common.util.logging.SimplifiedLog
      • isEnabledLevel

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

        public java.lang.Void call()
                            throws java.lang.Exception
        Specified by:
        call in interface java.util.concurrent.Callable<java.lang.Void>
        Throws:
        java.lang.Exception
      • resolveServerKeys

        protected void resolveServerKeys​(org.apache.sshd.client.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<org.apache.sshd.common.NamedFactory<org.apache.sshd.common.signature.Signature>>> sigFactories)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • resolveServerKeys

        protected void resolveServerKeys​(org.apache.sshd.client.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​(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,
                                     java.lang.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,
                                            java.util.Map<org.apache.sshd.common.kex.KexProposalOption,​java.lang.String> clientProposal,
                                            java.util.Map<org.apache.sshd.common.kex.KexProposalOption,​java.lang.String> serverProposal)
        Specified by:
        sessionNegotiationStart in interface org.apache.sshd.common.session.SessionListener
      • logNegotiationProposal

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

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

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

        public boolean verifyServerKey​(org.apache.sshd.client.session.ClientSession sshClientSession,
                                       java.net.SocketAddress remoteAddress,
                                       java.security.PublicKey serverKey)
        Specified by:
        verifyServerKey in interface org.apache.sshd.client.keyverifier.ServerKeyVerifier
      • 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<org.apache.sshd.common.NamedFactory<org.apache.sshd.common.signature.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:
        isOpen in interface java.nio.channels.Channel
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.nio.channels.Channel
        Specified by:
        close in interface java.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