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 marshals a {@link GlobalRequestsOk} 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) {
+ // global-requests-ok
+ marshaller.accept(GlobalRequestsOk.NAME, "");
+ }
}
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/kex/extension/DefaultServerKexExtensionHandler.java b/sshd-core/src/main/java/org/apache/sshd/common/kex/extension/DefaultServerKexExtensionHandler.java
index 7d5924622..07ebb4bd1 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/kex/extension/DefaultServerKexExtensionHandler.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/kex/extension/DefaultServerKexExtensionHandler.java
@@ -19,6 +19,7 @@
package org.apache.sshd.common.kex.extension;
+import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedHashMap;
@@ -27,6 +28,7 @@
import org.apache.sshd.common.AttributeRepository.AttributeKey;
import org.apache.sshd.common.kex.KexProposalOption;
+import org.apache.sshd.common.kex.extension.parser.GlobalRequestsOk;
import org.apache.sshd.common.kex.extension.parser.ServerSignatureAlgorithms;
import org.apache.sshd.common.session.Session;
import org.apache.sshd.common.util.GenericUtils;
@@ -130,6 +132,16 @@ public void sendKexExtensions(Session session, KexPhase phase) throws Exception
}
}
+ @Override
+ public boolean handleKexExtensionRequest(
+ Session session, int index, int count, String name, byte[] data)
+ throws IOException {
+ if (GlobalRequestsOk.NAME.equals(name)) {
+ GlobalRequestsOk.INSTANCE.parseExtension(data);
+ }
+ return true;
+ }
+
/**
* Collects extension info records, handing them off to the given {@code marshaller} for writing into an
* {@link KexExtensions#SSH_MSG_EXT_INFO} message.
@@ -157,5 +169,7 @@ public void collectExtensions(Session session, KexPhase phase, BiConsumer