From 3349f11f30ad4cc5ed74e0fc67901838bd2e4e3a Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Fri, 12 Apr 2013 23:13:55 -0700 Subject: Partial support for importing EC keys --- src/org/connectbot/bean/PubkeyBean.java | 7 +++++++ src/org/connectbot/util/PubkeyUtils.java | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+) (limited to 'src/org') diff --git a/src/org/connectbot/bean/PubkeyBean.java b/src/org/connectbot/bean/PubkeyBean.java index d7213f0..272793a 100644 --- a/src/org/connectbot/bean/PubkeyBean.java +++ b/src/org/connectbot/bean/PubkeyBean.java @@ -44,6 +44,8 @@ public class PubkeyBean extends AbstractBean { private static final String KEY_TYPE_DSA = "DSA"; + private static final String KEY_TYPE_EC = "EC"; + /* Database fields */ private long id; private String nickname; @@ -125,6 +127,11 @@ public class PubkeyBean extends AbstractBean { publicKey = decodePublicKeyAs(pubKeySpec, KEY_TYPE_DSA); if (publicKey != null) { type = KEY_TYPE_DSA; + } else { + publicKey = decodePublicKeyAs(pubKeySpec, KEY_TYPE_EC); + if (publicKey != null) { + type = KEY_TYPE_EC; + } } } } diff --git a/src/org/connectbot/util/PubkeyUtils.java b/src/org/connectbot/util/PubkeyUtils.java index b9e97ab..f3ea5ef 100644 --- a/src/org/connectbot/util/PubkeyUtils.java +++ b/src/org/connectbot/util/PubkeyUtils.java @@ -64,11 +64,14 @@ import org.keyczar.jce.EcCore; import android.util.Log; import com.trilead.ssh2.crypto.Base64; +import com.trilead.ssh2.crypto.SimpleDERReader; import com.trilead.ssh2.signature.DSASHA1Verify; import com.trilead.ssh2.signature.ECDSASHA2Verify; import com.trilead.ssh2.signature.RSASHA1Verify; public class PubkeyUtils { + private static final String TAG = "PubkeyUtils"; + public static final String PKCS8_START = "-----BEGIN PRIVATE KEY-----"; public static final String PKCS8_END = "-----END PRIVATE KEY-----"; @@ -170,6 +173,23 @@ public class PubkeyUtils { PrivateKey priv; PublicKey pub; KeyFactory kf; + + SimpleDERReader reader = new SimpleDERReader(encoded); + final String oid; + try { + if (!reader.readInt().equals(BigInteger.ZERO)) { + throw new InvalidKeySpecException("Not PKCS#8 encoded"); + } + + oid = reader.readOid(); + } catch (IOException e) { + Log.w(TAG, "Could not read OID"); + throw new InvalidKeySpecException(e); + } + + kf = KeyFactory.getInstance(oid); + Log.d(TAG, "here's the algo: " + kf.getAlgorithm()); + try { kf = KeyFactory.getInstance(PubkeyDatabase.KEY_TYPE_RSA); priv = kf.generatePrivate(privKeySpec); -- cgit v1.2.3