Skip to content

Commit

Permalink
Support for new client side extension
Browse files Browse the repository at this point in the history
  • Loading branch information
gnodet committed Jul 26, 2024
1 parent 4b30ab0 commit e58d2f1
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@
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;
import org.apache.sshd.common.kex.extension.parser.HostBoundPubkeyAuthentication;
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;

/**
Expand Down Expand Up @@ -133,4 +137,33 @@ protected void handleServerSignatureAlgorithms(Session session, Collection<Strin
session.setSignatureFactories(clientAlgorithms);
}
}

@Override
public void sendKexExtensions(Session session, KexPhase phase) throws Exception {
Map<String, Object> 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.
* <p>
* This default implementation does not marshal any extension.
* </p>
*
* @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<String, Object> marshaller) {
}
}

0 comments on commit e58d2f1

Please sign in to comment.