changeset 296:8c55d7714d03 ganymed

start conversion from trilead to ganymed
author Carl Byington <carl@five-ten-sg.com>
date Tue, 29 Jul 2014 16:35:48 -0700
parents deb5fb087b6f
children c1f929cb3dd0
files src/com/five_ten_sg/connectbot/service/AuthAgentService.java src/com/five_ten_sg/connectbot/transport/SSH.java
diffstat 2 files changed, 23 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/com/five_ten_sg/connectbot/service/AuthAgentService.java	Fri Jul 18 20:48:40 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/service/AuthAgentService.java	Tue Jul 29 16:35:48 2014 -0700
@@ -90,6 +90,9 @@
             else if (privKey instanceof DSAPrivateKey) {
                 return sshEncodedSignatureFor(data, (DSAPrivateKey) privKey);
             }
+            else if (privKey instanceof ECPrivateKey) {
+                return sshEncodedSignatureFor(data, (ECPrivateKey) privKey);
+            }
 
             return null;
         }
@@ -136,6 +139,10 @@
                     DSAPublicKey pubkey = (DSAPublicKey)pair.getPublic();
                     return DSASHA1Verify.encodeSSHDSAPublicKey(pubkey);
                 }
+                else if (privKey instanceof ECPrivateKey) {
+                    ECPublicKey pubkey = (ECPublicKey) pair.getPublic();
+                    return ECDSASHA2Verify.encodeSSHECDSAPublicKey(pubkey);
+                }
             }
             catch (IOException e) {
                 Log.e(TAG, "Couldn't encode " + pair, e);
@@ -161,6 +168,15 @@
                 throw new RuntimeException(e);
             }
         }
+        private byte[] sshEncodedSignatureFor(byte[] data, ECPrivateKey privKey) {
+            try {
+                byte[] signature = ECDSASHA2Verify.generateSignature(data, privKey);
+                return ECDSASHA2Verify.encodeSSHECDSASignature(signature);
+            }
+            catch (IOException e) {
+                throw new RuntimeException(e);
+            }
+        }
         private KeyPair keyPairFor(byte[] publicKey) {
             String nickname = manager.getKeyNickname(publicKey);
 
--- a/src/com/five_ten_sg/connectbot/transport/SSH.java	Fri Jul 18 20:48:40 2014 -0700
+++ b/src/com/five_ten_sg/connectbot/transport/SSH.java	Tue Jul 29 16:35:48 2014 -0700
@@ -31,6 +31,8 @@
 import java.security.PublicKey;
 import java.security.interfaces.DSAPrivateKey;
 import java.security.interfaces.DSAPublicKey;
+import java.security.interfaces.ECPrivateKey;
+import java.security.interfaces.ECPublicKey;
 import java.security.interfaces.RSAPrivateKey;
 import java.security.interfaces.RSAPublicKey;
 import java.security.spec.InvalidKeySpecException;
@@ -75,6 +77,7 @@
 import ch.ethz.ssh2.HTTPProxyException;
 import ch.ethz.ssh2.crypto.PEMDecoder;
 import ch.ethz.ssh2.signature.DSASHA1Verify;
+import ch.ethz.ssh2.signature.ECDSASHA2Verify;
 import ch.ethz.ssh2.signature.RSASHA1Verify;
 
 /**
@@ -1062,6 +1065,10 @@
                     DSAPublicKey pubkey = (DSAPublicKey) pair.getPublic();
                     pubKeys.put(entry.getKey(), DSASHA1Verify.encodeSSHDSAPublicKey(pubkey));
                 }
+                else if (privKey instanceof ECPrivateKey) {
+                    ECPublicKey pubkey = (ECPublicKey) pair.getPublic();
+                    pubKeys.put(entry.getKey(), ECDSASHA2Verify.encodeSSHECDSAPublicKey(pubkey));
+                }
                 else
                     continue;
             }