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 --- .../trilead/ssh2/auth/AuthenticationManager.java | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'sshlib/src/main/java/com/trilead/ssh2/auth') diff --git a/sshlib/src/main/java/com/trilead/ssh2/auth/AuthenticationManager.java b/sshlib/src/main/java/com/trilead/ssh2/auth/AuthenticationManager.java index e551495..dfafcbd 100644 --- a/sshlib/src/main/java/com/trilead/ssh2/auth/AuthenticationManager.java +++ b/sshlib/src/main/java/com/trilead/ssh2/auth/AuthenticationManager.java @@ -15,6 +15,8 @@ import java.util.Vector; import com.trilead.ssh2.InteractiveCallback; import com.trilead.ssh2.crypto.PEMDecoder; +import com.trilead.ssh2.crypto.key.Ed25519PrivateKey; +import com.trilead.ssh2.crypto.key.Ed25519PublicKey; import com.trilead.ssh2.packets.PacketServiceAccept; import com.trilead.ssh2.packets.PacketServiceRequest; import com.trilead.ssh2.packets.PacketUserauthBanner; @@ -29,6 +31,7 @@ import com.trilead.ssh2.packets.Packets; import com.trilead.ssh2.packets.TypesWriter; import com.trilead.ssh2.signature.DSASHA1Verify; import com.trilead.ssh2.signature.ECDSASHA2Verify; +import com.trilead.ssh2.signature.Ed25519Verify; import com.trilead.ssh2.signature.RSASHA1Verify; import com.trilead.ssh2.transport.MessageHandler; import com.trilead.ssh2.transport.TransportManager; @@ -276,6 +279,39 @@ public class AuthenticationManager implements MessageHandler tm.sendMessage(ua.getPayload()); } + else if (key instanceof Ed25519PrivateKey) + { + Ed25519PrivateKey pk = (Ed25519PrivateKey) key; + + final String algo = Ed25519Verify.ED25519_ID; + + byte[] pk_enc = Ed25519Verify.encodeSSHEd25519PublicKey((Ed25519PublicKey) pair.getPublic()); + + TypesWriter tw = new TypesWriter(); + { + byte[] H = tm.getSessionIdentifier(); + + tw.writeString(H, 0, H.length); + tw.writeByte(Packets.SSH_MSG_USERAUTH_REQUEST); + tw.writeString(user); + tw.writeString("ssh-connection"); + tw.writeString("publickey"); + tw.writeBoolean(true); + tw.writeString(algo); + tw.writeString(pk_enc, 0, pk_enc.length); + } + + byte[] msg = tw.getBytes(); + + byte[] ds = Ed25519Verify.generateSignature(msg, pk); + + byte[] ed_sig_enc = Ed25519Verify.encodeSSHEd25519Signature(ds); + + PacketUserauthRequestPublicKey ua = new PacketUserauthRequestPublicKey("ssh-connection", user, + algo, pk_enc, ed_sig_enc); + + tm.sendMessage(ua.getPayload()); + } else { throw new IOException("Unknown private key type returned by the PEM decoder."); -- cgit v1.2.3