From 9984dffd818905483b9e72b31543c01fc96dc04e Mon Sep 17 00:00:00 2001 From: eshizhan Date: Thu, 28 Mar 2024 23:44:36 +0800 Subject: [PATCH] support get new format fingerprint from HostKey --- src/main/java/com/jcraft/jsch/HostKey.java | 6 +++++- src/test/java/com/jcraft/jsch/KnownHostsTest.java | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/jcraft/jsch/HostKey.java b/src/main/java/com/jcraft/jsch/HostKey.java index 0f9922b6..de518202 100644 --- a/src/main/java/com/jcraft/jsch/HostKey.java +++ b/src/main/java/com/jcraft/jsch/HostKey.java @@ -118,6 +118,10 @@ public String getKey() { } public String getFingerPrint(JSch jsch) { + return getFingerPrint(jsch, false); + } + + public String getFingerPrint(JSch jsch, boolean isNewFormat) { HASH hash = null; try { String _c = JSch.getConfig("FingerprintHash").toLowerCase(Locale.ROOT); @@ -128,7 +132,7 @@ public String getFingerPrint(JSch jsch) { jsch.getInstanceLogger().log(Logger.ERROR, "getFingerPrint: " + e.getMessage(), e); } } - return Util.getFingerPrint(hash, key, false, true); + return Util.getFingerPrint(hash, key, isNewFormat, !isNewFormat); } public String getComment() { diff --git a/src/test/java/com/jcraft/jsch/KnownHostsTest.java b/src/test/java/com/jcraft/jsch/KnownHostsTest.java index c74df310..3f8bd0b5 100644 --- a/src/test/java/com/jcraft/jsch/KnownHostsTest.java +++ b/src/test/java/com/jcraft/jsch/KnownHostsTest.java @@ -1057,6 +1057,8 @@ private void checkResultForKeyResult(HostKey[] keys, String rsaKey, String expec assertEquals( "9d:38:5b:83:a9:17:52:92:56:1a:5e:c4:d4:81:8e:0a:ca:51:a2:64:f1:74:20:11:2e:f8:8a:c3:a1:39:49:8f", key.getFingerPrint(jsch), "fingerprint mismatch"); + assertEquals("SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8", + key.getFingerPrint(jsch, true), "fingerprint mismatch"); assertEquals(expectedHostResult, key.getHost(), "host mismatch"); assertEquals(rsaKey, key.getKey(), "key mismatch"); assertEquals(expectedMarker, key.getMarker(), "marker mismatch");