Skip to content

Commit

Permalink
Improving logging for KeyExchanger (#458)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andremoniy authored and hierynomus committed Oct 23, 2018
1 parent 17c368f commit 8134696
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import net.schmizz.sshj.common.Buffer;
import net.schmizz.sshj.common.SSHRuntimeException;
import net.schmizz.sshj.common.SecurityUtils;
import net.schmizz.sshj.transport.verification.HostKeyVerifier;

public class FingerprintVerifier implements HostKeyVerifier {
private static final Pattern MD5_FINGERPRINT_PATTERN = Pattern.compile("[0-9a-f]{2}+(:[0-9a-f]{2}+){15}+");
Expand Down Expand Up @@ -121,4 +120,8 @@ public boolean verify(String hostname, int port, PublicKey key) {
return Arrays.equals(fingerprintData, digestData);
}

@Override
public String toString() {
return "FingerprintVerifier{digestAlgorithm='" + digestAlgorithm + "'}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -440,4 +440,10 @@ public static Marker fromString(String str) {
return null;
}
}

@Override
public String toString() {
return "OpenSSHKnownHosts{khFile='" + khFile + "'}";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ host1 ecdsa-sha2-nistp256 AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBL
h << ["schmizz.net", "69.163.155.180"]
}

def "should produce meaningful toString()"() {
given:
def f = knownHosts("schmizz.net,69.163.155.180 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6P9Hlwdahh250jGZYKg2snRq2j2lFJVdKSHyxqbJiVy9VX9gTkN3K2MD48qyrYLYOyGs3vTttyUk+cK++JMzURWsrP4piby7LpeOT+3Iq8CQNj4gXZdcH9w15Vuk2qS11at6IsQPVHpKD9HGg9//EFUccI/4w06k4XXLm/IxOGUwj6I2AeWmEOL3aDi+fe07TTosSdLUD6INtR0cyKsg0zC7Da24ixoShT8Oy3x2MpR7CY3PQ1pUVmvPkr79VeA+4qV9F1JM09WdboAMZgWQZ+XrbtuBlGsyhpUHSCQOya+kOJ+bYryS+U7A+6nmTW3C9FX4FgFqTF89UHOC7V0zZQ==")

when:
def knownhosts = new OpenSSHKnownHosts(f)

def toStringValue = knownhosts.toString()
then:
toStringValue == "OpenSSHKnownHosts{khFile='" + f + "'}"
}

def knownHosts(String s) {
def f = temp.newFile("known_hosts")
f.write(s)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@ class FingerprintVerifierSpec extends Specification {

}

def "should produce meaningful toString()"() {
given:
def verifier = FingerprintVerifier.getInstance("SHA1:2Fo8c/96zv32xc8GZWbOGYOlRak")
when:
def toStringValue = verifier.toString()
then:
toStringValue == "FingerprintVerifier{digestAlgorithm='SHA-1'}"
}
def getPublicKey() {
def lines = new File("src/test/resources/keytypes/test_ed25519.pub").readLines()
Expand Down

0 comments on commit 8134696

Please sign in to comment.