Skip to content

Commit 18cba35

Browse files
committed
Support for new client side extension
1 parent 2e0e432 commit 18cba35

1 file changed

Lines changed: 33 additions & 0 deletions

File tree

sshd-core/src/main/java/org/apache/sshd/common/kex/extension/DefaultClientKexExtensionHandler.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,20 @@
2323
import java.util.ArrayList;
2424
import java.util.Collection;
2525
import java.util.Iterator;
26+
import java.util.LinkedHashMap;
2627
import java.util.List;
28+
import java.util.Map;
2729
import java.util.Set;
2830
import java.util.TreeSet;
31+
import java.util.function.BiConsumer;
2932

3033
import org.apache.sshd.common.AttributeRepository.AttributeKey;
3134
import org.apache.sshd.common.NamedFactory;
3235
import org.apache.sshd.common.kex.extension.parser.HostBoundPubkeyAuthentication;
3336
import org.apache.sshd.common.kex.extension.parser.ServerSignatureAlgorithms;
3437
import org.apache.sshd.common.session.Session;
3538
import org.apache.sshd.common.signature.Signature;
39+
import org.apache.sshd.common.util.buffer.Buffer;
3640
import org.apache.sshd.common.util.logging.AbstractLoggingBean;
3741

3842
/**
@@ -133,4 +137,33 @@ protected void handleServerSignatureAlgorithms(Session session, Collection<Strin
133137
session.setSignatureFactories(clientAlgorithms);
134138
}
135139
}
140+
141+
@Override
142+
public void sendKexExtensions(Session session, KexPhase phase) throws Exception {
143+
Map<String, Object> extensions = new LinkedHashMap<>();
144+
collectExtensions(session, phase, extensions::put);
145+
if (!extensions.isEmpty()) {
146+
Buffer buffer = session.createBuffer(KexExtensions.SSH_MSG_EXT_INFO);
147+
KexExtensions.putExtensions(extensions.entrySet(), buffer);
148+
if (log.isDebugEnabled()) {
149+
log.debug("sendKexExtensions({})[{}]: sending SSH_MSG_EXT_INFO with {} info records", session, phase,
150+
extensions.size());
151+
}
152+
session.writePacket(buffer);
153+
}
154+
}
155+
156+
/**
157+
* Collects extension info records, handing them off to the given {@code marshaller} for writing into an
158+
* {@link KexExtensions#SSH_MSG_EXT_INFO} message.
159+
* <p>
160+
* This default implementation does not marshal any extension.
161+
* </p>
162+
*
163+
* @param session {@link Session} to send the KEX extension information for
164+
* @param phase {@link KexPhase} of the SSH protocol
165+
* @param marshaller {@link BiConsumer} writing the extensions into an SSH message
166+
*/
167+
public void collectExtensions(Session session, KexPhase phase, BiConsumer<String, Object> marshaller) {
168+
}
136169
}

0 commit comments

Comments
 (0)