mirror of
https://github.com/hierynomus/sshj.git
synced 2025-12-06 07:10:53 +03:00
known_hosts parsing does not ignore malformed base64 strings since 0.36.0 (#922)
This commit is contained in:
@@ -292,8 +292,8 @@ public class OpenSSHKnownHosts
|
||||
try {
|
||||
byte[] keyBytes = Base64.getDecoder().decode(sKey);
|
||||
key = new Buffer.PlainBuffer(keyBytes).readPublicKey();
|
||||
} catch (IOException ioe) {
|
||||
log.warn("Error decoding Base64 key bytes", ioe);
|
||||
} catch (IOException | IllegalArgumentException exception) {
|
||||
log.warn("Error decoding Base64 key bytes", exception);
|
||||
return new BadHostEntry(line);
|
||||
}
|
||||
} else if (isBits(sType)) {
|
||||
|
||||
@@ -23,11 +23,9 @@ import static org.assertj.core.api.Assertions.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.module.ModuleDescriptor.Opens;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.security.PublicKey;
|
||||
import java.security.Security;
|
||||
import java.util.Base64;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@@ -110,6 +108,16 @@ public class OpenSSHKnownHostsTest {
|
||||
assertTrue(ohk.verify("host1", 22, k));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotFailOnMalformedBase64String() throws IOException {
|
||||
File knownHosts = knownHosts(
|
||||
"1.1.1.1 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBA/CkqWXSlbdo7jPshvIWT/m3FAdpSIKUx/uTmz87ObpBxXsfF8aMSiwGMKHjqviTV4cG6F7vFf28ll+9CbGsbs=192\n"
|
||||
);
|
||||
OpenSSHKnownHosts ohk = new OpenSSHKnownHosts(knownHosts);
|
||||
assertEquals(1, ohk.entries().size());
|
||||
assertThat(ohk.entries().get(0)).isInstanceOf(OpenSSHKnownHosts.BadHostEntry.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMarkBadLineAndNotFail() throws Exception {
|
||||
File knownHosts = knownHosts(
|
||||
|
||||
Reference in New Issue
Block a user