Class KiwiJSchHelpers

java.lang.Object
org.kiwiproject.jsch.KiwiJSchHelpers

public final class KiwiJSchHelpers extends Object
Static utilities for working with JSch.
  • Method Details

    • detectKeyExchangeTypeForHost

      public static Optional<String> detectKeyExchangeTypeForHost(String host, com.jcraft.jsch.HostKeyRepository knownHosts)
      Detect the key exchange for a given host (or IP address) and HostKeyRepository, which is JSch's encapsulation of the known_hosts file.

      This method supports only a subset of the possible formats in known_hosts. The supported formats are:

      • hostname, e.g. dev-svc-1.acme.com
      • ip_address, e.g. 192.168.1.150
      • hostname,ip_address, e,g, dev-svc-1.acme.com,192.168.1.150
      known_hosts can have various other formats, but we do not support them at the present time. See this discussion on known_hosts formats for additional information.
      Parameters:
      host - the host name or IP to match
      knownHosts - the known hosts
      Returns:
      an Optional containing the detected key exchange type, or an empty Optional
      Implementation Note:
      Finds the first matching known host entry
    • setSessionKeyExchangeType

      public static void setSessionKeyExchangeType(com.jcraft.jsch.Session session, String keyExchangeType)
      Sets the given key exchange type, e.g. ssh-rsa or ecdsa-sha2-nistp256 on the specified session.
      Parameters:
      session - the JSch session
      keyExchangeType - key exchange type
      Implementation Note:
      JSch does not appear to have any constants to use, so it's just raw strings