Skip to content

Commit 64f448d

Browse files
Send ext-info-c with kex algorithms (#622)
Some SSH servers will not honor the negotiated rsa-sha2-256 algorithms if the client does not indicate support for SSH_MSG_EXT_INFO messages. Since we only need to accept these messages, but are free to ignore their contents, adding support amounts to sending "ext-info-c" with our kex algorithm proposal.
1 parent a5efdf1 commit 64f448d

File tree

4 files changed

+43
-1
lines changed

4 files changed

+43
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (C)2009 - SSHJ Contributors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.hierynomus.sshj.transport.kex;
17+
18+
import net.schmizz.sshj.transport.kex.KeyExchange;
19+
20+
/**
21+
* Stub kex algorithm factory that indicates support for SSH2_MSG_EXT_INFO.
22+
* Some servers will not send `rsa-sha2-*` signatures if the client doesn't indicate support.
23+
*
24+
* Note: Since the server sends `ext-info-s` to indicate support, this fake kex algorithm is never negotiated.
25+
*/
26+
public class ExtInfoClientFactory implements net.schmizz.sshj.common.Factory.Named<KeyExchange> {
27+
@Override
28+
public String getName() {
29+
return "ext-info-c";
30+
}
31+
32+
@Override
33+
public KeyExchange create() {
34+
return null;
35+
}
36+
}

src/main/java/net/schmizz/sshj/DefaultConfig.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import com.hierynomus.sshj.transport.cipher.BlockCiphers;
2121
import com.hierynomus.sshj.transport.cipher.StreamCiphers;
2222
import com.hierynomus.sshj.transport.kex.DHGroups;
23+
import com.hierynomus.sshj.transport.kex.ExtInfoClientFactory;
2324
import com.hierynomus.sshj.transport.kex.ExtendedDHGroups;
2425
import com.hierynomus.sshj.transport.mac.Macs;
2526
import com.hierynomus.sshj.userauth.keyprovider.OpenSSHKeyV1KeyFile;
@@ -125,7 +126,8 @@ protected void initKeyExchangeFactories(boolean bouncyCastleRegistered) {
125126
ExtendedDHGroups.Group16SHA256(),
126127
ExtendedDHGroups.Group16SHA384AtSSH(),
127128
ExtendedDHGroups.Group16SHA512AtSSH(),
128-
ExtendedDHGroups.Group18SHA512AtSSH());
129+
ExtendedDHGroups.Group18SHA512AtSSH(),
130+
new ExtInfoClientFactory());
129131
} else {
130132
setKeyExchangeFactories(DHGroups.Group1SHA1(), new DHGexSHA1.Factory());
131133
}

src/main/java/net/schmizz/sshj/common/Message.java

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public enum Message {
2525
DEBUG(4),
2626
SERVICE_REQUEST(5),
2727
SERVICE_ACCEPT(6),
28+
EXT_INFO(7),
2829
KEXINIT(20),
2930
NEWKEYS(21),
3031

src/main/java/net/schmizz/sshj/transport/TransportImpl.java

+3
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,9 @@ public void handle(Message msg, SSHPacket buf)
529529
case SERVICE_ACCEPT:
530530
gotServiceAccept();
531531
break;
532+
case EXT_INFO:
533+
log.debug("Received SSH_MSG_EXT_INFO");
534+
break;
532535
case USERAUTH_BANNER:
533536
log.debug("Received USERAUTH_BANNER");
534537
break;

0 commit comments

Comments
 (0)