From 4271e2ed172a016e9455f0e43b628a744907ce63 Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Sun, 3 Feb 2013 19:00:31 -0800 Subject: Remove J2ME compatibility layer for keys Use JCE instead of the DIY crypto library that is in Trilead. This was apparently for J2ME devices. Well, I'm sorry, J2ME devices, you're dead to me. --- .../trilead/ssh2/auth/AuthenticationManager.java | 30 ++++++++++++---------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'lib/src/main/java/com/trilead/ssh2/auth') diff --git a/lib/src/main/java/com/trilead/ssh2/auth/AuthenticationManager.java b/lib/src/main/java/com/trilead/ssh2/auth/AuthenticationManager.java index 43c226a..e1e416e 100644 --- a/lib/src/main/java/com/trilead/ssh2/auth/AuthenticationManager.java +++ b/lib/src/main/java/com/trilead/ssh2/auth/AuthenticationManager.java @@ -2,7 +2,13 @@ package com.trilead.ssh2.auth; import java.io.IOException; +import java.security.KeyPair; +import java.security.PrivateKey; import java.security.SecureRandom; +import java.security.interfaces.DSAPrivateKey; +import java.security.interfaces.DSAPublicKey; +import java.security.interfaces.RSAPrivateKey; +import java.security.interfaces.RSAPublicKey; import java.util.Vector; import com.trilead.ssh2.InteractiveCallback; @@ -19,12 +25,8 @@ import com.trilead.ssh2.packets.PacketUserauthRequestPassword; import com.trilead.ssh2.packets.PacketUserauthRequestPublicKey; import com.trilead.ssh2.packets.Packets; import com.trilead.ssh2.packets.TypesWriter; -import com.trilead.ssh2.signature.DSAPrivateKey; import com.trilead.ssh2.signature.DSASHA1Verify; -import com.trilead.ssh2.signature.DSASignature; -import com.trilead.ssh2.signature.RSAPrivateKey; import com.trilead.ssh2.signature.RSASHA1Verify; -import com.trilead.ssh2.signature.RSASignature; import com.trilead.ssh2.transport.MessageHandler; import com.trilead.ssh2.transport.TransportManager; @@ -161,14 +163,16 @@ public class AuthenticationManager implements MessageHandler public boolean authenticatePublicKey(String user, char[] PEMPrivateKey, String password, SecureRandom rnd) throws IOException { - Object key = PEMDecoder.decode(PEMPrivateKey, password); - - return authenticatePublicKey(user, key, rnd); + KeyPair pair = PEMDecoder.decode(PEMPrivateKey, password); + + return authenticatePublicKey(user, pair, rnd); } - - public boolean authenticatePublicKey(String user, Object key, SecureRandom rnd) + + public boolean authenticatePublicKey(String user, KeyPair pair, SecureRandom rnd) throws IOException { + PrivateKey key = pair.getPrivate(); + try { initialize(user); @@ -180,7 +184,7 @@ public class AuthenticationManager implements MessageHandler { DSAPrivateKey pk = (DSAPrivateKey) key; - byte[] pk_enc = DSASHA1Verify.encodeSSHDSAPublicKey(pk.getPublicKey()); + byte[] pk_enc = DSASHA1Verify.encodeSSHDSAPublicKey((DSAPublicKey) pair.getPublic()); TypesWriter tw = new TypesWriter(); @@ -197,7 +201,7 @@ public class AuthenticationManager implements MessageHandler byte[] msg = tw.getBytes(); - DSASignature ds = DSASHA1Verify.generateSignature(msg, pk, rnd); + byte[] ds = DSASHA1Verify.generateSignature(msg, pk, rnd); byte[] ds_enc = DSASHA1Verify.encodeSSHDSASignature(ds); @@ -209,7 +213,7 @@ public class AuthenticationManager implements MessageHandler { RSAPrivateKey pk = (RSAPrivateKey) key; - byte[] pk_enc = RSASHA1Verify.encodeSSHRSAPublicKey(pk.getPublicKey()); + byte[] pk_enc = RSASHA1Verify.encodeSSHRSAPublicKey((RSAPublicKey) pair.getPublic()); TypesWriter tw = new TypesWriter(); { @@ -227,7 +231,7 @@ public class AuthenticationManager implements MessageHandler byte[] msg = tw.getBytes(); - RSASignature ds = RSASHA1Verify.generateSignature(msg, pk); + byte[] ds = RSASHA1Verify.generateSignature(msg, pk); byte[] rsa_sig_enc = RSASHA1Verify.encodeSSHRSASignature(ds); -- cgit v1.2.3