diff src/com/five_ten_sg/connectbot/service/AuthAgentService.java @ 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 91a31873c42a
children c1f929cb3dd0
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);