Skip to content

Commit 1b7a4e7

Browse files
committed
Implement ext-info-in-auth@openssh.com extension
# Conflicts: # sshd-common/src/main/java/org/apache/sshd/common/kex/extension/KexExtensions.java # sshd-core/src/main/java/org/apache/sshd/common/kex/extension/DefaultClientKexExtensionHandler.java
1 parent e58d2f1 commit 1b7a4e7

3 files changed

Lines changed: 61 additions & 1 deletion

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.apache.sshd.common.NamedResource;
4040
import org.apache.sshd.common.kex.extension.parser.DelayCompression;
4141
import org.apache.sshd.common.kex.extension.parser.Elevation;
42+
import org.apache.sshd.common.kex.extension.parser.ExtInfoInAuth;
4243
import org.apache.sshd.common.kex.extension.parser.NoFlowControl;
4344
import org.apache.sshd.common.kex.extension.parser.ServerSignatureAlgorithms;
4445
import org.apache.sshd.common.util.GenericUtils;
@@ -84,7 +85,8 @@ public final class KexExtensions {
8485
ServerSignatureAlgorithms.INSTANCE,
8586
NoFlowControl.INSTANCE,
8687
Elevation.INSTANCE,
87-
DelayCompression.INSTANCE)
88+
DelayCompression.INSTANCE,
89+
ExtInfoInAuth.INSTANCE)
8890
.collect(Collectors.toMap(
8991
NamedResource::getName, Function.identity(),
9092
MapEntryUtils.throwingMerger(), () -> new TreeMap<>(String.CASE_INSENSITIVE_ORDER)));
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.sshd.common.kex.extension.parser;
20+
21+
import java.io.IOException;
22+
import java.nio.charset.StandardCharsets;
23+
24+
import org.apache.sshd.common.util.buffer.Buffer;
25+
26+
/**
27+
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
28+
* @see <A HREF=
29+
* "https://github.com/openssh/openssh-portable/blob/V_9_8/PROTOCOL#L167-L184">ext-info-in-auth@openssh.com</A>
30+
*/
31+
public class ExtInfoInAuth extends AbstractKexExtensionParser<String> {
32+
33+
public static final String NAME = "ext-info-in-auth@openssh.com";
34+
35+
public static final ExtInfoInAuth INSTANCE = new ExtInfoInAuth();
36+
37+
public ExtInfoInAuth() {
38+
super(NAME);
39+
}
40+
41+
@Override
42+
protected void encode(String value, Buffer buffer) throws IOException {
43+
buffer.putString(value);
44+
}
45+
46+
@Override
47+
public String parseExtension(byte[] data, int off, int len) throws IOException {
48+
return (len <= 0) ? "" : new String(data, off, len, StandardCharsets.UTF_8);
49+
}
50+
51+
@Override
52+
public String parseExtension(Buffer buffer) throws IOException {
53+
return parseExtension(buffer.array(), buffer.rpos(), buffer.available());
54+
}
55+
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import org.apache.sshd.common.AttributeRepository.AttributeKey;
3434
import org.apache.sshd.common.NamedFactory;
35+
import org.apache.sshd.common.kex.extension.parser.ExtInfoInAuth;
3536
import org.apache.sshd.common.kex.extension.parser.HostBoundPubkeyAuthentication;
3637
import org.apache.sshd.common.kex.extension.parser.ServerSignatureAlgorithms;
3738
import org.apache.sshd.common.session.Session;
@@ -165,5 +166,7 @@ public void sendKexExtensions(Session session, KexPhase phase) throws Exception
165166
* @param marshaller {@link BiConsumer} writing the extensions into an SSH message
166167
*/
167168
public void collectExtensions(Session session, KexPhase phase, BiConsumer<String, Object> marshaller) {
169+
// ext-info-in-auth@openssh.com
170+
marshaller.accept(ExtInfoInAuth.NAME, "");
168171
}
169172
}

0 commit comments

Comments
 (0)