Skip to content

Commit d68f27b

Browse files
Fix: if the client knows CA key, it should send host key algo proposal for certificates
1 parent 3256f53 commit d68f27b

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/itest/groovy/com/hierynomus/sshj/signature/KeyWithCertificateSpec.groovy

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,13 @@ class KeyWithCertificateSpec extends IntegrationBaseSpec {
9090
and:
9191
def config = new DefaultConfig()
9292
config.keyAlgorithms = config.keyAlgorithms.stream()
93-
.filter { it.name == hostKeyAlgo }
93+
.filter {
94+
// This filter is added only because the current integration test infrastructure doesn't allow
95+
// to spawn different sshd on the fly. In reality, few users would specify key algorithms
96+
// explicitly.
97+
// The filter let a bug pass through the tests. Now the filter is as broad as possible.
98+
it.name == hostKeyAlgo || !it.name.contains("cert")
99+
}
94100
.collect(Collectors.toList())
95101
SSHClient sshClient = new SSHClient(config)
96102
sshClient.addHostKeyVerifier(new OpenSSHKnownHosts(knownHosts))

src/main/java/net/schmizz/sshj/transport/verification/OpenSSHKnownHosts.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,19 @@ public List<String> findExistingAlgorithms(String hostname, int port) {
138138
for (KnownHostEntry e : entries) {
139139
try {
140140
if (e.appliesTo(adjustedHostname)) {
141-
knownHostAlgorithms.add(e.getType().toString());
141+
final KeyType type = e.getType();
142+
if (e instanceof HostEntry && ((HostEntry) e).marker == Marker.CA_CERT) {
143+
// Only the CA key type is known, but the type of the host key is not.
144+
// Adding all supported types for keys with certificates.
145+
for (final KeyType candidate : KeyType.values()) {
146+
if (candidate.getParent() != null) {
147+
knownHostAlgorithms.add(candidate.toString());
148+
}
149+
}
150+
}
151+
else {
152+
knownHostAlgorithms.add(type.toString());
153+
}
142154
}
143155
} catch (IOException ioe) {
144156
}

0 commit comments

Comments
 (0)