diff --git a/sshd-core/src/main/java/org/apache/sshd/common/kex/extension/DefaultClientKexExtensionHandler.java b/sshd-core/src/main/java/org/apache/sshd/common/kex/extension/DefaultClientKexExtensionHandler.java index f70128e40..a0924c559 100644 --- a/sshd-core/src/main/java/org/apache/sshd/common/kex/extension/DefaultClientKexExtensionHandler.java +++ b/sshd-core/src/main/java/org/apache/sshd/common/kex/extension/DefaultClientKexExtensionHandler.java @@ -23,9 +23,12 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; import java.util.Set; import java.util.TreeSet; +import java.util.function.BiConsumer; import org.apache.sshd.common.AttributeRepository.AttributeKey; import org.apache.sshd.common.NamedFactory; @@ -33,6 +36,7 @@ import org.apache.sshd.common.kex.extension.parser.ServerSignatureAlgorithms; import org.apache.sshd.common.session.Session; import org.apache.sshd.common.signature.Signature; +import org.apache.sshd.common.util.buffer.Buffer; import org.apache.sshd.common.util.logging.AbstractLoggingBean; /** @@ -133,4 +137,33 @@ protected void handleServerSignatureAlgorithms(Session session, Collection extensions = new LinkedHashMap<>(); + collectExtensions(session, phase, extensions::put); + if (!extensions.isEmpty()) { + Buffer buffer = session.createBuffer(KexExtensions.SSH_MSG_EXT_INFO); + KexExtensions.putExtensions(extensions.entrySet(), buffer); + if (log.isDebugEnabled()) { + log.debug("sendKexExtensions({})[{}]: sending SSH_MSG_EXT_INFO with {} info records", session, phase, + extensions.size()); + } + session.writePacket(buffer); + } + } + + /** + * Collects extension info records, handing them off to the given {@code marshaller} for writing into an + * {@link KexExtensions#SSH_MSG_EXT_INFO} message. + *

+ * This default implementation does not marshal any extension. + *

+ * + * @param session {@link Session} to send the KEX extension information for + * @param phase {@link KexPhase} of the SSH protocol + * @param marshaller {@link BiConsumer} writing the extensions into an SSH message + */ + public void collectExtensions(Session session, KexPhase phase, BiConsumer marshaller) { + } }