diff options
author | Kenny Root <kenny@the-b.org> | 2013-04-12 00:13:42 -0700 |
---|---|---|
committer | Kenny Root <kenny@the-b.org> | 2013-04-12 00:33:11 -0700 |
commit | 1adfa1979549740665d0e6d845d7575ebad5faae (patch) | |
tree | 8d05c69145cbe584f161935513b696524f5891a1 /lib/src/main | |
parent | 3359a7f6d20f4d799140e304f646491863735028 (diff) | |
download | sshlib-1adfa1979549740665d0e6d845d7575ebad5faae.tar.gz sshlib-1adfa1979549740665d0e6d845d7575ebad5faae.tar.bz2 sshlib-1adfa1979549740665d0e6d845d7575ebad5faae.zip |
Add EC pubkey to UI
Diffstat (limited to 'lib/src/main')
-rw-r--r-- | lib/src/main/java/com/trilead/ssh2/auth/AuthenticationManager.java | 6 | ||||
-rw-r--r-- | lib/src/main/java/com/trilead/ssh2/signature/ECDSASHA2Verify.java | 37 |
2 files changed, 36 insertions, 7 deletions
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 7a1305b..e551495 100644 --- a/lib/src/main/java/com/trilead/ssh2/auth/AuthenticationManager.java +++ b/lib/src/main/java/com/trilead/ssh2/auth/AuthenticationManager.java @@ -246,6 +246,8 @@ public class AuthenticationManager implements MessageHandler else if (key instanceof ECPrivateKey) { ECPrivateKey pk = (ECPrivateKey) key; + final String algo = ECDSASHA2Verify.ECDSA_SHA2_PREFIX + + ECDSASHA2Verify.getCurveName(pk.getParams()); byte[] pk_enc = ECDSASHA2Verify.encodeSSHECDSAPublicKey((ECPublicKey) pair.getPublic()); @@ -259,7 +261,7 @@ public class AuthenticationManager implements MessageHandler tw.writeString("ssh-connection"); tw.writeString("publickey"); tw.writeBoolean(true); - tw.writeString("ecdsa-sha2-nistp256"); + tw.writeString(algo); tw.writeString(pk_enc, 0, pk_enc.length); } @@ -270,7 +272,7 @@ public class AuthenticationManager implements MessageHandler byte[] ec_sig_enc = ECDSASHA2Verify.encodeSSHECDSASignature(ds, pk.getParams()); PacketUserauthRequestPublicKey ua = new PacketUserauthRequestPublicKey("ssh-connection", user, - "ecdsa-sha2-nistp256", pk_enc, ec_sig_enc); + algo, pk_enc, ec_sig_enc); tm.sendMessage(ua.getPayload()); } diff --git a/lib/src/main/java/com/trilead/ssh2/signature/ECDSASHA2Verify.java b/lib/src/main/java/com/trilead/ssh2/signature/ECDSASHA2Verify.java index 4f3bae2..7b4f6af 100644 --- a/lib/src/main/java/com/trilead/ssh2/signature/ECDSASHA2Verify.java +++ b/lib/src/main/java/com/trilead/ssh2/signature/ECDSASHA2Verify.java @@ -55,6 +55,23 @@ public class ECDSASHA2Verify { CURVE_SIZES.put(521, NISTP521); } + public static int[] getCurveSizes() { + int[] keys = new int[CURVE_SIZES.size()]; + int i = 0; + for (Integer n : CURVE_SIZES.keySet().toArray(new Integer[keys.length])) { + keys[i++] = n; + } + return keys; + } + + public static ECParameterSpec getCurveForSize(int size) { + final String name = CURVE_SIZES.get(size); + if (name == null) { + return null; + } + return CURVES.get(name); + } + public static ECPublicKey decodeSSHECDSAPublicKey(byte[] key) throws IOException { TypesReader tr = new TypesReader(key); @@ -112,21 +129,30 @@ public class ECDSASHA2Verify { tw.writeString(curveName); - tw.writeBytes(encodeECPoint(key.getW(), key.getParams().getCurve())); + byte[] encoded = encodeECPoint(key.getW(), key.getParams().getCurve()); + tw.writeString(encoded, 0, encoded.length); return tw.getBytes(); } - private static String getCurveName(ECParameterSpec params) throws IOException { + public static String getCurveName(ECParameterSpec params) throws IOException { int fieldSize = getCurveSize(params); + final String curveName = getCurveName(fieldSize); + if (curveName == null) { + throw new IOException("invalid curve size " + fieldSize); + } + return curveName; + } + + public static String getCurveName(int fieldSize) { String curveName = CURVE_SIZES.get(fieldSize); if (curveName == null) { - throw new IOException("Unsupported curve field size: " + fieldSize); + return null; } return curveName; } - private static int getCurveSize(ECParameterSpec params) { + public static int getCurveSize(ECParameterSpec params) { return params.getCurve().getField().getFieldSize(); } @@ -258,7 +284,8 @@ public class ECDSASHA2Verify { TypesWriter rsWriter = new TypesWriter(); rsWriter.writeMPInt(r); rsWriter.writeMPInt(s); - tw.writeBytes(rsWriter.getBytes()); + byte[] encoded = rsWriter.getBytes(); + tw.writeString(encoded, 0, encoded.length); return tw.getBytes(); } |