From f8fffe5e29f55856b93b5e21f1a672bb1a0fec40 Mon Sep 17 00:00:00 2001 From: hsm Date: Sun, 29 May 2016 04:17:53 +0100 Subject: Add support for auth with open-keychain --- .../trilead/ssh2/auth/AuthenticationManager.java | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'sshlib/src/main/java/com/trilead/ssh2/auth/AuthenticationManager.java') 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 dfafcbd..117ed57 100644 --- a/sshlib/src/main/java/com/trilead/ssh2/auth/AuthenticationManager.java +++ b/sshlib/src/main/java/com/trilead/ssh2/auth/AuthenticationManager.java @@ -33,6 +33,8 @@ 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.signature.TokenRSAPrivateKey; +import com.trilead.ssh2.signature.TokenRSASHA1Verify; import com.trilead.ssh2.transport.MessageHandler; import com.trilead.ssh2.transport.TransportManager; @@ -246,6 +248,37 @@ public class AuthenticationManager implements MessageHandler tm.sendMessage(ua.getPayload()); } + else if (key instanceof TokenRSAPrivateKey) + { + TokenRSAPrivateKey pk = (TokenRSAPrivateKey) key; + + byte[] pk_enc = RSASHA1Verify.encodeSSHRSAPublicKey((RSAPublicKey) 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("ssh-rsa"); + tw.writeString(pk_enc, 0, pk_enc.length); + } + + byte[] msg = tw.getBytes(); + + byte[] ds = TokenRSASHA1Verify.generateSignature(msg, pk); + + byte[] rsa_sig_enc = RSASHA1Verify.encodeSSHRSASignature(ds); + + PacketUserauthRequestPublicKey ua = new PacketUserauthRequestPublicKey("ssh-connection", user, + "ssh-rsa", pk_enc, rsa_sig_enc); + + tm.sendMessage(ua.getPayload()); + } else if (key instanceof ECPrivateKey) { ECPrivateKey pk = (ECPrivateKey) key; -- cgit v1.2.3