From 1538c32d65152d1792e6d2404f2018c9db29ab19 Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Sat, 4 Apr 2015 17:17:58 -0700 Subject: Add Ed25519 host key support --- .../src/main/java/com/trilead/ssh2/KnownHosts.java | 25 +++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'sshlib/src/main/java/com/trilead/ssh2/KnownHosts.java') diff --git a/sshlib/src/main/java/com/trilead/ssh2/KnownHosts.java b/sshlib/src/main/java/com/trilead/ssh2/KnownHosts.java index 4e75de1..1a5f0a8 100644 --- a/sshlib/src/main/java/com/trilead/ssh2/KnownHosts.java +++ b/sshlib/src/main/java/com/trilead/ssh2/KnownHosts.java @@ -28,8 +28,10 @@ import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; import com.trilead.ssh2.crypto.Base64; +import com.trilead.ssh2.crypto.key.Ed25519PublicKey; import com.trilead.ssh2.signature.DSASHA1Verify; import com.trilead.ssh2.signature.ECDSASHA2Verify; +import com.trilead.ssh2.signature.Ed25519Verify; import com.trilead.ssh2.signature.RSASHA1Verify; @@ -121,12 +123,22 @@ public class KnownHosts { ECPublicKey epk = ECDSASHA2Verify.decodeSSHECDSAPublicKey(serverHostKey); - synchronized (publicKeys) { + synchronized (publicKeys) + { publicKeys.add(new KnownHostsEntry(hostnames, epk)); } } + else if (Ed25519Verify.ED25519_ID.equals(serverHostKeyAlgorithm)) + { + Ed25519PublicKey edpk = Ed25519Verify.decodeSSHEd25519PublicKey(serverHostKey); + + synchronized (publicKeys) + { + publicKeys.add(new KnownHostsEntry(hostnames, edpk)); + } + } else - throw new IOException("Unknwon host key type (" + serverHostKeyAlgorithm + ")"); + throw new IOException("Unknown host key type (" + serverHostKeyAlgorithm + ")"); } /** @@ -604,6 +616,10 @@ public class KnownHosts { remoteKey = ECDSASHA2Verify.decodeSSHECDSAPublicKey(serverHostKey); } + else if (Ed25519Verify.ED25519_ID.equals(serverHostKeyAlgorithm)) + { + remoteKey = Ed25519Verify.decodeSSHEd25519PublicKey(serverHostKey); + } else throw new IllegalArgumentException("Unknown hostkey type " + serverHostKeyAlgorithm); @@ -719,7 +735,10 @@ public class KnownHosts throw new IllegalArgumentException("Unknown hash type " + type); } - if (keyType.startsWith("ecdsa-sha2-")) + if (Ed25519Verify.ED25519_ID.equals(keyType)) + { + } + else if (keyType.startsWith("ecdsa-sha2-")) { } else if ("ssh-rsa".equals(keyType)) -- cgit v1.2.3