|
23 | 23 | import java.util.ArrayList; |
24 | 24 | import java.util.Collection; |
25 | 25 | import java.util.Iterator; |
| 26 | +import java.util.LinkedHashMap; |
26 | 27 | import java.util.List; |
| 28 | +import java.util.Map; |
27 | 29 | import java.util.Set; |
28 | 30 | import java.util.TreeSet; |
| 31 | +import java.util.function.BiConsumer; |
29 | 32 |
|
30 | 33 | import org.apache.sshd.common.AttributeRepository.AttributeKey; |
31 | 34 | import org.apache.sshd.common.NamedFactory; |
32 | 35 | import org.apache.sshd.common.kex.extension.parser.HostBoundPubkeyAuthentication; |
33 | 36 | import org.apache.sshd.common.kex.extension.parser.ServerSignatureAlgorithms; |
34 | 37 | import org.apache.sshd.common.session.Session; |
35 | 38 | import org.apache.sshd.common.signature.Signature; |
| 39 | +import org.apache.sshd.common.util.buffer.Buffer; |
36 | 40 | import org.apache.sshd.common.util.logging.AbstractLoggingBean; |
37 | 41 |
|
38 | 42 | /** |
@@ -133,4 +137,33 @@ protected void handleServerSignatureAlgorithms(Session session, Collection<Strin |
133 | 137 | session.setSignatureFactories(clientAlgorithms); |
134 | 138 | } |
135 | 139 | } |
| 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 | + } |
136 | 169 | } |
0 commit comments