Class KexExtensions


  • public final class KexExtensions
    extends java.lang.Object
    Provides some helpers for RFC 8308
    • Field Detail

      • CLIENT_KEX_EXTENSION

        public static final java.lang.String CLIENT_KEX_EXTENSION
        See Also:
        Constant Field Values
      • SERVER_KEX_EXTENSION

        public static final java.lang.String SERVER_KEX_EXTENSION
        See Also:
        Constant Field Values
      • IS_KEX_EXTENSION_SIGNAL

        public static final java.util.function.Predicate<java.lang.String> IS_KEX_EXTENSION_SIGNAL
      • EXTENSION_PARSERS

        private static final java.util.NavigableMap<java.lang.String,​KexExtensionParser<?>> EXTENSION_PARSERS
        A case insensitive map of all the default known KexExtensionParser where key=the extension name
    • Constructor Detail

      • KexExtensions

        private KexExtensions()
    • Method Detail

      • getRegisteredExtensionParserNames

        public static java.util.NavigableSet<java.lang.String> getRegisteredExtensionParserNames()
        Returns:
        A case insensitive copy of the currently registered KexExtensionParsers names
      • getRegisteredExtensionParser

        public static KexExtensionParser<?> getRegisteredExtensionParser​(java.lang.String name)
        Parameters:
        name - The (never null/empty) extension name
        Returns:
        The registered KexExtensionParser for the (case insensitive) extension name - null if no match found
      • registerExtensionParser

        public static KexExtensionParser<?> registerExtensionParser​(KexExtensionParser<?> parser)
        Registers a KexExtensionParser for a named extension
        Parameters:
        parser - The (never null) parser to register
        Returns:
        The replaced parser for the named extension (case insensitive) - null if no previous parser registered for this extension
      • unregisterExtensionParser

        public static KexExtensionParser<?> unregisterExtensionParser​(java.lang.String name)
        Registers KexExtensionParser for a named extension
        Parameters:
        name - The (never null/empty) extension name
        Returns:
        The removed KexExtensionParser for the (case insensitive) extension name - null if no match found
      • parseExtensions

        public static java.util.List<java.util.Map.Entry<java.lang.String,​?>> parseExtensions​(Buffer buffer)
                                                                                             throws java.io.IOException
        Attempts to parse an SSH_MSG_EXT_INFO message
        Parameters:
        buffer - The Buffer containing the message
        Returns:
        A List of key/value "pairs" where key=the extension name, value=the parsed value using the matching registered KexExtensionParser. If no such parser found then the raw value bytes are set as the extension value.
        Throws:
        java.io.IOException - If failed to parse one of the extensions
        See Also:
        RFC-8308 - section 2.3
      • putExtensions

        public static void putExtensions​(java.util.Collection<? extends java.util.Map.Entry<java.lang.String,​?>> exts,
                                         Buffer buffer)
                                  throws java.io.IOException
        Creates an SSH_MSG_EXT_INFO message using the provided extensions.
        Parameters:
        exts - A Collection of key/value "pairs" where key=the extension name, value=the extension value. Note: if a registered KexExtensionParser exists for the name, then it is assumed that the value is of the correct type. If no registered parser found the value is assumed to be either the encoded value as an array of bytes or as another Readable (e.g., another Buffer) or a ByteBuffer.
        buffer - The target Buffer - assumed to already contain the SSH_MSG_EXT_INFO opcode
        Throws:
        java.io.IOException - If failed to encode