Skip to content

Commit

Permalink
Merge branch 'master' into ssh-with-connected-socket
Browse files Browse the repository at this point in the history
  • Loading branch information
martin-volf committed Jan 29, 2024
2 parents fa5b5ce + 03f8b22 commit 09ca364
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,8 @@ public KnownHostEntry parseEntry(String line)
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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@

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;

Expand Down Expand Up @@ -110,6 +108,16 @@ public void shouldNotFailOnBadBase64Entry() throws Exception {
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(
Expand Down

0 comments on commit 09ca364

Please sign in to comment.